void grabLock() { DBRM dbrm; uint64_t id; vector<uint> pmlist; string name = "init"; uint32_t pid = 1; int32_t sid = 5678; pmlist.push_back(1); try { id = dbrm.getTableLock(pmlist, 1234, &name, &pid, &sid, &sid, LOADING); } catch (exception &e) { cout << "caught an exception: " << e.what() << endl; exit(1); } cout << "lock ID = " << id << endl; if (id == 0) cout << " existing owner name = " << name << " pid = " << pid << " session = " << sid << endl; }
void *DBRM_deadlock(void *arg) { DBRM dbrm; int terr; VER_t txn = 2; vector<LBIDRange> ranges; LBIDRange range; vector<VBRange> freeList; range.start = 2000; range.size = 1000; ranges.push_back(range); terr = dbrm.beginVBCopy(txn, ranges, freeList); range.start = 1000; range.size = 1000; ranges.clear(); freeList.clear(); ranges.push_back(range); terr = dbrm.beginVBCopy(txn, ranges, freeList); // block waiting on the main thread, main thread deadlocks, rolls back, // thread wakes CPPUNIT_ASSERT(terr == 0); terr = dbrm.endVBCopy(txn, ranges); CPPUNIT_ASSERT(terr == 0); terr = dbrm.vbCommit(txn); CPPUNIT_ASSERT(terr == 0); return NULL; }
//------------------------------------------------------------------------------ // Test delivery of a single numeric column //------------------------------------------------------------------------------ void deliveryStep_1() //number column { DistributedEngineComm* dec; CalpontSystemCatalog *cat; ResourceManager rm; dec = DistributedEngineComm::instance(rm); cat = CalpontSystemCatalog::makeCalpontSystemCatalog(1); DBRM dbrm; uint32_t uniqueID = dbrm.getUnique32(); dec->addQueue(uniqueID); JobStepAssociation inJs; AnyDataListSPtr spdl1(new AnyDataList()); FIFO<UintRowGroup>* dl1 = new FIFO<UintRowGroup>(1,100); addElements(dl1); spdl1->fifoDL(dl1); inJs.outAdd(spdl1); DeliveryStep dstep(inJs, JobStepAssociation(), make_table(schema, table), cat, 1, 1, 1, flushInterval); runStep(dstep, string("deliveryStep_1")); dec->removeQueue(uniqueID); }
bool filterWithDictionary(execplan::erydbSystemCatalog::OID dictOid, uint64_t n) { // if n == 0, no dictionary scan, alway filter with dictionary. if (n == 0) return true; // if n == ulong_max, always use dictionary scan if (n == ULONG_MAX) return false; vector<struct EMEntry> entries; DBRM dbrm; if (dbrm.getExtents(dictOid, entries) != 0) return false; // Just do pdictionaryscan and let job step handle this. vector<struct EMEntry>::iterator it = entries.begin(); bool ret = false; n--; // HWM starts at 0 while (it != entries.end()) { if (it->HWM > n) { ret = true; break; } it++; } return ret; }
void BCTest::setUp() { LBIDRange_v r; HWM_t hwm; OID_t oid=1000; extentSize = dbrm.getExtentSize(); maxBlocksAvailable=0; int i=0; fExtentSize=dbrm.getExtentSize(); while ( oid < 5000 ) { int ret=0; ret = dbrm.lookup(oid, r); if (ret==0 && r.size()>0) { dbrm.getHWM(oid, hwm); maxBlocksAvailable+=(r.size()*extentSize); OidRanges_t oid_range(oid, hwm, r); OidRangesList.push_back(oid_range); //cout << "Setup i: " << i++ << " o: " << oid // << " r: " << ret << " s: " << r.size() // << " m: " << maxBlocksAvailable // << endl; hwm=0; r.clear(); } oid++; } //cout << "\t" << OidRangesList.size() << " oid ranges loaded " << endl << endl; i=0; } // setUp()
void sessionmanager_1() { DBRM dbrm; int tmp = -1; tmp = dbrm.verID(); // there's no "correct" value b/c it's monotonically increasing. }
//------------------------------------------------------------------------------ // Test delivery of multiple (numCols) numeric columns //------------------------------------------------------------------------------ void deliverTest(int numCols) { DistributedEngineComm* dec; CalpontSystemCatalog *cat; ResourceManager rm; dec = DistributedEngineComm::instance(rm); cat = CalpontSystemCatalog::makeCalpontSystemCatalog(1); // Get the oid for the first column in the table - usually lineitem.l_orderkey. CalpontSystemCatalog::TableName tableName = make_table(schema, colstable); CalpontSystemCatalog::ROPair p = cat->tableRID(tableName); startingOid = p.objnum + 1; int startingOid = 3416; // Oid for lineitem.l_orderkey on your database. DBRM dbrm; uint32_t uniqueID = dbrm.getUnique32(); dec->addQueue(uniqueID); JobStepAssociation inJs; stringstream ss; pthread_t threads[ numCols ]; for (int i = 0; i < numCols; ++i) { AnyDataListSPtr spdl1(new AnyDataList()); // Make FIFO big enough to contain the elements for a flush interval FIFO<UintRowGroup>* dl1 = new FIFO<UintRowGroup>(1, fifoSize); // BandedDL<ElementType>* dl1 = new BandedDL<ElementType>(1); dl1->OID(i+startingOid); // lineitem first col object id spdl1->fifoDL(dl1); // spdl1->bandedDL(dl1); inJs.outAdd(spdl1); pthread_create(&threads[i], 0, addElementsThreadWrapper, dl1 ); } DeliveryStep dstep(inJs, JobStepAssociation(), tableName, cat, 12345, 1, 1, flushInterval); ss << "DeliverStep test for " << numCols; string message = ss.str(); runStep(dstep, ss.str()); for (int i = 0; i < numCols; ++i) { pthread_join(threads[i], 0); } dec->removeQueue(uniqueID); }
void FileBufferMgr::flushPartition(const vector<OID_t> &oids, const set<BRM::LogicalPartition> &partitions) { DBRM dbrm; uint32_t i; vector<EMEntry> extents; int err; uint32_t currentExtent; LBID_t currentLBID; typedef tr1::unordered_multimap<LBID_t, filebuffer_uset_t::iterator> byLBID_t; byLBID_t byLBID; pair<byLBID_t::iterator, byLBID_t::iterator> itList; filebuffer_uset_t::iterator it; uint32_t count = oids.size(); mutex::scoped_lock lk(fWLock); if (fCacheSize == 0 || oids.size() == 0 || partitions.size() == 0) return; /* Index the cache by LBID */ for (it = fbSet.begin(); it != fbSet.end(); it++) byLBID.insert(pair<LBID_t, filebuffer_uset_t::iterator>(it->lbid, it)); for (i = 0; i < count; i++) { extents.clear(); err = dbrm.getExtents(oids[i], extents, true, true,true); // @Bug 3838 Include outofservice extents if (err < 0) { lk.unlock(); flushCache(); // better than returning an error code to the user return; } for (currentExtent = 0; currentExtent < extents.size(); currentExtent++) { EMEntry &range = extents[currentExtent]; LogicalPartition logicalPartNum(range.dbRoot, range.partitionNum, range.segmentNum); if (partitions.find(logicalPartNum) == partitions.end()) continue; LBID_t lastLBID = range.range.start + (range.range.size * 1024); for (currentLBID = range.range.start; currentLBID < lastLBID; currentLBID++) { itList = byLBID.equal_range(currentLBID); for (byLBID_t::iterator tmpIt = itList.first; tmpIt != itList.second; tmpIt++) { fbList.erase(fFBPool[tmpIt->second->poolIdx].listLoc()); fEmptyPoolSlots.push_back(tmpIt->second->poolIdx); fbSet.erase(tmpIt->second); fCacheSize--; } } } } }
void FileBufferMgr::flushOIDs(const uint32_t *oids, uint32_t count) { DBRM dbrm; uint32_t i; vector<EMEntry> extents; int err; uint32_t currentExtent; LBID_t currentLBID; typedef tr1::unordered_multimap<LBID_t, filebuffer_uset_t::iterator> byLBID_t; byLBID_t byLBID; pair<byLBID_t::iterator, byLBID_t::iterator> itList; filebuffer_uset_t::iterator it; // If there are more than this # of extents to drop, the whole cache will be cleared const uint32_t clearThreshold = 50000; mutex::scoped_lock lk(fWLock); if (fCacheSize == 0 || count == 0) return; /* Index the cache by LBID */ for (it = fbSet.begin(); it != fbSet.end(); it++) byLBID.insert(pair<LBID_t, filebuffer_uset_t::iterator>(it->lbid, it)); for (i = 0; i < count; i++) { extents.clear(); err = dbrm.getExtents(oids[i], extents, true,true,true); // @Bug 3838 Include outofservice extents if (err < 0 || (i == 0 && (extents.size() * count) > clearThreshold)) { // (The i == 0 should ensure it's not a dictionary column) lk.unlock(); flushCache(); return; } for (currentExtent = 0; currentExtent < extents.size(); currentExtent++) { EMEntry &range = extents[currentExtent]; LBID_t lastLBID = range.range.start + (range.range.size * 1024); for (currentLBID = range.range.start; currentLBID < lastLBID; currentLBID++) { itList = byLBID.equal_range(currentLBID); for (byLBID_t::iterator tmpIt = itList.first; tmpIt != itList.second; tmpIt++) { fbList.erase(fFBPool[tmpIt->second->poolIdx].listLoc()); fEmptyPoolSlots.push_back(tmpIt->second->poolIdx); fbSet.erase(tmpIt->second); fCacheSize--; } } } } }
void printTxnIDs() { DBRM brm; set<VER_t> txnList; set<VER_t>::iterator it; int err; err = brm.getCurrentTxnIDs(txnList); if (err != 0) return; for (it = txnList.begin(); it != txnList.end(); it++) cout << *it << endl; }
void releaseAllLocks() { DBRM dbrm; try { dbrm.releaseAllTableLocks(); } catch (exception &e) { cout << "caught an exception: " << e.what() << endl; exit(1); } cout << "OK\n"; }
void rollbackTxn(VER_t txnID) { DBRM brm; vector<LBID_t> lbidList; int err; err = brm.getUncommittedLBIDs(txnID, lbidList); if (err != 0) return; err = brm.vbRollback(txnID, lbidList); if (err != 0) return; cout << "OK." << endl; }
void sessionmanager_2() { DBRM dbrm; SessionManagerServer::TxnID tmp; int ver1, ver2; ver1 = dbrm.verID(); tmp = dbrm.newTxnID(1000, true); ver2 = dbrm.verID(); CPPUNIT_ASSERT(ver2 == ver1 + 1); CPPUNIT_ASSERT(ver2 == tmp.id); CPPUNIT_ASSERT(tmp.valid == true); dbrm.committed(tmp); CPPUNIT_ASSERT(tmp.valid == false); }
void sessionmanager_3() { DBRM dbrm; SessionManagerServer::TxnID txn, txn2; txn = dbrm.newTxnID(1000, true); txn2 = dbrm.getTxnID(1000); CPPUNIT_ASSERT(txn.id == txn2.id); CPPUNIT_ASSERT(txn.valid == txn2.valid == true); dbrm.rolledback(txn); CPPUNIT_ASSERT(txn.valid == false); txn2 = dbrm.getTxnID(1000); CPPUNIT_ASSERT(txn2.valid == false); }
void brm_dumb_1() { DBRM brm; vector<LBID_t> lbids; int allocdSize, err; const uint32_t extentSize = brm.getExtentSize(); err = brm.createExtent(extentSize, 1, lbids, allocdSize); CPPUNIT_ASSERT(err == 0); err = brm.markExtentInvalid(lbids[0]); CPPUNIT_ASSERT(err == 0); int64_t min; int64_t max; int32_t seq; err = brm.getExtentMaxMin(lbids[0], max, min, seq); #ifdef SAFE_CP CPPUNIT_ASSERT(err == 0); #else CPPUNIT_ASSERT(err == 1); #endif err = brm.setExtentMaxMin(lbids[0], max, min, seq); CPPUNIT_ASSERT(err == 0); err = brm.deleteOID(1); CPPUNIT_ASSERT(err == 0); }
void sessionmanager_4() { DBRM dbrm; SessionManagerServer::TxnID txn, txn2; const SessionManagerServer::SIDTIDEntry *stmap; int len; txn = dbrm.newTxnID(1000, true); txn2 = dbrm.newTxnID(1001, true); stmap = dbrm.SIDTIDMap(len); CPPUNIT_ASSERT(len == 2); #ifdef BRM_VERBOSE int i; cerr << "len = " << len << endl; for (i = 0; i < len; i++) { cerr << " " << i << ": txnid=" << stmap[i].txnid.id << " valid=" << stmap[i].txnid.valid << " sessionid=" << stmap[i].sessionid << endl; } #endif dbrm.committed(txn); dbrm.committed(txn2); delete [] stmap; stmap = dbrm.SIDTIDMap(len); CPPUNIT_ASSERT(len == 0); delete [] stmap; }
void brm_markExtentsInvalid() { DBRM brm; int i, err, allocdSize, iterations = 100; // (EM_INITIAL_SIZE + 3*EM_INCREMENT) vector<LBID_t> lbids; int64_t min, max; int32_t seqNum; const uint32_t extentSize = brm.getExtentSize(); cerr << "brm_markExtentsInvalid" << endl; err = brm.createExtent(extentSize * iterations, 1, lbids, allocdSize); CPPUNIT_ASSERT(lbids.size() == iterations); CPPUNIT_ASSERT(err == 0); // mark all extents valid for (i = 0; i < iterations; i++) { err = brm.setExtentMaxMin(lbids[i], 1, 0, 0); CPPUNIT_ASSERT(err == 0); } err = brm.markExtentsInvalid(lbids); CPPUNIT_ASSERT(err == 0); // check that they are all invalid/updating/whatever. // != CP_VALID is what we're looking for for (i = 0; i < iterations; i++) { err = brm.getExtentMaxMin(lbids[i], max, min, seqNum); CPPUNIT_ASSERT(err == CP_UPDATING); } // cleanup err = brm.deleteOID(1); }
/* This test verifies that deleteOID returns an error for non-existant OIDs (bug #105) */ void brm_deleteOID() { DBRM brm; int err; vector<EMEntry> extents; cerr << "brm_deleteOID" << endl; err = brm.getExtents(1, extents); #ifdef BRM_DEBUG if (err == 0) cerr << "Make sure OID 1 isn't allocated in the extent map" << endl; #endif CPPUNIT_ASSERT(err != 0); CPPUNIT_ASSERT(extents.empty()); err = brm.deleteOID(1); CPPUNIT_ASSERT(err != 0); }
void printAllLocks() { DBRM dbrm; vector<TableLockInfo> locks; uint i; try { locks = dbrm.getAllTableLocks(); } catch (exception &e) { cout << "caught an exception: " << e.what() << endl; exit(1); } cout << "got " << locks.size() << " locks\n"; for (i = 0; i < locks.size(); i++) cout << " lock[" << i << "] id=" << locks[i].id << " tableOID=" << locks[i].tableOID << " owner: " << locks[i].ownerName << ":" << locks[i].ownerPID << ":" << locks[i].ownerSessionID << " " << ctime(&locks[i].creationTime) << endl; }
void getLockInfo(uint64_t id) { DBRM dbrm; bool ret; TableLockInfo tli; try { ret = dbrm.getTableLockInfo(id, &tli); } catch (exception &e) { cout << "caught an exception: " << e.what() << endl; exit(1); } if (ret) cout << "id=" << tli.id << " tableOID=" << tli.tableOID << " owner: " << tli.ownerName << ":" << tli.ownerPID << ":" << tli.ownerSessionID << endl; else cout << "failed\n"; }
void changeState(uint64_t id) { DBRM dbrm; bool ret; cout << "changing state of lock " << id << endl; try { ret = dbrm.changeState(id, CLEANUP); } catch (exception &e) { cout << "caught an exception: " << e.what() << endl; exit(1); } if (ret) cout << "success\n"; else cout << "failed\n"; }
void releaseLock(uint64_t id) { DBRM dbrm; bool ret; cout << "releasing lock " << id << endl; try { ret = dbrm.releaseTableLock(id); } catch (exception &e) { cout << "caught an exception: " << e.what() << endl; exit(1); } if (ret) cout << "success\n"; else cout << "failed\n"; }
void brm_HWM() { DBRM brm; int err; HWM_t hwm; vector<EMEntry> extents; cerr << "brm_HWM" << endl; err = brm.getExtents(1, extents); #ifdef BRM_DEBUG if (err == 0) cerr << "Make sure OID 1 isn't allocated in the extent map" << endl; #endif CPPUNIT_ASSERT(extents.size() == 0); err = brm.setHWM(1, 10); CPPUNIT_ASSERT(err != 0); err = brm.getHWM(1, hwm); CPPUNIT_ASSERT(err != 0); }
void changeOwner(uint64_t id) { DBRM dbrm; bool ret; cout << "changing owner of lock " << id << endl; try { ret = dbrm.changeOwner(id, "blah blah", 5678, 1234, 9999); } catch (exception &e) { cout << "caught an exception: " << e.what() << endl; exit(1); } if (ret) cout << "success\n"; else cout << "failed\n"; }
void *DBRM_dummy_1(void *arg) { DBRM dbrm; int err; VER_t txn = 2; vector<LBIDRange> ranges; LBIDRange range; vector<VBRange> freeList; range.start = 500; range.size = 1000; ranges.push_back(range); err = dbrm.beginVBCopy(txn, ranges, freeList); CPPUNIT_ASSERT(err == 0); err = dbrm.endVBCopy(txn, ranges); CPPUNIT_ASSERT(err == 0); err = dbrm.vbCommit(txn); CPPUNIT_ASSERT(err == 0); return NULL; }
int DDLProcessor::commitTransaction(uint32_t txnID, std::string & errorMsg) { fWEClient = new WriteEngine::WEClients(WriteEngine::WEClients::DDLPROC); fPMCount = fWEClient->getPmCount(); ByteStream bytestream; DBRM dbrm; uint64_t uniqueId = dbrm.getUnique64(); fWEClient->addQueue(uniqueId); bytestream << (ByteStream::byte)WE_SVR_COMMIT_VERSION; bytestream << uniqueId; bytestream << txnID; uint32_t msgRecived = 0; fWEClient->write_to_all(bytestream); boost::shared_ptr<messageqcpp::ByteStream> bsIn; bsIn.reset(new ByteStream()); int rc = 0; ByteStream::byte tmp8; while (1) { if (msgRecived == fPMCount) break; fWEClient->read(uniqueId, bsIn); if ( bsIn->length() == 0 ) //read error { rc = 1; errorMsg = "DDL cannot communicate with WES"; fWEClient->removeQueue(uniqueId); break; } else { *bsIn >> tmp8; rc = tmp8; if (rc != 0) { *bsIn >> errorMsg; fWEClient->removeQueue(uniqueId); break; } else msgRecived++; }
void DBRM_resource_graph_1() { DBRM dbrm; pthread_t t; VER_t txn = 1; int err, allocSize; LBIDRange range; vector<LBID_t> lbids; vector<LBIDRange> ranges; vector<VBRange> freeList; err = dbrm.createExtent(8000, 1, lbids, allocSize); CPPUNIT_ASSERT(err == 0); range.start = 1000; range.size = 1000; ranges.push_back(range); err = dbrm.beginVBCopy(txn, ranges, freeList); CPPUNIT_ASSERT(err == 0); pthread_create(&t, NULL, DBRM_dummy_1, NULL); sleep(1); // thread tries to grab 500-1500, blocks err = dbrm.endVBCopy(txn, ranges); CPPUNIT_ASSERT(err == 0); err = dbrm.vbCommit(txn); CPPUNIT_ASSERT(err == 0); dbrm.deleteOID(1); //thread finishes pthread_join(t, NULL); }
// cut & pasted from brm_good_2(), but with rollback instead of commit. void brm_good_3() { DBRM brm; VBBM vbbm; VSS vss; CopyLocks cl; int i, err, size; vector<LBID_t> lbids; vector<LBID_t>::iterator lbid; vector<EMEntry> extents; LBIDRange_v ranges; LBIDRange_v::iterator lbidRangeIT; VBRange_v vbRanges, vbRanges2; VBRange_v::iterator vbRangesIT; LBIDRange_v tmp; EMEntry em; OID_t oid; uint32_t fbo; LBIDRange range; VBRange vbRange; VER_t verID; bool vbFlag; bool caughtException; // Buildbot times out on the getBlocks() call during leakcheck b/c it takes // > 5 mins for some reason. Have to ping it before 300 seconds go by. void (*oldsig)(int); cerr << "brm_good_3" << endl; oldsig = signal(SIGALRM, keepalive); alarm(290); err = brm.lookup(0, 0, false, oid, fbo); CPPUNIT_ASSERT(err != 0); err = brm.lookup(0, 0, true, oid, fbo); CPPUNIT_ASSERT(err != 0); err = brm.createExtent(8000, 1, lbids, size); CPPUNIT_ASSERT(err == 0); CPPUNIT_ASSERT(size == brm.getExtentSize()); CPPUNIT_ASSERT(lbids.size() == 1); CPPUNIT_ASSERT(*(lbids.begin()) == 0); err = brm.getExtents(1, extents); CPPUNIT_ASSERT(err == 0); CPPUNIT_ASSERT(extents.size() == 1); em = *(extents.begin()); CPPUNIT_ASSERT(em.range.start == 0); CPPUNIT_ASSERT(em.range.size*1024 == static_cast<uint32_t>(brm.getExtentSize())); CPPUNIT_ASSERT(em.HWM == 0); CPPUNIT_ASSERT(em.blockOffset == 0); for (i = 0; i < 5; i++) { range.start = i * 100; range.size = 100; ranges.push_back(range); } CPPUNIT_ASSERT(brm.checkConsistency() == 0); err = brm.beginVBCopy(1, ranges, vbRanges); CPPUNIT_ASSERT(err == 0); CPPUNIT_ASSERT(brm.checkConsistency() == 0); cl.lock(CopyLocks::READ); for (lbidRangeIT = ranges.begin(); lbidRangeIT != ranges.end(); lbidRangeIT++) CPPUNIT_ASSERT(cl.isLocked(*lbidRangeIT)); cl.release(CopyLocks::READ); err = brm.beginVBCopy(1, ranges, vbRanges2); CPPUNIT_ASSERT(err != 0); CPPUNIT_ASSERT(brm.checkConsistency() == 0); cl.lock(CopyLocks::READ); for (lbidRangeIT = ranges.begin(); lbidRangeIT != ranges.end(); lbidRangeIT++) CPPUNIT_ASSERT(cl.isLocked(*lbidRangeIT)); cl.release(CopyLocks::READ); for (i = 0; i < 500; i++) { verID = MAXINT; err = brm.vssLookup(i, verID, 1, vbFlag); CPPUNIT_ASSERT(err != 0); } vbRange = *(vbRanges.begin()); // CPPUNIT_ASSERT(vbRange.vbFBO == 0); for (i = 0; i < (int)vbRange.size; i++) { err = brm.writeVBEntry(1, i, vbRange.vbOID, vbRange.vbFBO + i); CPPUNIT_ASSERT(err == 0); } CPPUNIT_ASSERT(brm.checkConsistency() == 0); for (i = 0; i < (int)vbRange.size; i++) { verID = MAXINT; err = brm.vssLookup(i, verID, 1, vbFlag); CPPUNIT_ASSERT(err == 0); CPPUNIT_ASSERT(verID == 1); CPPUNIT_ASSERT(vbFlag == false); verID = MAXINT; err = brm.vssLookup(i, verID, 0, vbFlag); CPPUNIT_ASSERT(err == 0); CPPUNIT_ASSERT(verID == 0); CPPUNIT_ASSERT(vbFlag == true); } for (; i < 500; i++) { verID = MAXINT; err = brm.vssLookup(i, verID, 1, vbFlag); CPPUNIT_ASSERT(err != 0); } err = brm.endVBCopy(0, ranges); CPPUNIT_ASSERT(brm.checkConsistency() == 0); cl.lock(CopyLocks::READ); for (lbidRangeIT = ranges.begin(); lbidRangeIT != ranges.end(); lbidRangeIT++) CPPUNIT_ASSERT(!cl.isLocked(*lbidRangeIT)); cl.release(CopyLocks::READ); err = brm.getUncommittedLBIDs(1, lbids); CPPUNIT_ASSERT(err == 0); CPPUNIT_ASSERT(lbids.size() == vbRange.size); sort<vector<LBID_t>::iterator>(lbids.begin(), lbids.end()); lbid = lbids.begin(); for (i = 0; i < static_cast<int>(lbids.size()); i++, lbid++) CPPUNIT_ASSERT((*lbid) == static_cast<LBID_t>(i)); range.start = 0; range.size = i; tmp.push_back(range); err = brm.vbRollback(1, tmp); CPPUNIT_ASSERT(err == 0); CPPUNIT_ASSERT(brm.checkConsistency() == 0); for (i = 0; i < (int)vbRange.size; i++) { verID = MAXINT; err = brm.vssLookup(i, verID, 0, vbFlag); CPPUNIT_ASSERT(err == 0); CPPUNIT_ASSERT(verID == 0); CPPUNIT_ASSERT(vbFlag == false); err = brm.lookup(i, verID, vbFlag, oid, fbo); CPPUNIT_ASSERT(err == 0); CPPUNIT_ASSERT(oid == 1); CPPUNIT_ASSERT(fbo == static_cast<uint32_t>(i)); vbbm.lock(VBBM::WRITE); vss.lock(VSS::WRITE); #ifdef BRM_DEBUG caughtException = false; try { vbbm.removeEntry(i, verID); vbbm.confirmChanges(); } catch (logic_error &e) { vbbm.undoChanges(); caughtException = true; } CPPUNIT_ASSERT(caughtException); caughtException = false; try { vss.removeEntry(i, 1); vss.confirmChanges(); } catch (logic_error &e) { vss.undoChanges(); caughtException = true; } CPPUNIT_ASSERT(caughtException); #endif vss.removeEntry(i, verID); vss.confirmChanges(); vss.release(VSS::WRITE); vbbm.release(VBBM::WRITE); } CPPUNIT_ASSERT(brm.checkConsistency() == 0); brm.deleteOID(1); vbbm.lock(VBBM::READ); vss.lock(VSS::READ); CPPUNIT_ASSERT(vbbm.size() == 0); CPPUNIT_ASSERT(vbbm.hashEmpty()); CPPUNIT_ASSERT(vss.size() == 0); CPPUNIT_ASSERT(vss.hashEmpty()); vss.release(VSS::READ); vbbm.release(VBBM::READ); CPPUNIT_ASSERT(brm.checkConsistency() == 0); err = brm.saveState(); CPPUNIT_ASSERT(err==0); }
void dbrm_clear() { DBRM dbrm; VSS vss; VBBM vbbm; int err, vssShmid, vbbmShmid, txnID = 1, i; struct shmid_ds vssShminfo[3], vbbmShminfo[3]; LBIDRange_v ranges; LBIDRange range; VBRange_v freelist; err = dbrm.clear(); CPPUNIT_ASSERT(err == ERR_OK); // grab the size of vss and vbbm shmsegs somehow vss.lock(VSS::READ); vbbm.lock(VBBM::READ); vssShmid = vss.getShmid(); vbbmShmid = vbbm.getShmid(); err = shmctl(vssShmid, IPC_STAT, &vssShminfo[0]); CPPUNIT_ASSERT(err == 0); err = shmctl(vbbmShmid, IPC_STAT, &vbbmShminfo[0]); CPPUNIT_ASSERT(err == 0); vss.release(VSS::READ); vbbm.release(VBBM::READ); // do begin, write, end vbcopy for 150k blocks cerr << endl << "Adding 150k block entries. "; range.start = 1; range.size = 150000; ranges.push_back(range); err = dbrm.beginVBCopy(txnID, ranges, freelist); CPPUNIT_ASSERT(err == 0); for (i = range.start; (uint32_t) i < range.size; i++) { if (i % 50000 == 0) cerr << " ... " << i; err = dbrm.writeVBEntry(txnID, i, 1, i); CPPUNIT_ASSERT(err == 0); } err = dbrm.endVBCopy(txnID, ranges); CPPUNIT_ASSERT(err == 0); cerr << " done." << endl; // grab the sizes again vss.lock(VSS::READ); vbbm.lock(VBBM::READ); vssShmid = vss.getShmid(); vbbmShmid = vbbm.getShmid(); err = shmctl(vssShmid, IPC_STAT, &vssShminfo[1]); CPPUNIT_ASSERT(err == 0); err = shmctl(vbbmShmid, IPC_STAT, &vbbmShminfo[1]); CPPUNIT_ASSERT(err == 0); vss.release(VSS::READ); vbbm.release(VBBM::READ); // make sure they grew CPPUNIT_ASSERT(vssShminfo[0].shm_segsz < vssShminfo[1].shm_segsz); CPPUNIT_ASSERT(vbbmShminfo[0].shm_segsz < vbbmShminfo[1].shm_segsz); dbrm.clear(); // check that the new size is the same as the original vss.lock(VSS::READ); vbbm.lock(VBBM::READ); vssShmid = vss.getShmid(); vbbmShmid = vbbm.getShmid(); err = shmctl(vssShmid, IPC_STAT, &vssShminfo[2]); CPPUNIT_ASSERT(err == 0); err = shmctl(vbbmShmid, IPC_STAT, &vbbmShminfo[2]); CPPUNIT_ASSERT(err == 0); vss.release(VSS::READ); vbbm.release(VBBM::READ); CPPUNIT_ASSERT(vssShminfo[0].shm_segsz == vssShminfo[2].shm_segsz); CPPUNIT_ASSERT(vbbmShminfo[0].shm_segsz == vbbmShminfo[2].shm_segsz); }
void DBRM_resource_graph_deadlock() { DBRM dbrm; pthread_t t; VER_t txn = 1; int err, i; LBIDRange range; vector<LBID_t> lbids; vector<LBIDRange> ranges; vector<VBRange> freeList; range.start = 1000; range.size = 1000; ranges.push_back(range); err = dbrm.beginVBCopy(txn, ranges, freeList); CPPUNIT_ASSERT(err == 0); for (i = range.start; i < range.start + range.size; i++) { err = dbrm.writeVBEntry(txn, i, 1, i); CPPUNIT_ASSERT(err == 0); } err = dbrm.endVBCopy(txn, ranges); CPPUNIT_ASSERT(err == 0); pthread_create(&t, NULL, DBRM_deadlock, NULL); // thread grabs 2000-2999 and 1000-1999 as 2 seperate ranges sleep(1); range.start = 2000; range.size = 1000; ranges.clear(); ranges.push_back(range); err = dbrm.beginVBCopy(txn, ranges, freeList); CPPUNIT_ASSERT(err == ERR_DEADLOCK); // roll back the blocks we "wrote" range.start = 1000; range.size = 1000; ranges.clear(); ranges.push_back(range); err = dbrm.vbRollback(txn, ranges); CPPUNIT_ASSERT(err == ERR_OK); // thread finishes txn = 3; err = dbrm.beginVBCopy(txn, ranges, freeList); CPPUNIT_ASSERT(err == 0); for (i = range.start; i < range.start + range.size; i++) { err = dbrm.writeVBEntry(txn, i, 1, i); CPPUNIT_ASSERT(err == 0); } err = dbrm.endVBCopy(txn, ranges); CPPUNIT_ASSERT(err == 0); err = dbrm.vbRollback(txn, ranges); CPPUNIT_ASSERT(err == 0); pthread_join(t, NULL); }