CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Public Attributes | Private Member Functions | Private Attributes
cond::persistency::SessionImpl Class Reference

#include <SessionImpl.h>

Public Types

enum  FailureOnOpeningPolicy { THROW, DO_NOT_THROW, CREATE }
 

Public Member Functions

void close ()
 
void commitTransaction ()
 
IGTSchemagtSchema ()
 
IIOVSchemaiovSchema ()
 
bool isActive () const
 
bool isTransactionActive (bool deep=true) const
 
void openDb ()
 
void openGTDb (FailureOnOpeningPolicy policy=THROW)
 
void openIovDb (FailureOnOpeningPolicy policy=THROW)
 
void openRunInfoDb ()
 
void rollbackTransaction ()
 
IRunInfoSchemarunInfoSchema ()
 
 SessionImpl ()
 
 SessionImpl (std::shared_ptr< coral::ISessionProxy > &session, const std::string &connectionString, const std::string &principalName)
 
void startTransaction (bool readOnly=true)
 
 ~SessionImpl ()
 

Public Attributes

std::string connectionString
 
std::shared_ptr< coral::ISessionProxy > coralSession
 
std::unique_ptr< IGTSchemagtSchemaHandle
 
std::unique_ptr< IIOVSchemaiovSchemaHandle
 
std::set< std::string > lockedTags
 
std::string principalName
 
std::unique_ptr< IRunInfoSchemarunInfoSchemaHandle
 
std::string sessionHash
 
std::unique_ptr< ITransactiontransaction
 

Private Member Functions

void releaseTagLocks ()
 

Private Attributes

std::unique_lock< std::recursive_mutex > transactionLock
 
std::recursive_mutex transactionMutex
 

Detailed Description

Definition at line 40 of file SessionImpl.h.

Member Enumeration Documentation

◆ FailureOnOpeningPolicy

Constructor & Destructor Documentation

◆ SessionImpl() [1/2]

cond::persistency::SessionImpl::SessionImpl ( )

Definition at line 33 of file SessionImpl.cc.

33 : coralSession() {}
std::shared_ptr< coral::ISessionProxy > coralSession
Definition: SessionImpl.h:69

◆ SessionImpl() [2/2]

cond::persistency::SessionImpl::SessionImpl ( std::shared_ptr< coral::ISessionProxy > &  session,
const std::string &  connectionString,
const std::string &  principalName 
)

Definition at line 35 of file SessionImpl.cc.

References cond::auth::COND_SESSION_HASH_SIZE, cond::auth::KeyGenerator::make(), and sessionHash.

38  : coralSession(session), sessionHash(""), connectionString(connectionStr), principalName(principalNm) {
41  }
std::shared_ptr< coral::ISessionProxy > coralSession
Definition: SessionImpl.h:69
static constexpr size_t COND_SESSION_HASH_SIZE
Definition: Auth.h:40
std::string make(size_t keySize)
Definition: DecodingKey.cc:75

◆ ~SessionImpl()

cond::persistency::SessionImpl::~SessionImpl ( )

Definition at line 43 of file SessionImpl.cc.

References close().

Member Function Documentation

◆ close()

void cond::persistency::SessionImpl::close ( void  )

Definition at line 45 of file SessionImpl.cc.

References commitTransaction(), coralSession, isActive(), lockedTags, releaseTagLocks(), rollbackTransaction(), startTransaction(), and transaction.

Referenced by esMonitoring.AsyncLineReaderMixin::handle_close(), esMonitoring.FDJsonServer::handle_close(), and ~SessionImpl().

45  {
46  if (isActive()) {
47  if (coralSession->transaction().isActive()) {
49  }
50  if (!lockedTags.empty()) {
51  startTransaction(false);
54  }
55  coralSession.reset();
56  }
57  transaction.reset();
58  }
std::set< std::string > lockedTags
Definition: SessionImpl.h:73
std::shared_ptr< coral::ISessionProxy > coralSession
Definition: SessionImpl.h:69
void startTransaction(bool readOnly=true)
Definition: SessionImpl.cc:62
std::unique_ptr< ITransaction > transaction
Definition: SessionImpl.h:74

◆ commitTransaction()

void cond::persistency::SessionImpl::commitTransaction ( )

Definition at line 78 of file SessionImpl.cc.

References gtSchemaHandle, iovSchemaHandle, CommonMethods::lock(), runInfoSchemaHandle, transaction, and transactionLock.

Referenced by close(), and cond::persistency::Transaction::commit().

