本文整理汇总了C++中BSONElement::OID方法的典型用法代码示例。如果您正苦于以下问题:C++ BSONElement::OID方法的具体用法?C++ BSONElement::OID怎么用?C++ BSONElement::OID使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BSONElement
的用法示例。
在下文中一共展示了BSONElement::OID方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: applyRefOp
// find all oplog entries for a given OID in the oplog.refs collection and apply them
// TODO this should be a range query on oplog.refs where _id.oid == oid and applyOps to
// each entry found. The locking of the query interleaved with the locking in the applyOps
// did not work, so it a sequence of point queries.
// TODO verify that the query plan is a indexed lookup.
// TODO verify that the query plan does not fetch too many docs and then only process one of them.
void applyRefOp(BSONObj entry) {
OID oid = entry["ref"].OID();
LOG(3) << "apply ref " << entry << " oid " << oid << endl;
long long seq = 0; // note that 0 is smaller than any of the seq numbers
while (1) {
BSONObj entry;
{
LOCK_REASON(lockReason, "repl: finding oplog.refs entry to apply");
Client::ReadContext ctx(rsOplogRefs, lockReason);
// TODO: Should this be using rsOplogRefsDetails, verifying non-null?
Collection *cl = getCollection(rsOplogRefs);
if (cl == NULL || !cl->findOne(BSON("_id" << BSON("$gt" << BSON("oid" << oid << "seq" << seq))), entry, true)) {
break;
}
}
BSONElement e = entry.getFieldDotted("_id.seq");
seq = e.Long();
BSONElement eOID = entry.getFieldDotted("_id.oid");
if (oid != eOID.OID()) {
break;
}
LOG(3) << "apply " << entry << " seq=" << seq << endl;
applyOps(entry["ops"].Array());
}
}
示例2: bsonExtractOIDField
Status bsonExtractOIDField(const BSONObj& object, StringData fieldName, OID* out) {
BSONElement element;
Status status = bsonExtractTypedField(object, fieldName, jstOID, &element);
if (status.isOK())
*out = element.OID();
return status;
}
示例3: Status
StatusWith<ShardingMetadata> ShardingMetadata::readFromMetadata(const BSONObj& metadataObj) {
BSONElement smElem;
auto smExtractStatus =
bsonExtractTypedField(metadataObj, kGLEStatsFieldName, mongo::Object, &smElem);
if (!smExtractStatus.isOK()) {
return smExtractStatus;
}
if (smElem.embeddedObject().nFields() != 2) {
return Status(ErrorCodes::InvalidOptions,
str::stream() << "The $gleStats object can only have 2 fields, but got "
<< smElem.embeddedObject().toString());
}
BSONElement lastOpTimeElem;
auto lastOpTimeExtractStatus = bsonExtractTypedField(smElem.embeddedObject(),
kGLEStatsLastOpTimeFieldName,
mongo::bsonTimestamp,
&lastOpTimeElem);
if (!lastOpTimeExtractStatus.isOK()) {
return lastOpTimeExtractStatus;
}
BSONElement lastElectionIdElem;
auto lastElectionIdExtractStatus = bsonExtractTypedField(
smElem.embeddedObject(), kGLEStatsElectionIdFieldName, mongo::jstOID, &lastElectionIdElem);
if (!lastElectionIdExtractStatus.isOK()) {
return lastElectionIdExtractStatus;
}
return ShardingMetadata(lastOpTimeElem.timestamp(), lastElectionIdElem.OID());
}
示例4: initialize
Status HandshakeArgs::initialize(const BSONObj& argsObj) {
Status status = bsonCheckOnlyHasFields("HandshakeArgs", argsObj, kLegalHandshakeFieldNames);
if (!status.isOK())
return status;
BSONElement oid;
status = bsonExtractTypedField(argsObj, kRIDFieldName, jstOID, &oid);
if (!status.isOK())
return status;
_rid = oid.OID();
_hasRid = true;
status = bsonExtractIntegerField(argsObj, kMemberIdFieldName, &_memberId);
if (!status.isOK()) {
// field not necessary for master slave, do not return NoSuchKey Error
if (status != ErrorCodes::NoSuchKey) {
return status;
}
_memberId = -1;
} else {
_hasMemberId = true;
}
return Status::OK();
}
示例5: bsonExtractStringField
StatusWith<LocksType> LocksType::fromBSON(const BSONObj& source) {
LocksType lock;
{
std::string lockName;
Status status = bsonExtractStringField(source, name.name(), &lockName);
if (!status.isOK())
return status;
lock._name = lockName;
}
{
long long lockStateInt;
Status status = bsonExtractIntegerField(source, state.name(), &lockStateInt);
if (!status.isOK())
return status;
lock._state = static_cast<State>(lockStateInt);
}
if (source.hasField(process.name())) {
std::string lockProcess;
Status status = bsonExtractStringField(source, process.name(), &lockProcess);
if (!status.isOK())
return status;
lock._process = lockProcess;
}
if (source.hasField(lockID.name())) {
BSONElement lockIDElem;
Status status = bsonExtractTypedField(source, lockID.name(), BSONType::jstOID, &lockIDElem);
if (!status.isOK())
return status;
lock._lockID = lockIDElem.OID();
}
if (source.hasField(who.name())) {
std::string lockWho;
Status status = bsonExtractStringField(source, who.name(), &lockWho);
if (!status.isOK())
return status;
lock._who = lockWho;
}
if (source.hasField(why.name())) {
std::string lockWhy;
Status status = bsonExtractStringField(source, why.name(), &lockWhy);
if (!status.isOK())
return status;
lock._why = lockWhy;
}
return lock;
}
示例6: copyOplogRefsRange
// Copy a range of documents to the local oplog.refs collection
static void copyOplogRefsRange(OplogReader &r, OID oid) {
shared_ptr<DBClientCursor> c = r.getOplogRefsCursor(oid);
Client::ReadContext ctx(rsOplogRefs);
while (c->more()) {
BSONObj b = c->next();
BSONElement eOID = b.getFieldDotted("_id.oid");
if (oid != eOID.OID()) {
break;
}
LOG(6) << "copyOplogRefsRange " << b << endl;
writeEntryToOplogRefs(b);
}
}
示例7: csvString
// Gets the string representation of a BSON object that can be correctly written to a CSV file
string csvString (const BSONElement& object) {
const char* binData; // Only used with BinData type
switch (object.type()) {
case MinKey:
return "$MinKey";
case MaxKey:
return "$MaxKey";
case NumberInt:
case NumberDouble:
case NumberLong:
case Bool:
return object.toString(false);
case String:
case Symbol:
return csvEscape(object.toString(false), true);
case Object:
return csvEscape(object.jsonString(Strict, false));
case Array:
return csvEscape(object.jsonString(Strict, false));
case BinData:
int len;
binData = object.binDataClean(len);
return toHex(binData, len);
case jstOID:
return "ObjectID(" + object.OID().toString() + ")"; // OIDs are always 24 bytes
case Date:
return timeToISOString(object.Date() / 1000);
case Timestamp:
return csvEscape(object.jsonString(Strict, false));
case RegEx:
return csvEscape("/" + string(object.regex()) + "/" + string(object.regexFlags()));
case Code:
return csvEscape(object.toString(false));
case CodeWScope:
if (string(object.codeWScopeScopeDataUnsafe()) == "") {
return csvEscape(object.toString(false));
} else {
return csvEscape(object.jsonString(Strict, false));
}
case EOO:
case Undefined:
case DBRef:
case jstNULL:
cerr << "Invalid BSON object type for CSV output: " << object.type() << endl;
return "";
}
// Can never get here
verify(false);
return "";
}
示例8: bsonExtractOIDFieldWithDefault
Status bsonExtractOIDFieldWithDefault(const BSONObj& object,
StringData fieldName,
const OID& defaultValue,
OID* out) {
BSONElement element;
Status status = bsonExtractTypedFieldImpl(object, fieldName, jstOID, &element, true);
if (status == ErrorCodes::NoSuchKey) {
*out = defaultValue;
return Status::OK();
}
if (status.isOK())
*out = element.OID();
return status;
}
示例9: _addWriteBack
void ClientInfo::_addWriteBack( vector<WBInfo>& all , const BSONObj& gle ) {
BSONElement w = gle["writeback"];
if ( w.type() != jstOID )
return;
BSONElement cid = gle["connectionId"];
if ( cid.eoo() ) {
error() << "getLastError writeback can't work because of version mis-match" << endl;
return;
}
all.push_back( WBInfo( cid.numberLong() , w.OID() ) );
}
示例10: Status
StatusWith<ShardingMetadata> ShardingMetadata::readFromMetadata(const BSONObj& metadataObj) {
BSONElement smElem;
auto smExtractStatus =
bsonExtractTypedField(metadataObj, kGLEStatsFieldName, mongol::Object, &smElem);
if (!smExtractStatus.isOK()) {
return smExtractStatus;
}
if (smElem.embeddedObject().nFields() != 2) {
return Status(ErrorCodes::InvalidOptions,
str::stream() << "The $gleStats object can only have 2 fields, but got "
<< smElem.embeddedObject().toString());
}
repl::OpTime opTime;
const BSONElement opTimeElement = smElem.embeddedObject()[kGLEStatsLastOpTimeFieldName];
if (opTimeElement.eoo()) {
return Status(ErrorCodes::NoSuchKey, "lastOpTime field missing");
} else if (opTimeElement.type() == bsonTimestamp) {
opTime = repl::OpTime(opTimeElement.timestamp(), repl::OpTime::kUninitializedTerm);
} else if (opTimeElement.type() == Date) {
opTime = repl::OpTime(Timestamp(opTimeElement.date()), repl::OpTime::kUninitializedTerm);
} else if (opTimeElement.type() == Object) {
Status status =
bsonExtractOpTimeField(smElem.embeddedObject(), kGLEStatsLastOpTimeFieldName, &opTime);
if (!status.isOK()) {
return status;
}
} else {
return Status(ErrorCodes::TypeMismatch,
str::stream() << "Expected \"" << kGLEStatsLastOpTimeFieldName
<< "\" field in response to replSetHeartbeat "
"command to have type Date or Timestamp, but found type "
<< typeName(opTimeElement.type()));
}
BSONElement lastElectionIdElem;
auto lastElectionIdExtractStatus = bsonExtractTypedField(
smElem.embeddedObject(), kGLEStatsElectionIdFieldName, mongol::jstOID, &lastElectionIdElem);
if (!lastElectionIdExtractStatus.isOK()) {
return lastElectionIdExtractStatus;
}
return ShardingMetadata(opTime, lastElectionIdElem.OID());
}
示例11: it
StatusWith<ChunkVersion> ChunkVersion::parseFromBSONWithFieldForCommands(const BSONObj& obj,
StringData field) {
BSONElement versionElem;
Status status = bsonExtractField(obj, field, &versionElem);
if (!status.isOK())
return status;
if (versionElem.type() != Array) {
return {ErrorCodes::TypeMismatch,
str::stream() << "Invalid type " << versionElem.type()
<< " for shardVersion element. Expected an array"};
}
BSONObjIterator it(versionElem.Obj());
if (!it.more())
return {ErrorCodes::BadValue, "Unexpected empty version"};
ChunkVersion version;
// Expect the timestamp
{
BSONElement tsPart = it.next();
if (tsPart.type() != bsonTimestamp)
return {ErrorCodes::TypeMismatch,
str::stream() << "Invalid type " << tsPart.type()
<< " for version timestamp part."};
version._combined = tsPart.timestamp().asULL();
}
// Expect the epoch OID
{
BSONElement epochPart = it.next();
if (epochPart.type() != jstOID)
return {ErrorCodes::TypeMismatch,
str::stream() << "Invalid type " << epochPart.type()
<< " for version epoch part."};
version._epoch = epochPart.OID();
}
return version;
}
示例12: _addWriteBack
void ClientInfo::_addWriteBack( vector<WBInfo>& all, const BSONObj& gle, bool fromLastOperation ) {
BSONElement w = gle["writeback"];
if ( w.type() != jstOID )
return;
BSONElement cid = gle["connectionId"];
if ( cid.eoo() ) {
error() << "getLastError writeback can't work because of version mismatch" << endl;
return;
}
string ident = "";
if ( gle["instanceIdent"].type() == String )
ident = gle["instanceIdent"].String();
all.push_back( WBInfo( WriteBackListener::ConnectionIdent( ident , cid.numberLong() ),
w.OID(),
fromLastOperation ) );
}
示例13: rollbackRefOp
void rollbackRefOp(BSONObj entry) {
OID oid = entry["ref"].OID();
LOG(3) << "rollback ref " << entry << " oid " << oid << endl;
long long seq = LLONG_MAX;
while (1) {
BSONObj currEntry;
{
LOCK_REASON(lockReason, "repl: rolling back entry from oplog.refs");
Client::ReadContext ctx(rsOplogRefs, lockReason);
verify(rsOplogRefsDetails != NULL);
shared_ptr<Cursor> c(
Cursor::make(
rsOplogRefsDetails,
rsOplogRefsDetails->getPKIndex(),
KeyPattern::toKeyFormat(BSON( "_id" << BSON("oid" << oid << "seq" << seq))), // right endpoint
KeyPattern::toKeyFormat(BSON( "_id" << BSON("oid" << oid << "seq" << 0))), // left endpoint
false,
-1 // direction
)
);
if (c->ok()) {
currEntry = c->current().copy();
}
else {
break;
}
}
BSONElement e = currEntry.getFieldDotted("_id.seq");
seq = e.Long();
BSONElement eOID = currEntry.getFieldDotted("_id.oid");
if (oid != eOID.OID()) {
break;
}
LOG(3) << "apply " << currEntry << " seq=" << seq << endl;
rollbackOps(currEntry["ops"].Array());
// decrement seq so next query gets the next value
seq--;
}
}
示例14: applyRefOp
// find all oplog entries for a given OID in the oplog.refs collection and apply them
// TODO this should be a range query on oplog.refs where _id.oid == oid and applyOps to
// each entry found. The locking of the query interleaved with the locking in the applyOps
// did not work, so it a sequence of point queries.
// TODO verify that the query plan is a indexed lookup.
// TODO verify that the query plan does not fetch too many docs and then only process one of them.
void applyRefOp(BSONObj entry) {
OID oid = entry["ref"].OID();
LOG(3) << "apply ref " << entry << " oid " << oid << endl;
long long seq = 0; // note that 0 is smaller than any of the seq numbers
while (1) {
BSONObj entry;
{
Client::ReadContext ctx(rsOplogRefs);
// TODO: Should this be using rsOplogRefsDetails, verifying non-null?
NamespaceDetails *d = nsdetails(rsOplogRefs);
if (d == NULL || !d->findOne(BSON("_id" << BSON("$gt" << BSON("oid" << oid << "seq" << seq))), entry, true)) {
break;
}
}
BSONElement e = entry.getFieldDotted("_id.seq");
seq = e.Long();
BSONElement eOID = entry.getFieldDotted("_id.oid");
if (oid != eOID.OID()) {
break;
}
LOG(3) << "apply " << entry << " seq=" << seq << endl;
applyOps(entry["ops"].Array());
}
}
示例15: open
// PD_TRACE_DECLARE_FUNCTION ( SDB__RTNCONTEXTLOB_OPEN, "_rtnContextLob::open" )
INT32 _rtnContextLob::open( const BSONObj &lob,
BOOLEAN isLocal,
_pmdEDUCB *cb,
SDB_DPSCB *dpsCB )
{
INT32 rc = SDB_OK ;
PD_TRACE_ENTRY( SDB__RTNCONTEXTLOB_OPEN ) ;
BSONElement mode ;
BSONElement oid ;
BSONElement fullName = lob.getField( FIELD_NAME_COLLECTION ) ;
if ( String != fullName.type() )
{
PD_LOG( PDERROR, "can not find collection name in lob[%s]",
lob.toString( FALSE, TRUE ).c_str() ) ;
rc = SDB_INVALIDARG ;
goto error ;
}
oid = lob.getField( FIELD_NAME_LOB_OID ) ;
if ( jstOID != oid.type() )
{
PD_LOG( PDERROR, "invalid oid in meta bsonobj:%s",
lob.toString( FALSE, TRUE ).c_str() ) ;
rc = SDB_INVALIDARG ;
goto error ;
}
mode = lob.getField( FIELD_NAME_LOB_OPEN_MODE ) ;
if ( NumberInt != mode.type() )
{
PD_LOG( PDERROR, "invalid mode in meta bsonobj:%s",
lob.toString( FALSE, TRUE ).c_str() ) ;
rc = SDB_INVALIDARG ;
goto error ;
}
if ( isLocal )
{
_stream = SDB_OSS_NEW _rtnLocalLobStream() ;
}
else
{
_stream = SDB_OSS_NEW _rtnCoordLobStream() ;
}
if ( NULL == _stream )
{
PD_LOG( PDERROR, "failed to allocate mem." ) ;
rc = SDB_OOM ;
goto error ;
}
_stream->setDPSCB( dpsCB ) ;
rc = _stream->open( fullName.valuestr(),
oid.OID(),
mode.Int(), cb ) ;
if ( SDB_OK != rc )
{
PD_LOG( PDERROR, "failed to open lob stream:%d", rc ) ;
goto error ;
}
_isOpened = TRUE ;
_hitEnd = FALSE ;
done:
PD_TRACE_EXITRC( SDB__RTNCONTEXTLOB_OPEN, rc ) ;
return rc ;
error:
goto done ;
}