-
Notifications
You must be signed in to change notification settings - Fork 48
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
20
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.
Open
Changes from 17 commits
Commits
Show all changes
20 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 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,255 @@ | ||
| 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_multi_exec_queue(self): | ||
| self.client.execute_command("ft._debug PAUSEPOINT SET block_mutation_queue") | ||
| self.client.execute_command("CONFIG SET search.info-developer-visible yes") | ||
| index.create(self.client, True) | ||
| records = make_data() | ||
| # | ||
| # Now, load the data as a multi/exec... But this won't block us. | ||
| # | ||
| self.client.execute_command("MULTI") | ||
| for i in range(len(records)): | ||
| index.write_data(self.client, i, records[i]) | ||
| self.client.execute_command("EXEC") | ||
|
|
||
| self.client.execute_command("save") | ||
|
|
||
| i = self.client.info("search") | ||
| assert i["search_rdb_save_multi_exec_entries"] == len(records) | ||
|
|
||
| self.client.execute_command("ft._debug pausepoint reset block_mutation_queue") | ||
|
|
||
| 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_multi_exec_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.