diff --git a/versioning/BRM/brmtypes.h b/versioning/BRM/brmtypes.h index d3c61c201..76598fc81 100644 --- a/versioning/BRM/brmtypes.h +++ b/versioning/BRM/brmtypes.h @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - + Copyright (C) 2016-2022 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of @@ -295,6 +295,9 @@ class LBIDRange : public messageqcpp::Serializeable uint32_t size; EXPORT LBIDRange(); + LBIDRange(const LBID_t aStart, const uint32_t aSize) : start(aStart), size(aSize) + { + } EXPORT LBIDRange(const LBIDRange& l); EXPORT LBIDRange(const InlineLBIDRange& l); EXPORT LBIDRange& operator=(const LBIDRange& l); diff --git a/versioning/BRM/extentmap.cpp b/versioning/BRM/extentmap.cpp index f02623dfe..bb2ea78ed 100644 --- a/versioning/BRM/extentmap.cpp +++ b/versioning/BRM/extentmap.cpp @@ -523,10 +523,10 @@ LBID_tFindResult ExtentMapIndexImpl::search3dLayer(PartitionIndexContainerT& par bool ExtentMapIndexImpl::isDBRootEmpty(const DBRootT dbroot) { - ExtentMapIndex& extMapIndex = *get(); - if (dbroot >= extMapIndex.size()) - return true; - return extMapIndex[dbroot].empty(); + ExtentMapIndex& extMapIndex = *get(); + if (dbroot >= extMapIndex.size()) + return true; + return extMapIndex[dbroot].empty(); } void ExtentMapIndexImpl::deleteDbRoot(const DBRootT dbroot) @@ -1440,7 +1440,7 @@ void ExtentMap::getCPMaxMin(const BRM::LBID_t lbid, BRM::CPMaxMin& cpMaxMin) auto emIt = findByLBID(lbid); if (emIt == fExtentMapRBTree->end()) throw logic_error("ExtentMap::getMaxMin(): that lbid isn't allocated"); - + auto& emEntry = emIt->second; cpMaxMin.bigMax = emEntry.partition.cprange.bigHiVal; cpMaxMin.bigMin = emEntry.partition.cprange.bigLoVal; @@ -1697,13 +1697,13 @@ void ExtentMap::loadVersion4or5(T* in, bool upgradeV4ToV5) << emEntry.dbRoot << '\t' << emEntry.status << '\t' << emEntry.partition.cprange.hiVal << '\t' << emEntry.partition.cprange.loVal << '\t' << emEntry.partition.cprange.sequenceNum << '\t' << (int)(emEntry.partition.cprange.isValid) << endl; - } + } - cout << "Free list entries:" << endl; - cout << "start\tsize" << endl; + cout << "Free list entries:" << endl; + cout << "start\tsize" << endl; - for (uint32_t i = 0; i < flNumElements; i++) - cout << fFreeList[i].start << '\t' << fFreeList[i].size << endl; + for (uint32_t i = 0; i < flNumElements; i++) + cout << fFreeList[i].start << '\t' << fFreeList[i].size << endl; #endif } @@ -2382,7 +2382,7 @@ int ExtentMap::lookupLocal(LBID_t lbid, int& OID, uint16_t& dbRoot, uint32_t& pa // TODO: Offset logic. auto offset = lbid - emEntry.range.start; fileBlockOffset = emEntry.blockOffset + offset; - + releaseEMIndex(READ); releaseEMEntryTable(READ); return 0; @@ -2471,17 +2471,15 @@ int ExtentMap::lookupLocal_DBroot(int OID, uint16_t dbroot, uint32_t partitionNu grabEMEntryTable(READ); grabEMIndex(READ); - for (auto emIt = fExtentMapRBTree->begin(), end = fExtentMapRBTree->end(); emIt != end; ++emIt) + const auto lbids = fPExtMapIndexImpl_->find(dbroot, OID, partitionNum); + const auto emIdents = getEmIdentsByLbids(lbids); + for (auto& emEntry : emIdents) { - const auto& emEntry = emIt->second; - // TODO: Blockoffset logic. - if (emEntry.fileID == OID && emEntry.dbRoot == dbroot && emEntry.partitionNum == partitionNum && - emEntry.segmentNum == segmentNum && emEntry.blockOffset <= fileBlockOffset && + if (emEntry.segmentNum == segmentNum && emEntry.blockOffset <= fileBlockOffset && fileBlockOffset <= (emEntry.blockOffset + (static_cast(emEntry.range.size) * 1024) - 1)) { auto offset = fileBlockOffset - emEntry.blockOffset; LBID = emEntry.range.start + offset; - releaseEMIndex(READ); releaseEMEntryTable(READ); return 0; @@ -2821,7 +2819,7 @@ LBID_t ExtentMap::_createColumnExtent_DBroot(uint32_t size, int OID, uint32_t co uint32_t targetDbRootPartNext = targetDbRootPart + 1; partHighSeg = lastExtent->segmentNum; targetDbRootSegs.insert(TargetDbRootSegsMap::value_type(lastExtent->segmentNum, lastExtent->blockOffset)); - + for (auto dbRootFromList : dbRootVec) { if (dbRootFromList == dbRoot) @@ -2854,8 +2852,8 @@ LBID_t ExtentMap::_createColumnExtent_DBroot(uint32_t size, int OID, uint32_t co iter->second = emEntry.blockOffset; } } - } // loop over em idents - } // current dbroot == target dbroot + } // loop over em idents + } // current dbroot == target dbroot else { // 4. Track hi seg for hwm+1 partition @@ -3136,22 +3134,22 @@ LBID_t ExtentMap::_createColumnExtent_DBroot(uint32_t size, int OID, uint32_t co segmentNum = e.segmentNum; startBlockOffset = e.blockOffset; - makeUndoRecordRBTree(UndoRecordType::INSERT, e); - makeUndoRecord(fEMRBTreeShminfo, sizeof(MSTEntry)); + makeUndoRecordRBTree(UndoRecordType::INSERT, e); + makeUndoRecord(fEMRBTreeShminfo, sizeof(MSTEntry)); - // Insert into RBTree. - std::pair lbidEmEntryPair = make_pair(startLBID, e); - fExtentMapRBTree->insert(lbidEmEntryPair); - fEMRBTreeShminfo->currentSize += EM_RB_TREE_NODE_SIZE; + // Insert into RBTree. + std::pair lbidEmEntryPair = make_pair(startLBID, e); + fExtentMapRBTree->insert(lbidEmEntryPair); + fEMRBTreeShminfo->currentSize += EM_RB_TREE_NODE_SIZE; - // Insert into Index. - auto resShmemHasGrownPair = fPExtMapIndexImpl_->insert(e, startLBID); - if (resShmemHasGrownPair.second) - fEMIndexShminfo->allocdSize = fPExtMapIndexImpl_->getShmemSize(); - if (!resShmemHasGrownPair.first) - logAndSetEMIndexReadOnly("_createColumnExtent_DBroot"); + // Insert into Index. + auto resShmemHasGrownPair = fPExtMapIndexImpl_->insert(e, startLBID); + if (resShmemHasGrownPair.second) + fEMIndexShminfo->allocdSize = fPExtMapIndexImpl_->getShmemSize(); + if (!resShmemHasGrownPair.first) + logAndSetEMIndexReadOnly("_createColumnExtent_DBroot"); - return startLBID; + return startLBID; } //------------------------------------------------------------------------------ @@ -3325,7 +3323,6 @@ LBID_t ExtentMap::_createColumnExtentExactFile(uint32_t size, int OID, uint32_t newEmEntry.segmentNum = segmentNum; newEmEntry.status = EXTENTUNAVAILABLE; // mark extent as in process - if (isUnsigned(colDataType)) { if (colWidth != datatypes::MAXDECIMALWIDTH) @@ -3670,8 +3667,6 @@ void ExtentMap::printFL() const void ExtentMap::rollbackColumnExtents_DBroot(int oid, bool bDeleteAll, uint16_t dbRoot, uint32_t partitionNum, uint16_t segmentNum, HWM_t hwm) { - // bool oidExists = false; - #ifdef BRM_INFO if (fDebug) { @@ -3810,6 +3805,7 @@ void ExtentMap::rollbackColumnExtents_DBroot(int oid, bool bDeleteAll, uint16_t } } } + // If this function is called, we are already in error recovery mode; so // don't worry about reporting an error if the OID is not found, because // we don't want/need the extents for that OID anyway. @@ -3851,8 +3847,6 @@ void ExtentMap::rollbackColumnExtents_DBroot(int oid, bool bDeleteAll, uint16_t void ExtentMap::rollbackDictStoreExtents_DBroot(int oid, uint16_t dbRoot, uint32_t partitionNum, const vector& segNums, const vector& hwms) { - // bool oidExists = false; - #ifdef BRM_INFO if (fDebug) { @@ -3885,8 +3879,8 @@ void ExtentMap::rollbackDictStoreExtents_DBroot(int oid, uint16_t dbRoot, uint32 bDeleteAll = true; // segToHwmMap maps segment file number to corresponding pair - tr1::unordered_map> segToHwmMap; - tr1::unordered_map>::const_iterator segToHwmMapIter; + tr1::unordered_map > segToHwmMap; + tr1::unordered_map >::const_iterator segToHwmMapIter; grabEMEntryTable(WRITE); grabEMIndex(WRITE); @@ -3980,20 +3974,6 @@ void ExtentMap::rollbackDictStoreExtents_DBroot(int oid, uint16_t dbRoot, uint32 } } } - - // If this function is called, we are already in error recovery mode; so - // don't worry about reporting an error if the OID is not found, because - // we don't want/need the extents for that OID anyway. - // if (!oidExists) - //{ - // ostringstream oss; - // oss << "ExtentMap::rollbackDictStoreExtents_DBroot(): " - // "Rollback failed: no extents exist for: OID-" << oid << - // "; dbRoot-" << dbRoot << - // "; partition-" << partitionNum; - // log(oss.str(), logging::LOG_TYPE_CRITICAL); - // throw invalid_argument(oss.str()); - //} } } @@ -4271,6 +4251,7 @@ void ExtentMap::deleteOID(int OID) // Clean up the index and tell deleteExtent to skip the clean-up. DBRootVec dbRootVec(getAllDbRoots()); + for (auto dbRoot : dbRootVec) { const auto lbids = fPExtMapIndexImpl_->find(dbRoot, OID); @@ -4504,14 +4485,12 @@ HWM_t ExtentMap::getLastHWM_DBroot(int OID, uint16_t dbRoot, uint32_t& partition log(oss.str(), logging::LOG_TYPE_CRITICAL); throw invalid_argument(oss.str()); } - grabEMEntryTable(READ); grabEMIndex(READ); const auto lbids = fPExtMapIndexImpl_->find(dbRoot, OID); const auto emIdents = getEmIdentsByLbids(lbids); auto lastEmEntry = emIdents.begin(); - for (auto emEntry = emIdents.begin(); emEntry < emIdents.end(); ++emEntry) { if (((emEntry->status == EXTENTAVAILABLE) || (emEntry->status == EXTENTOUTOFSERVICE)) && @@ -4595,7 +4574,6 @@ void ExtentMap::getDbRootHWMInfo(int OID, uint16_t pmNumber, EmDbRootHWMInfo_v& grabEMEntryTable(READ); grabEMIndex(READ); tr1::unordered_map::iterator emIter; - // Indicates that we found an extent, the index itself means nothing. // TODO: Update to flag. uint32_t foundIndex = 0; @@ -4787,6 +4765,7 @@ HWM_t ExtentMap::getLocalHWM(int OID, uint32_t partitionNum, uint16_t segmentNum grabEMIndex(READ); DBRootVec dbRootVec(getAllDbRoots()); + for (auto dbRoot : dbRootVec) { const auto lbids = fPExtMapIndexImpl_->find(dbRoot, OID, partitionNum); @@ -4950,7 +4929,6 @@ void ExtentMap::setLocalHWM(int OID, uint32_t partitionNum, uint16_t segmentNum, log(os.str(), logging::LOG_TYPE_DEBUG); } - #endif } @@ -5089,7 +5067,6 @@ void ExtentMap::getExtents_dbroot(int OID, vector& entries, cons #endif entries.clear(); - if (OID < 0) { ostringstream oss; @@ -5237,7 +5214,6 @@ void ExtentMap::deletePartition(const set& oids, const set foundPartitions; std::vector extents; - for (auto oid : oids) { for (auto& partition : partitionNums) @@ -5297,7 +5273,6 @@ void ExtentMap::markPartitionForDeletion(const set& oids, const set& oids, const set::const_iterator it; grabEMEntryTable(WRITE); grabEMIndex(WRITE); @@ -5734,12 +5708,7 @@ void ExtentMap::lookup(OID_t OID, LBIDRange_v& ranges) for (auto& emEntry : emIdents) { if (emEntry.status != EXTENTOUTOFSERVICE) - { - LBIDRange tmp; - tmp.start = emEntry.range.start; - tmp.size = emEntry.range.size * 1024; - ranges.emplace_back(tmp); - } + ranges.emplace_back(emEntry.range.start, emEntry.range.size * 1024); } } @@ -5909,7 +5878,7 @@ int ExtentMap::checkConsistency() cout << "Test 1d passed\n"; #endif - // test 2 - verify that the freelist is consolidated + // test 2 - verify that the freelist is consolidated for (i = 0; i < flEntries; i++) { if (fFreeList[i].size != 0) diff --git a/versioning/BRM/extentmap.h b/versioning/BRM/extentmap.h index 6ece3f096..e161a42b1 100644 --- a/versioning/BRM/extentmap.h +++ b/versioning/BRM/extentmap.h @@ -1066,11 +1066,10 @@ class ExtentMap : public Undoable static const constexpr size_t EM_FREELIST_INITIAL_SIZE = 50 * sizeof(InlineLBIDRange); static const constexpr size_t EM_FREELIST_INCREMENT = 50 * sizeof(InlineLBIDRange); // RBTree constants. - static const size_t EM_RB_TREE_NODE_SIZE = 10 * (sizeof(EMEntry) + 8 * sizeof(uint64_t)); + static const size_t EM_RB_TREE_NODE_SIZE = sizeof(EMEntry) + 8 * sizeof(uint64_t); static const size_t EM_RB_TREE_EMPTY_SIZE = 1024; - static const size_t EM_RB_TREE_INITIAL_SIZE = - EM_INCREMENT_ROWS * 10 * EM_RB_TREE_NODE_SIZE + EM_RB_TREE_EMPTY_SIZE; - static const size_t EM_RB_TREE_INCREMENT = EM_INCREMENT_ROWS * EM_RB_TREE_NODE_SIZE; + static const size_t EM_RB_TREE_INITIAL_SIZE = 16 * 1024 * 1024; + static const size_t EM_RB_TREE_INCREMENT = 16 * 1024 * 1024; ExtentMap(const ExtentMap& em); ExtentMap& operator=(const ExtentMap& em);