本文整理汇总了C++中WriteConcernOptions::validForConfigServers方法的典型用法代码示例。如果您正苦于以下问题:C++ WriteConcernOptions::validForConfigServers方法的具体用法?C++ WriteConcernOptions::validForConfigServers怎么用?C++ WriteConcernOptions::validForConfigServers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WriteConcernOptions
的用法示例。
在下文中一共展示了WriteConcernOptions::validForConfigServers方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: validateWriteConcern
Status validateWriteConcern(OperationContext* txn,
const WriteConcernOptions& writeConcern,
const std::string& dbName) {
const bool isJournalEnabled = getGlobalServiceContext()->getGlobalStorageEngine()->isDurable();
if (writeConcern.syncMode == WriteConcernOptions::SyncMode::JOURNAL && !isJournalEnabled) {
return Status(ErrorCodes::BadValue,
"cannot use 'j' option when a host does not have journaling enabled");
}
const bool isConfigServer = serverGlobalParams.clusterRole == ClusterRole::ConfigServer;
const bool isLocalDb(dbName == kLocalDB);
const repl::ReplicationCoordinator::Mode replMode =
repl::getGlobalReplicationCoordinator()->getReplicationMode();
if (isConfigServer) {
if (!writeConcern.validForConfigServers()) {
return Status(
ErrorCodes::BadValue,
str::stream()
<< "w:1 and w:'majority' are the only valid write concerns when writing to "
"config servers, got: "
<< writeConcern.toBSON().toString());
}
if (replMode == repl::ReplicationCoordinator::modeReplSet &&
// Allow writes performed within the server to have a write concern of { w: 1 }.
// This is so commands have the option to skip waiting for replication if they are
// holding locks (ex. addShardToZone). This also allows commands that perform
// multiple writes to batch the wait at the end.
!txn->getClient()->isInDirectClient() &&
!isLocalDb && writeConcern.wMode.empty()) {
invariant(writeConcern.wNumNodes == 1);
return Status(
ErrorCodes::BadValue,
str::stream()
<< "w: 'majority' is the only valid write concern when writing to config "
"server replica sets, got: "
<< writeConcern.toBSON().toString());
}
}
if (replMode == repl::ReplicationCoordinator::modeNone) {
if (writeConcern.wNumNodes > 1) {
return Status(ErrorCodes::BadValue, "cannot use 'w' > 1 when a host is not replicated");
}
}
if (replMode != repl::ReplicationCoordinator::modeReplSet && !writeConcern.wMode.empty() &&
writeConcern.wMode != WriteConcernOptions::kMajority) {
return Status(ErrorCodes::BadValue,
string("cannot use non-majority 'w' mode ") + writeConcern.wMode +
" when a host is not a member of a replica set");
}
return Status::OK();
}
示例2: validateWriteConcern
Status validateWriteConcern(const WriteConcernOptions& writeConcern, const std::string& dbName) {
const bool isJournalEnabled = getGlobalServiceContext()->getGlobalStorageEngine()->isDurable();
if (writeConcern.syncMode == WriteConcernOptions::JOURNAL && !isJournalEnabled) {
return Status(ErrorCodes::BadValue,
"cannot use 'j' option when a host does not have journaling enabled");
}
const bool isConfigServer = serverGlobalParams.configsvr;
const bool isLocalDb(dbName == kLocalDB);
const repl::ReplicationCoordinator::Mode replMode =
repl::getGlobalReplicationCoordinator()->getReplicationMode();
if (isConfigServer) {
if (!writeConcern.validForConfigServers()) {
return Status(
ErrorCodes::BadValue,
str::stream()
<< "w:1 and w:'majority' are the only valid write concerns when writing to "
"config servers, got: " << writeConcern.toBSON().toString());
}
if (serverGlobalParams.configsvrMode == CatalogManager::ConfigServerMode::CSRS &&
replMode == repl::ReplicationCoordinator::modeReplSet && !isLocalDb &&
writeConcern.wMode.empty()) {
invariant(writeConcern.wNumNodes == 1);
return Status(
ErrorCodes::BadValue,
str::stream()
<< "w: 'majority' is the only valid write concern when writing to config "
"server replica sets, got: " << writeConcern.toBSON().toString());
}
}
if (replMode == repl::ReplicationCoordinator::modeNone) {
if (writeConcern.wNumNodes > 1) {
return Status(ErrorCodes::BadValue, "cannot use 'w' > 1 when a host is not replicated");
}
}
if (replMode != repl::ReplicationCoordinator::modeReplSet && !writeConcern.wMode.empty() &&
writeConcern.wMode != WriteConcernOptions::kMajority) {
return Status(ErrorCodes::BadValue,
string("cannot use non-majority 'w' mode ") + writeConcern.wMode +
" when a host is not a member of a replica set");
}
return Status::OK();
}
示例3: validateWriteConcern
Status validateWriteConcern(OperationContext* txn,
const WriteConcernOptions& writeConcern,
StringData dbName) {
if (writeConcern.syncMode == WriteConcernOptions::SyncMode::JOURNAL &&
!txn->getServiceContext()->getGlobalStorageEngine()->isDurable()) {
return Status(ErrorCodes::BadValue,
"cannot use 'j' option when a host does not have journaling enabled");
}
// Remote callers of the config server (as in callers making network calls, not the internal
// logic) should never be making non-majority writes against the config server, because sharding
// is not resilient against rollbacks of metadata writes.
if (serverGlobalParams.clusterRole == ClusterRole::ConfigServer &&
dbName != NamespaceString::kLocalDb && !writeConcern.validForConfigServers()) {
// The only cases where we allow non-majority writes are from within the config servers
// themselves, because these wait for write concern explicitly.
if (!txn->getClient()->isInDirectClient()) {
return {ErrorCodes::BadValue,
str::stream() << "w:'majority' is the only valid write concern when writing "
"to config servers, got: "
<< writeConcern.toBSON()};
}
}
const auto replMode = repl::ReplicationCoordinator::get(txn)->getReplicationMode();
if (replMode == repl::ReplicationCoordinator::modeNone && writeConcern.wNumNodes > 1) {
return Status(ErrorCodes::BadValue, "cannot use 'w' > 1 when a host is not replicated");
}
if (replMode != repl::ReplicationCoordinator::modeReplSet && !writeConcern.wMode.empty() &&
writeConcern.wMode != WriteConcernOptions::kMajority) {
return Status(ErrorCodes::BadValue,
string("cannot use non-majority 'w' mode ") + writeConcern.wMode +
" when a host is not a member of a replica set");
}
return Status::OK();
}
示例4: write
void ClusterWriter::write(OperationContext* txn,
const BatchedCommandRequest& origRequest,
BatchedCommandResponse* response) {
// Add _ids to insert request if req'd
unique_ptr<BatchedCommandRequest> idRequest(BatchedCommandRequest::cloneWithIds(origRequest));
const BatchedCommandRequest* request = NULL != idRequest.get() ? idRequest.get() : &origRequest;
const NamespaceString& nss = request->getNS();
if (!nss.isValid()) {
toBatchError(Status(ErrorCodes::InvalidNamespace, nss.ns() + " is not a valid namespace"),
response);
return;
}
if (!NamespaceString::validCollectionName(nss.coll())) {
toBatchError(
Status(ErrorCodes::BadValue, str::stream() << "invalid collection name " << nss.coll()),
response);
return;
}
if (request->sizeWriteOps() == 0u) {
toBatchError(Status(ErrorCodes::InvalidLength, "no write ops were included in the batch"),
response);
return;
}
if (request->sizeWriteOps() > BatchedCommandRequest::kMaxWriteBatchSize) {
toBatchError(Status(ErrorCodes::InvalidLength,
str::stream() << "exceeded maximum write batch size of "
<< BatchedCommandRequest::kMaxWriteBatchSize),
response);
return;
}
string errMsg;
if (request->isInsertIndexRequest() && !request->isValidIndexRequest(&errMsg)) {
toBatchError(Status(ErrorCodes::InvalidOptions, errMsg), response);
return;
}
// Config writes and shard writes are done differently
const string dbName = nss.db().toString();
unique_ptr<BatchedCommandRequest> requestWithWriteConcern;
if (dbName == "config" || dbName == "admin") {
// w:majority is the only valid write concern for writes to the config servers.
// We also allow w:1 to come in on a user-initiated write, though we convert it here to
// w:majority before sending it to the config servers.
bool rewriteCmdWithWriteConcern = false;
WriteConcernOptions writeConcern;
if (request->isWriteConcernSet()) {
Status status = writeConcern.parse(request->getWriteConcern());
if (!status.isOK()) {
toBatchError(status, response);
return;
}
if (!writeConcern.validForConfigServers()) {
toBatchError(Status(ErrorCodes::InvalidOptions,
"Invalid replication write concern. Writes to config servers "
"must use w:'majority'"),
response);
return;
}
if (writeConcern.wMode == "") {
invariant(writeConcern.wNumNodes == 1);
rewriteCmdWithWriteConcern = true;
}
} else {
rewriteCmdWithWriteConcern = true;
}
if (rewriteCmdWithWriteConcern) {
requestWithWriteConcern.reset(new BatchedCommandRequest(request->getBatchType()));
request->cloneTo(requestWithWriteConcern.get());
writeConcern.wMode = WriteConcernOptions::kMajority;
writeConcern.wNumNodes = 0;
requestWithWriteConcern->setWriteConcern(writeConcern.toBSON());
request = requestWithWriteConcern.get();
}
grid.catalogClient(txn)->writeConfigServerDirect(txn, *request, response);
} else {
TargeterStats targeterStats;
{
ChunkManagerTargeter targeter(request->getTargetingNSS(), &targeterStats);
Status targetInitStatus = targeter.init(txn);
if (!targetInitStatus.isOK()) {
toBatchError(Status(targetInitStatus.code(),
str::stream()
<< "unable to target"
<< (request->isInsertIndexRequest() ? " index" : "")
<< " write op for collection "
<< request->getTargetingNS()
<< causedBy(targetInitStatus)),
response);
return;
}
//.........这里部分代码省略.........