4 #include <openssl/sha.h>
8 namespace persistency {
12 if( !SHA1_Init( &ctx ) ){
13 throwException(
"SHA1 initialization error.",
"IOVSchema::makeHash");
15 if( !SHA1_Update( &ctx, objectType.c_str(), objectType.size() ) ){
16 throwException(
"SHA1 processing error (1).",
"IOVSchema::makeHash");
18 if( !SHA1_Update( &ctx, data.
data(), data.
size() ) ){
19 throwException(
"SHA1 processing error (2).",
"IOVSchema::makeHash");
21 unsigned char hash[SHA_DIGEST_LENGTH];
22 if( !SHA1_Final(hash, &ctx) ){
26 char tmp[SHA_DIGEST_LENGTH*2+1];
28 for (
unsigned int i = 0;
i < 20;
i++) {
29 ::sprintf(&tmp[
i * 2],
"%02x", hash[i]);
39 bool TAG::Table::Table::exists(){
40 return existsTable( m_schema,
tname );
46 "TAG::Table::create");
50 createTable( m_schema, descr.
get() );
56 for (
auto row : q ) {}
58 return q.retrievedRows();
70 for (
auto row : q ) std::tie( timeType, objectType, synchronizationType, endOfValidity, description, lastValidatedTime ) = row;
72 return q.retrievedRows();
77 boost::posix_time::ptime& insertionTime,
78 boost::posix_time::ptime& modificationTime ){
81 for (
auto row : q ) std::tie( description, insertionTime, modificationTime ) = row;
82 return q.retrievedRows();
92 const boost::posix_time::ptime& insertionTime ){
94 dataToInsert( std::tie( name, timeType, objectType, synchronizationType, endOfValidity, description, lastValidatedTime, insertionTime, insertionTime ) );
95 insertInTable( m_schema,
tname, dataToInsert.
get() );
102 const boost::posix_time::ptime& updateTime ){
106 updateTable( m_schema,
tname, buffer );
111 const boost::posix_time::ptime& updateTime ){
115 updateTable( m_schema,
tname, buffer );
123 return existsTable( m_schema,
tname );
129 "IOV::Schema::create");
136 createTable( m_schema, descr.
get() );
145 groups.push_back(std::get<0>(row));
147 return q.retrievedRows();
157 groups.push_back(std::get<0>(row));
159 return q.retrievedRows();
163 std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ){
170 size_t initialSize = iovs.
size();
173 if( iovs.size()-initialSize && std::get<0>(iovs.back()) == std::get<0>(row) )
continue;
174 iovs.push_back( row );
176 return iovs.size()-initialSize;
180 const boost::posix_time::ptime& snapshotTime,
181 std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ){
189 size_t initialSize = iovs.
size();
190 for (
auto row : q ) {
192 if( iovs.size()-initialSize && std::get<0>(iovs.back()) == std::get<0>(row) )
continue;
193 iovs.push_back( row );
195 return iovs.size()-initialSize;
199 std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ){
204 size_t initialSize = iovs.
size();
205 for (
auto row : q ) {
207 if( iovs.size()-initialSize && std::get<0>(iovs.back()) == std::get<0>(row) )
continue;
208 iovs.push_back( row );
210 return iovs.size()-initialSize;
214 const boost::posix_time::ptime& snapshotTime,
215 std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs){
221 size_t initialSize = iovs.
size();
222 for (
auto row : q ) {
224 if( iovs.size()-initialSize && std::get<0>(iovs.back()) == std::get<0>(row) )
continue;
225 iovs.push_back( row );
227 return iovs.size()-initialSize;
235 for (
auto row : q ) {
236 since = std::get<0>(row);
237 hash = std::get<1>(row);
249 for (
auto row : q ) {
250 since = std::get<0>(row);
251 hash = std::get<1>(row);
260 for (
auto row : q ) {
261 size = std::get<0>(row);
271 for (
auto row : q ) {
272 size = std::get<0>(row);
281 const boost::posix_time::ptime& insertTimeStamp ){
283 insertInTable( m_schema,
tname, dataToInsert.
get() );
287 const std::vector<std::tuple<cond::Time_t,cond::Hash,boost::posix_time::ptime> >& iovs ){
289 for(
auto row : iovs ) inserter.
insert( std::tuple_cat( std::tie(tag),row ) );
297 deleteFromTable( m_schema,
tname, buffer );
305 return existsTable( m_schema,
tname );
311 "PAYLOAD::Schema::create");
316 createTable( m_schema, descr.
get() );
322 for (
auto row : q ) {}
324 return q.retrievedRows();
330 for (
auto row : q ) {
331 objectType = std::get<0>(row);
334 return q.retrievedRows();
343 for (
auto row : q ) {
344 std::tie( payloadData, streamerInfoData, objectType ) = row;
346 return q.retrievedRows();
353 const boost::posix_time::ptime& insertionTime ){
357 RowBuffer< HASH, OBJECT_TYPE, DATA, STREAMER_INFO, VERSION, INSERTION_TIME > dataToInsert( std::tie( payloadHash, objectType, payloadData, sinfoData, version, insertionTime ) );
358 bool failOnDuplicate =
false;
359 return insertInTable( m_schema,
tname, dataToInsert.
get(), failOnDuplicate );
365 const boost::posix_time::ptime& insertionTime ){
368 if( !
select( payloadHash ) ){
369 insert( payloadHash, payloadObjectType, payloadData, streamerInfoData, insertionTime );
379 return existsTable( m_schema,
tname );
384 throwException(
"TAG_MIGRATION table already exists in this schema.",
385 "TAG_MIGRATION::create");
390 createTable( m_schema, descr.
get() );
397 for (
auto row : q ) {
398 std::tie( tagName, statusCode ) = row;
401 return q.retrievedRows();
406 int statusCode,
const boost::posix_time::ptime& insertionTime ){
408 dataToInsert( std::tie( sourceAccount, sourceTag, tagName, statusCode, insertionTime ) );
409 insertInTable( m_schema,
tname, dataToInsert.
get() );
417 updateTable( m_schema,
tname, buffer );
425 return existsTable( m_schema,
tname );
430 throwException(
"PAYLOAD_MIGRATION table already exists in this schema.",
431 "PAYLOAD_MIGRATION::create");
436 createTable( m_schema, descr.
get() );
443 for (
auto row : q ) {
444 std::tie( payloadId ) = row;
447 return q.retrievedRows();
451 const boost::posix_time::ptime& insertionTime ){
453 dataToInsert( std::tie( sourceAccount, sourceToken, payloadId, insertionTime ) );
454 insertInTable( m_schema,
tname, dataToInsert.
get() );
458 const boost::posix_time::ptime& insertionTime ){
463 updateTable( m_schema,
tname, buffer );
467 m_tagTable( schema ),
468 m_iovTable( schema ),
469 m_payloadTable( schema ),
470 m_tagMigrationTable( schema ),
471 m_payloadMigrationTable( schema ){
482 bool created =
false;
513 throwException(
"CondDB V2 can't parse a pool token.",
"IOVSchema::parsePoolToken");
Table(coral::ISchema &schema)
void updateValidationCode(const std::string &sourceAccount, const std::string &sourceTag, int statusCode)
bool getSnapshotLastIov(const std::string &tag, const boost::posix_time::ptime &snapshotTime, cond::Time_t &since, cond::Hash &hash)
bool select(const std::string &sourceAccount, const std::string &sourceToken, std::string &payloadId)
bool getSnapshotSize(const std::string &tag, const boost::posix_time::ptime &snapshotTime, size_t &size)
static std::string group()
static char const * tname
bool getSize(const std::string &tag, size_t &size)
const coral::TableDescription & get()
void insert(const std::string &sourceAccount, const std::string &sourceToken, const std::string &payloadId, const boost::posix_time::ptime &insertionTime)
void updateValidity(const std::string &name, cond::Time_t lastValidatedTime, const boost::posix_time::ptime &updateTime)
void insert(const P ¶ms)
size_t selectLatest(const std::string &tag, std::vector< std::tuple< cond::Time_t, cond::Hash > > &iovs)
bool getLastIov(const std::string &tag, cond::Time_t &since, cond::Hash &hash)
PAYLOAD::Table m_payloadTable
std::string parsePoolToken(const std::string &)
void insertMany(const std::string &tag, const std::vector< std::tuple< cond::Time_t, cond::Hash, boost::posix_time::ptime > > &iovs)
size_t selectGroups(const std::string &tag, std::vector< cond::Time_t > &groups)
static char const * tname
void update(const std::string &sourceAccount, const std::string &sourceToken, const std::string &payloadId, const boost::posix_time::ptime &insertionTime)
void setForeignKey(const std::string &name)
bool select(const cond::Hash &payloadHash)
unsigned long long Time_t
void addCondition(const T &value, const std::string condition="=")
static char const * tname
bool select(const std::string &sourceAccount, const std::string &sourceTag, std::string &tagName, int &statusCode)
const coral::AttributeList & get() const
void addOrderClause(bool ascending=true)
TAG_MIGRATION::Table m_tagMigrationTable
void erase(const std::string &tag)
void copy(const std::string &source)
void update(const std::string &name, cond::Time_t &endOfValidity, const std::string &description, cond::Time_t lastValidatedTime, const boost::posix_time::ptime &updateTime)
IPayloadTable & payloadTable()
PAYLOAD_MIGRATION::Table m_payloadMigrationTable
bool insert(Storage &iStorage, ItemType *iItem, const IdTag &iIdTag)
bool select(const std::string &name)
ITagMigrationTable & tagMigrationTable()
bool getType(const cond::Hash &payloadHash, std::string &objectType)
const void * data() const
void setColumnData(const Params ¶ms)
static char const * tname
Table(coral::ISchema &schema)
IOVSchema(coral::ISchema &schema)
cond::Hash insertIfNew(const std::string &objectType, const cond::Binary &payloadData, const cond::Binary &streamerInfoData, const boost::posix_time::ptime &insertionTime)
size_t selectSnapshot(const std::string &tag, const boost::posix_time::ptime &snapshotTime, std::vector< std::tuple< cond::Time_t, cond::Hash > > &iovs)
std::vector< std::vector< double > > tmp
char data[epos_bytes_allocation]
void groupBy(const std::string &expression)
cond::Hash makeHash(const std::string &objectType, const cond::Binary &data)
Table(coral::ISchema &schema)
size_t selectSnapshotByGroup(const std::string &tag, cond::Time_t lowerGroup, cond::Time_t upperGroup, const boost::posix_time::ptime &snapshotTime, std::vector< std::tuple< cond::Time_t, cond::Hash > > &iovs)
bool insert(const cond::Hash &payloadHash, const std::string &objectType, const cond::Binary &payloadData, const cond::Binary &streamerInfoData, const boost::posix_time::ptime &insertionTime)
Table(coral::ISchema &schema)
volatile std::atomic< bool > shutdown_flag false
void insert(const std::string &sourceAccount, const std::string &sourceTag, const std::string &tagName, int statusCode, const boost::posix_time::ptime &insertionTime)
IPayloadMigrationTable & payloadMigrationTable()
Table(coral::ISchema &schema)
static char const * tname
void insert(const std::string &name, cond::TimeType timeType, const std::string &objectType, cond::SynchronizationType synchronizationType, cond::Time_t endOfValidity, const std::string &description, cond::Time_t lastValidatedTime, const boost::posix_time::ptime &insertionTime)
void addWhereCondition(const P ¶m, const std::string condition="=")
bool getMetadata(const std::string &name, std::string &description, boost::posix_time::ptime &insertionTime, boost::posix_time::ptime &modificationTime)
const Time_t MAX_VAL(std::numeric_limits< Time_t >::max())
void insertOne(const std::string &tag, cond::Time_t since, cond::Hash payloadHash, const boost::posix_time::ptime &insertTime)
tuple size
Write out results.
void throwException(const std::string &message, const std::string &methodName)
size_t selectSnapshotGroups(const std::string &tag, const boost::posix_time::ptime &snapshotTime, std::vector< cond::Time_t > &groups)
size_t selectLatestByGroup(const std::string &tag, cond::Time_t lowerGroup, cond::Time_t upperGroup, std::vector< std::tuple< cond::Time_t, cond::Hash > > &iovs)
void addWhereCondition(const P ¶m, const std::string condition="=")