本文整理汇总了C++中StatusWith类的典型用法代码示例。如果您正苦于以下问题:C++ StatusWith类的具体用法?C++ StatusWith怎么用?C++ StatusWith使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了StatusWith类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: NamespaceString
StatusWith<std::string> KVCatalog::newOrphanedIdent(OperationContext* opCtx, std::string ident) {
// The collection will be named local.orphan.xxxxx.
std::string identNs = ident;
std::replace(identNs.begin(), identNs.end(), '-', '_');
std::string ns = NamespaceString(NamespaceString::kOrphanCollectionDb,
NamespaceString::kOrphanCollectionPrefix + identNs)
.ns();
stdx::lock_guard<stdx::mutex> lk(_identsLock);
Entry& old = _idents[ns];
if (!old.ident.empty()) {
return Status(ErrorCodes::NamespaceExists,
str::stream() << ns << " already exists in the catalog");
}
opCtx->recoveryUnit()->registerChange(new AddIdentChange(this, ns));
// Generate a new UUID for the orphaned collection.
CollectionOptions optionsWithUUID;
optionsWithUUID.uuid.emplace(CollectionUUID::gen());
BSONObj obj;
{
BSONObjBuilder b;
b.append("ns", ns);
b.append("ident", ident);
BSONCollectionCatalogEntry::MetaData md;
md.ns = ns;
// Default options with newly generated UUID.
md.options = optionsWithUUID;
// Not Prefixed.
md.prefix = KVPrefix::kNotPrefixed;
b.append("md", md.toBSON());
obj = b.obj();
}
StatusWith<RecordId> res = _rs->insertRecord(opCtx, obj.objdata(), obj.objsize(), Timestamp());
if (!res.isOK())
return res.getStatus();
old = Entry(ident, res.getValue());
LOG(1) << "stored meta data for orphaned collection " << ns << " @ " << res.getValue();
return StatusWith<std::string>(std::move(ns));
}
示例2: invariant
Status KVCatalog::newCollection(OperationContext* opCtx,
StringData ns,
const CollectionOptions& options) {
invariant(opCtx->lockState() == NULL ||
opCtx->lockState()->isDbLockedForMode(nsToDatabaseSubstring(ns), MODE_X));
std::unique_ptr<Lock::ResourceLock> rLk;
if (!_isRsThreadSafe && opCtx->lockState()) {
rLk.reset(new Lock::ResourceLock(opCtx->lockState(), resourceIdCatalogMetadata, MODE_X));
}
const string ident = _newUniqueIdent(ns, "collection");
stdx::lock_guard<stdx::mutex> lk(_identsLock);
Entry& old = _idents[ns.toString()];
if (!old.ident.empty()) {
return Status(ErrorCodes::NamespaceExists, "collection already exists");
}
opCtx->recoveryUnit()->registerChange(new AddIdentChange(this, ns));
BSONObj obj;
{
BSONObjBuilder b;
b.append("ns", ns);
b.append("ident", ident);
BSONCollectionCatalogEntry::MetaData md;
md.ns = ns.toString();
md.options = options;
b.append("md", md.toBSON());
obj = b.obj();
}
StatusWith<RecordId> res = _rs->insertRecord(opCtx, obj.objdata(), obj.objsize(), false);
if (!res.isOK())
return res.getStatus();
old = Entry(ident, res.getValue());
LOG(1) << "stored meta data for " << ns << " @ " << res.getValue();
return Status::OK();
}
示例3: _handleHeartbeatResponseAction
void ReplicationCoordinatorImpl::_handleHeartbeatResponseAction(
const HeartbeatResponseAction& action,
const StatusWith<ReplSetHeartbeatResponse>& responseStatus) {
switch (action.getAction()) {
case HeartbeatResponseAction::NoAction:
// Update the cached member state if different than the current topology member state
if (_memberState != _topCoord->getMemberState()) {
stdx::unique_lock<stdx::mutex> lk(_mutex);
const PostMemberStateUpdateAction postUpdateAction =
_updateMemberStateFromTopologyCoordinator_inlock();
lk.unlock();
_performPostMemberStateUpdateAction(postUpdateAction);
}
break;
case HeartbeatResponseAction::Reconfig:
invariant(responseStatus.isOK());
_scheduleHeartbeatReconfig(responseStatus.getValue().getConfig());
break;
case HeartbeatResponseAction::StartElection:
if (isV1ElectionProtocol()) {
_startElectSelfV1();
} else {
_startElectSelf();
}
break;
case HeartbeatResponseAction::StepDownSelf:
invariant(action.getPrimaryConfigIndex() == _selfIndex);
log() << "Stepping down from primary in response to heartbeat";
_stepDownStart();
break;
case HeartbeatResponseAction::StepDownRemotePrimary: {
invariant(action.getPrimaryConfigIndex() != _selfIndex);
_requestRemotePrimaryStepdown(
_rsConfig.getMemberAt(action.getPrimaryConfigIndex()).getHostAndPort());
break;
}
default:
severe() << "Illegal heartbeat response action code " << int(action.getAction());
invariant(false);
}
}
示例4: TEST_F
TEST_F(WiredTigerRecoveryUnitTestFixture, CreateAndCheckForCachePressure) {
int time = 1;
// Reconfigure the size of the cache to be very small so that building cache pressure is fast.
WiredTigerKVEngine* engine = harnessHelper->getEngine();
std::string cacheSizeReconfig = "cache_size=1MB";
ASSERT_EQ(engine->reconfigure(cacheSizeReconfig.c_str()), 0);
OperationContext* opCtx = clientAndCtx1.second.get();
std::unique_ptr<RecordStore> rs(harnessHelper->createRecordStore(opCtx, "a.b"));
// Insert one document so that we can then update it in a loop to create cache pressure.
// Note: inserts will not create cache pressure.
WriteUnitOfWork wu(opCtx);
ASSERT_OK(ru1->setTimestamp(Timestamp(time++)));
std::string str = str::stream() << "foobarbaz";
StatusWith<RecordId> ress = rs->insertRecord(opCtx, str.c_str(), str.size() + 1, Timestamp());
ASSERT_OK(ress.getStatus());
auto recordId = ress.getValue();
wu.commit();
for (int j = 0; j < 1000; ++j) {
// Once we hit the cache pressure threshold, i.e. have successfully created cache pressure
// that is detectable, we are done.
if (engine->isCacheUnderPressure(opCtx)) {
invariant(j != 0);
break;
}
try {
WriteUnitOfWork wuow(opCtx);
ASSERT_OK(ru1->setTimestamp(Timestamp(time++)));
std::string s = str::stream()
<< "abcbcdcdedefefgfghghihijijkjklklmlmnmnomopopqpqrqrsrststutuv" << j;
ASSERT_OK(rs->updateRecord(opCtx, recordId, s.c_str(), s.size() + 1));
wuow.commit();
} catch (const DBException& ex) {
invariant(ex.toStatus().code() == ErrorCodes::WriteConflict);
}
}
}
示例5: init
Status MultiIndexBlock::init(std::vector<BSONObj>& indexSpecs) {
for ( size_t i = 0; i < indexSpecs.size(); i++ ) {
BSONObj info = indexSpecs[i];
string pluginName = IndexNames::findPluginName( info["key"].Obj() );
if ( pluginName.size() ) {
Status s =
_collection->getIndexCatalog()->_upgradeDatabaseMinorVersionIfNeeded(_txn, pluginName);
if ( !s.isOK() )
return s;
}
}
for ( size_t i = 0; i < indexSpecs.size(); i++ ) {
BSONObj info = indexSpecs[i];
StatusWith<BSONObj> statusWithInfo =
_collection->getIndexCatalog()->prepareSpecForCreate( info );
Status status = statusWithInfo.getStatus();
if ( !status.isOK() )
return status;
info = statusWithInfo.getValue();
IndexState state;
state.block = new IndexCatalog::IndexBuildBlock(_txn, _collection, info);
status = state.block->init();
if ( !status.isOK() )
return status;
state.real = state.block->getEntry()->accessMethod();
status = state.real->initializeAsEmpty(_txn);
if ( !status.isOK() )
return status;
state.bulk = state.real->initiateBulk(_txn);
_states.push_back( state );
}
return Status::OK();
}
示例6: recordFor
StatusWith<DiskLoc> RecordStoreV1Base::updateRecord( OperationContext* txn,
const DiskLoc& oldLocation,
const char* data,
int dataSize,
bool enforceQuota,
UpdateMoveNotifier* notifier ) {
Record* oldRecord = recordFor( oldLocation );
if ( oldRecord->netLength() >= dataSize ) {
// we fit
_paddingFits( txn );
memcpy( txn->recoveryUnit()->writingPtr( oldRecord->data(), dataSize ), data, dataSize );
return StatusWith<DiskLoc>( oldLocation );
}
if ( isCapped() )
return StatusWith<DiskLoc>( ErrorCodes::InternalError,
"failing update: objects in a capped ns cannot grow",
10003 );
// we have to move
_paddingTooSmall( txn );
StatusWith<DiskLoc> newLocation = _insertRecord( txn, data, dataSize, enforceQuota );
if ( !newLocation.isOK() )
return newLocation;
// insert worked, so we delete old record
if ( notifier ) {
Status moveStatus = notifier->recordStoreGoingToMove( txn,
oldLocation,
oldRecord->data(),
oldRecord->netLength() );
if ( !moveStatus.isOK() )
return StatusWith<DiskLoc>( moveStatus );
}
deleteRecord( txn, oldLocation );
return newLocation;
}
示例7: newSortedDataInterface
std::unique_ptr<SortedDataInterface> newSortedDataInterface(bool unique) final {
std::string ns = "test.wt";
OperationContextNoop txn(newRecoveryUnit().release());
BSONObj spec = BSON("key" << BSON("a" << 1) << "name"
<< "testIndex"
<< "ns" << ns);
IndexDescriptor desc(NULL, "", spec);
StatusWith<std::string> result =
TerichDbIndex::generateCreateString(kTerichDbEngineName, "", "", desc);
ASSERT_OK(result.getStatus());
string uri = "table:" + ns;
invariantTerichDbOK(TerichDbIndex::Create(&txn, uri, result.getValue()));
if (unique)
return stdx::make_unique<TerichDbIndexUnique>(&txn, uri, &desc);
return stdx::make_unique<TerichDbIndexStandard>(&txn, uri, &desc);
}
示例8: singleInsert
/**
* Perform a single insert into a collection. Requires the insert be preprocessed and the
* collection already has been created.
*
* Might fault or error, otherwise populates the result.
*/
static void singleInsert( OperationContext* txn,
const BSONObj& docToInsert,
Collection* collection,
WriteOpResult* result ) {
const string& insertNS = collection->ns().ns();
txn->lockState()->assertWriteLocked( insertNS );
WriteUnitOfWork wunit(txn);
StatusWith<DiskLoc> status = collection->insertDocument( txn, docToInsert, true );
if ( !status.isOK() ) {
result->setError(toWriteError(status.getStatus()));
}
else {
repl::logOp( txn, "i", insertNS.c_str(), docToInsert );
result->getStats().n = 1;
wunit.commit();
}
}
示例9: run
virtual bool run(const string& dbname, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool) {
string coll = cmdObj[ "godinsert" ].valuestrsafe();
log() << "test only command godinsert invoked coll:" << coll << endl;
uassert( 13049, "godinsert must specify a collection", !coll.empty() );
string ns = dbname + "." + coll;
BSONObj obj = cmdObj[ "obj" ].embeddedObjectUserCheck();
Lock::DBWrite lk(ns);
Client::Context ctx( ns );
Database* db = ctx.db();
Collection* collection = db->getCollection( ns );
if ( !collection ) {
collection = db->createCollection( ns );
if ( !collection ) {
errmsg = "could not create collection";
return false;
}
}
StatusWith<DiskLoc> res = collection->insertDocument( obj, false );
return appendCommandStatus( result, res.getStatus() );
}
示例10: recordStore
BtreeLogicTestHelper<OnDiskFormat>::BtreeLogicTestHelper(const BSONObj& order)
: recordStore("TestRecordStore"),
btree(&headManager,
&recordStore,
&cursorRegistry,
Ordering::make(order),
"TestIndex",
/*isUnique*/ false) {
static const string randomData("RandomStuff");
// Generate a valid record location for a "fake" record, which we will repeatedly use
// thoughout the tests.
OperationContextNoop opCtx;
StatusWith<RecordId> s =
recordStore.insertRecord(&opCtx, randomData.c_str(), randomData.length(), false);
ASSERT_TRUE(s.isOK());
ASSERT_EQUALS(1, recordStore.numRecords(NULL));
dummyDiskLoc = DiskLoc::fromRecordId(s.getValue());
}
示例11: TEST
TEST( RecordStoreTestHarness, Simple1InsertDocWroter ) {
scoped_ptr<HarnessHelper> harnessHelper( newHarnessHelper() );
scoped_ptr<RecordStore> rs( harnessHelper->newNonCappedRecordStore() );
DiskLoc loc1;
{
scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
{
WriteUnitOfWork uow( opCtx.get() );
DummyDocWriter dw;
StatusWith<DiskLoc> res = rs->insertRecord( opCtx.get(), &dw, false );
ASSERT_OK( res.getStatus() );
loc1 = res.getValue();
uow.commit();
}
ASSERT_EQUALS( string("eliot"), rs->dataFor( opCtx.get(), loc1 ).data() );
}
}
示例12: invariant
void ReplicationCoordinatorImpl::_startVoteRequester(long long newTerm) {
invariant(_voteRequester);
invariant(!_electionWinnerDeclarer);
LoseElectionGuardV1 lossGuard(this);
_voteRequester.reset(new VoteRequester);
StatusWith<ReplicationExecutor::EventHandle> nextPhaseEvh = _voteRequester->start(
&_replExecutor,
_rsConfig,
_rsConfig.getMemberAt(_selfIndex).getId(),
_topCoord->getTerm(),
false,
getMyLastOptime(),
stdx::bind(&ReplicationCoordinatorImpl::_onVoteRequestComplete, this, newTerm));
if (nextPhaseEvh.getStatus() == ErrorCodes::ShutdownInProgress) {
return;
}
fassert(28643, nextPhaseEvh.getStatus());
lossGuard.dismiss();
}
示例13: normalizeInserts
// Goes over the request and preprocesses normalized versions of all the inserts in the request
static void normalizeInserts( const BatchedCommandRequest& request,
vector<StatusWith<BSONObj> >* normalizedInserts,
vector<PregeneratedKeys>* pregen ) {
normalizedInserts->reserve(request.sizeWriteOps());
for ( size_t i = 0; i < request.sizeWriteOps(); ++i ) {
BSONObj insertDoc = request.getInsertRequest()->getDocumentsAt( i );
StatusWith<BSONObj> normalInsert = fixDocumentForInsert( insertDoc );
normalizedInserts->push_back( normalInsert );
if ( request.getOrdered() && !normalInsert.isOK() )
break;
if ( !normalInsert.getValue().isEmpty() )
insertDoc = normalInsert.getValue();
pregen->push_back( PregeneratedKeys() );
GeneratorHolder::getInstance()->prepare( request.getTargetingNS(),
insertDoc,
&pregen->back() );
}
}
示例14:
StatusWith<DiskLoc> Collection::insertDocument( OperationContext* txn,
const BSONObj& doc,
MultiIndexBlock& indexBlock ) {
StatusWith<DiskLoc> loc = _recordStore->insertRecord( txn,
doc.objdata(),
doc.objsize(),
0 );
if ( !loc.isOK() )
return loc;
InsertDeleteOptions indexOptions;
indexOptions.logIfError = false;
indexOptions.dupsAllowed = true; // in repair we should be doing no checking
Status status = indexBlock.insert( doc, loc.getValue(), indexOptions );
if ( !status.isOK() )
return StatusWith<DiskLoc>( status );
return loc;
}
示例15: lk
StatusWith<ReplicationExecutor::CallbackHandle>
ReplicationExecutor::scheduleWorkWithGlobalExclusiveLock(
const CallbackFn& work) {
boost::lock_guard<boost::mutex> lk(_mutex);
StatusWith<CallbackHandle> handle = enqueueWork_inlock(&_exclusiveLockInProgressQueue,
work);
if (handle.isOK()) {
const stdx::function<void (OperationContext*)> doOp = stdx::bind(
&ReplicationExecutor::doOperationWithGlobalExclusiveLock,
this,
stdx::placeholders::_1,
handle.getValue());
_dblockWorkers.schedule(
makeNoExcept(stdx::bind(
&NetworkInterface::runCallbackWithGlobalExclusiveLock,
_networkInterface.get(),
doOp)));
}
return handle;
}