void RocksRecoveryUnit::_commit() { invariant(_writeBatch); for (auto pair : _deltaCounters) { auto& counter = pair.second; counter._value->fetch_add(counter._delta, std::memory_order::memory_order_relaxed); long long newValue = counter._value->load(std::memory_order::memory_order_relaxed); // TODO: make the encoding platform indepdent. const char* nr_ptr = reinterpret_cast<char*>(&newValue); writeBatch()->Put(pair.first, rocksdb::Slice(nr_ptr, sizeof(long long))); } if (_writeBatch->GetWriteBatch()->Count() != 0) { // Order of operations here is important. It needs to be synchronized with // _transaction.recordSnapshotId() and _db->GetSnapshot() and rocksdb::WriteOptions writeOptions; writeOptions.disableWAL = !_durable; auto status = _db->Write(rocksdb::WriteOptions(), _writeBatch->GetWriteBatch()); if (!status.ok()) { log() << "uh oh: " << status.ToString(); invariant(!"rocks write batch commit failed"); } _transaction.commit(); } _deltaCounters.clear(); _writeBatch.reset(); }
bool WriteCmd::run(const string& dbName, BSONObj& cmdObj, int options, string& errMsg, BSONObjBuilder& result, bool fromRepl) { verify(!fromRepl); // Can't be run on secondaries (logTheOp() == false, slaveOk() == false). if (cmdObj.firstElementType() != mongo::String) { errMsg = "expected string type for collection name"; return false; } string ns = parseNs(dbName, cmdObj); if (!NamespaceString(ns).isValid()) { errMsg = mongoutils::str::stream() << "invalid namespace: \"" << ns << "\""; return false; } { // Commands with locktype == NONE need to acquire a Context in order to set // CurOp::_ns. Setting a CurOp's namespace is necessary for higher-level // functionality (e.g. profiling) to operate on the correct database (note that // WriteBatchExecutor doesn't do this for us, since its job is to create child CurOp // objects and operate on them). // // Acquire ReadContext momentarily, for satisfying this purpose. Client::ReadContext ctx(dbName + ".$cmd"); } WriteBatch writeBatch(ns, _writeType); if (!writeBatch.parse(cmdObj, &errMsg)) { return false; } WriteBatchExecutor writeBatchExecutor(&cc(), &globalOpCounters, lastError.get()); return writeBatchExecutor.executeBatch(writeBatch, &errMsg, &result); }
void BatchWriter::performScheduledTask () { writeBatch (); }