void MoveChunkRequest::appendAsCommand(BSONObjBuilder* builder, const NamespaceString& nss, const ChunkVersion& shardVersion, const ConnectionString& configServerConnectionString, const ShardId& fromShardId, const ShardId& toShardId, const ChunkRange& range, int64_t maxChunkSizeBytes, const MigrationSecondaryThrottleOptions& secondaryThrottle, bool waitForDelete, bool takeDistLock) { invariant(builder->asTempObj().isEmpty()); invariant(nss.isValid()); builder->append(kMoveChunk, nss.ns()); shardVersion.appendForCommands(builder); builder->append(kConfigServerConnectionString, configServerConnectionString.toString()); builder->append(kFromShardId, fromShardId.toString()); builder->append(kToShardId, toShardId.toString()); range.append(builder); builder->append(kMaxChunkSizeBytes, static_cast<long long>(maxChunkSizeBytes)); secondaryThrottle.append(builder); builder->append(kWaitForDelete, waitForDelete); builder->append(kTakeDistLock, takeDistLock); }
void MoveChunkRequest::appendAsCommand(BSONObjBuilder* builder, const NamespaceString& nss, ChunkVersion chunkVersion, const ConnectionString& configServerConnectionString, const ShardId& fromShardId, const ShardId& toShardId, const ChunkRange& range, int64_t maxChunkSizeBytes, const MigrationSecondaryThrottleOptions& secondaryThrottle, bool waitForDelete) { invariant(builder->asTempObj().isEmpty()); invariant(nss.isValid()); builder->append(kMoveChunk, nss.ns()); chunkVersion.appendToCommand(builder); // 3.4 shard compatibility builder->append(kEpoch, chunkVersion.epoch()); // config connection string is included for 3.4 shard compatibility builder->append(kConfigServerConnectionString, configServerConnectionString.toString()); builder->append(kFromShardId, fromShardId.toString()); builder->append(kToShardId, toShardId.toString()); range.append(builder); builder->append(kMaxChunkSizeBytes, static_cast<long long>(maxChunkSizeBytes)); secondaryThrottle.append(builder); builder->append(kWaitForDelete, waitForDelete); builder->append(kTakeDistLock, false); }
void StartChunkCloneRequest::appendAsCommand( BSONObjBuilder* builder, const NamespaceString& nss, const MigrationSessionId& sessionId, const ConnectionString& configServerConnectionString, const ConnectionString& fromShardConnectionString, const ShardId& fromShardId, const ShardId& toShardId, const BSONObj& chunkMinKey, const BSONObj& chunkMaxKey, const BSONObj& shardKeyPattern, const MigrationSecondaryThrottleOptions& secondaryThrottle) { invariant(builder->asTempObj().isEmpty()); invariant(nss.isValid()); invariant(fromShardConnectionString.isValid()); builder->append(kRecvChunkStart, nss.ns()); sessionId.append(builder); builder->append(kConfigServerConnectionString, configServerConnectionString.toString()); builder->append(kFromShardConnectionString, fromShardConnectionString.toString()); builder->append(kFromShardId, fromShardId.toString()); builder->append(kToShardId, toShardId.toString()); builder->append(kChunkMinKey, chunkMinKey); builder->append(kChunkMaxKey, chunkMaxKey); builder->append(kShardKeyPattern, shardKeyPattern); secondaryThrottle.append(builder); }
StatusWith<WriteConcernOptions> ChunkMoveWriteConcernOptions::getEffectiveWriteConcern( OperationContext* opCtx, const MigrationSecondaryThrottleOptions& options) { auto secondaryThrottle = options.getSecondaryThrottle(); if (secondaryThrottle == MigrationSecondaryThrottleOptions::kDefault) { if (opCtx->getServiceContext()->getStorageEngine()->supportsDocLocking()) { secondaryThrottle = MigrationSecondaryThrottleOptions::kOff; } else { secondaryThrottle = MigrationSecondaryThrottleOptions::kOn; } } if (secondaryThrottle == MigrationSecondaryThrottleOptions::kOff) { return kWriteConcernLocal; } WriteConcernOptions writeConcern; if (options.isWriteConcernSpecified()) { writeConcern = options.getWriteConcern(); repl::ReplicationCoordinator* replCoordinator = repl::ReplicationCoordinator::get(opCtx); Status status = replCoordinator->checkIfWriteConcernCanBeSatisfied(writeConcern); if (!status.isOK() && status != ErrorCodes::NoReplicationEnabled) { return status; } } else { writeConcern = getDefaultWriteConcernForMigration(opCtx); } if (writeConcern.shouldWaitForOtherNodes() && writeConcern.wTimeout == WriteConcernOptions::kNoTimeout) { // Don't allow no timeout writeConcern.wTimeout = durationCount<Milliseconds>(kDefaultWriteTimeoutForMigration); } return writeConcern; }
StatusWith<WriteConcernOptions> ChunkMoveWriteConcernOptions::getEffectiveWriteConcern( const MigrationSecondaryThrottleOptions& options) { if (options.getSecondaryThrottle() == MigrationSecondaryThrottleOptions::kOff) { return kWriteConcernLocal; } WriteConcernOptions writeConcern; if (options.isWriteConcernSpecified()) { writeConcern = options.getWriteConcern(); repl::ReplicationCoordinator* replCoordinator = repl::getGlobalReplicationCoordinator(); if (replCoordinator->getReplicationMode() == repl::ReplicationCoordinator::modeMasterSlave && writeConcern.shouldWaitForOtherNodes()) { warning() << "moveChunk cannot check if secondary throttle setting " << writeConcern.toBSON() << " can be enforced in a master slave configuration"; } Status status = replCoordinator->checkIfWriteConcernCanBeSatisfied(writeConcern); if (!status.isOK() && status != ErrorCodes::NoReplicationEnabled) { return status; } } else { writeConcern = getDefaultWriteConcernForMigration(); } if (writeConcern.shouldWaitForOtherNodes() && writeConcern.wTimeout == WriteConcernOptions::kNoTimeout) { // Don't allow no timeout writeConcern.wTimeout = durationCount<Milliseconds>(kDefaultWriteTimeoutForMigration); } return writeConcern; }
BSONObj BalanceChunkRequest::serializeToMoveCommandForConfig( const ChunkType& chunk, const ShardId& newShardId, int64_t maxChunkSizeBytes, const MigrationSecondaryThrottleOptions& secondaryThrottle, bool waitForDelete) { invariantOK(chunk.validate()); BSONObjBuilder cmdBuilder; cmdBuilder.append(kConfigSvrMoveChunk, 1); cmdBuilder.appendElements(chunk.toBSON()); cmdBuilder.append(kToShardId, newShardId); cmdBuilder.append(kMaxChunkSizeBytes, static_cast<long long>(maxChunkSizeBytes)); { BSONObjBuilder secondaryThrottleBuilder(cmdBuilder.subobjStart(kSecondaryThrottle)); secondaryThrottle.append(&secondaryThrottleBuilder); secondaryThrottleBuilder.doneFast(); } cmdBuilder.append(kWaitForDelete, waitForDelete); return cmdBuilder.obj(); }