Skip to content

Commit

Permalink
PBM. Avoid dropping data in the middle of PITR for selective restore,…
Browse files Browse the repository at this point in the history
… detailed test for this case T281
  • Loading branch information
sandraromanchenko committed Dec 11, 2024
1 parent fbead63 commit 0e70af5
Showing 1 changed file with 6 additions and 25 deletions.
31 changes: 6 additions & 25 deletions pbm-functional/pytest/test_sharded.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ def test_logical_selective_PBM_T218(start_cluster, cluster):
backup_partial = cluster.make_backup("logical --ns=test1.test_coll11,test2.*")
cluster.enable_pitr(pitr_extra_args="--set pitr.oplogSpanMin=0.1")
time.sleep(5)
client.drop_database("test1")
for i in range(10):
client["test1"]["test_coll11"].insert_one({"key": i + 10, "data": i + 10})
client["test1"]["test_coll11"].create_index("data", name="test_coll11_index_new")
Expand All @@ -100,51 +99,33 @@ def test_logical_selective_PBM_T218(start_cluster, cluster):
)
cluster.make_restore(backup_partial, check_pbm_status=True)
assert client["test1"]["test_coll11"].count_documents({}) == 10

Check failure on line 101 in pbm-functional/pytest/test_sharded.py

View workflow job for this annotation

GitHub Actions / JUnit Test Report

test_sharded.test_logical_selective_PBM_T218

AssertionError: assert 20 == 10 + where 20 = count_documents({}) + where count_documents = Collection(Database(MongoClient(host=['mongos:27017'], document_class=dict, tz_aware=False, connect=True), 'test1'), 'test_coll11').count_documents
Raw output
start_cluster = True, cluster = <cluster.Cluster object at 0x7fe8676b4a10>

    @pytest.mark.timeout(300, func_only=True)
    def test_logical_selective_PBM_T218(start_cluster, cluster):
        cluster.check_pbm_status()
        client = pymongo.MongoClient(cluster.connection)
        client.admin.command("enableSharding", "test2")
        client.admin.command("shardCollection", "test2.test_coll21", key={"_id": "hashed"})
        for i in range(10):
            client["test1"]["test_coll11"].insert_one({"key": i, "data": i})
            client["test2"]["test_coll21"].insert_one({"key": i, "data": i})
            client["test2"]["test_coll22"].insert_one({"key": i, "data": i})
        client["test1"]["test_coll11"].create_index(["key"], name="test_coll11_index_old")
        client["test2"]["test_coll21"].create_index(["key"], name="test_coll21_index_old")
        backup_full = cluster.make_backup("logical")
        backup_partial = cluster.make_backup("logical --ns=test1.test_coll11,test2.*")
        cluster.enable_pitr(pitr_extra_args="--set pitr.oplogSpanMin=0.1")
        time.sleep(5)
        for i in range(10):
            client["test1"]["test_coll11"].insert_one({"key": i + 10, "data": i + 10})
        client["test1"]["test_coll11"].create_index("data", name="test_coll11_index_new")
        client["test2"]["test_coll22"].create_index("data", name="test_coll22_index_new")
        time.sleep(10)
        pitr = datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%S")
        pitr = " --time=" + pitr
        Cluster.log("Time for PITR is: " + pitr)
        cluster.disable_pitr()
        time.sleep(10)
        client.drop_database("test1")
        client.drop_database("test2")
        backup_partial = " --base-snapshot=" + backup_partial + pitr
        backup_full = (
            " --base-snapshot=" + backup_full + pitr + " --ns=test1.test_coll11,test2.*"
        )
        cluster.make_restore(backup_partial, check_pbm_status=True)
>       assert client["test1"]["test_coll11"].count_documents({}) == 10
E       AssertionError: assert 20 == 10
E        +  where 20 = count_documents({})
E        +    where count_documents = Collection(Database(MongoClient(host=['mongos:27017'], document_class=dict, tz_aware=False, connect=True), 'test1'), 'test_coll11').count_documents

test_sharded.py:101: AssertionError
assert (
client["test1"].command("collstats", "test_coll11").get("sharded", True)
is False
)
assert client["test1"].command("collstats", "test_coll11").get("sharded", True) is False
assert client["test2"]["test_coll21"].count_documents({}) == 10
assert client["test2"].command("collstats", "test_coll21").get("sharded", False)
assert client["test2"]["test_coll22"].count_documents({}) == 10
assert (
client["test2"].command("collstats", "test_coll22").get("sharded", True)
is False
)
assert client["test2"].command("collstats", "test_coll22").get("sharded", True) is False
for i in range(10):
assert client["test1"]["test_coll11"].find_one({"key": i + 10, "data": i + 10})
assert client["test2"]["test_coll21"].find_one({"key": i, "data": i})
assert client["test2"]["test_coll22"].find_one({"key": i, "data": i})
assert (
"test_coll11_index_old"
not in client["test1"]["test_coll11"].index_information()
)
assert "test_coll11_index_old" not in client["test1"]["test_coll11"].index_information()
assert "test_coll11_index_new" in client["test1"]["test_coll11"].index_information()
assert "test_coll21_index_old" in client["test2"]["test_coll21"].index_information()
assert "test_coll22_index_new" in client["test2"]["test_coll22"].index_information()
client.drop_database("test1")
client.drop_database("test2")
cluster.make_restore(backup_full, check_pbm_status=True)
assert client["test1"]["test_coll11"].count_documents({}) == 10
assert (
client["test1"].command("collstats", "test_coll11").get("sharded", True)
is False
)
assert client["test1"].command("collstats", "test_coll11").get("sharded", True) is False
assert client["test2"]["test_coll21"].count_documents({}) == 10
assert client["test2"].command("collstats", "test_coll21").get("sharded", False)
assert client["test2"]["test_coll22"].count_documents({}) == 10
assert (
client["test2"].command("collstats", "test_coll22").get("sharded", True)
is False
)
assert client["test2"].command("collstats", "test_coll22").get("sharded", True) is False
for i in range(10):
assert client["test1"]["test_coll11"].find_one({"key": i + 10, "data": i + 10})
assert client["test2"]["test_coll21"].find_one({"key": i, "data": i})
assert client["test2"]["test_coll22"].find_one({"key": i, "data": i})
assert (
"test_coll11_index_old"
not in client["test1"]["test_coll11"].index_information()
)
assert "test_coll11_index_old" not in client["test1"]["test_coll11"].index_information()
assert "test_coll11_index_new" in client["test1"]["test_coll11"].index_information()
assert "test_coll21_index_old" in client["test2"]["test_coll21"].index_information()
assert "test_coll22_index_new" in client["test2"]["test_coll22"].index_information()
Expand Down

0 comments on commit 0e70af5

Please sign in to comment.