virtual Status set(const BSONElement& newValueElement) { long long newValue; if (!newValueElement.isNumber()) { StringBuilder sb; sb << "Expected number type for journalCommitInterval via setParameter command: " << newValueElement; return Status(ErrorCodes::BadValue, sb.str()); } if (newValueElement.type() == NumberDouble && (newValueElement.numberDouble() - newValueElement.numberLong()) > 0) { StringBuilder sb; sb << "journalCommitInterval must be a whole number: " << newValueElement; return Status(ErrorCodes::BadValue, sb.str()); } newValue = newValueElement.numberLong(); if (newValue <= 1 || newValue >= 500) { StringBuilder sb; sb << "journalCommitInterval must be between 1 and 500, but attempted to set to: " << newValue; return Status(ErrorCodes::BadValue, sb.str()); } storageGlobalParams.journalCommitInterval = static_cast<unsigned>(newValue); return Status::OK(); }
KVCatalog::FeatureTracker::FeatureBits KVCatalog::FeatureTracker::getInfo( OperationContext* opCtx) const { if (_rid.isNull()) { return {}; } auto record = _catalog->_rs->dataFor(opCtx, _rid); BSONObj obj = record.toBson(); invariant(isFeatureDocument(obj)); BSONElement nonRepairableFeaturesElem; auto nonRepairableFeaturesStatus = bsonExtractTypedField( obj, kNonRepairableFeaturesFieldName, BSONType::NumberLong, &nonRepairableFeaturesElem); fassert(40111, nonRepairableFeaturesStatus); BSONElement repairableFeaturesElem; auto repairableFeaturesStatus = bsonExtractTypedField( obj, kRepairableFeaturesFieldName, BSONType::NumberLong, &repairableFeaturesElem); fassert(40112, repairableFeaturesStatus); FeatureBits versionInfo; versionInfo.nonRepairableFeatures = static_cast<NonRepairableFeatureMask>(nonRepairableFeaturesElem.numberLong()); versionInfo.repairableFeatures = static_cast<RepairableFeatureMask>(repairableFeaturesElem.numberLong()); return versionInfo; }
static long long applySkipLimit(long long num, const BSONObj& cmd) { BSONElement s = cmd["skip"]; BSONElement l = cmd["limit"]; if (s.isNumber()) { num = num - s.numberLong(); if (num < 0) { num = 0; } } if (l.isNumber()) { long long limit = l.numberLong(); if (limit < 0) { limit = -limit; } // 0 means no limit. if (limit < num && limit != 0) { num = limit; } } return num; }
int compareNumbers(const BSONElement& lhs, const BSONElement& rhs) { invariant(lhs.isNumber()); invariant(rhs.isNumber()); if (lhs.type() == NumberInt || lhs.type() == NumberLong) { if (rhs.type() == NumberInt || rhs.type() == NumberLong) { return COMPARE_HELPER(lhs.numberLong(), rhs.numberLong()); } return compareLongToDouble(lhs.numberLong(), rhs.Double()); } else { // double if (rhs.type() == NumberDouble) { return COMPARE_HELPER(lhs.Double(), rhs.Double()); } return -compareLongToDouble(rhs.numberLong(), lhs.Double()); } }
static bool isCursorCommand(BSONObj cmdObj) { BSONElement cursorElem = cmdObj["cursor"]; if (cursorElem.eoo()) return false; uassert(16954, "cursor field must be missing or an object", cursorElem.type() == Object); BSONObj cursor = cursorElem.embeddedObject(); BSONElement batchSizeElem = cursor["batchSize"]; if (batchSizeElem.eoo()) { uassert(16955, "cursor object can't contain fields other than batchSize", cursor.isEmpty()); } else { uassert(16956, "cursor.batchSize must be a number", batchSizeElem.isNumber()); // This can change in the future, but for now all negatives are reserved. uassert(16957, "Cursor batchSize must not be negative", batchSizeElem.numberLong() >= 0); } return true; }
intrusive_ptr<DocumentSource> DocumentSourceLimit::createFromBson( BSONElement elem, const intrusive_ptr<ExpressionContext>& pExpCtx) { uassert(15957, "the limit must be specified as a number", elem.isNumber()); long long limit = elem.numberLong(); return DocumentSourceLimit::create(pExpCtx, limit); }
INT32 _omaHandleTaskNotify::init ( const CHAR *pInstallInfo ) { INT32 rc = SDB_OK ; UINT64 taskID = 0 ; BSONObj obj ; BSONElement ele ; try { obj = BSONObj( pInstallInfo ).copy() ; ele = obj.getField( OMA_FIELD_TASKID ) ; if ( NumberInt != ele.type() && NumberLong != ele.type() ) { PD_LOG_MSG ( PDERROR, "Receive invalid task id from omsvc" ) ; rc = SDB_INVALIDARG ; goto error ; } taskID = ele.numberLong() ; _taskIDObj = BSON( OMA_FIELD_TASKID << (INT64)taskID ) ; } catch ( std::exception &e ) { rc = SDB_INVALIDARG ; PD_LOG ( PDERROR, "Failed to build bson, exception is: %s", e.what() ) ; goto error ; } done: return rc ; error : goto done ; }
StatusWith<long long> retrieveTotalShardSize(OperationContext* opCtx, const ShardId& shardId) { auto shardStatus = Grid::get(opCtx)->shardRegistry()->getShard(opCtx, shardId); if (!shardStatus.isOK()) { return shardStatus.getStatus(); } // Since 'listDatabases' is potentially slow in the presence of large number of collections, use // a higher maxTimeMS to prevent it from prematurely timing out const Minutes maxTimeMSOverride{10}; auto listDatabasesStatus = shardStatus.getValue()->runCommandWithFixedRetryAttempts( opCtx, ReadPreferenceSetting{ReadPreference::PrimaryPreferred}, "admin", BSON("listDatabases" << 1), maxTimeMSOverride, Shard::RetryPolicy::kIdempotent); if (!listDatabasesStatus.isOK()) { return std::move(listDatabasesStatus.getStatus()); } if (!listDatabasesStatus.getValue().commandStatus.isOK()) { return std::move(listDatabasesStatus.getValue().commandStatus); } BSONElement totalSizeElem = listDatabasesStatus.getValue().response["totalSize"]; if (!totalSizeElem.isNumber()) { return {ErrorCodes::NoSuchKey, "totalSize field not found in listDatabases"}; } return totalSizeElem.numberLong(); }
StatusWith<long long> retrieveTotalShardSize(OperationContext* txn, const ShardId& shardId) { auto shard = Grid::get(txn)->shardRegistry()->getShard(txn, shardId); if (!shard) { return Status(ErrorCodes::ShardNotFound, str::stream() << "shard " << shardId << " not found"); } auto listDatabasesStatus = shard->runCommand(txn, ReadPreferenceSetting{ReadPreference::PrimaryPreferred}, "admin", BSON("listDatabases" << 1), Shard::RetryPolicy::kIdempotent); if (!listDatabasesStatus.isOK()) { return std::move(listDatabasesStatus.getStatus()); } if (!listDatabasesStatus.getValue().commandStatus.isOK()) { return std::move(listDatabasesStatus.getValue().commandStatus); } BSONElement totalSizeElem = listDatabasesStatus.getValue().response["totalSize"]; if (!totalSizeElem.isNumber()) { return {ErrorCodes::NoSuchKey, "totalSize field not found in listDatabases"}; } return totalSizeElem.numberLong(); }
INT32 _rtnCancelTask::init( INT32 flags, INT64 numToSkip, INT64 numToReturn, const CHAR * pMatcherBuff, const CHAR * pSelectBuff, const CHAR * pOrderByBuff, const CHAR * pHintBuff ) { INT32 rc = SDB_OK ; try { BSONObj matcher( pMatcherBuff ) ; BSONElement ele = matcher.getField( CAT_TASKID_NAME ) ; if ( ele.eoo() || !ele.isNumber() ) { PD_LOG( PDERROR, "Field[%s] type[%d] is error", CAT_TASKID_NAME, ele.type() ) ; rc = SDB_INVALIDARG ; goto error ; } _taskID = (UINT64)ele.numberLong() ; } catch ( std::exception &e ) { PD_LOG( PDERROR, "Occur exception: %s", e.what() ) ; rc = SDB_SYS ; goto error ; } done: return rc ; error: goto done ; }
// static StatusWith<BSONObj> S2AccessMethod::fixSpec(const BSONObj& specObj) { // If the spec object has the field "2dsphereIndexVersion", validate it. If it doesn't, add // {2dsphereIndexVersion: 3}, which is the default for newly-built indexes. BSONElement indexVersionElt = specObj[kIndexVersionFieldName]; if (indexVersionElt.eoo()) { BSONObjBuilder bob; bob.appendElements(specObj); bob.append(kIndexVersionFieldName, S2_INDEX_VERSION_3); return bob.obj(); } if (!indexVersionElt.isNumber()) { return {ErrorCodes::CannotCreateIndex, str::stream() << "Invalid type for geo index version { " << kIndexVersionFieldName << " : " << indexVersionElt << " }, only versions: [" << S2_INDEX_VERSION_1 << "," << S2_INDEX_VERSION_2 << "," << S2_INDEX_VERSION_3 << "] are supported"}; } if (indexVersionElt.type() == BSONType::NumberDouble && !std::isnormal(indexVersionElt.numberDouble())) { return {ErrorCodes::CannotCreateIndex, str::stream() << "Invalid value for geo index version { " << kIndexVersionFieldName << " : " << indexVersionElt << " }, only versions: [" << S2_INDEX_VERSION_1 << "," << S2_INDEX_VERSION_2 << "," << S2_INDEX_VERSION_3 << "] are supported"}; } const auto indexVersion = indexVersionElt.numberLong(); if (indexVersion != S2_INDEX_VERSION_1 && indexVersion != S2_INDEX_VERSION_2 && indexVersion != S2_INDEX_VERSION_3) { return {ErrorCodes::CannotCreateIndex, str::stream() << "unsupported geo index version { " << kIndexVersionFieldName << " : " << indexVersionElt << " }, only versions: [" << S2_INDEX_VERSION_1 << "," << S2_INDEX_VERSION_2 << "," << S2_INDEX_VERSION_3 << "] are supported"}; } return specObj; }
static void handleCursorCommand(CursorId id, BSONObj& cmdObj, BSONObjBuilder& result) { BSONElement batchSizeElem = cmdObj.getFieldDotted("cursor.batchSize"); const long long batchSize = batchSizeElem.isNumber() ? batchSizeElem.numberLong() : 101; // same as query ClientCursorPin pin(id); ClientCursor* cursor = pin.c(); massert(16958, "Cursor shouldn't have been deleted", cursor); verify(cursor->isAggCursor); PipelineRunner* runner = dynamic_cast<PipelineRunner*>(cursor->getRunner()); verify(runner); try { const string cursorNs = cursor->ns(); // we need this after cursor may have been deleted // can't use result BSONObjBuilder directly since it won't handle exceptions correctly. BSONArrayBuilder resultsArray; const int byteLimit = MaxBytesToReturnToClientAtOnce; BSONObj next; for (int objCount = 0; objCount < batchSize; objCount++) { // The initial getNext() on a PipelineRunner may be very expensive so we don't do it // when batchSize is 0 since that indicates a desire for a fast return. if (runner->getNext(&next, NULL) != Runner::RUNNER_ADVANCED) { pin.deleteUnderlying(); id = 0; cursor = NULL; // make it an obvious error to use cursor after this point break; } if (resultsArray.len() + next.objsize() > byteLimit) { // too big. next will be the first doc in the second batch runner->pushBack(next); break; } resultsArray.append(next); } if (cursor) { // If a time limit was set on the pipeline, remaining time is "rolled over" to the // cursor (for use by future getmore ops). cursor->setLeftoverMaxTimeMicros( cc().curop()->getRemainingMaxTimeMicros() ); } BSONObjBuilder cursorObj(result.subobjStart("cursor")); cursorObj.append("id", id); cursorObj.append("ns", cursorNs); cursorObj.append("firstBatch", resultsArray.arr()); cursorObj.done(); } catch (...) { // Clean up cursor on way out of scope. pin.deleteUnderlying(); throw; } }
void reload() { list<BSONObj> all; { ScopedDbConnection conn( configServer.getPrimary() ); auto_ptr<DBClientCursor> c = conn->query( ShardNS::shard , Query() ); massert( 13632 , "couldn't get updated shard list from config server" , c.get() ); while ( c->more() ) { all.push_back( c->next().getOwned() ); } conn.done(); } scoped_lock lk( _mutex ); // We use the _lookup table for all shards and for the primary config DB. The config DB info, // however, does not come from the ShardNS::shard. So when cleaning the _lookup table we leave // the config state intact. The rationale is that this way we could drop shards that // were removed without reinitializing the config DB information. map<string,Shard>::iterator i = _lookup.find( "config" ); if ( i != _lookup.end() ) { Shard config = i->second; _lookup.clear(); _lookup[ "config" ] = config; } else { _lookup.clear(); } for ( list<BSONObj>::iterator i=all.begin(); i!=all.end(); ++i ) { BSONObj o = *i; string name = o["_id"].String(); string host = o["host"].String(); long long maxSize = 0; BSONElement maxSizeElem = o[ ShardFields::maxSize.name() ]; if ( ! maxSizeElem.eoo() ) { maxSize = maxSizeElem.numberLong(); } bool isDraining = false; BSONElement isDrainingElem = o[ ShardFields::draining.name() ]; if ( ! isDrainingElem.eoo() ) { isDraining = isDrainingElem.Bool(); } Shard s( name , host , maxSize , isDraining ); _lookup[name] = s; _lookup[host] = s; // add rs name to lookup (if it exists) size_t pos; if ((pos = host.find('/', 0)) != string::npos) { _lookup[host.substr(0, pos)] = s; } } }
INT32 dpsArchiveInfoMgr::_fromBson( const BSONObj& data, dpsArchiveInfo& info, INT64& count ) { INT32 rc = SDB_OK ; BSONElement ele ; dpsArchiveInfo _info ; INT64 _count = 0 ; ele = data.getField( DPS_ARCHIVE_INFO_COUNTER ) ; if ( NumberLong != ele.type() && NumberInt != ele.type() ) { rc = SDB_INVALIDARG ; goto error ; } _count = ele.numberLong() ; if ( _count <= 0 ) { rc = SDB_INVALIDARG ; goto error ; } ele = data.getField( DPS_ARCHIVE_INFO_NEXTLSN ) ; if ( NumberLong != ele.type() && NumberInt != ele.type() ) { rc = SDB_INVALIDARG ; goto error ; } _info.startLSN.offset = ele.numberLong() ; if ( _info.startLSN.offset == DPS_INVALID_LSN_OFFSET ) { rc = SDB_INVALIDARG ; goto error ; } info = _info ; count = _count ; done: return rc ; error: goto done ; }
intrusive_ptr<DocumentSource> DocumentSourceSkip::createFromBson( BSONElement elem, const intrusive_ptr<ExpressionContext>& pExpCtx) { uassert(15972, str::stream() << "Argument to $skip must be a number not a " << typeName(elem.type()), elem.isNumber()); auto nToSkip = elem.numberLong(); uassert(15956, "Argument to $skip cannot be negative", nToSkip >= 0); return DocumentSourceSkip::create(pExpCtx, nToSkip); }
Status Command::parseCommandCursorOptions(const BSONObj& cmdObj, long long defaultBatchSize, long long* batchSize) { invariant(batchSize); *batchSize = defaultBatchSize; BSONElement cursorElem = cmdObj["cursor"]; if (cursorElem.eoo()) { return Status::OK(); } if (cursorElem.type() != mongo::Object) { return Status(ErrorCodes::TypeMismatch, "cursor field must be missing or an object"); } BSONObj cursor = cursorElem.embeddedObject(); BSONElement batchSizeElem = cursor["batchSize"]; const int expectedNumberOfCursorFields = batchSizeElem.eoo() ? 0 : 1; if (cursor.nFields() != expectedNumberOfCursorFields) { return Status(ErrorCodes::BadValue, "cursor object can't contain fields other than batchSize"); } if (batchSizeElem.eoo()) { return Status::OK(); } if (!batchSizeElem.isNumber()) { return Status(ErrorCodes::TypeMismatch, "cursor.batchSize must be a number"); } // This can change in the future, but for now all negatives are reserved. if (batchSizeElem.numberLong() < 0) { return Status(ErrorCodes::BadValue, "cursor.batchSize must not be negative"); } *batchSize = batchSizeElem.numberLong(); return Status::OK(); }
BSONObj ClusteredCursor::explain(){ // Note: by default we filter out allPlans and oldPlan in the shell's // explain() function. If you add any recursive structures, make sure to // edit the JS to make sure everything gets filtered. BSONObjBuilder b; b.append( "clusteredType" , type() ); long long millis = 0; double numExplains = 0; map<string,long long> counters; map<string,list<BSONObj> > out; { _explain( out ); BSONObjBuilder x( b.subobjStart( "shards" ) ); for ( map<string,list<BSONObj> >::iterator i=out.begin(); i!=out.end(); ++i ){ string shard = i->first; list<BSONObj> l = i->second; BSONArrayBuilder y( x.subarrayStart( shard ) ); for ( list<BSONObj>::iterator j=l.begin(); j!=l.end(); ++j ){ BSONObj temp = *j; y.append( temp ); BSONObjIterator k( temp ); while ( k.more() ){ BSONElement z = k.next(); if ( z.fieldName()[0] != 'n' ) continue; long long& c = counters[z.fieldName()]; c += z.numberLong(); } millis += temp["millis"].numberLong(); numExplains++; } y.done(); } x.done(); } for ( map<string,long long>::iterator i=counters.begin(); i!=counters.end(); ++i ) b.appendNumber( i->first , i->second ); b.appendNumber( "millisTotal" , millis ); b.append( "millisAvg" , (int)((double)millis / numExplains ) ); b.append( "numQueries" , (int)numExplains ); b.append( "numShards" , (int)out.size() ); return b.obj(); }
intrusive_ptr<DocumentSource> DocumentSourceSkip::createFromBson( BSONElement elem, const intrusive_ptr<AggregationExecContext>& pAggrExcCtx) { uassert(15972, str::stream() << "Argument to $skip must be a number not a " << typeName(elem.type()), elem.isNumber()); intrusive_ptr<DocumentSourceSkip> pSkip(DocumentSourceSkip::create(pAggrExcCtx)); pSkip->_skip = elem.numberLong(); uassert(15956, "Argument to $skip cannot be negative", pSkip->_skip >= 0); return pSkip; }
static void handleCursorCommand(CursorId id, BSONObj& cmdObj, BSONObjBuilder& result) { BSONElement batchSizeElem = cmdObj.getFieldDotted("cursor.batchSize"); const long long batchSize = batchSizeElem.isNumber() ? batchSizeElem.numberLong() : 101; // same as query // Using limited cursor API that ignores many edge cases. Should be sufficient for commands. ClientCursor::Pin pin(id); ClientCursor* cursor = pin.c(); massert(16958, "Cursor shouldn't have been deleted", cursor); // Make sure this cursor won't disappear on us fassert(16959, !cursor->c()->shouldDestroyOnNSDeletion()); fassert(16960, !cursor->c()->requiresLock()); try { // can't use result BSONObjBuilder directly since it won't handle exceptions correctly. BSONArrayBuilder resultsArray; const int byteLimit = MaxBytesToReturnToClientAtOnce; for (int objs = 0; objs < batchSize && cursor->ok() && resultsArray.len() <= byteLimit; objs++) { // TODO may need special logic if cursor->current() would cause results to be > 16MB resultsArray.append(cursor->current()); cursor->advance(); } // The initial ok() on a cursor may be very expensive so we don't do it when batchSize // is 0 since that indicates a desire for a fast return. if (batchSize != 0 && !cursor->ok()) { // There is no more data. Kill the cursor. pin.release(); ClientCursor::erase(id); id = 0; } BSONObjBuilder cursorObj(result.subobjStart("cursor")); cursorObj.append("id", id); cursorObj.append("ns", cursor->ns()); cursorObj.append("firstBatch", resultsArray.arr()); cursorObj.done(); } catch (...) { // Clean up cursor on way out of scope. pin.release(); ClientCursor::erase(id); throw; } }
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() ) ); }
virtual bool run(const string& , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) { if( cmdObj.hasElement("expireOplogDays") || cmdObj.hasElement("expireOplogHours") ) { uint32_t expireOplogDays = cmdLine.expireOplogDays; uint32_t expireOplogHours = cmdLine.expireOplogHours; if (cmdObj.hasElement("expireOplogHours")) { BSONElement e = cmdObj["expireOplogHours"]; if (!e.isNumber()) { errmsg = "bad expireOplogHours"; return false; } expireOplogHours = e.numberLong(); } if (cmdObj.hasElement("expireOplogDays")) { BSONElement e = cmdObj["expireOplogDays"]; if (!e.isNumber()) { errmsg = "bad expireOplogDays"; return false; } expireOplogDays = e.numberLong(); } theReplSet->changeExpireOplog(expireOplogDays, expireOplogHours); } return true; }
intrusive_ptr<DocumentSource> DocumentSourceSkip::createFromBson( BSONElement elem, const intrusive_ptr<ExpressionContext> &pExpCtx) { uassert(15972, str::stream() << DocumentSourceSkip::skipName << ": the value to skip must be a number", elem.isNumber()); intrusive_ptr<DocumentSourceSkip> pSkip( DocumentSourceSkip::create(pExpCtx)); pSkip->_skip = elem.numberLong(); uassert(15956, str::stream() << DocumentSourceSkip::skipName << ": the number to skip cannot be negative", pSkip->_skip >= 0); return pSkip; }
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 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() ) ); }
INT32 catSplitCleanup( const BSONObj & splitInfo, pmdEDUCB * cb, INT16 w ) { INT32 rc = SDB_OK ; UINT64 taskID = 0 ; INT32 status = CLS_TASK_STATUS_READY ; BSONElement ele = splitInfo.getField( CAT_TASKID_NAME ) ; PD_CHECK( ele.isNumber(), SDB_INVALIDARG, error, PDERROR, "Failed to get field[%s], type: %d", CAT_TASKID_NAME, ele.type() ) ; taskID = ( UINT64 )ele.numberLong() ; rc = catGetTaskStatus( taskID, status, cb ) ; if ( rc ) { goto error ; } if ( CLS_TASK_STATUS_META == status ) { rc = catUpdateTaskStatus( taskID, CLS_TASK_STATUS_FINISH, cb, w ) ; if ( rc ) { goto error ; } } else if ( CLS_TASK_STATUS_FINISH == status ) { } else { PD_LOG( PDERROR, "Task[%ll] status error in clean up step", taskID, status ) ; rc = SDB_SYS ; goto error ; } done: return rc ; error: goto done ; }
INT32 catSplitFinish( const BSONObj & splitInfo, pmdEDUCB * cb, INT16 w ) { INT32 rc = SDB_OK ; UINT64 taskID = 0 ; BSONElement ele = splitInfo.getField( CAT_TASKID_NAME ) ; PD_CHECK( ele.isNumber(), SDB_INVALIDARG, error, PDERROR, "Failed to get field[%s], type: %d", CAT_TASKID_NAME, ele.type() ) ; taskID = ( UINT64 )ele.numberLong() ; rc = catRemoveTask( taskID, cb, w ) ; PD_RC_CHECK( rc, PDERROR, "Remove task[%lld] failed, rc: %d", taskID, rc ) ; done: return rc ; error: goto done ; }
bool BitTestMatchExpression::matchesSingleElement(const BSONElement& e, MatchDetails* details) const { // Validate 'e' is a number or a BinData. if (!e.isNumber() && e.type() != BSONType::BinData) { return false; } if (e.type() == BSONType::BinData) { int eBinaryLen; // Length of eBinary (in bytes). const char* eBinary = e.binData(eBinaryLen); return performBitTest(eBinary, eBinaryLen); } invariant(e.isNumber()); if (e.type() == BSONType::NumberDouble) { double eDouble = e.numberDouble(); // NaN doubles are rejected. if (std::isnan(eDouble)) { return false; } // Integral doubles that are too large or small to be represented as a 64-bit signed // integer are treated as 0. We use 'kLongLongMaxAsDouble' because if we just did // eDouble > 2^63-1, it would be compared against 2^63. eDouble=2^63 would not get caught // that way. if (eDouble >= BSONElement::kLongLongMaxPlusOneAsDouble || eDouble < std::numeric_limits<long long>::min()) { return false; } // This checks if e is an integral double. if (eDouble != static_cast<double>(static_cast<long long>(eDouble))) { return false; } } long long eValue = e.numberLong(); return performBitTest(eValue); }
FieldParser::FieldState FieldParser::extractNumber(BSONElement elem, const BSONField<long long>& field, long long* out, string* errMsg) { if (elem.eoo()) { if (field.hasDefault()) { *out = field.getDefault(); return FIELD_DEFAULT; } else { return FIELD_NONE; } } if (elem.isNumber()) { *out = elem.numberLong(); return FIELD_SET; } _genFieldErrMsg(elem, field, "number", errMsg); return FIELD_INVALID; }
ShardStatus Shard::getStatus() const { BSONObj listDatabases; uassert(28589, str::stream() << "call to listDatabases on " << getConnString().toString() << " failed: " << listDatabases, runCommand("admin", BSON("listDatabases" << 1), listDatabases)); BSONElement totalSizeElem = listDatabases["totalSize"]; uassert(28590, "totalSize field not found in listDatabases", totalSizeElem.isNumber()); BSONObj serverStatus; uassert(28591, str::stream() << "call to serverStatus on " << getConnString().toString() << " failed: " << serverStatus, runCommand("admin", BSON("serverStatus" << 1), serverStatus)); BSONElement versionElement = serverStatus["version"]; uassert(28599, "version field not found in serverStatus", versionElement.type() == String); return ShardStatus(totalSizeElem.numberLong(), versionElement.str()); }
INT32 catSplitStart( const BSONObj & splitInfo, pmdEDUCB * cb, INT16 w ) { INT32 rc = SDB_OK ; UINT64 taskID = 0 ; INT32 status = CLS_TASK_STATUS_READY ; BSONElement ele = splitInfo.getField( CAT_TASKID_NAME ) ; PD_CHECK( ele.isNumber(), SDB_INVALIDARG, error, PDERROR, "Failed to get field[%s], type: %d", CAT_TASKID_NAME, ele.type() ) ; taskID = ( UINT64 )ele.numberLong() ; rc = catGetTaskStatus( taskID, status, cb ) ; if ( rc ) { goto error ; } if ( CLS_TASK_STATUS_READY == status || CLS_TASK_STATUS_PAUSE == status ) { rc = catUpdateTaskStatus( taskID, CLS_TASK_STATUS_RUN, cb, w ) ; if ( rc ) { goto error ; } } else if ( CLS_TASK_STATUS_CANCELED == status ) { rc = SDB_TASK_HAS_CANCELED ; goto error ; } done: return rc ; error: goto done ; }
FieldParser::FieldState FieldParser::extract(BSONObj doc, const BSONField<long long>& field, long long* out, string* errMsg) { BSONElement elem = doc[field.name()]; if (elem.eoo()) { if (field.hasDefault()) { *out = field.getDefault(); return FIELD_DEFAULT; } else { return FIELD_NONE; } } if (elem.type() == NumberLong) { *out = elem.numberLong(); return FIELD_SET; } _genFieldErrMsg(doc, field, "long", errMsg); return FIELD_INVALID; }