-
Notifications
You must be signed in to change notification settings - Fork 42
Fix external merge in python index module #437
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b341092
parse GetKeyviMergerBin to get args
hendrikmuhs f3879b4
fix deprecated call
hendrikmuhs 9778e5c
fix deprecation
hendrikmuhs 0586dcb
add test
hendrikmuhs 456a091
Merge branch 'master' into fix-external-merge
hendrikmuhs 60cc60e
Apply batched suggestions from code review
hendrikmuhs 23e0426
preco python changes
hendrikmuhs b747614
add missing utility header to merge_job.h
hendrikmuhs 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,126 @@ | ||
| # -*- coding: utf-8 -*- | ||
| # Usage: py.test tests | ||
|
|
||
| from keyvi.index import Index, ReadOnlyIndex | ||
| import os | ||
| import tempfile | ||
| import time | ||
|
|
||
|
|
||
| def test_external_merge(): | ||
| with tempfile.TemporaryDirectory() as test_dir: | ||
| index_dir = os.path.join(test_dir, "index") | ||
| index = Index(index_dir, {"segment_external_merge_key_threshold": "100"}) | ||
|
|
||
| for batch in range(10): | ||
| key_values = [] | ||
| for i in range(50): | ||
| key = "key-{:05d}".format(batch * 50 + i) | ||
| value = "value-{}".format(batch * 50 + i) | ||
| key_values.append((key, value)) | ||
| index.bulk_set(key_values) | ||
| index.flush() | ||
|
|
||
| # wait for external merge to complete | ||
| time.sleep(5) | ||
|
|
||
| # verify all keys are still accessible | ||
| for i in range(500): | ||
| key = "key-{:05d}".format(i) | ||
| assert key in index, "missing key: {}".format(key) | ||
| match = index[key] | ||
| assert match.value == "value-{}".format(i) | ||
|
|
||
|
|
||
| def test_external_merge_with_deletes(): | ||
| with tempfile.TemporaryDirectory() as test_dir: | ||
| index_dir = os.path.join(test_dir, "index") | ||
| index = Index(index_dir, {"segment_external_merge_key_threshold": "100"}) | ||
|
|
||
| for batch in range(10): | ||
| key_values = [] | ||
| for i in range(50): | ||
| key = "key-{:05d}".format(batch * 50 + i) | ||
| value = "value-{}".format(batch * 50 + i) | ||
| key_values.append((key, value)) | ||
| index.bulk_set(key_values) | ||
| index.flush() | ||
|
|
||
| # delete every other key | ||
| for i in range(0, 500, 2): | ||
| index.delete("key-{:05d}".format(i)) | ||
| index.flush() | ||
|
|
||
| # wait for external merge to complete | ||
| time.sleep(5) | ||
|
|
||
| for i in range(500): | ||
| key = "key-{:05d}".format(i) | ||
| if i % 2 == 0: | ||
| assert key not in index, "key should be deleted: {}".format(key) | ||
| else: | ||
| assert key in index, "missing key: {}".format(key) | ||
| match = index[key] | ||
| assert match.value == "value-{}".format(i) | ||
|
|
||
|
|
||
| def test_external_merge_with_overwrite(): | ||
| with tempfile.TemporaryDirectory() as test_dir: | ||
| index_dir = os.path.join(test_dir, "index") | ||
| index = Index(index_dir, {"segment_external_merge_key_threshold": "100"}) | ||
|
|
||
| # write initial data across multiple segments | ||
| for batch in range(5): | ||
| key_values = [] | ||
| for i in range(50): | ||
| key = "key-{:05d}".format(batch * 50 + i) | ||
| value = "value-v1-{}".format(batch * 50 + i) | ||
| key_values.append((key, value)) | ||
| index.bulk_set(key_values) | ||
| index.flush() | ||
|
|
||
| # overwrite some keys with new values in new segments | ||
| for batch in range(5): | ||
| key_values = [] | ||
| for i in range(50): | ||
| key = "key-{:05d}".format(batch * 50 + i) | ||
| value = "value-v2-{}".format(batch * 50 + i) | ||
| key_values.append((key, value)) | ||
| index.bulk_set(key_values) | ||
| index.flush() | ||
|
|
||
| # wait for external merge to complete | ||
| time.sleep(5) | ||
|
|
||
| # verify that the latest values are returned | ||
| for i in range(250): | ||
| key = "key-{:05d}".format(i) | ||
| assert key in index, "missing key: {}".format(key) | ||
| match = index[key] | ||
| assert match.value == "value-v2-{}".format(i), ( | ||
| "expected v2 value for {}, got {}".format(key, match.value) | ||
| ) | ||
|
|
||
|
|
||
| def test_external_merge_read_only_index(): | ||
| with tempfile.TemporaryDirectory() as test_dir: | ||
| index_dir = os.path.join(test_dir, "index") | ||
| index = Index(index_dir, {"segment_external_merge_key_threshold": "100"}) | ||
|
|
||
| for batch in range(10): | ||
| key_values = [] | ||
| for i in range(50): | ||
| key = "key-{:05d}".format(batch * 50 + i) | ||
| value = "value-{}".format(batch * 50 + i) | ||
| key_values.append((key, value)) | ||
| index.bulk_set(key_values) | ||
| index.flush() | ||
|
|
||
| # wait for external merge to complete | ||
| time.sleep(5) | ||
|
|
||
| # open a read-only index and verify all data | ||
| reader = ReadOnlyIndex(index_dir) | ||
| for i in range(500): | ||
| key = "key-{:05d}".format(i) | ||
| assert key in reader, "missing key in reader: {}".format(key) |
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.