78  {
79  std::unique_lock<std::recursive_mutex> lock;
80  lock.swap(transactionLock);
81  if (transaction) {
82  transaction->clients--;
83  if (!transaction->clients) {
84  transaction->commit();
85  transaction.reset();
86  iovSchemaHandle.reset();
87  gtSchemaHandle.reset();
88  runInfoSchemaHandle.reset();
89  }
90  }
91  }
std::unique_ptr< IIOVSchema > iovSchemaHandle
Definition: SessionImpl.h:75
std::unique_ptr< IRunInfoSchema > runInfoSchemaHandle
Definition: SessionImpl.h:77
std::unique_lock< std::recursive_mutex > transactionLock
Definition: SessionImpl.h:82
std::unique_ptr< IGTSchema > gtSchemaHandle
Definition: SessionImpl.h:76
std::unique_ptr< ITransaction > transaction
Definition: SessionImpl.h:74

◆ gtSchema()

IGTSchema & cond::persistency::SessionImpl::gtSchema ( )

Definition at line 202 of file SessionImpl.cc.

References gtSchemaHandle.

202 { return *gtSchemaHandle; }
std::unique_ptr< IGTSchema > gtSchemaHandle
Definition: SessionImpl.h:76

◆ iovSchema()

IIOVSchema & cond::persistency::SessionImpl::iovSchema ( )

Definition at line 200 of file SessionImpl.cc.

References iovSchemaHandle.

Referenced by releaseTagLocks().

200 { return *iovSchemaHandle; }
std::unique_ptr< IIOVSchema > iovSchemaHandle
Definition: SessionImpl.h:75

◆ isActive()

bool cond::persistency::SessionImpl::isActive ( ) const

Definition at line 60 of file SessionImpl.cc.

References coralSession.

Referenced by close().

60 { return coralSession.get(); }
std::shared_ptr< coral::ISessionProxy > coralSession
Definition: SessionImpl.h:69

◆ isTransactionActive()

bool cond::persistency::SessionImpl::isTransactionActive ( bool  deep = true) const

Definition at line 105 of file SessionImpl.cc.

References transaction.

Referenced by cond::persistency::Transaction::isActive().

105  {
106  if (!transaction)
107  return false;
108  if (!deep)
109  return true;
110  return transaction->isActive();
111  }
std::unique_ptr< ITransaction > transaction
Definition: SessionImpl.h:74

◆ openDb()

void cond::persistency::SessionImpl::openDb ( )

Definition at line 179 of file SessionImpl.cc.

References gtSchemaHandle, iovSchemaHandle, cond::persistency::throwException(), and transaction.

179  {
180  if (!transaction.get())
181  throwException("The transaction is not active.", "SessionImpl::openIovDb");
182  if (!transaction->iovDbOpen) {
183  transaction->iovDbExists = iovSchemaHandle->exists();
184  transaction->iovDbOpen = true;
185  }
186  if (!transaction->gtDbOpen) {
187  transaction->gtDbExists = gtSchemaHandle->exists();
188  transaction->gtDbOpen = true;
189  }
190  if (!transaction->iovDbExists) {
191  iovSchemaHandle->create();
192  transaction->iovDbExists = true;
193  if (!transaction->gtDbExists) {
194  gtSchemaHandle->create();
195  transaction->gtDbExists = true;
196  }
197  }
198  }
std::unique_ptr< IIOVSchema > iovSchemaHandle
Definition: SessionImpl.h:75
std::unique_ptr< IGTSchema > gtSchemaHandle
Definition: SessionImpl.h:76
std::unique_ptr< ITransaction > transaction
Definition: SessionImpl.h:74
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:12

◆ openGTDb()

void cond::persistency::SessionImpl::openGTDb ( SessionImpl::FailureOnOpeningPolicy  policy = THROW)

Definition at line 149 of file SessionImpl.cc.

References CREATE, gtSchemaHandle, THROW, cond::persistency::throwException(), and transaction.

149  {
150  if (!transaction.get())
151  throwException("The transaction is not active.", "SessionImpl::openGTDb");
152  if (!transaction->gtDbOpen) {
153  transaction->gtDbExists = gtSchemaHandle->exists();
154  transaction->gtDbOpen = true;
155  }
156  if (!transaction->gtDbExists) {
157  if (policy == CREATE) {
158  gtSchemaHandle->create();
159  transaction->gtDbExists = true;
160  } else {
161  if (policy == THROW)
162  throwException("GT Database does not exist.", "SessionImpl::openGTDb");
163  }
164  }
165  }
std::unique_ptr< IGTSchema > gtSchemaHandle
Definition: SessionImpl.h:76
std::unique_ptr< ITransaction > transaction
Definition: SessionImpl.h:74
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:12

◆ openIovDb()

