Files
mongo/jstests/sharding/flushRoutingTableCacheUpdates_enforced_on_collections.js
Zac 591928c619 SERVER-108478 JS formatted by prettier and remove clang-format (#39656)
GitOrigin-RevId: 6c8f6aded47f260aa4f7c231b17dae3302cb1e04
2025-08-21 17:27:09 +00:00

38 lines
1.3 KiB
JavaScript

// Ensure that a call to _flushRoutingTableCacheUpdates in a sharded cluster will return error if
// attempted on a database instead of a collection.
import {ShardingTest} from "jstests/libs/shardingtest.js";
let st = new ShardingTest({});
const testDBName = jsTestName();
const collName = "coll";
const testDB = st.s.getDB(testDBName);
assert.commandWorked(testDB.adminCommand({enableSharding: testDBName}));
assert.commandWorked(testDB.adminCommand({shardCollection: testDB[collName].getFullName(), key: {x: 1}}));
// On a collection, the command works
assert.commandWorked(st.shard0.adminCommand({_flushRoutingTableCacheUpdates: testDB[collName].getFullName()}));
// But on a database, the command fails with error "IllegalOperation"
assert.commandFailedWithCode(
st.shard0.adminCommand({_flushRoutingTableCacheUpdates: testDBName}),
ErrorCodes.IllegalOperation,
);
// Test also variant _flushRoutingTableCacheUpdatesWithWriteConcern
assert.commandWorked(
st.shard0.adminCommand({
_flushRoutingTableCacheUpdatesWithWriteConcern: testDB[collName].getFullName(),
writeConcern: {w: "majority"},
}),
);
assert.commandFailedWithCode(
st.shard0.adminCommand({
_flushRoutingTableCacheUpdatesWithWriteConcern: testDBName,
writeConcern: {w: "majority"},
}),
ErrorCodes.IllegalOperation,
);
st.stop();