Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DB connection handling upgraded to support sqlite fip and new frontier c... #2748

Merged
merged 1 commit into from Mar 11, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
5 changes: 2 additions & 3 deletions CondCore/CondDB/interface/ConnectionPool.h
Expand Up @@ -39,14 +39,14 @@ namespace cond {
bool isLoggingEnabled() const;
void setParameters( const edm::ParameterSet& connectionPset );
void configure();
Session createSession( const std::string& connectionString, bool writeCapable=false, BackendType backType=ORA_DB );
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,
BackendType backType=ORA_DB );
BackendType backType=DEFAULT_DB );
void configure( coral::IConnectionServiceConfiguration& coralConfig);
private:
std::string m_authPath;
Expand All @@ -55,7 +55,6 @@ namespace cond {
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
2 changes: 1 addition & 1 deletion CondCore/CondDB/interface/Serialization.h
Expand Up @@ -114,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
39 changes: 26 additions & 13 deletions CondCore/CondDB/interface/Utils.h
Expand Up @@ -26,28 +26,41 @@ namespace cond {
return ret;
}

inline 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 "+connectionString+" is invalid format.",
"parseConnectionString" );
std::string technology = connectionString.substr(ptr,techEnd);
std::string service("");
ptr = techEnd+1;
if( technology != "sqlite_file" && technology != "sqlite" ){
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 \""+
technology+"\".","parseConnectionString" );
protocol+"\".","parseConnectionString" );
ptr += 2;
size_t serviceEnd = connectionString.find( '/', ptr );
if( serviceEnd == std::string::npos ) throwException( "Connection string "+connectionString+" is invalid.",
"parseConnectionString" );
service = connectionString.substr( ptr, serviceEnd-ptr );
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
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();
}


36 changes: 21 additions & 15 deletions CondCore/CondDB/src/ConnectionPool.cc
@@ -1,6 +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 @@ -20,19 +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_pluginManager = new cond::CoralServiceManager;
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");
configure();
}

Expand Down Expand Up @@ -140,17 +136,27 @@ namespace cond {
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().setTableTimeToLive( fullConnectionPars.second, TAG::tname, 1 );
connServ.webCacheControl().setTableTimeToLive( fullConnectionPars.second, IOV::tname, 1 );
connServ.webCacheControl().setTableTimeToLive( fullConnectionPars.second, PAYLOAD::tname, 3 );
}

