-
Notifications
You must be signed in to change notification settings - Fork 7
PCSM-249. Data mismatch after movePrimary command #163
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
sandraromanchenko
wants to merge
1
commit into
main
Choose a base branch
from
PCSM-249
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 all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| # pylint: disable=missing-docstring,redefined-outer-name | ||
| import pytest | ||
| from pymongo.errors import OperationFailure | ||
| from pcsm import Runner | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("phase", [Runner.Phase.APPLY]) | ||
| def test_move_primary(t, phase: Runner.Phase): | ||
sandraromanchenko marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| """ | ||
| Test to verify movePrimary command | ||
| """ | ||
| db_name = "move_primary_test_db" | ||
| coll_name = "test_coll" | ||
| t.source.admin.command("enableSharding", db_name) | ||
| collection = t.source[db_name][coll_name] | ||
| collection.insert_many([{"_id": i} for i in range(10)]) | ||
| config_db = t.source.get_database("config") | ||
| shards = list(config_db.shards.find()) | ||
sandraromanchenko marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| shard_names = [shard["_id"] for shard in shards] | ||
| db_info = config_db.databases.find_one({"_id": db_name}) | ||
| current_primary = db_info.get("primary") | ||
| target_shard = next((s for s in shard_names if s != current_primary), None) | ||
sandraromanchenko marked this conversation as resolved.
Show resolved
Hide resolved
sandraromanchenko marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| with t.run(phase): | ||
| try: | ||
| t.source.admin.command("movePrimary", db_name, to=target_shard) | ||
| except OperationFailure as e: | ||
| if "movePrimary" in str(e) or "not supported" in str(e).lower() or "command not found" in str(e).lower(): | ||
| pytest.skip(f"movePrimary not supported: {e}") | ||
| raise | ||
| db_info_after = config_db.databases.find_one({"_id": db_name}) | ||
| assert db_info_after is not None, f"Database {db_name} not found after movePrimary" | ||
| assert db_info_after.get("primary") == target_shard, f"Primary shard should be {target_shard}, got {db_info_after.get('primary')}" | ||
| t.compare_all() | ||
sandraromanchenko marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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.