void cond::persistency::SessionImpl::openIovDb ( SessionImpl::FailureOnOpeningPolicy  policy = THROW)

Definition at line 131 of file SessionImpl.cc.

References CREATE, iovSchemaHandle, THROW, cond::persistency::throwException(), and transaction.

131  {
132  if (!transaction.get())
133  throwException("The transaction is not active.", "SessionImpl::openIovDb");
134  if (!transaction->iovDbOpen) {
135  transaction->iovDbExists = iovSchemaHandle->exists();
136  transaction->iovDbOpen = true;
137  }
138  if (!transaction->iovDbExists) {
139  if (policy == CREATE) {
140  iovSchemaHandle->create();
141  transaction->iovDbExists = true;
142  } else {
143  if (policy == THROW)
144  throwException("IOV Database does not exist.", "SessionImpl::openIovDb");
145  }
146  }
147  }
std::unique_ptr< IIOVSchema > iovSchemaHandle
Definition: SessionImpl.h:75
std::unique_ptr< ITransaction > transaction
Definition: SessionImpl.h:74
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:12

◆ openRunInfoDb()

void cond::persistency::SessionImpl::openRunInfoDb ( )

Definition at line 167 of file SessionImpl.cc.

References runInfoSchemaHandle, cond::persistency::throwException(), and transaction.

167  {
168  if (!transaction.get())
169  throwException("The transaction is not active.", "SessionImpl::openRunInfoDb");
170  if (!transaction->runInfoDbOpen) {
171  transaction->runInfoDbExists = runInfoSchemaHandle->exists();
172  transaction->runInfoDbOpen = true;
173  }
174  if (!transaction->runInfoDbExists) {
175  throwException("RunInfo Database does not exist.", "SessionImpl::openRunInfoDb");
176  }
177  }
std::unique_ptr< IRunInfoSchema > runInfoSchemaHandle
Definition: SessionImpl.h:77
std::unique_ptr< ITransaction > transaction
Definition: SessionImpl.h:74
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:12

◆ releaseTagLocks()

void cond::persistency::SessionImpl::releaseTagLocks ( )
private

Definition at line 113 of file SessionImpl.cc.

References writedatasetfile::action, cond::auth::COND_DBTAG_LOCK_ACCESS_CODE, cond::auth::COND_SESSION_HASH_CODE, cond::persistency::ITagLogTable::insert(), iovSchema(), lockedTags, cond::persistency::ITagAccessPermissionTable::removeEntriesForCredential(), sessionHash, AlCaHLTBitMon_QueryRunRegistry::string, makeGlobalPositionRcd_cfg::tag, cond::persistency::IIOVSchema::tagAccessPermissionTable(), cond::persistency::IIOVSchema::tagLogTable(), cond::persistency::IIOVSchema::tagTable(), and cond::persistency::ITagTable::unsetProtectionCode().

Referenced by close().

113  {
116  std::string lt("-");
117  std::string action("Lock removed by session ");
118  action += sessionHash;
119  for (const auto& tag : lockedTags) {
122  boost::posix_time::microsec_clock::universal_time(),
123  cond::getUserName(),
124  cond::getHostName(),
125  cond::getCommand(),
126  action,
127  lt);
128  }
129  }
virtual void removeEntriesForCredential(const std::string &credential, int credentialType)=0
std::set< std::string > lockedTags
Definition: SessionImpl.h:73
virtual void unsetProtectionCode(const std::string &name, int code)=0
virtual ITagLogTable & tagLogTable()=0
virtual void insert(const std::string &tag, const boost::posix_time::ptime &eventTime, const std::string &userName, const std::string &hostName, const std::string &command, const std::string &action, const std::string &userText)=0
static constexpr int COND_DBTAG_LOCK_ACCESS_CODE
Definition: Auth.h:45
virtual ITagAccessPermissionTable & tagAccessPermissionTable()=0
virtual ITagTable & tagTable()=0
static constexpr int COND_SESSION_HASH_CODE
Definition: Auth.h:42

◆ rollbackTransaction()

void cond::persistency::SessionImpl::rollbackTransaction ( )

Definition at line 93 of file SessionImpl.cc.

References gtSchemaHandle, iovSchemaHandle, CommonMethods::lock(), runInfoSchemaHandle, transaction, and transactionLock.

Referenced by close(), and cond::persistency::Transaction::rollback().

