TEST( IntegerToHex, VariousConversions ) { ASSERT_EQUALS(std::string("0"), integerToHex(0)); ASSERT_EQUALS(std::string("1"), integerToHex(1)); ASSERT_EQUALS(std::string("1337"), integerToHex(0x1337)); ASSERT_EQUALS(std::string("FFFFD499"), integerToHex(-11111)); ASSERT_EQUALS(std::string("F1FE60C4"), integerToHex(-234987324)); ASSERT_EQUALS(std::string("80000000"), integerToHex(std::numeric_limits<int>::min())); ASSERT_EQUALS(std::string("7FFFFFFF"), integerToHex(std::numeric_limits<int>::max())); ASSERT_EQUALS(std::string("7FFFFFFFFFFFFFFF"), integerToHex(std::numeric_limits<long long>::max())); ASSERT_EQUALS(std::string("8000000000000000"), integerToHex(std::numeric_limits<long long>::min())); }
void WiredTigerRecoveryUnit::_txnClose(bool commit) { invariant(_isActive(), toString(_state)); WT_SESSION* s = _session->getSession(); if (_timer) { const int transactionTime = _timer->millis(); // `serverGlobalParams.slowMs` can be set to values <= 0. In those cases, give logging a // break. if (transactionTime >= std::max(1, serverGlobalParams.slowMS)) { LOG(kSlowTransactionSeverity) << "Slow WT transaction. Lifetime of SnapshotId " << _mySnapshotId << " was " << transactionTime << "ms"; } } int wtRet; if (commit) { if (!_commitTimestamp.isNull()) { const std::string conf = "commit_timestamp=" + integerToHex(_commitTimestamp.asULL()); invariantWTOK(s->timestamp_transaction(s, conf.c_str())); _isTimestamped = true; } wtRet = s->commit_transaction(s, nullptr); LOG(3) << "WT commit_transaction for snapshot id " << _mySnapshotId; } else { wtRet = s->rollback_transaction(s, nullptr); invariant(!wtRet); LOG(3) << "WT rollback_transaction for snapshot id " << _mySnapshotId; } if (_isTimestamped) { if (!_orderedCommit) { // We only need to update oplog visibility where commits can be out-of-order with // respect to their assigned optime and such commits might otherwise be visible. // This should happen only on primary nodes. _oplogManager->triggerJournalFlush(); } _isTimestamped = false; } invariantWTOK(wtRet); invariant(!_lastTimestampSet || _commitTimestamp.isNull(), str::stream() << "Cannot have both a _lastTimestampSet and a " "_commitTimestamp. _lastTimestampSet: " << _lastTimestampSet->toString() << ". _commitTimestamp: " << _commitTimestamp.toString()); // We reset the _lastTimestampSet between transactions. Since it is legal for one // transaction on a RecoveryUnit to call setTimestamp() and another to call // setCommitTimestamp(). _lastTimestampSet = boost::none; _prepareTimestamp = Timestamp(); _mySnapshotId = nextSnapshotId.fetchAndAdd(1); _isOplogReader = false; _orderedCommit = true; // Default value is true; we assume all writes are ordered. }
void WiredTigerRecoveryUnit::prepareUnitOfWork() { invariant(_inUnitOfWork(), toString(_state)); invariant(!_prepareTimestamp.isNull()); auto session = getSession(); WT_SESSION* s = session->getSession(); LOG(1) << "preparing transaction at time: " << _prepareTimestamp; const std::string conf = "prepare_timestamp=" + integerToHex(_prepareTimestamp.asULL()); // Prepare the transaction. invariantWTOK(s->prepare_transaction(s, conf.c_str())); }
void BSONObj::_assertInvalid() const { StringBuilder ss; int os = objsize(); ss << "BSONObj size: " << os << " (0x" << integerToHex( os ) << ") is invalid. " << "Size must be between 0 and " << BSONObjMaxInternalSize << "(" << ( BSONObjMaxInternalSize/(1024*1024) ) << "MB)"; try { BSONElement e = firstElement(); ss << " First element: " << e.toString(); } catch ( ... ) { } massert( 10334 , ss.str() , 0 ); }
bool Extent::validates(const DiskLoc diskLoc, vector<string>* errors) const { bool extentOk = true; if (magic != extentSignature) { if (errors) { StringBuilder sb; sb << "bad extent signature " << integerToHex(magic) << " in extent " << diskLoc.toString(); errors->push_back( sb.str() ); } extentOk = false; } if (myLoc != diskLoc) { if (errors) { StringBuilder sb; sb << "extent " << diskLoc.toString() << " self-pointer is " << myLoc.toString(); errors->push_back( sb.str() ); } extentOk = false; } if (firstRecord.isNull() != lastRecord.isNull()) { if (errors) { StringBuilder sb; if (firstRecord.isNull()) { sb << "in extent " << diskLoc.toString() << ", firstRecord is null but lastRecord is " << lastRecord.toString(); } else { sb << "in extent " << diskLoc.toString() << ", firstRecord is " << firstRecord.toString() << " but lastRecord is null"; } errors->push_back( sb.str() ); } extentOk = false; } static const int minSize = 0x1000; if (length < minSize) { if (errors) { StringBuilder sb; sb << "length of extent " << diskLoc.toString() << " is " << length << ", which is less than minimum length of " << minSize; errors->push_back( sb.str() ); } extentOk = false; } return extentOk; }
bool Extent::validates(const DiskLoc diskLoc, BSONArrayBuilder* errors) { bool extentOk = true; if (magic != extentSignature) { if (errors) { StringBuilder sb; sb << "bad extent signature " << integerToHex(magic) << " in extent " << diskLoc.toString(); *errors << sb.str(); } extentOk = false; } if (myLoc != diskLoc) { if (errors) { StringBuilder sb; sb << "extent " << diskLoc.toString() << " self-pointer is " << myLoc.toString(); *errors << sb.str(); } extentOk = false; } if (firstRecord.isNull() != lastRecord.isNull()) { if (errors) { StringBuilder sb; if (firstRecord.isNull()) { sb << "in extent " << diskLoc.toString() << ", firstRecord is null but lastRecord is " << lastRecord.toString(); } else { sb << "in extent " << diskLoc.toString() << ", firstRecord is " << firstRecord.toString() << " but lastRecord is null"; } *errors << sb.str(); } extentOk = false; } if (length < minSize()) { if (errors) { StringBuilder sb; sb << "length of extent " << diskLoc.toString() << " is " << length << ", which is less than minimum length of " << minSize(); *errors << sb.str(); } extentOk = false; } return extentOk; }
Status WiredTigerRecoveryUnit::setTimestamp(Timestamp timestamp) { _ensureSession(); LOG(3) << "WT set timestamp of future write operations to " << timestamp; WT_SESSION* session = _session->getSession(); invariant(_inUnitOfWork(), toString(_state)); invariant(_prepareTimestamp.isNull()); invariant(_commitTimestamp.isNull(), str::stream() << "Commit timestamp set to " << _commitTimestamp.toString() << " and trying to set WUOW timestamp to " << timestamp.toString()); _lastTimestampSet = timestamp; // Starts the WT transaction associated with this session. getSession(); const std::string conf = "commit_timestamp=" + integerToHex(timestamp.asULL()); auto rc = session->timestamp_transaction(session, conf.c_str()); if (rc == 0) { _isTimestamped = true; } return wtRCToStatus(rc, "timestamp_transaction"); }
DiskLoc Extent::_reuse(const char *nsname, bool capped) { LOG(3) << "_reuse extent was:" << nsDiagnostic.toString() << " now:" << nsname << endl; if (magic != extentSignature) { StringBuilder sb; sb << "bad extent signature " << integerToHex(magic) << " for namespace '" << nsDiagnostic.toString() << "' found in Extent::_reuse"; msgasserted(10360, sb.str()); } nsDiagnostic = nsname; markEmpty(); DiskLoc emptyLoc; int delRecLength; extent_getEmptyLoc(nsname, myLoc, length, capped, emptyLoc, delRecLength); // todo: some dup code here and below in Extent::init DeletedRecord* empty = getDur().writing(DataFileMgr::getDeletedRecord(emptyLoc)); empty->lengthWithHeaders() = delRecLength; empty->extentOfs() = myLoc.getOfs(); empty->nextDeleted().Null(); return emptyLoc; }
string integerToHex(long long value) { char buf[sizeof(long long) * 2 + 1]; integerToHex(value, buf); return string(buf); }