0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-11-27 15:06:34 +01:00
mongodb/jstests/sharding/banned_txn_databases_sharded.js
Pol Piñol Castuera 2a2f77ba58 SERVER-97258 Rename TODO server tickets to use a unique identifier SERVER-97257 (#29286)
GitOrigin-RevId: 97a00f943202e86c5cb04695c00f38e7726a7f19
2024-11-25 13:38:14 +00:00

61 lines
2.2 KiB
JavaScript

/**
* Tests that:
* 1. Read and writes to the config database are forbidden from mongos within single replica set
* transactions on sharded clusters.
* 2. Reads and writes to the config.transactions namespace are forbidden within single replica set
* transactions on sharded clusters, BUT read and writes to other namespaces in the config
* database are allowed.
*
* @tags: [
* uses_transactions,
* # TODO (SERVER-97257): Re-enable this test or add an explanation why it is incompatible.
* embedded_router_incompatible,
* ]
*/
import {ShardingTest} from "jstests/libs/shardingtest.js";
const st = new ShardingTest({shards: 1});
const mongosSession = st.s.startSession();
const shardSession = st.shard0.getDB("test").getMongo().startSession();
const collName = "banned_txn_dbs";
jsTestLog("Verify that read and write operations within transactions are forbidden for the " +
"config database when accessed through mongos.");
const mongosConfigDB = mongosSession.getDatabase("config");
const clusterColls = [
mongosConfigDB["test"],
mongosConfigDB["actionlog"],
mongosConfigDB["transaction_coords"],
mongosConfigDB["transactions"]
];
mongosSession.startTransaction();
clusterColls.forEach((coll) => {
const error = assert.throws(() => coll.find().itcount());
assert.commandFailedWithCode(error, ErrorCodes.OperationNotSupportedInTransaction);
});
mongosSession.endSession();
jsTestLog("Verify that read operations within transactions work fine for the config database " +
"when not config.transactions (and directly accessed through the shard).");
const configDB = shardSession.getDatabase("config");
const shardColls = [configDB["test"], configDB["actionlog"], configDB["transaction_coords"]];
shardSession.startTransaction();
shardColls.forEach((coll) => {
coll.find().itcount();
});
jsTestLog("Verify that read operations will not work for the config.transactions namespace.");
const shardCollTransactions = configDB["transactions"];
const error = assert.throws(() => shardCollTransactions.find().itcount());
assert.commandFailedWithCode(error, ErrorCodes.OperationNotSupportedInTransaction);
shardSession.endSession();
st.stop();