-
Notifications
You must be signed in to change notification settings - Fork 51
Revise Save/Restore for true pit snapshot. #401
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
allenss-amazon
wants to merge
46
commits into
valkey-io:main
Choose a base branch
from
allenss-amazon:saverestore
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,089
−258
Open
Changes from 16 commits
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
c23b19e
Initial wiring
allenss-amazon ab61e93
formating
allenss-amazon 0116204
Code complete
allenss-amazon 230682e
Finished testing
allenss-amazon d52dcaa
add missing file
allenss-amazon 6344430
Revert
allenss-amazon 9c0d6f6
Cleanup
allenss-amazon 667d77e
fix spelling
allenss-amazon c7bd274
fix bad merge
allenss-amazon 233c675
bad merge
allenss-amazon 047f043
experiment
allenss-amazon 923c3d4
Cleanup
allenss-amazon e4ac641
Revised
allenss-amazon d535c91
hopefully fix valkey server version
allenss-amazon 386686c
Merge branch 'main' into saverestore
allenss-amazon 9b8ee70
Merge branch 'main' into saverestore
allenss-amazon df9cd25
Revise per review. Add save/restore of multi/exec
allenss-amazon c0f27dd
Fix validation of vector-only indexes. Add test cases for same.
allenss-amazon 058e7d8
review comments update
allenss-amazon 38189b6
Fix review issue
allenss-amazon 3966629
Merge branch 'main' into saverestore
allenss-amazon 8374c6e
Fixup merge errors
allenss-amazon 2857cac
Stop writer threads during restore
allenss-amazon 0113af0
prevent run-away test runtimes
allenss-amazon 71fc6ac
Merge branch 'main' into saverestore
allenss-amazon dab6546
hack the timeouts
allenss-amazon 4173b85
Revert "hack the timeouts"
allenss-amazon a7a659c
limit pytest to 30 minutes
allenss-amazon 7d985ae
limit pytest to 30 minutes
allenss-amazon 5d60325
formatting
allenss-amazon 1e92d43
rejigger timeouts
allenss-amazon c887927
more debugging
allenss-amazon f0466e8
more debug
allenss-amazon 13e6583
more test output
allenss-amazon 9426112
more debugging output
allenss-amazon 9fb131d
more debugging
allenss-amazon a0dc8fe
Merge branch 'main' into saverestore
allenss-amazon 3c03a5c
fix test_CMD, disable stability test
allenss-amazon 4468376
debug on multi/exec
allenss-amazon 642e2dc
fix
allenss-amazon 3912ad0
fix
allenss-amazon c35fa44
Implement drain on reload
allenss-amazon 9fbee29
Merge branch 'main' into saverestore
allenss-amazon 4f8edf2
Drain queue of non-backfill before reload
allenss-amazon d5c1d9a
Cleanup
allenss-amazon 796e27b
Fixup timeout
allenss-amazon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,223 @@ | ||
| import base64 | ||
| import os | ||
| import tempfile | ||
| import time | ||
| import subprocess | ||
| import shutil | ||
| import socket | ||
| from valkey import ResponseError, Valkey | ||
| from valkey_search_test_case import ValkeySearchTestCaseDebugMode, ValkeySearchTestCaseDebugMode | ||
| from valkeytestframework.conftest import resource_port_tracker | ||
| from indexes import * | ||
| import pytest | ||
| import logging | ||
| from util import waiters | ||
| import threading | ||
| from ft_info_parser import FTInfoParser | ||
|
|
||
| index = Index("index", [Vector("v", 3, type="HNSW", m=2, efc=1), Numeric("n"), Tag("t")]) | ||
| NUM_VECTORS = 10 | ||
|
|
||
| # Keys that are in all results | ||
| full_key_names = [index.keyname(i).encode() for i in range(NUM_VECTORS)] | ||
|
|
||
| def check_keys(received_keys, expected_keys): | ||
| received_set = set(received_keys) | ||
| expected_set = set(expected_keys) | ||
| print("Result.keys ", received_set) | ||
| print("expected.keys", expected_set) | ||
| assert received_set == expected_set | ||
|
|
||
| def do_search(client: Valkey.client, query: str, extra: list[str] = []) -> dict[str, dict[str, str]]: | ||
| cmd = ["ft.search index", query, "limit", "0", "100"] + extra | ||
| print("Cmd: ", cmd) | ||
| res = client.execute_command(*cmd)[1:] | ||
| result = dict() | ||
| for i in range(0, len(res), 2): | ||
| row = res[i+1] | ||
| row_dict = dict() | ||
| for j in range(0, len(row), 2): | ||
| row_dict[row[j]] = row[j+1] | ||
| result[res[i]] = row_dict | ||
| print("Result is ", result) | ||
| return result | ||
|
|
||
| def make_data(): | ||
| records = [] | ||
| for i in range(0, NUM_VECTORS): | ||
| records += [index.make_data(i)] | ||
|
|
||
| data = index.make_data(len(records)) | ||
| data["v"] = "0" | ||
| records += [data] | ||
|
|
||
| data = index.make_data(len(records)) | ||
| data["n"] = "fred" | ||
| records += [data] | ||
|
|
||
| data = index.make_data(len(records)) | ||
| data["t"] = "" | ||
| records += [data] | ||
| return records | ||
|
|
||
| def load_data(client: Valkey.client): | ||
| records = make_data() | ||
| for i in range(0, len(records)): | ||
| index.write_data(client, i, records[i]) | ||
| return len(records) | ||
|
|
||
| def verify_data(client: Valkey.client): | ||
| ''' | ||
| Do query operations against each index to ensure that all keys are present | ||
| ''' | ||
|
|
||
| res = do_search(client, "@n:[0 100]") | ||
| check_keys(res.keys(), full_key_names + [index.keyname(NUM_VECTORS+0).encode(), index.keyname(NUM_VECTORS+2).encode()]) | ||
| res = do_search(client, "@t:{Tag*}") | ||
| check_keys(res.keys(), full_key_names + [index.keyname(NUM_VECTORS+0).encode(), index.keyname(NUM_VECTORS+1).encode()]) | ||
|
|
||
| def do_save_restore_test(test, write_v2: bool, read_v2: bool): | ||
| index.create(test.client, True) | ||
| key_count = load_data(test.client) | ||
| verify_data(test.client) | ||
| test.client.config_set("search.rdb-validate-on-write", "yes") | ||
| test.client.execute_command("save") | ||
| os.environ["SKIPLOGCLEAN"] = "1" | ||
| test.client.execute_command("CONFIG SET search.info-developer-visible yes") | ||
| i = test.client.info("search") | ||
| print("Info after save: ", i) | ||
| writes = [ | ||
| i["search_rdb_save_sections"], | ||
| i["search_rdb_save_keys"], | ||
| i["search_rdb_save_mutation_entries"], | ||
| ] | ||
| if write_v2: | ||
| assert writes == [5, key_count, 0] | ||
| else: | ||
| assert writes == [4, 0, 0] | ||
| test.server.restart(remove_rdb=False) | ||
| time.sleep(5) | ||
| print(test.client.ping()) | ||
| verify_data(test.client) | ||
| test.client.execute_command("CONFIG SET search.info-developer-visible yes") | ||
|
|
||
| i = test.client.info("search") | ||
| print("Info after load: ", i) | ||
| reads = [ | ||
| i["search_rdb_load_sections"], | ||
| i["search_rdb_load_sections_skipped"], | ||
| i["search_rdb_load_keys"], | ||
| i["search_rdb_load_mutation_entries"], | ||
| ] | ||
| if not write_v2: | ||
| assert reads == [4, 0, 0, 0] | ||
| elif read_v2: | ||
| assert reads == [5, 0, key_count, 0] | ||
| else: | ||
| assert reads == [5, 1, 0, 0] | ||
|
|
||
|
|
||
| class TestSaveRestore_v1_v1(ValkeySearchTestCaseDebugMode): | ||
| def append_startup_args(self, args): | ||
| args["search.rdb_write_v2"] = "no" | ||
| args["search.rdb_read_v2"] = "no" | ||
| return args | ||
|
|
||
| def test_saverestore_v1_v1(self): | ||
| do_save_restore_test(self, False, False) | ||
|
|
||
| class TestSaveRestore_v1_v2(ValkeySearchTestCaseDebugMode): | ||
| def append_startup_args(self, args): | ||
| args["search.rdb_write_v2"] = "no" | ||
| args["search.rdb_read_v2"] = "yes" | ||
| return args | ||
|
|
||
| def test_saverestore_v1_v2(self): | ||
| do_save_restore_test(self, False, True) | ||
|
|
||
| class TestSaveRestore_v2_v1(ValkeySearchTestCaseDebugMode): | ||
| def append_startup_args(self, args): | ||
| args["search.rdb_write_v2"] = "yes" | ||
| args["search.rdb_read_v2"] = "no" | ||
| return args | ||
|
|
||
| def test_saverestore_v2_v1(self): | ||
| do_save_restore_test(self, True, False) | ||
|
|
||
| class TestSaveRestore_v2_v2(ValkeySearchTestCaseDebugMode): | ||
| def append_startup_args(self, args): | ||
| args["search.rdb_write_v2"] = "yes" | ||
| args["search.rdb_read_v2"] = "yes" | ||
| return args | ||
|
|
||
| def test_saverestore_v2_v2(self): | ||
| do_save_restore_test(self, True, True) | ||
|
|
||
| class TestMutationQueue(ValkeySearchTestCaseDebugMode): | ||
| def append_startup_args(self, args): | ||
| args["search.rdb_write_v2"] = "yes" | ||
| args["search.rdb_read_v2"] = "yes" | ||
| return args | ||
|
|
||
| def mutation_queue_size(self): | ||
| info = FTInfoParser(self.client.execute_command("ft.info ", index.name)) | ||
| return info.mutation_queue_size | ||
|
|
||
| def test_mutation_queue(self): | ||
| self.client.execute_command("ft._debug PAUSEPOINT SET block_mutation_queue") | ||
| index.create(self.client, True) | ||
| records = make_data() | ||
| # | ||
| # Now, load the data.... But since the mutation queue is blocked it will be stopped.... | ||
| # | ||
| client_threads = [] | ||
| for i in range(len(records)): | ||
| new_client = self.server.get_new_client() | ||
| t = threading.Thread(target = index.write_data, args=(new_client, i, records[i]) ) | ||
| t.start() | ||
| client_threads += [t] | ||
|
|
||
| # | ||
| # Now, wait for the mutation queue to get fully loaded | ||
| # | ||
| waiters.wait_for_true(lambda: self.mutation_queue_size() == len(records)) | ||
| print("MUTATION QUEUE LOADED") | ||
|
|
||
| self.client.execute_command("save") | ||
|
|
||
| self.client.execute_command("ft._debug pausepoint reset block_mutation_queue") | ||
|
|
||
| for t in client_threads: | ||
| t.join() | ||
|
|
||
| verify_data(self.client) | ||
| os.environ["SKIPLOGCLEAN"] = "1" | ||
| self.server.restart(remove_rdb=False) | ||
| verify_data(self.client) | ||
| self.client.execute_command("CONFIG SET search.info-developer-visible yes") | ||
| i = self.client.info("search") | ||
| print("Info: ", i) | ||
| reads = [ | ||
| i["search_rdb_load_mutation_entries"], | ||
| ] | ||
| assert reads == [len(records)] | ||
|
|
||
| def test_saverestore_backfill(self): | ||
| # | ||
| # Delay the backfill and ensure that with new format we will trigger the backfill.... | ||
| # | ||
| self.client.execute_command("FT._DEBUG CONTROLLED_VARIABLE SET StopBackfill yes") | ||
| load_data(self.client) | ||
| index.create(self.client, False) | ||
| self.client.execute_command("save") | ||
|
|
||
| os.environ["SKIPLOGCLEAN"] = "1" | ||
| self.server.restart(remove_rdb=False) | ||
| verify_data(self.client) | ||
| self.client.execute_command("CONFIG SET search.info-developer-visible yes") | ||
| i = self.client.info("search") | ||
| print("Info: ", i) | ||
| reads = [ | ||
| i["search_backfill_hash_keys"], | ||
| ] | ||
| assert reads == [len(make_data())] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.