boost::shared_ptr<coral::ISessionProxy> coralSession( connServ.connect( fullConnectionPars.first,
writeCapable?Auth::COND_WRITER_ROLE:Auth::COND_READER_ROLE,
writeCapable?coral::Update:coral::ReadOnly ) );
BackendType bt;
auto it = m_dbTypes.find( connectionString);
if( it == m_dbTypes.end() ){
bt = checkBackendType( coralSession, connectionString );
if( bt == UNKNOWN_DB ) bt = DEFAULT_DB;
if( bt == UNKNOWN_DB && writeCapable) bt = backType;
m_dbTypes.insert( std::make_pair( connectionString, bt ) ).first;
} else {
bt = (BackendType) it->second;
Expand Down
84 changes: 41 additions & 43 deletions CondCore/CondDB/src/DbConnectionString.cc
Expand Up @@ -2,13 +2,15 @@
#include "CondCore/CondDB/interface/Utils.h"
#include "DbConnectionString.h"
//
#include "CondCore/DBCommon/interface/FipProtocolParser.h"
#include "FWCore/Catalog/interface/SiteLocalConfig.h"
#include "FWCore/ServiceRegistry/interface/Service.h"

namespace cond {

namespace persistency {


unsigned int
countslash(const std::string& input) {
unsigned int count=0;
Expand All @@ -24,52 +26,48 @@ namespace cond {
return count;
}

std::pair<std::string,std::string> makeFrontierConnectionString( const std::string& initialConnection,
const std::string& transactionId ){
std::string realConn = initialConnection;
std::string proto("frontier://");
std::string::size_type fpos=initialConnection.find(proto);
unsigned int nslash=countslash(initialConnection.substr(proto.size(),initialConnection.size()-fpos));
if(nslash==1){
edm::Service<edm::SiteLocalConfig> localconfservice;
if( !localconfservice.isAvailable() ){
throwException("SiteLocalConfigService is not available","cond::makeRealConnectString");
std::pair<std::string,std::string> getConnectionParams( const std::string& connectionString,
const std::string& transactionId ){
if( connectionString.empty() ) throwException( "The connection string is empty.","getConnectionParams");
std::string protocol = getConnectionProtocol( connectionString );
std::string finalConn = connectionString;
std::string refreshConn("");
if( protocol == "frontier" ){
std::string protocol("frontier://");
std::string::size_type fpos=connectionString.find(protocol);
unsigned int nslash=countslash(connectionString.substr(protocol.size(),connectionString.size()-fpos));
if(nslash==1){
edm::Service<edm::SiteLocalConfig> localconfservice;
if( !localconfservice.isAvailable() ){
throwException("edm::SiteLocalConfigService is not available","getConnectionParams");
}
finalConn=localconfservice->lookupCalibConnect(connectionString);
}
realConn=localconfservice->lookupCalibConnect(initialConnection);
}
if (!transactionId.empty()) {
size_t l = realConn.rfind('/');
realConn.insert(l,"(freshkey="+transactionId+')');
}

std::string refreshConnect;
std::string::size_type startRefresh = realConn.find("://");
if (startRefresh != std::string::npos){
startRefresh += 3;
}
std::string::size_type endRefresh=realConn.rfind("/", std::string::npos);
if (endRefresh == std::string::npos){
refreshConnect = realConn;
}else{
refreshConnect = realConn.substr(startRefresh, endRefresh-startRefresh);
if(refreshConnect.substr(0,1) != "("){
//if the connect string is not a complicated parenthesized string,
// an http:// needs to be at the beginning of it
refreshConnect.insert(0, "http://");
if (!transactionId.empty()) {
size_t l = finalConn.rfind('/');
finalConn.insert(l,"(freshkey="+transactionId+')');
}

std::string::size_type startRefresh = finalConn.find("://");
if (startRefresh != std::string::npos){
startRefresh += 3;
}
std::string::size_type endRefresh=finalConn.rfind("/", std::string::npos);
if (endRefresh == std::string::npos){
refreshConn = finalConn;
} else{
refreshConn = finalConn.substr(startRefresh, endRefresh-startRefresh);
if(refreshConn.substr(0,1) != "("){
//if the connect string is not a complicated parenthesized string,
// an http:// needs to be at the beginning of it
refreshConn.insert(0, "http://");
}
}
} else if ( protocol == "sqlite_fip" ){
cond::FipProtocolParser parser;
finalConn = parser.getRealConnect( connectionString );
}
return std::make_pair(realConn,refreshConnect);
}

std::pair<std::string,std::string> getRealConnectionString( const std::string& initialConnection ){
return getRealConnectionString( initialConnection, "" );
}

std::pair<std::string,std::string> getRealConnectionString( const std::string& initialConnection,
const std::string& transId ){
auto connData = parseConnectionString( initialConnection );
if( std::get<0>(connData) == "frontier" ) return makeFrontierConnectionString( initialConnection, transId );
return std::make_pair(initialConnection,"");
return std::make_pair( finalConn, refreshConn );
}

}
Expand Down
5 changes: 2 additions & 3 deletions CondCore/CondDB/src/DbConnectionString.h
@@ -1,16 +1,15 @@
#ifndef CondCore_CondDB_DbConnectionString_h
#define CondCore_CondDB_DbConnectionString_h

#include "CondCore/CondDB/interface/Utils.h"
//
#include <string>

namespace cond {

namespace persistency {

std::pair<std::string,std::string> getRealConnectionString( const std::string& initialConnection );

std::pair<std::string,std::string> getRealConnectionString( const std::string& initialConnection, const std::string& transId );
std::pair<std::string,std::string> getConnectionParams( const std::string& initialConnection, const std::string& transId );

}

Expand Down
13 changes: 13 additions & 0 deletions CondCore/CondDB/src/GTProxy.cc
Expand Up @@ -5,6 +5,19 @@ namespace cond {

namespace persistency {

std::pair<std::string,std::string> parseTag( const std::string& tag ){
std::string pfn("");
std::string t(tag);
size_t pos = tag.rfind('@');
if( pos != std::string::npos && tag.size() >= pos+3 ){
if( tag[pos+1]=='[' && tag[tag.size()-1]==']' ) {
pfn = tag.substr( pos+2,tag.size()-pos-3 );
t = tag.substr( 0, pos );
}
}
return std::make_pair( t, pfn );
}

// implementation details...
// only hosting data in this case
class GTProxyData {
Expand Down