From a6578ee25f2e875b68ef8b3906a5b54ffb86f22c Mon Sep 17 00:00:00 2001 From: Giacomo Govi Date: Fri, 15 May 2015 17:35:53 +0200 Subject: [PATCH] Introduced IOV caching in pages --- CondCore/CondDB/src/DbCore.h | 4 ++++ CondCore/CondDB/src/IOVProxy.cc | 40 +++++++++++--------------------- CondCore/CondDB/src/IOVSchema.cc | 4 +++- CondCore/CondDB/src/IOVSchema.h | 19 ++++++--------- 4 files changed, 27 insertions(+), 40 deletions(-) diff --git a/CondCore/CondDB/src/DbCore.h b/CondCore/CondDB/src/DbCore.h index dff16772efe60..74a74d0414200 100644 --- a/CondCore/CondDB/src/DbCore.h +++ b/CondCore/CondDB/src/DbCore.h @@ -442,6 +442,10 @@ namespace cond { m_coralQuery->addToOrderList( orderClause ); } + void groupBy( const std::string& expression ){ + m_coralQuery->groupBy( expression ); + } + void setForUpdate(){ m_coralQuery->setForUpdate(); } diff --git a/CondCore/CondDB/src/IOVProxy.cc b/CondCore/CondDB/src/IOVProxy.cc index cacc47894f036..210d8cb8a7f9d 100644 --- a/CondCore/CondDB/src/IOVProxy.cc +++ b/CondCore/CondDB/src/IOVProxy.cc @@ -120,22 +120,24 @@ namespace cond { m_session = rhs.m_session; return *this; } - + void IOVProxy::load( const std::string& tag, bool full ){ + if( !m_data.get() ) return; + // clear reset(); checkTransaction( "IOVProxy::load" ); + std::string dummy; if(!m_session->iovSchema().tagTable().select( tag, m_data->timeType, m_data->payloadType, m_data->synchronizationType, m_data->endOfValidity, dummy, m_data->lastValidatedTime ) ){ throwException( "Tag \""+tag+"\" has not been found in the database.","IOVProxy::load"); } m_data->tag = tag; - + // now get the iov sequence when required if( full ) { - // load the full iov sequence in this case! m_session->iovSchema().iovTable().selectLatest( m_data->tag, m_data->iovSequence ); m_data->groupLowerIov = cond::time::MIN_VAL; @@ -216,7 +218,7 @@ namespace cond { m_data->groupLowerIov = cond::time::MIN_VAL; } if( higherGroup < cond::time::MAX_VAL ) { - m_data->groupHigherIov = std::get<0>(m_data->iovSequence.back()); + m_data->groupHigherIov = higherGroup-1; } else { m_data->groupHigherIov = cond::time::MAX_VAL; } @@ -257,43 +259,27 @@ namespace cond { IOVProxy::Iterator IOVProxy::find(cond::Time_t time) { checkTransaction( "IOVProxy::find" ); + // organize iovs in pages... // first check the available iov cache: - // case 0 empty cache ( the first request ) - - /** Pageing switched off temporarily - if( m_data->groupLowerIov == cond::time::MAX_VAL || - // case 1 : target outside - time < m_data->groupLowerIov || time >= m_data->groupHigherIov ){ + if( m_data->groupLowerIov == cond::time::MAX_VAL || // case 0 : empty cache ( the first request ) + time < m_data->groupLowerIov || time >= m_data->groupHigherIov ){ // case 1 : target outside // a new query required! // first determine the groups auto iGLow = search( time, m_data->sinceGroups ); if( iGLow == m_data->sinceGroups.end() ){ - // so suitable group=no iov at all! exiting... + // no suitable group=no iov at all! exiting... return end(); } auto iGHigh = iGLow; - cond::Time_t lowG = 0; - // unless the low group is the first one available, move the previous one to fully cover the interval - if( iGLow != m_data->sinceGroups.begin() ){ - iGLow--; - lowG = *iGLow; - } - // the upper group will be also extended to the next (covering in total up to three groups ) + cond::Time_t lowG = *iGLow; iGHigh++; cond::Time_t highG = cond::time::MAX_VAL; - if( iGHigh != m_data->sinceGroups.end() ) { - iGHigh++; - if( iGHigh != m_data->sinceGroups.end() ) highG = *iGHigh; - } + if( iGHigh != m_data->sinceGroups.end() ) highG = *iGHigh; + // finally, get the iovs for the selected group interval!! fetchSequence( lowG, highG ); } - **/ - // only one page... - if( m_data->groupLowerIov == cond::time::MAX_VAL ){ - fetchSequence( cond::time::MIN_VAL, cond::time::MAX_VAL ); - } // the current iov set is a good one... auto iIov = search( time, m_data->iovSequence ); diff --git a/CondCore/CondDB/src/IOVSchema.cc b/CondCore/CondDB/src/IOVSchema.cc index da599dcb7b20a..7612f2c31d7fd 100644 --- a/CondCore/CondDB/src/IOVSchema.cc +++ b/CondCore/CondDB/src/IOVSchema.cc @@ -114,7 +114,7 @@ namespace cond { buffer.addWhereCondition( name ); updateTable( m_schema, tname, buffer ); } - + IOV::Table::Table( coral::ISchema& schema ): m_schema( schema ){ } @@ -139,6 +139,7 @@ namespace cond { size_t IOV::Table::selectGroups( const std::string& tag, std::vector& groups ){ Query< SINCE_GROUP > q( m_schema, true ); q.addCondition( tag ); + q.groupBy(SINCE_GROUP::group()); q.addOrderClause(); for( auto row : q ){ groups.push_back(std::get<0>(row)); @@ -150,6 +151,7 @@ namespace cond { Query< SINCE_GROUP > q( m_schema, true ); q.addCondition( tag ); q.addCondition( snapshotTime,"<=" ); + q.groupBy(SINCE_GROUP::group()); q.addOrderClause(); for( auto row : q ){ groups.push_back(std::get<0>(row)); diff --git a/CondCore/CondDB/src/IOVSchema.h b/CondCore/CondDB/src/IOVSchema.h index 2396e607d2295..0a999c875ab4d 100644 --- a/CondCore/CondDB/src/IOVSchema.h +++ b/CondCore/CondDB/src/IOVSchema.h @@ -82,25 +82,20 @@ namespace cond { column( SINCE, cond::Time_t ); column( PAYLOAD_HASH, std::string, PAYLOAD::PAYLOAD_HASH_SIZE ); column( INSERTION_TIME, boost::posix_time::ptime ); - - struct MAX_SINCE { - typedef cond::Time_t type; - static constexpr size_t size = 0; - static std::string tableName(){ return SINCE::tableName(); } - static std::string fullyQualifiedName(){ - return std::string("MAX(")+SINCE::fullyQualifiedName()+")"; - } - }; + struct SINCE_GROUP { typedef cond::Time_t type; static constexpr size_t size = 0; static std::string tableName(){ return SINCE::tableName(); } static std::string fullyQualifiedName(){ - std::string sgroupSize = boost::lexical_cast(cond::time::SINCE_GROUP_SIZE); - return "("+SINCE::fullyQualifiedName()+"/"+sgroupSize+")*"+sgroupSize; + return "MIN("+SINCE::fullyQualifiedName()+")"; } + static std::string group(){ + std::string sgroupSize = boost::lexical_cast( cond::time::SINCE_GROUP_SIZE); + return "CAST("+SINCE::fullyQualifiedName()+"/"+sgroupSize+" AS INT )*"+sgroupSize; + } }; - + struct SEQUENCE_SIZE { typedef unsigned int type; static constexpr size_t size = 0;