const ChunkReader* Cache::fetch( const std::string& readerPath, const FetchInfo& fetchInfo) { std::unique_lock<std::mutex> globalLock(m_mutex); DataChunkState& chunkState(*m_chunkManager.at(readerPath).at(fetchInfo.id)); globalLock.unlock(); std::lock_guard<std::mutex> lock(chunkState.mutex); if (!chunkState.chunkReader) { const Reader& reader(fetchInfo.reader); const Metadata& metadata(reader.metadata()); const std::string path(metadata.structure().maybePrefix(fetchInfo.id)); chunkState.chunkReader = makeUnique<ChunkReader>( metadata, fetchInfo.id, fetchInfo.depth, makeUnique<std::vector<char>>( reader.endpoint().getBinary(path))); globalLock.lock(); m_activeBytes += chunkState.chunkReader->size(); } return chunkState.chunkReader.get(); }
Status doTxn(OperationContext* opCtx, const std::string& dbName, const BSONObj& doTxnCmd, BSONObjBuilder* result) { auto txnNumber = opCtx->getTxnNumber(); uassert(ErrorCodes::InvalidOptions, "doTxn can only be run with a transaction ID.", txnNumber); auto txnParticipant = TransactionParticipant::get(opCtx); uassert(ErrorCodes::InvalidOptions, "doTxn must be run within a transaction", txnParticipant); invariant(txnParticipant->inMultiDocumentTransaction()); invariant(opCtx->getWriteUnitOfWork()); uassert( ErrorCodes::InvalidOptions, "doTxn supports only CRUD opts.", _areOpsCrudOnly(doTxnCmd)); auto hasPrecondition = _hasPrecondition(doTxnCmd); // Acquire global lock in IX mode so that the replication state check will remain valid. Lock::GlobalLock globalLock(opCtx, MODE_IX); auto replCoord = repl::ReplicationCoordinator::get(opCtx); bool userInitiatedWritesAndNotPrimary = opCtx->writesAreReplicated() && !replCoord->canAcceptWritesForDatabase(opCtx, dbName); if (userInitiatedWritesAndNotPrimary) return Status(ErrorCodes::NotMaster, str::stream() << "Not primary while applying ops to database " << dbName); int numApplied = 0; try { BSONObjBuilder intermediateResult; // The transaction takes place in a global unit of work, so the precondition check // and the writes will share the same snapshot. if (hasPrecondition) { uassertStatusOK(_checkPrecondition(opCtx, doTxnCmd, result)); } numApplied = 0; uassertStatusOK(_doTxn(opCtx, dbName, doTxnCmd, &intermediateResult, &numApplied)); txnParticipant->commitUnpreparedTransaction(opCtx); result->appendElements(intermediateResult.obj()); } catch (const DBException& ex) { txnParticipant->abortActiveUnpreparedOrStashPreparedTransaction(opCtx); BSONArrayBuilder ab; ++numApplied; for (int j = 0; j < numApplied; j++) ab.append(false); result->append("applied", numApplied); result->append("code", ex.code()); result->append("codeName", ErrorCodes::errorString(ex.code())); result->append("errmsg", ex.what()); result->append("results", ab.arr()); return Status(ErrorCodes::UnknownError, ex.what()); } return Status::OK(); }
/** * Constructor * @param resId MPAL resource to open */ RMRes::RMRes(uint32 resID) { _buf = NULL; _h = g_vm->_resUpdate.queryResource(resID); if (_h == NULL) _h = mpalQueryResource(resID); if (_h != NULL) _buf = (byte *)globalLock(_h); }
TEST_F(SyncTailTest, SyncApplyInsertDocumentCollectionMissing) { { Lock::GlobalWrite globalLock(_txn->lockState()); bool justCreated = false; Database* db = dbHolder().openDb(_txn.get(), "test", &justCreated); ASSERT_TRUE(db); ASSERT_TRUE(justCreated); } _testSyncApplyInsertDocument(MODE_X); }
static bool ClipboardSetData(UINT uFormat, const void *data, size_t size) { NMemory::CGlobal global; if (!global.Alloc(GMEM_DDESHARE | GMEM_MOVEABLE, size)) return false; { NMemory::CGlobalLock globalLock(global); LPVOID p = globalLock.GetPointer(); if (p == NULL) return false; memcpy(p, data, size); } if (::SetClipboardData(uFormat, global) == NULL) return false; global.Detach(); return true; }
MpalHandle RMResUpdate::queryResource(uint32 dwRes) { // If there isn't an update file, return NULL if (!_hFile.isOpen()) return NULL; uint32 i; for (i = 0; i < _numUpd; ++i) if (_infos[i]._dwRes == dwRes) // Found the index break; if (i == _numUpd) // Couldn't find a matching resource, so return NULL return NULL; const ResUpdInfo &info = _infos[i]; byte *cmpBuf = new byte[info._cmpSize]; uint32 dwRead; // Move to the correct offset and read in the compressed data _hFile.seek(info._offset); dwRead = _hFile.read(cmpBuf, info._cmpSize); if (info._cmpSize > dwRead) { // Error occurred reading data, so return NULL delete[] cmpBuf; return NULL; } // Allocate space for the output resource MpalHandle destBuf = globalAllocate(0, info._size); byte *lpDestBuf = (byte *)globalLock(destBuf); uint32 dwSize; // Decompress the data lzo1x_decompress(cmpBuf, info._cmpSize, lpDestBuf, &dwSize); // Delete buffer for compressed data delete [] cmpBuf; // Return the resource globalUnlock(destBuf); return destBuf; }