Skip to content

Commit

Permalink
Merge pull request #3110 from ggovi/new-conddb-fix-0-for-70X
Browse files Browse the repository at this point in the history
Back-ported fixes and improvements
  • Loading branch information
davidlange6 committed Apr 1, 2014
2 parents 102f39e + 76ab8c2 commit 0addcd4
Show file tree
Hide file tree
Showing 33 changed files with 342 additions and 246 deletions.
18 changes: 8 additions & 10 deletions CondCore/CondDB/interface/Binary.h
@@ -1,6 +1,8 @@
#ifndef CondCore_CondDB_Binary_h
#define CondCore_CondDB_Binary_h

// for the old system, this will go away
#include "CondCore/ORA/interface/Object.h"
#include <string>
#include <memory>
// temporarely
Expand All @@ -13,19 +15,12 @@ namespace coral {

namespace cond {

struct Nodelete {
Nodelete(){}
void operator()( void* ptr ){}
};

class Binary {
public:
Binary();

template <typename T> explicit Binary( const T& object );

explicit Binary( const boost::shared_ptr<void>& objectPtr );

Binary( const void* data, size_t size );

explicit Binary( const coral::Blob& data );
Expand All @@ -44,16 +39,19 @@ namespace cond {

size_t size() const;

boost::shared_ptr<void> share() const;
ora::Object oraObject() const;

void fromOraObject( const ora::Object& object );

private:
std::shared_ptr<coral::Blob> m_data;
//
boost::shared_ptr<void> m_object;
// workaround to support the non-streamed, packed objects ( the old system )
ora::Object m_object;
};

template <typename T> Binary::Binary( const T& object ):
m_object( &const_cast<T&>(object), Nodelete() ){
m_object( object ){
}
}

Expand Down
12 changes: 8 additions & 4 deletions CondCore/CondDB/interface/ConnectionPool.h
Expand Up @@ -26,6 +26,7 @@ namespace cond {
//
enum DbAuthenticationSystem { UndefinedAuthentication=0,CondDbKey, CoralXMLFile };

// a wrapper for the coral connection service.
class ConnectionPool {
public:
ConnectionPool();
Expand All @@ -38,20 +39,23 @@ namespace cond {
bool isLoggingEnabled() const;
void setParameters( const edm::ParameterSet& connectionPset );
void configure();
Session createSession( const std::string& connectionString, bool writeCapable=false );
Session createSession( const std::string& connectionString, bool writeCapable=false, BackendType backType=DEFAULT_DB );
Session createReadOnlySession( const std::string& connectionString, const std::string& transactionId );

private:
Session createSession( const std::string& connectionString, const std::string& transactionId, bool writeCapable=false );
Session createSession( const std::string& connectionString,
const std::string& transactionId,
bool writeCapable=false,
BackendType backType=DEFAULT_DB );
void configure( coral::IConnectionServiceConfiguration& coralConfig);
private:
std::string m_authPath;
int m_authSys = 0;
coral::MsgLevel m_messageLevel = coral::Info;
coral::MsgLevel m_messageLevel = coral::Error;
bool m_loggingEnabled = false;
// this one has to be moved!
cond::CoralServiceManager* m_pluginManager = 0;
std::vector<std::string> m_refreshtablelist;
std::map<std::string,int> m_dbTypes;
};
}
}
Expand Down
3 changes: 3 additions & 0 deletions CondCore/CondDB/interface/GTProxy.h
Expand Up @@ -21,6 +21,9 @@ namespace cond {

namespace persistency {

// required in the "bridge" mode, to be removed with the ORA based code after the transition
std::pair<std::string,std::string> parseTag( const std::string& tag );

class SessionImpl;
class GTProxyData;

Expand Down
7 changes: 4 additions & 3 deletions CondCore/CondDB/interface/Serialization.h
Expand Up @@ -28,8 +28,9 @@ namespace cond {

// default payload factory
template <typename T> T* createPayload( const std::string& payloadTypeName ){
if( demangledName( typeid(T) )!= payloadTypeName )
throwException(std::string("Type mismatch, target object is type \"")+payloadTypeName+"\"",
std::string userTypeName = demangledName( typeid(T) );
if( userTypeName != payloadTypeName )
throwException(std::string("Type mismatch, user type: \""+userTypeName+"\", target type: \"")+payloadTypeName+"\"",
"createPayload" );
return new T;
}
Expand Down Expand Up @@ -113,7 +114,7 @@ namespace cond {
payload.reset( createPayload<T>(payloadType) );
ia >> (*payload);
} else {
payload = boost::static_pointer_cast<T>(payloadData.share());
payload = boost::static_pointer_cast<T>(payloadData.oraObject().makeShared());
}
return payload;
}
Expand Down
6 changes: 2 additions & 4 deletions CondCore/CondDB/interface/Session.h
Expand Up @@ -64,9 +64,6 @@ namespace cond {
// constructor
explicit Session( const std::shared_ptr<SessionImpl>& sessionImpl );

// constructor
Session( boost::shared_ptr<coral::ISessionProxy>& session, const std::string& connectionString );

//
Session( const Session& rhs );

Expand Down Expand Up @@ -141,9 +138,10 @@ namespace cond {
coral::ISchema& nominalSchema();

bool isOraSession();

private:
cond::Hash storePayloadData( const std::string& payloadObjectType, const cond::Binary& payloadData, const boost::posix_time::ptime& creationTime );

private:

std::shared_ptr<SessionImpl> m_session;
Expand Down
4 changes: 4 additions & 0 deletions CondCore/CondDB/interface/Types.h
Expand Up @@ -19,6 +19,10 @@

namespace cond {

// to be removed after the transition to new DB
typedef enum { UNKNOWN_DB=0, COND_DB, ORA_DB } BackendType;
static constexpr BackendType DEFAULT_DB = ORA_DB;

typedef enum {
SYNCHRONIZATION_UNKNOWN = -1,
OFFLINE=0,
Expand Down
46 changes: 32 additions & 14 deletions CondCore/CondDB/interface/Utils.h
Expand Up @@ -7,12 +7,13 @@
#include <cxxabi.h>
#include <algorithm>
#include <iostream>
#include <tuple>

namespace cond {

namespace {

std::string demangledName( const std::type_info& typeInfo ){
inline std::string demangledName( const std::type_info& typeInfo ){
int status = 0;
std::string ret("");
char* realname = abi::__cxa_demangle( typeInfo.name(), 0, 0, &status);
Expand All @@ -25,24 +26,41 @@ namespace cond {
return ret;
}

std::tuple<std::string,std::string,std::string> parseConnectionString( const std::string& connectionString ){
size_t ptr = 0;
}

namespace persistency {

inline std::string getConnectionProtocol( const std::string& connectionString ){
size_t techEnd = connectionString.find( ':' );
if( techEnd == std::string::npos ) throwException( "Connection string is invalid (0)","parseConnectionString" );
std::string technology = connectionString.substr(ptr,techEnd);
std::string service("");
ptr = techEnd+1;
if( technology != "sqlite_file" ){
if( connectionString.substr( ptr,2 )!="//" ) throwException( "Connection string is invalid (1)","parseConnectionString" );
if( techEnd == std::string::npos ) throwException( "Could not resolve the connection protocol on "+connectionString+".",
"getConnectionProtocol" );
std::string technology = connectionString.substr(0,techEnd);
return technology;
}

inline std::tuple<std::string,std::string,std::string> parseConnectionString( const std::string& connectionString ){
std::string protocol = getConnectionProtocol( connectionString );
std::string serviceName("");
std::string databaseName("");
if( protocol == "sqlite" || protocol == "sqlite_file" || protocol == "sqlite_fip" ){
databaseName = connectionString.substr( protocol.size()+1 );
} else if ( protocol == "oracle" || protocol == "frontier" ){
size_t ptr = protocol.size()+1;
if( connectionString.substr( ptr,2 )!="//" ) throwException( "Connection string "+connectionString+
" is invalid format for technology \""+
protocol+"\".","parseConnectionString" );
ptr += 2;
size_t serviceEnd = connectionString.find( '/', ptr );
if( serviceEnd == std::string::npos ) throwException( "Connection string is invalid (2)","parseConnectionString" );
service = connectionString.substr( ptr, serviceEnd-ptr );
if( serviceEnd == std::string::npos ) throwException( "Connection string "+connectionString+" is invalid.",
"parseConnectionString" );
serviceName = connectionString.substr( ptr, serviceEnd-ptr );
ptr = serviceEnd+1;
}
std::string schema = connectionString.substr( ptr );
return std::make_tuple( technology, service, schema );
databaseName = connectionString.substr( ptr );
} else throwException( "Technology "+protocol+" is not known.","parseConnectionString" );

return std::make_tuple( protocol, serviceName, databaseName );
}

}

}
Expand Down
4 changes: 3 additions & 1 deletion CondCore/CondDB/python/CondDB_cfi.py
Expand Up @@ -3,8 +3,10 @@
CondDB = cms.PSet(
DBParameters = cms.PSet(
authenticationPath = cms.untracked.string(''),
authenticationSystem = cms.untracked.int32(0),
messageLevel = cms.untracked.int32(0),
),
connect = cms.string('protocol://db/schema') ##db/schema"
connect = cms.string('protocol://db/schema'), ##db/schema"
dbFormat = cms.untracked.int32(0)
)

13 changes: 6 additions & 7 deletions CondCore/CondDB/src/Binary.cc
Expand Up @@ -12,10 +12,6 @@ cond::Binary::Binary():
m_data( new coral::Blob(0) ){
}

cond::Binary::Binary( const boost::shared_ptr<void>& objectPtr ):
m_object( objectPtr ){
}

cond::Binary::Binary( const void* data, size_t size ):
m_data( new coral::Blob( size ) ){
::memcpy( m_data->startingAddress(), data, size );
Expand Down Expand Up @@ -46,7 +42,7 @@ const coral::Blob& cond::Binary::get() const {
void cond::Binary::copy( const std::string& source ){
m_data.reset( new coral::Blob( source.size() ) );
::memcpy( m_data->startingAddress(), source.c_str(), source.size() );
m_object.reset();
m_object = ora::Object();
}

const void* cond::Binary::data() const {
Expand All @@ -63,10 +59,13 @@ size_t cond::Binary::size() const {
return m_data->size();
}

boost::shared_ptr<void> cond::Binary::share() const {
ora::Object cond::Binary::oraObject() const {
return m_object;
}


void cond::Binary::fromOraObject( const ora::Object& object ){
m_object = object;
m_data.reset();
}


63 changes: 39 additions & 24 deletions CondCore/CondDB/src/ConnectionPool.cc
@@ -1,5 +1,7 @@
#include "CondCore/CondDB/interface/ConnectionPool.h"
#include "DbConnectionString.h"
#include "SessionImpl.h"
#include "IOVSchema.h"
//
#include "CondCore/DBCommon/interface/CoralServiceManager.h"
#include "CondCore/DBCommon/interface/Auth.h"
Expand All @@ -19,24 +21,14 @@
namespace cond {

namespace persistency {

static const std::string POOL_IOV_TABLE_DATA("IOV_DATA");
static const std::string ORA_IOV_TABLE_1("ORA_C_COND_IOVSEQUENCE");
static const std::string ORA_IOV_TABLE_2("ORA_C_COND_IOVSEQU_A0");
static const std::string ORA_IOV_TABLE_3("ORA_C_COND_IOVSEQU_A1");

ConnectionPool::ConnectionPool():
m_authPath(),
m_authSys(0),
m_messageLevel( coral::Error ),
m_loggingEnabled( false ),
m_pluginManager( new cond::CoralServiceManager ),
m_refreshtablelist(){
m_refreshtablelist.reserve(6);
//table names for IOVSequence in the old POOL mapping
m_refreshtablelist.push_back("IOV");
m_refreshtablelist.push_back("IOV_DATA");
//table names for IOVSequence in ORA
m_refreshtablelist.push_back("ORA_C_COND_IOVSEQUENCE");
m_refreshtablelist.push_back("ORA_C_COND_IOVSEQU_A0");
m_refreshtablelist.push_back("ORA_C_COND_IOVSEQU_A1");
//table names for IOVSequence in CONDDB
m_refreshtablelist.push_back("TAG");
ConnectionPool::ConnectionPool(){
m_pluginManager = new cond::CoralServiceManager;
configure();
}

Expand Down Expand Up @@ -139,19 +131,42 @@ namespace cond {
configure( connServ.configuration() );
}

Session ConnectionPool::createSession( const std::string& connectionString, const std::string& transactionId, bool writeCapable ){
Session ConnectionPool::createSession( const std::string& connectionString,
const std::string& transactionId,
bool writeCapable,
BackendType backType){
coral::ConnectionService connServ;
std::pair<std::string,std::string> fullConnectionPars = getRealConnectionString( connectionString, transactionId );
if( !fullConnectionPars.second.empty() )
for( auto tableName : m_refreshtablelist ) connServ.webCacheControl().refreshTable( fullConnectionPars.second, tableName );
std::pair<std::string,std::string> fullConnectionPars = getConnectionParams( connectionString, transactionId );
if( !fullConnectionPars.second.empty() ) {
// the olds formats
connServ.webCacheControl().refreshTable( fullConnectionPars.second, POOL_IOV_TABLE_DATA );
connServ.webCacheControl().refreshTable( fullConnectionPars.second, ORA_IOV_TABLE_1 );
connServ.webCacheControl().refreshTable( fullConnectionPars.second, ORA_IOV_TABLE_2 );
connServ.webCacheControl().refreshTable( fullConnectionPars.second, ORA_IOV_TABLE_3 );
// the new schema...
connServ.webCacheControl().refreshTable( fullConnectionPars.second, TAG::tname );
connServ.webCacheControl().refreshTable( fullConnectionPars.second, IOV::tname );
}

boost::shared_ptr<coral::ISessionProxy> coralSession( connServ.connect( fullConnectionPars.first,
writeCapable?Auth::COND_WRITER_ROLE:Auth::COND_READER_ROLE,
writeCapable?coral::Update:coral::ReadOnly ) );
return Session( coralSession, connectionString );
BackendType bt;
auto it = m_dbTypes.find( connectionString);
if( it == m_dbTypes.end() ){
bt = checkBackendType( coralSession, connectionString );
if( bt == UNKNOWN_DB && writeCapable) bt = backType;
m_dbTypes.insert( std::make_pair( connectionString, bt ) ).first;
} else {
bt = (BackendType) it->second;
}

std::shared_ptr<SessionImpl> impl( new SessionImpl( coralSession, connectionString, bt ) );
return Session( impl );
}

Session ConnectionPool::createSession( const std::string& connectionString, bool writeCapable ){
return createSession( connectionString, "", writeCapable );
Session ConnectionPool::createSession( const std::string& connectionString, bool writeCapable, BackendType backType ){
return createSession( connectionString, "", writeCapable, backType );
}

Session ConnectionPool::createReadOnlySession( const std::string& connectionString, const std::string& transactionId ){
Expand Down

0 comments on commit 0addcd4

Please sign in to comment.