Skip to content

Commit

Permalink
Merge pull request #9110 from ggovi/new-conddb-iov-pages-with-boundaries
Browse files Browse the repository at this point in the history
Introduced IOV caching in pages
  • Loading branch information
cmsbuild committed May 16, 2015
2 parents 658917b + a6578ee commit 99e181b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 40 deletions.
4 changes: 4 additions & 0 deletions CondCore/CondDB/src/DbCore.h
Expand Up @@ -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();
}
Expand Down
40 changes: 13 additions & 27 deletions CondCore/CondDB/src/IOVProxy.cc
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 );
Expand Down
4 changes: 3 additions & 1 deletion CondCore/CondDB/src/IOVSchema.cc
Expand Up @@ -114,7 +114,7 @@ namespace cond {
buffer.addWhereCondition<NAME>( name );
updateTable( m_schema, tname, buffer );
}

IOV::Table::Table( coral::ISchema& schema ):
m_schema( schema ){
}
Expand All @@ -139,6 +139,7 @@ namespace cond {
size_t IOV::Table::selectGroups( const std::string& tag, std::vector<cond::Time_t>& groups ){
Query< SINCE_GROUP > q( m_schema, true );
q.addCondition<TAG_NAME>( tag );
q.groupBy(SINCE_GROUP::group());
q.addOrderClause<SINCE_GROUP>();
for( auto row : q ){
groups.push_back(std::get<0>(row));
Expand All @@ -150,6 +151,7 @@ namespace cond {
Query< SINCE_GROUP > q( m_schema, true );
q.addCondition<TAG_NAME>( tag );
q.addCondition<INSERTION_TIME>( snapshotTime,"<=" );
q.groupBy(SINCE_GROUP::group());
q.addOrderClause<SINCE_GROUP>();
for( auto row : q ){
groups.push_back(std::get<0>(row));
Expand Down
19 changes: 7 additions & 12 deletions CondCore/CondDB/src/IOVSchema.h
Expand Up @@ -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<std::string>(cond::time::SINCE_GROUP_SIZE);
return "("+SINCE::fullyQualifiedName()+"/"+sgroupSize+")*"+sgroupSize;
return "MIN("+SINCE::fullyQualifiedName()+")";
}
static std::string group(){
std::string sgroupSize = boost::lexical_cast<std::string>( 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;
Expand Down

0 comments on commit 99e181b

Please sign in to comment.