diff --git a/Database/APR/StorageSvc/src/DbDatabaseObj.cpp b/Database/APR/StorageSvc/src/DbDatabaseObj.cpp index 1088347cf3aeacd6bbaf3a9fff96786ba3e9249c..a977dd8660ec949e5218b8b4473f5417bf48b63f 100644 --- a/Database/APR/StorageSvc/src/DbDatabaseObj.cpp +++ b/Database/APR/StorageSvc/src/DbDatabaseObj.cpp @@ -35,6 +35,11 @@ using namespace std; using namespace pool; +ostream& operator << (ostream& os, const Token::OID_t oid ) { + os << "("< 0 ) { - // find the offset in the links table - Sections::const_iterator j = m_sections.find("##Links"); - if( j == m_sections.end() ) + new_oid = oid; + DbToken* link = nullptr; + if( oid.first > 0xFFFFFFFF ) { + // for indexed entries find Link vector entry directly + auto iter = m_indexMap.find( oid.first ); + if( iter == m_indexMap.end() ) return Error; - const ContainerSections& sections = (*j).second; - if( merge_section < (int)sections.size() ) { - shift.first = sections[merge_section].start; + new_oid.first = iter->second; + link = m_linkVec[ new_oid.first ]; + } + if( merge_section > 0 ) { + if( oid.first <= 0xFFFFFFFF ) { + // for non-indexed entries find the correct section for the Links table and add offset + // 1. find the offset in the links table + Sections::const_iterator j = m_sections.find("##Links"); + if( j == m_sections.end() ) + return Error; + const ContainerSections& sections = (*j).second; + if( merge_section >= (int)sections.size() ) + return Error; + new_oid.first = oid.first + sections[merge_section].start; + link = m_linkVec[ new_oid.first ]; } - DbToken* link = m_linkVec[ oid.first + shift.first ]; - if( link->isLocal() ) { - // MN: assuming only internal links need OID_2 adjustment + if( link->isLocal() && oid.second <= 0xFFFFFFFF ) { + // MN: assuming only non-indexed internal links need OID_2 adjustment // find the start of the section for this container - j = m_sections.find( link->contID() ); + Sections::const_iterator j = m_sections.find( link->contID() ); if( j == m_sections.end() ) return Error; const ContainerSections& sections = (*j).second; - if( merge_section < (int)sections.size() ) { - shift.second = sections[merge_section].start; - } + if( merge_section >= (int)sections.size() ) + return Error; + new_oid.second += sections[merge_section].start; } } return Success; @@ -706,24 +725,17 @@ DbStatus DbDatabaseObj::getLink(const Token::OID_t& oid, int merge_section, Toke { if ( 0 == m_info ) open(); if ( 0 != m_info && 0 != pTok && oid.first >= 0 ) { - Token::OID_t shift(0,0); - if( merge_section > 0 ) { - if( getRedirection(oid, merge_section, shift) != Success ) - return Error; - } - int lnk = oid.first + shift.first; - if( lnk >= int(m_linkVec.size()) ) - return Error; - - pTok->oid().first = lnk; - pTok->oid().second = oid.second + shift.second; + Token::OID_t redirected(0,0); + if( getRedirection(oid, merge_section, redirected) != Success ) + return Error; + pTok->oid() = redirected; if( !(pTok->type() & DbToken::TOKEN_FULL_KEY) ) { if( typeid(*pTok) == typeid(DbToken) ) { DbToken* pdbTok = (DbToken*)pTok; pdbTok->setKey(DbToken::TOKEN_FULL_KEY); } } - m_linkVec[lnk]->set(pTok); + m_linkVec[ redirected.first ]->set(pTok); return Success; } return Error; @@ -798,20 +810,19 @@ DbStatus DbDatabaseObj::read(const Token& token, ShapeH shape, void** object) // We get here if the token is *part* of a merged file, but still hosted within this DB Redirections::iterator i = m_redirects.find( token.dbID().toString() ); // find out which section to read from - if( i!=m_redirects.end() ) sectionN = i->second.first; - if( sectionN > 0 ) { - Token::OID_t shift(0,0); - getRedirection(oid, sectionN, shift); - if( DbPrintLvl::outputLvl == DbPrintLvl::Verbose ) { - DbPrint log( name() ); - log << DbPrintLvl::Verbose << "Reading object OID=(" << oid.first << ", " << oid.second - << ") from merged file section # " << sectionN - << ", Adjusted OID=(" << oid.first + shift.first << ", " << oid.second + shift.second << ")" - << DbPrint::endmsg; - } - oid.first += shift.first; - oid.second += shift.second; + if( i == m_redirects.end() ) + return Error; + sectionN = i->second.first; + Token::OID_t redirected(0,0); + if( getRedirection(oid, sectionN, redirected) == Error ) + return Error; + if( DbPrintLvl::outputLvl <= DbPrintLvl::Verbose ) { + DbPrint log( name() ); + log << DbPrintLvl::Verbose << "Reading object OID=" << oid + << " from merged file section # " << sectionN + << ", Adjusted OID=" << redirected << DbPrint::endmsg; } + oid = redirected; containerName = m_linkVec[ oid.first ]->contID(); } diff --git a/Database/APR/StorageSvc/src/DbDatabaseObj.h b/Database/APR/StorageSvc/src/DbDatabaseObj.h index 131dd5c539f7006cd4595c763fa027568ef9d3bc..6c6c7def0ec17cbb40dc3574562f6d8876207876 100644 --- a/Database/APR/StorageSvc/src/DbDatabaseObj.h +++ b/Database/APR/StorageSvc/src/DbDatabaseObj.h @@ -150,7 +150,7 @@ namespace pool { /// read an object referenced by the token DbStatus read(const Token& token, ShapeH shape, void** object); - /// Calculate required OID modification (shift) for source OID (oid) for a given merge section + /// Calculate new OID from the source OID (oid) for a given merge section DbStatus getRedirection(const Token::OID_t& oid, int merge_section, Token::OID_t& shift); /// Expand OID into a full Token, based on the Links table. For merged files provide links section# DbStatus getLink(const Token::OID_t& oid, int merge_section, Token* pTok);