|
| 1 | +/** |
| 2 | + * Tests that config.chunks and config.tags documents are correctly modified on FCV |
| 3 | + * upgrade/downgrade. |
| 4 | + */ |
| 5 | +(function() { |
| 6 | +"use strict"; |
| 7 | + |
| 8 | +load("jstests/libs/parallelTester.js"); // for Thread. |
| 9 | +load("jstests/multiVersion/libs/config_chunks_tags_shared.js"); |
| 10 | +load("jstests/sharding/libs/sharded_transactions_helpers.js"); |
| 11 | + |
| 12 | +// Assumes ns has the following chunk layout: [-inf, -50), [-50, 0) on shard0 and [0, inf) on |
| 13 | +// shard 1. |
| 14 | +function verifyChunkOperationsFailDuringSetFCV(st, ns) { |
| 15 | + assert.commandFailedWithCode(st.s.adminCommand({split: ns, middle: {_id: 50}}), |
| 16 | + ErrorCodes.ConflictingOperationInProgress); |
| 17 | + verifyChunkDistribution(st, ns, [2, 1]); |
| 18 | + |
| 19 | + assert.commandFailedWithCode( |
| 20 | + st.s.adminCommand({moveChunk: ns, find: {_id: 0}, to: st.shard0.shardName}), |
| 21 | + ErrorCodes.ConflictingOperationInProgress); |
| 22 | + verifyChunkDistribution(st, ns, [2, 1]); |
| 23 | + |
| 24 | + assert.commandFailedWithCode( |
| 25 | + st.s.adminCommand({mergeChunks: ns, bounds: [{_id: MinKey}, {_id: 0}]}), |
| 26 | + ErrorCodes.ConflictingOperationInProgress); |
| 27 | + verifyChunkDistribution(st, ns, [2, 1]); |
| 28 | +} |
| 29 | + |
| 30 | +// Assumes shard0 is in zone0 which contains [-inf, 0) and is not in zone1. |
| 31 | +function verifyZoneOperationsSucceedDuringSetFCV(st, ns) { |
| 32 | + assert.commandWorked( |
| 33 | + st.s.adminCommand({updateZoneKeyRange: ns, min: {_id: MinKey}, max: {_id: 0}, zone: null})); |
| 34 | + assert.commandWorked(st.s.adminCommand( |
| 35 | + {updateZoneKeyRange: ns, min: {_id: MinKey}, max: {_id: 0}, zone: "zone0"})); |
| 36 | + |
| 37 | + assert.commandWorked(st.s.adminCommand({addShardToZone: st.shard0.shardName, zone: "zone1"})); |
| 38 | + assert.commandWorked( |
| 39 | + st.s.adminCommand({removeShardFromZone: st.shard0.shardName, zone: "zone1"})); |
| 40 | +} |
| 41 | + |
| 42 | +const dbName = "test"; |
| 43 | +const chunkNs = dbName + ".chunk_coll"; |
| 44 | +const zoneNs = dbName + ".zone_coll"; |
| 45 | + |
| 46 | +const st = new ShardingTest({shards: 2}); |
| 47 | +const configPrimary = st.configRS.getPrimary(); |
| 48 | + |
| 49 | +assert.commandWorked(st.s.adminCommand({enableSharding: dbName})); |
| 50 | +st.ensurePrimaryShard(dbName, st.shard0.shardName); |
| 51 | + |
| 52 | +setUpCollectionForChunksTesting(st, chunkNs); |
| 53 | +setUpCollectionForZoneTesting(st, zoneNs); |
| 54 | + |
| 55 | +// |
| 56 | +// Verify chunk and tag documents are updated by setFeatureCompatibilityVersion. |
| 57 | +// |
| 58 | + |
| 59 | +checkFCV(configPrimary.getDB("admin"), latestFCV); |
| 60 | + |
| 61 | +verifyChunksAndTags(st, dbName, chunkNs, zoneNs, {expectNewFormat: true}); |
| 62 | + |
| 63 | +jsTestLog("Downgrading FCV to last stable"); |
| 64 | +assert.commandWorked(st.s.adminCommand({setFeatureCompatibilityVersion: lastStableFCV})); |
| 65 | +checkFCV(configPrimary.getDB("admin"), lastStableFCV); |
| 66 | + |
| 67 | +verifyChunksAndTags(st, dbName, chunkNs, zoneNs, {expectNewFormat: false}); |
| 68 | + |
| 69 | +jsTestLog("Upgrading FCV to latest"); |
| 70 | +assert.commandWorked(st.s.adminCommand({setFeatureCompatibilityVersion: latestFCV})); |
| 71 | +checkFCV(configPrimary.getDB("admin"), latestFCV); |
| 72 | + |
| 73 | +verifyChunksAndTags(st, dbName, chunkNs, zoneNs, {expectNewFormat: true}); |
| 74 | + |
| 75 | +// |
| 76 | +// Verify operations during setFeatureCompabitilityVersion use the correct format and that setFCV |
| 77 | +// blocks behind in-progress shard collections on shard servers. |
| 78 | +// |
| 79 | + |
| 80 | +function runInProgressSetFCVTest(st, {initialFCV, desiredFCV}) { |
| 81 | + const pauseInSetFCVFailPointName = desiredFCV === lastStableFCV |
| 82 | + ? "pauseBeforeDowngradingConfigMetadata" |
| 83 | + : "pauseBeforeUpgradingConfigMetadata"; |
| 84 | + |
| 85 | + clearRawMongoProgramOutput(); |
| 86 | + checkFCV(configPrimary.getDB("admin"), initialFCV); |
| 87 | + |
| 88 | + // Pause setFCV to test the in-progress states. |
| 89 | + assert.commandWorked(configPrimary.adminCommand( |
| 90 | + {configureFailPoint: pauseInSetFCVFailPointName, mode: "alwaysOn"})); |
| 91 | + |
| 92 | + // Start and pause a shard collection, and verify that the setFCV blocks behind it. |
| 93 | + const shardCollDuringSetFCV = new Thread((host, ns) => { |
| 94 | + const mongosConn = new Mongo(host); |
| 95 | + return mongosConn.adminCommand({shardCollection: ns, key: {_id: 1}}); |
| 96 | + }, st.s.host, dbName + ".setFCVTo" + desiredFCV); |
| 97 | + assert.commandWorked(st.rs0.getPrimary().adminCommand( |
| 98 | + {configureFailPoint: "pauseShardCollectionBeforeReturning", mode: "alwaysOn"})); |
| 99 | + shardCollDuringSetFCV.start(); |
| 100 | + waitForFailpoint("Hit pauseShardCollectionBeforeReturning", 1 /* numTimes */); |
| 101 | + |
| 102 | + // Assert setFCV can't hit the failpoint until the shard collection completes. |
| 103 | + const changeFCV = new Thread((host, fcv) => { |
| 104 | + const mongosConn = new Mongo(host); |
| 105 | + return mongosConn.adminCommand({setFeatureCompatibilityVersion: fcv}); |
| 106 | + }, st.s.host, desiredFCV); |
| 107 | + changeFCV.start(); |
| 108 | + assert.throws(() => { |
| 109 | + waitForFailpoint("Hit " + pauseInSetFCVFailPointName, 1 /* numTimes */, 3000 /* timeout */); |
| 110 | + }); |
| 111 | + |
| 112 | + // Unpause the shard collection and wait for setFCV to reach the failpoint. |
| 113 | + assert.commandWorked(st.rs0.getPrimary().adminCommand( |
| 114 | + {configureFailPoint: "pauseShardCollectionBeforeReturning", mode: "off"})); |
| 115 | + shardCollDuringSetFCV.join(); |
| 116 | + waitForFailpoint("Hit " + pauseInSetFCVFailPointName, 1 /* numTimes */); |
| 117 | + |
| 118 | + // Verify behavior while setFCV is in progress. |
| 119 | + verifyChunkOperationsFailDuringSetFCV(st, chunkNs); |
| 120 | + verifyZoneOperationsSucceedDuringSetFCV(st, zoneNs); |
| 121 | + testCRUDOperations(st, chunkNs); |
| 122 | + testCRUDOperations(st, zoneNs); |
| 123 | + |
| 124 | + // A collection can still be sharded during setFCV and should write chunks correctly. |
| 125 | + verifyInitialChunks( |
| 126 | + st, dbName + ".newCollDuringFCV" + desiredFCV, {expectNewFormat: desiredFCV === latestFCV}); |
| 127 | + |
| 128 | + // Unset the setFCV failpoint and allow setFCV to finish. |
| 129 | + assert.commandWorked( |
| 130 | + configPrimary.adminCommand({configureFailPoint: pauseInSetFCVFailPointName, mode: "off"})); |
| 131 | + changeFCV.join(); |
| 132 | + assert.commandWorked(changeFCV.returnData()); |
| 133 | + checkFCV(configPrimary.getDB("admin"), desiredFCV); |
| 134 | + |
| 135 | + verifyChunksAndTags(st, dbName, chunkNs, zoneNs, {expectNewFormat: desiredFCV === latestFCV}); |
| 136 | +} |
| 137 | + |
| 138 | +runInProgressSetFCVTest(st, {initialFCV: latestFCV, desiredFCV: lastStableFCV}); |
| 139 | +runInProgressSetFCVTest(st, {initialFCV: lastStableFCV, desiredFCV: latestFCV}); |
| 140 | + |
| 141 | +st.stop(); |
| 142 | +}()); |
0 commit comments