93  {
94  std::unique_lock<std::recursive_mutex> lock;
95  lock.swap(transactionLock);
96  if (transaction) {
97  transaction->rollback();
98  transaction.reset();
99  iovSchemaHandle.reset();
100  gtSchemaHandle.reset();
101  runInfoSchemaHandle.reset();
102  }
103  }
std::unique_ptr< IIOVSchema > iovSchemaHandle
Definition: SessionImpl.h:75
std::unique_ptr< IRunInfoSchema > runInfoSchemaHandle
Definition: SessionImpl.h:77
std::unique_lock< std::recursive_mutex > transactionLock
Definition: SessionImpl.h:82
std::unique_ptr< IGTSchema > gtSchemaHandle
Definition: SessionImpl.h:76
std::unique_ptr< ITransaction > transaction
Definition: SessionImpl.h:74

◆ runInfoSchema()

IRunInfoSchema & cond::persistency::SessionImpl::runInfoSchema ( )

Definition at line 204 of file SessionImpl.cc.

References runInfoSchemaHandle.

204 { return *runInfoSchemaHandle; }
std::unique_ptr< IRunInfoSchema > runInfoSchemaHandle
Definition: SessionImpl.h:77

◆ startTransaction()

void cond::persistency::SessionImpl::startTransaction ( bool  readOnly = true)

Definition at line 62 of file SessionImpl.cc.

References coralSession, gtSchemaHandle, iovSchemaHandle, CommonMethods::lock(), runInfoSchemaHandle, cond::persistency::throwException(), transaction, transactionLock, and transactionMutex.

Referenced by close(), and cond::persistency::Transaction::start().

62  {
63  std::unique_lock<std::recursive_mutex> lock(transactionMutex);
64  if (!transaction.get()) {
65  coralSession->transaction().start(readOnly);
66  iovSchemaHandle = std::make_unique<IOVSchema>(coralSession->nominalSchema());
67  gtSchemaHandle = std::make_unique<GTSchema>(coralSession->nominalSchema());
68  runInfoSchemaHandle = std::make_unique<RunInfoSchema>(coralSession->nominalSchema());
69  transaction = std::make_unique<CondDBTransaction>(coralSession);
70  } else {
71  if (!readOnly)
72  throwException("An update transaction is already active.", "SessionImpl::startTransaction");
73  }
74  transaction->clients++;
75  transactionLock.swap(lock);
76  }
std::shared_ptr< coral::ISessionProxy > coralSession
Definition: SessionImpl.h:69
std::unique_ptr< IIOVSchema > iovSchemaHandle
Definition: SessionImpl.h:75
std::unique_ptr< IRunInfoSchema > runInfoSchemaHandle
Definition: SessionImpl.h:77
std::recursive_mutex transactionMutex
Definition: SessionImpl.h:81
std::unique_lock< std::recursive_mutex > transactionLock
Definition: SessionImpl.h:82
std::unique_ptr< IGTSchema > gtSchemaHandle
Definition: SessionImpl.h:76
std::unique_ptr< ITransaction > transaction
Definition: SessionImpl.h:74
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:12

Member Data Documentation

◆ connectionString

std::string cond::persistency::SessionImpl::connectionString

Definition at line 71 of file SessionImpl.h.

◆ coralSession

std::shared_ptr<coral::ISessionProxy> cond::persistency::SessionImpl::coralSession

Definition at line 69 of file SessionImpl.h.

Referenced by close(), isActive(), and startTransaction().

◆ gtSchemaHandle

std::unique_ptr<IGTSchema> cond::persistency::SessionImpl::gtSchemaHandle

◆ iovSchemaHandle

std::unique_ptr<IIOVSchema> cond::persistency::SessionImpl::iovSchemaHandle

◆ lockedTags

std::set<std::string> cond::persistency::SessionImpl::lockedTags

Definition at line 73 of file SessionImpl.h.

Referenced by close(), and releaseTagLocks().

◆ principalName

std::string cond::persistency::SessionImpl::principalName

Definition at line 72 of file SessionImpl.h.

◆ runInfoSchemaHandle

std::unique_ptr<IRunInfoSchema> cond::persistency::SessionImpl::runInfoSchemaHandle

◆ sessionHash

std::string cond::persistency::SessionImpl::sessionHash

Definition at line 70 of file SessionImpl.h.

Referenced by releaseTagLocks(), and SessionImpl().

◆ transaction

std::unique_ptr<ITransaction> cond::persistency::SessionImpl::transaction

◆ transactionLock

std::unique_lock<std::recursive_mutex> cond::persistency::SessionImpl::transactionLock
private

Definition at line 82 of file SessionImpl.h.

Referenced by commitTransaction(), rollbackTransaction(), and startTransaction().

◆ transactionMutex

std::recursive_mutex cond::persistency::SessionImpl::transactionMutex
private

Definition at line 81 of file SessionImpl.h.

Referenced by startTransaction().