diff --git a/catalogue/ArchiveFileRowWithoutTimestamps.cpp b/catalogue/ArchiveFileRowWithoutTimestamps.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e8da05414da561f87ed069a59ad57c816c595cdc --- /dev/null +++ b/catalogue/ArchiveFileRowWithoutTimestamps.cpp @@ -0,0 +1,66 @@ +/* + * The CERN Tape Archive (CTA) project + * Copyright (C) 2015 CERN + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "catalogue/ArchiveFileRowWithoutTimestamps.hpp" + +namespace cta { +namespace catalogue { + +//------------------------------------------------------------------------------ +// constructor +//------------------------------------------------------------------------------ +ArchiveFileRowWithoutTimestamps::ArchiveFileRowWithoutTimestamps() : + archiveFileId(0), + size(0) { +} + +//------------------------------------------------------------------------------ +// operator== +//------------------------------------------------------------------------------ +bool ArchiveFileRowWithoutTimestamps::operator==(const ArchiveFileRowWithoutTimestamps &rhs) const { + return + archiveFileId == rhs.archiveFileId && + diskInstance == rhs.diskInstance && + diskFileId == rhs.diskFileId && + diskFileOwnerUid == rhs.diskFileOwnerUid && + diskFileGid == rhs.diskFileGid && + size == rhs.size && + checksumBlob == rhs.checksumBlob && + storageClassName == rhs.storageClassName; +} + +//------------------------------------------------------------------------------ +// operator<< +//------------------------------------------------------------------------------ +std::ostream &operator<<(std::ostream &os, const ArchiveFileRowWithoutTimestamps &obj) { + os << + "{" + "archiveFileId=" << obj.archiveFileId << + "diskInstance=" << obj.diskInstance << + "diskFileId=" << obj.diskFileId << + "diskFileOwnerUid=" << obj.diskFileOwnerUid << + "diskFileGid=" << obj.diskFileGid << + "size=" << obj.size << + "checksumBlob=" << obj.checksumBlob << + "storageClassName=" << obj.storageClassName << + "}"; + return os; +} + +} // namespace catalogue +} // namespace cta diff --git a/catalogue/ArchiveFileRowWithoutTimestamps.hpp b/catalogue/ArchiveFileRowWithoutTimestamps.hpp new file mode 100644 index 0000000000000000000000000000000000000000..f14fc6d92679d337fafffbf61f644b1ca135b54f --- /dev/null +++ b/catalogue/ArchiveFileRowWithoutTimestamps.hpp @@ -0,0 +1,106 @@ +/* + * The CERN Tape Archive (CTA) project + * Copyright (C) 2015 CERN + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#pragma once + +#include "common/checksum/ChecksumBlob.hpp" + +#include <stdint.h> +#include <string> + +namespace cta { +namespace catalogue { + +/** + * A row in the ArchiveFile table without the timestamp columns, namely + * CREATION_TIME and RECONCILIATION_TIME. + */ +struct ArchiveFileRowWithoutTimestamps { + + /** + * Constructor. + * + * Sets the value of all integer member-variables to zero. + */ + ArchiveFileRowWithoutTimestamps(); + + /** + * Equality operator. + * + * @param ths The right hand side of the operator. + */ + bool operator==(const ArchiveFileRowWithoutTimestamps &rhs) const; + + /** + * The unique identifier of the file being archived. + */ + uint64_t archiveFileId; + + /** + * The instance name of the source disk system. + */ + std::string diskInstance; + + /** + * The identifier of the source disk file which is unique within it's host + * disk system. Two files from different disk systems may have the same + * identifier. The combination of diskInstance and diskFileId must be + * globally unique, in other words unique within the CTA catalogue. + */ + std::string diskFileId; + + /** + * The user ID of the owner of the source disk file within its host disk system. + */ + uint32_t diskFileOwnerUid; + + /** + * The group ID of the source disk file within its host disk system. + */ + uint32_t diskFileGid; + + /** + * The uncompressed size of the tape file in bytes. + */ + uint64_t size; + + /** + * Set of checksum types and values + */ + checksum::ChecksumBlob checksumBlob; + + /** + * The name of the file's storage class. + */ + std::string storageClassName; + +}; // struct ArchiveFileRowWithoutTimestamps + +/** + * Output stream operator for an ArchiveFileRowWithoutTimestamps object. + * + * This function writes a human readable form of the specified object to the + * specified output stream. + * + * @param os The output stream. + * @param obj The object. + */ +std::ostream &operator<<(std::ostream &os, const ArchiveFileRowWithoutTimestamps &obj); + +} // namespace catalogue +} // namespace cta diff --git a/catalogue/CMakeLists.txt b/catalogue/CMakeLists.txt index f4116cdad79dc73e6c2326b2254a886ec273c7ac..a29d311794946562ac2315c9d5d1fdf41f60cf33 100644 --- a/catalogue/CMakeLists.txt +++ b/catalogue/CMakeLists.txt @@ -29,6 +29,7 @@ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wshadow") set (CATALOGUE_LIB_SRC_FILES ArchiveFileBuilder.cpp ArchiveFileRow.cpp + ArchiveFileRowWithoutTimestamps.cpp Catalogue.cpp CatalogueFactory.cpp CatalogueFactoryFactory.cpp diff --git a/catalogue/MysqlCatalogue.cpp b/catalogue/MysqlCatalogue.cpp index a1ddbf7c3b084c304b3ce433749a3d80e17a291b..9ae34600e729f95ecade195adf7fa48e1c088527 100644 --- a/catalogue/MysqlCatalogue.cpp +++ b/catalogue/MysqlCatalogue.cpp @@ -17,6 +17,7 @@ */ #include "catalogue/ArchiveFileRow.hpp" +#include "catalogue/ArchiveFileRowWithoutTimestamps.hpp" #include "catalogue/MysqlCatalogueSchema.hpp" #include "catalogue/MysqlCatalogue.hpp" #include "common/exception/Exception.hpp" @@ -438,7 +439,7 @@ void MysqlCatalogue::fileWrittenToTape(rdbms::Conn &conn, const TapeFileWritten // Try to insert a row into the ARCHIVE_FILE table - it is normal this will // fail if another tape copy has already been written to tape try { - ArchiveFileRow row; + ArchiveFileRowWithoutTimestamps row; row.archiveFileId = event.archiveFileId; row.diskFileId = event.diskFileId; row.diskInstance = event.diskInstance; diff --git a/catalogue/RdbmsCatalogue.cpp b/catalogue/RdbmsCatalogue.cpp index 257945f62136e4e742e5090bdf5afd0fa9c1f918..ce57a17688f3d1e0cef74a4fa5cf1d467d36eede 100644 --- a/catalogue/RdbmsCatalogue.cpp +++ b/catalogue/RdbmsCatalogue.cpp @@ -17,6 +17,7 @@ */ #include "catalogue/ArchiveFileRow.hpp" +#include "catalogue/ArchiveFileRowWithoutTimestamps.hpp" #include "catalogue/RdbmsCatalogue.hpp" #include "catalogue/RdbmsCatalogueGetArchiveFilesItor.hpp" #include "catalogue/RdbmsCatalogueGetArchiveFilesForRepackItor.hpp" @@ -6448,7 +6449,7 @@ void RdbmsCatalogue::modifyDiskSystemSleepTime(const common::dataStructures::Sec //------------------------------------------------------------------------------ // insertArchiveFile //------------------------------------------------------------------------------ -void RdbmsCatalogue::insertArchiveFile(rdbms::Conn &conn, const ArchiveFileRow &row) { +void RdbmsCatalogue::insertArchiveFile(rdbms::Conn &conn, const ArchiveFileRowWithoutTimestamps &row) { try { if(!storageClassExists(conn, row.storageClassName)) { throw exception::UserError(std::string("Storage class ") + row.diskInstance + ":" + row.storageClassName + diff --git a/catalogue/RdbmsCatalogue.hpp b/catalogue/RdbmsCatalogue.hpp index 7334c54c60c6cce4d3a87e260f044a60d12c8c7d..c07097a29181ea0a55727427d2dd4344eb34c4e8 100644 --- a/catalogue/RdbmsCatalogue.hpp +++ b/catalogue/RdbmsCatalogue.hpp @@ -48,6 +48,11 @@ namespace catalogue { */ class ArchiveFileRow; +/** + * Forward declaration. + */ +class ArchiveFileRowWithoutTimestamps; + /** * Forward declaration. */ @@ -1297,7 +1302,7 @@ protected: * @param conn The database connection. * @param row The row to be inserted. */ - void insertArchiveFile(rdbms::Conn &conn, const ArchiveFileRow &row); + void insertArchiveFile(rdbms::Conn &conn, const ArchiveFileRowWithoutTimestamps &row); /** * Creates the database schema. diff --git a/catalogue/SqliteCatalogue.cpp b/catalogue/SqliteCatalogue.cpp index db2d7c654c813e8556c0d52fd3f600ca3576150a..d5f2a12f369dc2ac9d0296ec1db2242fe47fa12a 100644 --- a/catalogue/SqliteCatalogue.cpp +++ b/catalogue/SqliteCatalogue.cpp @@ -17,10 +17,12 @@ */ #include "catalogue/ArchiveFileRow.hpp" +#include "catalogue/ArchiveFileRowWithoutTimestamps.hpp" #include "catalogue/SqliteCatalogueSchema.hpp" #include "catalogue/SqliteCatalogue.hpp" #include "common/exception/Exception.hpp" #include "common/exception/UserError.hpp" +#include "common/log/TimingList.hpp" #include "common/make_unique.hpp" #include "common/threading/MutexLocker.hpp" #include "common/Timer.hpp" @@ -28,7 +30,6 @@ #include "rdbms/AutoRollback.hpp" #include "rdbms/ConstraintError.hpp" #include "rdbms/PrimaryKeyError.hpp" -#include "common/log/TimingList.hpp" namespace cta { namespace catalogue { @@ -505,7 +506,7 @@ void SqliteCatalogue::fileWrittenToTape(rdbms::Conn &conn, const TapeFileWritten // Try to insert a row into the ARCHIVE_FILE table - it is normal this will // fail if another tape copy has already been written to tape try { - ArchiveFileRow row; + ArchiveFileRowWithoutTimestamps row; row.archiveFileId = event.archiveFileId; row.diskFileId = event.diskFileId; row.diskInstance = event.diskInstance;