Commit 71ac1c9d authored by Steven Murray's avatar Steven Murray
Browse files

cta/CTA#185 CTA should use cached SQL statements in order to improve database performance

Done
parent 80a2f8ac
......@@ -15,9 +15,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
cmake_minimum_required (VERSION 2.6)
if (OCCI_SUPPORT)
include_directories (${ORACLE-INSTANTCLIENT_INCLUDE_DIRS})
endif (OCCI_SUPPORT)
include_directories (${ORACLE-INSTANTCLIENT_INCLUDE_DIRS})
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wshadow")
......@@ -37,25 +35,17 @@ set (CATALOGUE_LIB_SRC_FILES
SqliteCatalogue.cpp
TapeForWriting.cpp)
if (OCCI_SUPPORT)
set (CATALOGUE_LIB_SRC_FILES
${CATALOGUE_LIB_SRC_FILES}
CatalogueFactory.cpp
OracleCatalogue.cpp)
else (OCCI_SUPPORT)
set (CATALOGUE_LIB_SRC_FILES
${CATALOGUE_LIB_SRC_FILES}
CatalogueFactory_OCCI_SUPPORT_OFF.cpp)
endif (OCCI_SUPPORT)
set (CATALOGUE_LIB_SRC_FILES
${CATALOGUE_LIB_SRC_FILES}
CatalogueFactory.cpp
OracleCatalogue.cpp)
add_library (ctacatalogue SHARED
${CATALOGUE_LIB_SRC_FILES})
set_property(TARGET ctacatalogue PROPERTY SOVERSION "${CTA_SOVERSION}")
set_property(TARGET ctacatalogue PROPERTY VERSION "${CTA_LIBVERSION}")
if (OCCI_SUPPORT)
set_property (TARGET ctacatalogue APPEND PROPERTY INSTALL_RPATH ${ORACLE-INSTANTCLIENT_RPATH})
endif (OCCI_SUPPORT)
set_property (TARGET ctacatalogue APPEND PROPERTY INSTALL_RPATH ${ORACLE-INSTANTCLIENT_RPATH})
install (TARGETS ctacatalogue DESTINATION usr/${CMAKE_INSTALL_LIBDIR})
......@@ -133,9 +123,7 @@ add_executable(cta-catalogue-schema-create
target_link_libraries (cta-catalogue-schema-create
ctacatalogue)
if (OCCI_SUPPORT)
set_property (TARGET cta-catalogue-schema-create APPEND PROPERTY INSTALL_RPATH ${ORACLE-INSTANTCLIENT_RPATH})
endif (OCCI_SUPPORT)
set_property (TARGET cta-catalogue-schema-create APPEND PROPERTY INSTALL_RPATH ${ORACLE-INSTANTCLIENT_RPATH})
install (TARGETS cta-catalogue-schema-create DESTINATION /usr/bin)
install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/cta-catalogue-schema-create.1cta DESTINATION /usr/share/man/man1)
......@@ -148,9 +136,7 @@ add_executable(cta-catalogue-schema-drop
target_link_libraries (cta-catalogue-schema-drop
ctacatalogue)
if (OCCI_SUPPORT)
set_property (TARGET cta-catalogue-schema-drop APPEND PROPERTY INSTALL_RPATH ${ORACLE-INSTANTCLIENT_RPATH})
endif (OCCI_SUPPORT)
set_property (TARGET cta-catalogue-schema-drop APPEND PROPERTY INSTALL_RPATH ${ORACLE-INSTANTCLIENT_RPATH})
install (TARGETS cta-catalogue-schema-drop DESTINATION /usr/bin)
install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/cta-catalogue-schema-drop.1cta DESTINATION /usr/share/man/man1)
......@@ -163,9 +149,7 @@ add_executable(cta-database-poll
target_link_libraries (cta-database-poll
ctacatalogue)
if (OCCI_SUPPORT)
set_property (TARGET cta-database-poll APPEND PROPERTY INSTALL_RPATH ${ORACLE-INSTANTCLIENT_RPATH})
endif (OCCI_SUPPORT)
set_property (TARGET cta-database-poll APPEND PROPERTY INSTALL_RPATH ${ORACLE-INSTANTCLIENT_RPATH})
install (TARGETS cta-database-poll DESTINATION /usr/bin)
install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/cta-database-poll.1cta DESTINATION /usr/share/man/man1)
......@@ -178,9 +162,7 @@ add_executable(cta-catalogue-admin-user-create
target_link_libraries (cta-catalogue-admin-user-create
ctacatalogue)
if (OCCI_SUPPORT)
set_property (TARGET cta-catalogue-admin-user-create APPEND PROPERTY INSTALL_RPATH ${ORACLE-INSTANTCLIENT_RPATH})
endif (OCCI_SUPPORT)
set_property (TARGET cta-catalogue-admin-user-create APPEND PROPERTY INSTALL_RPATH ${ORACLE-INSTANTCLIENT_RPATH})
install (TARGETS cta-catalogue-admin-user-create DESTINATION /usr/bin)
install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/cta-catalogue-admin-user-create.1cta DESTINATION /usr/share/man/man1)
......@@ -193,9 +175,7 @@ add_executable(cta-catalogue-admin-host-create
target_link_libraries (cta-catalogue-admin-host-create
ctacatalogue)
if (OCCI_SUPPORT)
set_property (TARGET cta-catalogue-admin-host-create APPEND PROPERTY INSTALL_RPATH ${ORACLE-INSTANTCLIENT_RPATH})
endif (OCCI_SUPPORT)
set_property (TARGET cta-catalogue-admin-host-create APPEND PROPERTY INSTALL_RPATH ${ORACLE-INSTANTCLIENT_RPATH})
install (TARGETS cta-catalogue-admin-host-create DESTINATION /usr/bin)
install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/cta-catalogue-admin-host-create.1cta DESTINATION /usr/share/man/man1)
......
......@@ -21,7 +21,7 @@
#include "catalogue/CatalogueTest.hpp"
#include "common/exception/Exception.hpp"
#include "common/exception/UserError.hpp"
#include "rdbms/ConnFactoryFactory.hpp"
#include "rdbms/wrapper/ConnFactoryFactory.hpp"
#include <algorithm>
#include <gtest/gtest.h>
......@@ -53,7 +53,7 @@ void cta_catalogue_CatalogueTest::SetUp() {
try {
const rdbms::Login &login = GetParam()->create();
auto connFactory = rdbms::ConnFactoryFactory::create(login);
auto connFactory = rdbms::wrapper::ConnFactoryFactory::create(login);
const uint64_t nbConns = 2;
const uint64_t nbArchiveFileListingConns = 2;
......
......@@ -22,7 +22,7 @@
#include "catalogue/CatalogueFactory.hpp"
#include "common/exception/Exception.hpp"
#include "common/log/DummyLogger.hpp"
#include "rdbms/Conn.hpp"
#include "rdbms/wrapper/Conn.hpp"
#include "rdbms/LoginFactory.hpp"
#include <gtest/gtest.h>
......@@ -48,7 +48,7 @@ protected:
* A general purpose database connection outside of the m_catalogue object to
* be used to run tests directly on the underlying "raw" catalogue database.
*/
std::unique_ptr<cta::rdbms::Conn> m_conn;
std::unique_ptr<cta::rdbms::wrapper::Conn> m_conn;
virtual void SetUp();
......
......@@ -21,7 +21,7 @@
#include "catalogue/CreateAdminHostCmdLineArgs.hpp"
#include "common/exception/Exception.hpp"
#include "common/log/DummyLogger.hpp"
#include "rdbms/ConnFactoryFactory.hpp"
#include "rdbms/wrapper/ConnFactoryFactory.hpp"
namespace cta {
namespace catalogue {
......
......@@ -21,7 +21,7 @@
#include "catalogue/CreateAdminUserCmdLineArgs.hpp"
#include "common/exception/Exception.hpp"
#include "common/log/DummyLogger.hpp"
#include "rdbms/ConnFactoryFactory.hpp"
#include "rdbms/wrapper/ConnFactoryFactory.hpp"
namespace cta {
namespace catalogue {
......
......@@ -16,14 +16,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "rdbms/ConnFactoryFactory.hpp"
#include "catalogue/CreateSchemaCmd.hpp"
#include "catalogue/CreateSchemaCmdLineArgs.hpp"
#include "catalogue/OracleCatalogueSchema.hpp"
#include "catalogue/SqliteCatalogueSchema.hpp"
#include "common/exception/Exception.hpp"
#include <iostream>
#include "rdbms/ConnPool.hpp"
#include "rdbms/Login.hpp"
namespace cta {
namespace catalogue {
......@@ -53,10 +52,11 @@ int CreateSchemaCmd::exceptionThrowingMain(const int argc, char *const *const ar
}
const auto login = rdbms::Login::parseFile(cmdLineArgs.dbConfigPath);
auto factory = rdbms::ConnFactoryFactory::create(login);
auto conn = factory->create();
const uint64_t maxNbConns = 1;
rdbms::ConnPool connPool(login, maxNbConns);
auto conn = connPool.getConn();;
const bool ctaCatalogueTableExists = tableExists("CTA_CATALOGUE", *conn);
const bool ctaCatalogueTableExists = tableExists("CTA_CATALOGUE", conn);
if(ctaCatalogueTableExists) {
std::cerr << "Cannot create the database schema because the CTA_CATALOGUE table already exists" << std::endl;
......@@ -68,13 +68,13 @@ int CreateSchemaCmd::exceptionThrowingMain(const int argc, char *const *const ar
case rdbms::Login::DBTYPE_SQLITE:
{
SqliteCatalogueSchema schema;
conn->executeNonQueries(schema.sql);
conn.executeNonQueries(schema.sql);
}
break;
case rdbms::Login::DBTYPE_ORACLE:
{
OracleCatalogueSchema schema;
conn->executeNonQueries(schema.sql);
conn.executeNonQueries(schema.sql);
}
break;
case rdbms::Login::DBTYPE_NONE:
......
......@@ -22,11 +22,9 @@
#include "catalogue/DropSchemaCmdLineArgs.hpp"
#include "catalogue/DropSqliteCatalogueSchema.hpp"
#include "common/exception/Exception.hpp"
#include "rdbms/ConnFactoryFactory.hpp"
#include "rdbms/OcciConn.hpp"
#include "rdbms/ConnPool.hpp"
#include <algorithm>
#include <rdbms/OcciConn.hpp>
namespace cta {
namespace catalogue {
......@@ -59,45 +57,20 @@ int DropSchemaCmd::exceptionThrowingMain(const int argc, char *const *const argv
}
const rdbms::Login dbLogin = rdbms::Login::parseFile(cmdLineArgs.dbConfigPath);
auto factory = rdbms::ConnFactoryFactory::create(dbLogin);
auto conn = factory->create();
const uint64_t maxNbConns = 1;
rdbms::ConnPool connPool(dbLogin, maxNbConns);
auto conn = connPool.getConn();
// Abort if the schema is already dropped
switch(dbLogin.dbType) {
case rdbms::Login::DBTYPE_IN_MEMORY:
case rdbms::Login::DBTYPE_SQLITE:
if (conn->getTableNames().empty()) {
m_out << "Database contains no tables." << std::endl <<
"Assuming the schema has already been dropped." << std::endl;
return 0;
}
break;
case rdbms::Login::DBTYPE_ORACLE:
{
rdbms::OcciConn *const occiConn = dynamic_cast<rdbms::OcciConn *>(conn.get());
if(nullptr == occiConn) {
throw exception::Exception("Failed to down cast rdbms::conn to rdbms::OcciConn");
}
if(occiConn->getTableNames().empty() && occiConn->getSequenceNames().empty()) {
m_out << "Database contains no tables and no sequences." << std::endl <<
"Assuming the schema has already been dropped." << std::endl;
return 0;
}
}
break;
case rdbms::Login::DBTYPE_NONE:
throw exception::Exception("Cannot delete the schema of catalogue database without a database type");
default:
{
exception::Exception ex;
ex.getMessage() << "Unknown database type: value=" << dbLogin.dbType;
throw ex;
}
if(conn.getTableNames().empty() && conn.getSequenceNames().empty()) {
m_out << "Database contains no tables and no sequences." << std::endl <<
"Assuming the schema has already been dropped." << std::endl;
return 0;
}
if(userConfirmsDropOfSchema(dbLogin)) {
m_out << "DROPPING the schema of the CTA calalogue database" << std::endl;
dropCatalogueSchema(dbLogin.dbType, *conn);
dropCatalogueSchema(dbLogin.dbType, conn);
} else {
m_out << "Aborting" << std::endl;
}
......@@ -186,7 +159,7 @@ void DropSchemaCmd::dropDatabaseTables(rdbms::Conn &conn, const std::list<std::s
for(auto tableToDrop : tablesToDrop) {
const bool tableToDropIsInDb = tablesInDb.end() != std::find(tablesInDb.begin(), tablesInDb.end(), tableToDrop);
if(tableToDropIsInDb) {
conn.executeNonQuery(std::string("DROP TABLE ") + tableToDrop, rdbms::Stmt::AutocommitMode::ON);
conn.executeNonQuery(std::string("DROP TABLE ") + tableToDrop, rdbms::AutocommitMode::ON);
m_out << "Dropped table " << tableToDrop << std::endl;
}
}
......@@ -220,8 +193,7 @@ void DropSchemaCmd::dropOracleCatalogueSchema(rdbms::Conn &conn) {
dropDatabaseTables(conn, tablesToDrop);
std::list<std::string> sequencesToDrop = {"ARCHIVE_FILE_ID_SEQ"};
rdbms::OcciConn &occiConn = dynamic_cast<rdbms::OcciConn &>(conn);
dropDatabaseSequences(occiConn, sequencesToDrop);
dropDatabaseSequences(conn, sequencesToDrop);
} catch(exception::Exception &ex) {
throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str());
}
......@@ -230,14 +202,14 @@ void DropSchemaCmd::dropOracleCatalogueSchema(rdbms::Conn &conn) {
//------------------------------------------------------------------------------
// dropDatabaseSequences
//------------------------------------------------------------------------------
void DropSchemaCmd::dropDatabaseSequences(rdbms::OcciConn &conn, const std::list<std::string> &sequencesToDrop) {
void DropSchemaCmd::dropDatabaseSequences(rdbms::Conn &conn, const std::list<std::string> &sequencesToDrop) {
try {
std::list<std::string> sequencesInDb = conn.getSequenceNames();
for(auto sequenceToDrop : sequencesToDrop) {
const bool sequenceToDropIsInDb = sequencesInDb.end() != std::find(sequencesInDb.begin(), sequencesInDb.end(),
sequenceToDrop);
if(sequenceToDropIsInDb) {
conn.executeNonQuery(std::string("DROP SEQUENCE ") + sequenceToDrop, rdbms::Stmt::AutocommitMode::ON);
conn.executeNonQuery(std::string("DROP SEQUENCE ") + sequenceToDrop, rdbms::AutocommitMode::ON);
m_out << "Dropped sequence " << sequenceToDrop << std::endl;
}
}
......
......@@ -22,7 +22,6 @@
#include "catalogue/CmdLineTool.hpp"
#include "rdbms/Conn.hpp"
#include "rdbms/Login.hpp"
#include "rdbms/OcciConn.hpp"
namespace cta {
namespace catalogue {
......@@ -109,9 +108,10 @@ private:
/**
* Drops the database sequences with the specified names.
*
* @param conn The database connection.
* @param seqeuncesToDrop The names of the database sequences to be dropped.
*/
void dropDatabaseSequences(rdbms::OcciConn &conn, const std::list<std::string> &sequencesToDrop);
void dropDatabaseSequences(rdbms::Conn &conn, const std::list<std::string> &sequencesToDrop);
}; // class DropSchemaCmd
......
......@@ -17,9 +17,6 @@
*/
#include "catalogue/InMemoryCatalogue.hpp"
#include "catalogue/SqliteCatalogueSchema.hpp"
#include "rdbms/SqliteConn.hpp"
#include "rdbms/SqliteConnFactory.hpp"
namespace cta {
namespace catalogue {
......
......@@ -25,14 +25,90 @@
#include "common/Timer.hpp"
#include "common/utils/utils.hpp"
#include "rdbms/AutoRollback.hpp"
#include "rdbms/ConnFactoryFactory.hpp"
#include "rdbms/OcciStmt.hpp"
#include "rdbms/wrapper/OcciColumn.hpp"
#include "rdbms/wrapper/OcciStmt.hpp"
#include <string.h>
namespace cta {
namespace catalogue {
namespace {
/**
* Structure used to assemble a batch of rows to insert into the TAPE_FILE
* table.
*/
struct TapeFileBatch {
size_t nbRows;
rdbms::wrapper::OcciColumn vid;
rdbms::wrapper::OcciColumn fSeq;
rdbms::wrapper::OcciColumn blockId;
rdbms::wrapper::OcciColumn compressedSize;
rdbms::wrapper::OcciColumn copyNb;
rdbms::wrapper::OcciColumn creationTime;
rdbms::wrapper::OcciColumn archiveFileId;
/**
* Constructor.
*
* @param nbRowsValue The Number of rows to be inserted.
*/
TapeFileBatch(const size_t nbRowsValue):
nbRows(nbRowsValue),
vid("VID", nbRows),
fSeq("FSEQ", nbRows),
blockId("BLOCK_ID", nbRows),
compressedSize("COMPRESSED_SIZE_IN_BYTES", nbRows),
copyNb("COPY_NB", nbRows),
creationTime("CREATION_TIME", nbRows),
archiveFileId("ARCHIVE_FILE_ID", nbRows) {
}
}; // struct TapeFileBatch
/**
* Structure used to assemble a batch of rows to insert into the ARCHIVE_FILE
* table.
*/
struct ArchiveFileBatch {
size_t nbRows;
rdbms::wrapper::OcciColumn archiveFileId;
rdbms::wrapper::OcciColumn diskInstance;
rdbms::wrapper::OcciColumn diskFileId;
rdbms::wrapper::OcciColumn diskFilePath;
rdbms::wrapper::OcciColumn diskFileUser;
rdbms::wrapper::OcciColumn diskFileGroup;
rdbms::wrapper::OcciColumn diskFileRecoveryBlob;
rdbms::wrapper::OcciColumn size;
rdbms::wrapper::OcciColumn checksumType;
rdbms::wrapper::OcciColumn checksumValue;
rdbms::wrapper::OcciColumn storageClassName;
rdbms::wrapper::OcciColumn creationTime;
rdbms::wrapper::OcciColumn reconciliationTime;
/**
* Constructor.
*
* @param nbRowsValue The Number of rows to be inserted.
*/
ArchiveFileBatch(const size_t nbRowsValue):
nbRows(nbRowsValue),
archiveFileId("ARCHIVE_FILE_ID", nbRows),
diskInstance("DISK_INSTANCE_NAME", nbRows),
diskFileId("DISK_FILE_ID", nbRows),
diskFilePath("DISK_FILE_PATH", nbRows),
diskFileUser("DISK_FILE_USER", nbRows),
diskFileGroup("DISK_FILE_GROUP", nbRows),
diskFileRecoveryBlob("DISK_FILE_RECOVERY_BLOB", nbRows),
size("SIZE_IN_BYTES", nbRows),
checksumType("CHECKSUM_TYPE", nbRows),
checksumValue("CHECKSUM_VALUE", nbRows),
storageClassName("STORAGE_CLASS_NAME", nbRows),
creationTime("CREATION_TIME", nbRows),
reconciliationTime("RECONCILIATION_TIME", nbRows) {
}
}; // struct ArchiveFileBatch
} // anonymous namespace
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
......@@ -45,7 +121,7 @@ OracleCatalogue::OracleCatalogue(
const uint64_t nbArchiveFileListingConns):
RdbmsCatalogue(
log,
rdbms::ConnFactoryFactory::create(rdbms::Login(rdbms::Login::DBTYPE_ORACLE, username, password, database)),
rdbms::Login(rdbms::Login::DBTYPE_ORACLE, username, password, database),
nbConns,
nbArchiveFileListingConns) {
......@@ -94,11 +170,11 @@ void OracleCatalogue::deleteArchiveFile(const std::string &diskInstanceName, con
utils::Timer t;
auto conn = m_connPool.getConn();
const auto getConnTime = t.secs(utils::Timer::resetCounter);
auto selectStmt = conn.createStmt(selectSql, rdbms::Stmt::AutocommitMode::OFF);
auto selectStmt = conn.createStmt(selectSql, rdbms::AutocommitMode::OFF);
const auto createStmtTime = t.secs();
selectStmt->bindUint64(":ARCHIVE_FILE_ID", archiveFileId);
selectStmt.bindUint64(":ARCHIVE_FILE_ID", archiveFileId);
t.reset();
rdbms::Rset selectRset = selectStmt->executeQuery();
rdbms::Rset selectRset = selectStmt.executeQuery();
const auto selectFromArchiveFileTime = t.secs();
std::unique_ptr<common::dataStructures::ArchiveFile> archiveFile;
while(selectRset.next()) {
......@@ -189,17 +265,17 @@ void OracleCatalogue::deleteArchiveFile(const std::string &diskInstanceName, con
t.reset();
{
const char *const sql = "DELETE FROM TAPE_FILE WHERE ARCHIVE_FILE_ID = :ARCHIVE_FILE_ID";
auto stmt = conn.createStmt(sql, rdbms::Stmt::AutocommitMode::OFF);
stmt->bindUint64(":ARCHIVE_FILE_ID", archiveFileId);
stmt->executeNonQuery();
auto stmt = conn.createStmt(sql, rdbms::AutocommitMode::OFF);
stmt.bindUint64(":ARCHIVE_FILE_ID", archiveFileId);
stmt.executeNonQuery();
}
const auto deleteFromTapeFileTime = t.secs(utils::Timer::resetCounter);
{
const char *const sql = "DELETE FROM ARCHIVE_FILE WHERE ARCHIVE_FILE_ID = :ARCHIVE_FILE_ID";
auto stmt = conn.createStmt(sql, rdbms::Stmt::AutocommitMode::OFF);
stmt->bindUint64(":ARCHIVE_FILE_ID", archiveFileId);
stmt->executeNonQuery();
auto stmt = conn.createStmt(sql, rdbms::AutocommitMode::OFF);
stmt.bindUint64(":ARCHIVE_FILE_ID", archiveFileId);
stmt.executeNonQuery();
}
const auto deleteFromArchiveFileTime = t.secs(utils::Timer::resetCounter);
......@@ -284,12 +360,12 @@ void OracleCatalogue::deleteArchiveFileByDiskFileId(const std::string &diskInsta
utils::Timer t;
auto conn = m_connPool.getConn();
const auto getConnTime = t.secs(utils::Timer::resetCounter);
auto selectStmt = conn.createStmt(selectSql, rdbms::Stmt::AutocommitMode::OFF);
auto selectStmt = conn.createStmt(selectSql, rdbms::AutocommitMode::OFF);
const auto createStmtTime = t.secs();
selectStmt->bindString(":DISK_INSTANCE_NAME", diskInstanceName);
selectStmt->bindString(":DISK_FILE_ID", diskFileId);
selectStmt.bindString(":DISK_INSTANCE_NAME", diskInstanceName);
selectStmt.bindString(":DISK_FILE_ID", diskFileId);
t.reset();
rdbms::Rset selectRset = selectStmt->executeQuery();
rdbms::Rset selectRset = selectStmt.executeQuery();
const auto selectFromArchiveFileTime = t.secs();
std::unique_ptr<common::dataStructures::ArchiveFile> archiveFile;
while(selectRset.next()) {
......@@ -339,17 +415,17 @@ void OracleCatalogue::deleteArchiveFileByDiskFileId(const std::string &diskInsta
t.reset();
{
const char *const sql = "DELETE FROM TAPE_FILE WHERE ARCHIVE_FILE_ID = :ARCHIVE_FILE_ID";
auto stmt = conn.createStmt(sql, rdbms::Stmt::AutocommitMode::OFF);
stmt->bindUint64(":ARCHIVE_FILE_ID", archiveFile->archiveFileID);
stmt->executeNonQuery();
auto stmt = conn.createStmt(sql, rdbms::AutocommitMode::OFF);
stmt.bindUint64(":ARCHIVE_FILE_ID", archiveFile->archiveFileID);
stmt.executeNonQuery();
}
const auto deleteFromTapeFileTime = t.secs(utils::Timer::resetCounter);
{
const char *const sql = "DELETE FROM ARCHIVE_FILE WHERE ARCHIVE_FILE_ID = :ARCHIVE_FILE_ID";
auto stmt = conn.createStmt(sql, rdbms::Stmt::AutocommitMode::OFF);
stmt->bindUint64(":ARCHIVE_FILE_ID", archiveFile->archiveFileID);
stmt->executeNonQuery();
auto stmt = conn.createStmt(sql, rdbms::AutocommitMode::OFF);
stmt.bindUint64(":ARCHIVE_FILE_ID", archiveFile->archiveFileID);
stmt.executeNonQuery();
}
const auto deleteFromArchiveFileTime = t.secs(utils::Timer::resetCounter);
......@@ -399,15 +475,15 @@ void OracleCatalogue::deleteArchiveFileByDiskFileId(const std::string &diskInsta
//------------------------------------------------------------------------------
// getNextArchiveFileId
//------------------------------------------------------------------------------
uint64_t OracleCatalogue::getNextArchiveFileId(rdbms::PooledConn &conn) {
uint64_t OracleCatalogue::getNextArchiveFileId(rdbms::Conn &conn) {
try {
const char *const sql =
"SELECT "
"ARCHIVE_FILE_ID_SEQ.NEXTVAL AS ARCHIVE_FILE_ID "
"FROM "
"DUAL";
auto stmt = conn.createStmt(sql, rdbms::Stmt::AutocommitMode::OFF);
auto rset = stmt->executeQuery();
auto stmt = conn.createStmt(sql, rdbms::AutocommitMode::OFF);
auto rset = stmt.executeQuery();
if (!rset.next()) {
throw exception::Exception(std::string("Result set is unexpectedly empty"));
}
......@@ -421,7 +497,7 @@ uint64_t OracleCatalogue::getNextArchiveFileId(rdbms::PooledConn &conn) {
//------------------------------------------------------------------------------
// selectTapeForUpdate
//------------------------------------------------------------------------------
common::dataStructures::Tape OracleCatalogue::selectTapeForUpdate(rdbms::PooledConn &conn, const std::string &vid) {
common::dataStructures::Tape OracleCatalogue::selectTapeForUpdate(rdbms::Conn &conn, const std::string &vid) {
try {
const char *const sql =
"SELECT "
......@@ -459,9 +535,9 @@ common::dataStructures::Tape OracleCatalogue::selectTapeForUpdate(rdbms::PooledC
"WHERE "
"VID = :VID "
"FOR UPDATE";
auto stmt = conn.createStmt(sql, rdbms::Stmt::AutocommitMode::OFF);
stmt->bindString(":VID", vid);
auto rset = stmt->executeQuery();
auto stmt = conn.createStmt(sql, rdbms::AutocommitMode::OFF);
stmt.bindString(":VID", vid);
auto rset = stmt.executeQuery();
if (!rset.next()) {
throw exception::Exception(std::string("The tape with VID " + vid + " does not exist"));
}
......@@ -568,10 +644,10 @@ void OracleCatalogue::filesWrittenToTape(const std::set<TapeFileWritten> &events
auto lastEventItor = events.cend();
lastEventItor--;
const TapeFileWritten &lastEvent = *lastEventItor;
updateTape(conn, rdbms::Stmt::AutocommitMode::OFF, lastEvent.vid, lastEvent.fSeq, totalCompressedBytesWritten,
updateTape(conn, rdbms::AutocommitMode::OFF, lastEvent.vid, lastEvent.fSeq, totalCompressedBytesWritten,
lastEvent.tapeDrive);
idempotentBatchInsertArchiveFiles(conn, rdbms::Stmt::AutocommitMode::OFF, events);
idempotentBatchInsertArchiveFiles(conn, rdbms::AutocommitMode::OFF, events);
// Store the value of each field
i = 0;
......@@ -603,8 +679,8 @@ void OracleCatalogue::filesWrittenToTape(const std::set<TapeFileWritten> &events
":COPY_NB,"
":CREATION_TIME,"
":ARCHIVE_FILE_ID)";
auto stmt = conn.createStmt(sql, rdbms::Stmt::AutocommitMode::OFF);
rdbms::OcciStmt &occiStmt = dynamic_cast<rdbms::OcciStmt &>(*stmt);
auto stmt = conn.createStmt(sql, rdbms::AutocommitMode::OFF);
rdbms::wrapper::OcciStmt &occiStmt = dynamic_cast<rdbms::wrapper::OcciStmt &>(stmt.getStmt());
occiStmt.setColumn(tapeFileBatch.vid);
occiStmt.setColumn(tapeFileBatch.fSeq);
occiStmt.setColumn(tapeFileBatch.blockId);
......@@ -626,8 +702,8 @@ void OracleCatalogue::filesWrittenToTape(const std::set<TapeFileWritten> &events
//------------------------------------------------------------------------------
// idempotentBatchInsertArchiveFiles
//------------------------------------------------------------------------------
void OracleCatalogue::idempotentBatchInsertArchiveFiles(rdbms::PooledConn &conn,
const rdbms::Stmt::AutocommitMode autocommitMode, const std::set<TapeFileWritten> &events) {
void OracleCatalogue::idempotentBatchInsertArchiveFiles(rdbms::Conn &conn,
const rdbms::AutocommitMode autocommitMode, const std::set<TapeFileWritten> &events) {
try {
ArchiveFileBatch archiveFileBatch(events.size());
const time_t now = time(nullptr);
......@@ -701,7 +777,7 @@ void OracleCatalogue::idempotentBatchInsertArchiveFiles(rdbms::PooledConn &conn,
":CREATION_TIME,"
":RECONCILIATION_TIME)";
auto stmt = conn.createStmt(sql, autocommitMode);
rdbms::OcciStmt &occiStmt = dynamic_cast<rdbms::OcciStmt &>(*stmt);
rdbms::wrapper::OcciStmt &occiStmt = dynamic_cast<rdbms::wrapper::OcciStmt &>(stmt.getStmt());
occiStmt->setBatchErrorMode(true);
occiStmt.setColumn(archiveFileBatch.archiveFileId);
......
......@@ -19,8 +19,7 @@
#pragma once
#include "catalogue/RdbmsCatalogue.hpp"
#include "rdbms/OcciColumn.hpp"
#include "rdbms/PooledConn.hpp"
#include "rdbms/Conn.hpp"
#include <occi.h>
#include <string.h>
......@@ -117,7 +116,7 @@ public:
* @return A unique archive ID that can be used by a new archive file within
* the catalogue.
*/
uint64_t getNextArchiveFileId(rdbms::PooledConn &conn) override;
uint64_t getNextArchiveFileId(rdbms::Conn &conn) override;