本文整理汇总了C++中BatchedCommandRequest::isValidIndexRequest方法的典型用法代码示例。如果您正苦于以下问题:C++ BatchedCommandRequest::isValidIndexRequest方法的具体用法?C++ BatchedCommandRequest::isValidIndexRequest怎么用?C++ BatchedCommandRequest::isValidIndexRequest使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BatchedCommandRequest
的用法示例。
在下文中一共展示了BatchedCommandRequest::isValidIndexRequest方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: validateBatch
// static
Status WriteBatchExecutor::validateBatch( const BatchedCommandRequest& request ) {
// Validate namespace
const NamespaceString nss = NamespaceString( request.getNS() );
if ( !nss.isValid() ) {
return Status( ErrorCodes::InvalidNamespace,
nss.ns() + " is not a valid namespace" );
}
// Make sure we can write to the namespace
Status allowedStatus = userAllowedWriteNS( nss );
if ( !allowedStatus.isOK() ) {
return allowedStatus;
}
// Validate insert index requests
// TODO: Push insert index requests through createIndex once all upgrade paths support it
string errMsg;
if ( request.isInsertIndexRequest() && !request.isValidIndexRequest( &errMsg ) ) {
return Status( ErrorCodes::InvalidOptions, errMsg );
}
return Status::OK();
}
示例2: executeBatch
void WriteBatchExecutor::executeBatch( const BatchedCommandRequest& request,
BatchedCommandResponse* response ) {
// Validate namespace
const NamespaceString nss = NamespaceString( request.getNS() );
if ( !nss.isValid() ) {
toBatchError( Status( ErrorCodes::InvalidNamespace,
nss.ns() + " is not a valid namespace" ),
response );
return;
}
// Make sure we can write to the namespace
Status allowedStatus = userAllowedWriteNS( nss );
if ( !allowedStatus.isOK() ) {
toBatchError( allowedStatus, response );
return;
}
// Validate insert index requests
// TODO: Push insert index requests through createIndex once all upgrade paths support it
string errMsg;
if ( request.isInsertIndexRequest() && !request.isValidIndexRequest( &errMsg ) ) {
toBatchError( Status( ErrorCodes::InvalidOptions, errMsg ), response );
return;
}
// Validate write concern
// TODO: Lift write concern parsing out of this entirely
WriteConcernOptions writeConcern;
BSONObj wcDoc;
if ( request.isWriteConcernSet() ) {
wcDoc = request.getWriteConcern();
}
Status wcStatus = Status::OK();
if ( wcDoc.isEmpty() ) {
// The default write concern if empty is w : 1
// Specifying w : 0 is/was allowed, but is interpreted identically to w : 1
wcStatus = writeConcern.parse(
_defaultWriteConcern.isEmpty() ?
WriteConcernOptions::Acknowledged : _defaultWriteConcern );
if ( writeConcern.wNumNodes == 0 && writeConcern.wMode.empty() ) {
writeConcern.wNumNodes = 1;
}
}
else {
wcStatus = writeConcern.parse( wcDoc );
}
if ( wcStatus.isOK() ) {
wcStatus = validateWriteConcern( writeConcern );
}
if ( !wcStatus.isOK() ) {
toBatchError( wcStatus, response );
return;
}
if ( request.sizeWriteOps() == 0u ) {
toBatchError( Status( ErrorCodes::InvalidLength,
"no write ops were included in the batch" ),
response );
return;
}
// Validate batch size
if ( request.sizeWriteOps() > BatchedCommandRequest::kMaxWriteBatchSize ) {
toBatchError( Status( ErrorCodes::InvalidLength,
stream() << "exceeded maximum write batch size of "
<< BatchedCommandRequest::kMaxWriteBatchSize ),
response );
return;
}
//
// End validation
//
bool silentWC = writeConcern.wMode.empty() && writeConcern.wNumNodes == 0
&& writeConcern.syncMode == WriteConcernOptions::NONE;
Timer commandTimer;
OwnedPointerVector<WriteErrorDetail> writeErrorsOwned;
vector<WriteErrorDetail*>& writeErrors = writeErrorsOwned.mutableVector();
OwnedPointerVector<BatchedUpsertDetail> upsertedOwned;
vector<BatchedUpsertDetail*>& upserted = upsertedOwned.mutableVector();
//
// Apply each batch item, possibly bulking some items together in the write lock.
// Stops on error if batch is ordered.
//
bulkExecute( request, &upserted, &writeErrors );
//.........这里部分代码省略.........
示例3: write
void ClusterWriter::write( const BatchedCommandRequest& request,
BatchedCommandResponse* response ) {
const NamespaceString nss = NamespaceString( 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() > BatchedCommandRequest::kMaxWriteBatchSize ) {
toBatchError( Status( ErrorCodes::FailedToParse,
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
string dbName = nss.db().toString();
if ( dbName == "config" || dbName == "admin" ) {
bool verboseWC = request.isVerboseWC();
// We only support batch sizes of one for config writes
if ( request.sizeWriteOps() != 1 ) {
toBatchError( Status( ErrorCodes::InvalidOptions,
mongoutils::str::stream() << "Writes to config servers must "
"have batch size of 1, found "
<< request.sizeWriteOps() ),
response );
return;
}
// We only support {w: 0}, {w: 1}, and {w: 'majority'} write concern for config writes
if ( request.isWriteConcernSet() && !validConfigWC( request.getWriteConcern() )) {
toBatchError( Status( ErrorCodes::InvalidOptions,
mongoutils::str::stream() << "Invalid write concern for write"
" to config servers: " << request.getWriteConcern() ),
response );
return;
}
// We need to support "best-effort" writes for pings to the config server.
// {w:0} (!verbose) writes are interpreted as best-effort in this case - they may still
// error, but do not do the initial fsync check.
configWrite( request, response, verboseWC );
}
else {
shardWrite( request, response );
}
}