Commit e5862d74 authored by Steven Murray's avatar Steven Murray
Browse files

[Catalogue] operations#179 Slow `cta-admin sq` even when there is very little activity

Added Catalogue::getTapePool()
parent c23bbfc9
......@@ -453,6 +453,13 @@ public:
virtual void deleteTapePool(const std::string &name) = 0;
virtual std::list<TapePool> getTapePools() const = 0;
/**
* @return The tape pool with the specified name.
* @param tapePoolName The name of the tape pool.
*/
virtual cta::optional<TapePool> getTapePool(const std::string &tapePoolName) const = 0;
virtual void modifyTapePoolVo(const common::dataStructures::SecurityIdentity &admin, const std::string &name, const std::string &vo) = 0;
virtual void modifyTapePoolNbPartialTapes(const common::dataStructures::SecurityIdentity &admin, const std::string &name, const uint64_t nbPartialTapes) = 0;
virtual void modifyTapePoolComment(const common::dataStructures::SecurityIdentity &admin, const std::string &name, const std::string &comment) = 0;
......
......@@ -228,6 +228,10 @@ public:
return retryOnLostConnection(m_log, [&]{return m_catalogue->getTapePools();}, m_maxTriesToConnect);
}
cta::optional<TapePool> getTapePool(const std::string &tapePoolName) const override {
return retryOnLostConnection(m_log, [&]{return m_catalogue->getTapePool(tapePoolName);}, m_maxTriesToConnect);
}
void modifyTapePoolVo(const common::dataStructures::SecurityIdentity &admin, const std::string &name, const std::string &vo) override {
return retryOnLostConnection(m_log, [&]{return m_catalogue->modifyTapePoolVo(admin, name, vo);}, m_maxTriesToConnect);
}
......
......@@ -1769,6 +1769,18 @@ TEST_P(cta_catalogue_CatalogueTest, getMediaTypeByVid) {
ASSERT_EQ(m_mediaType.secondaryDensityCode, tapeMediaType.secondaryDensityCode);
}
 
TEST_P(cta_catalogue_CatalogueTest, getTapePool_non_existent) {
using namespace cta;
const std::string tapePoolName = "non_existent_tape_pool";
ASSERT_FALSE(m_catalogue->tapePoolExists(tapePoolName));
const auto pool = m_catalogue->getTapePool(tapePoolName);
ASSERT_FALSE((bool)pool);
}
TEST_P(cta_catalogue_CatalogueTest, createTapePool) {
using namespace cta;
......@@ -1784,32 +1796,58 @@ TEST_P(cta_catalogue_CatalogueTest, createTapePool) {
m_catalogue->createTapePool(m_admin, m_tape1.tapePoolName, m_vo.name, nbPartialTapes, isEncrypted, supply, comment);
 
ASSERT_TRUE(m_catalogue->tapePoolExists(tapePoolName));
{
const auto pools = m_catalogue->getTapePools();
const auto pools = m_catalogue->getTapePools();
ASSERT_EQ(1, pools.size());
ASSERT_EQ(1, pools.size());
const auto &pool = pools.front();
ASSERT_EQ(tapePoolName, pool.name);
ASSERT_EQ(m_vo.name, pool.vo.name);
ASSERT_EQ(nbPartialTapes, pool.nbPartialTapes);
ASSERT_EQ(isEncrypted, pool.encryption);
ASSERT_TRUE((bool)pool.supply);
ASSERT_EQ(supply.value(), pool.supply.value());
ASSERT_EQ(supply, pool.supply);
ASSERT_EQ(0, pool.nbTapes);
ASSERT_EQ(0, pool.capacityBytes);
ASSERT_EQ(0, pool.dataBytes);
ASSERT_EQ(0, pool.nbPhysicalFiles);
ASSERT_EQ(comment, pool.comment);
const auto &pool = pools.front();
ASSERT_EQ(tapePoolName, pool.name);
ASSERT_EQ(m_vo.name, pool.vo.name);
ASSERT_EQ(nbPartialTapes, pool.nbPartialTapes);
ASSERT_EQ(isEncrypted, pool.encryption);
ASSERT_TRUE((bool)pool.supply);
ASSERT_EQ(supply.value(), pool.supply.value());
ASSERT_EQ(supply, pool.supply);
ASSERT_EQ(0, pool.nbTapes);
ASSERT_EQ(0, pool.capacityBytes);
ASSERT_EQ(0, pool.dataBytes);
ASSERT_EQ(0, pool.nbPhysicalFiles);
ASSERT_EQ(comment, pool.comment);
 
const common::dataStructures::EntryLog creationLog = pool.creationLog;
ASSERT_EQ(m_admin.username, creationLog.username);
ASSERT_EQ(m_admin.host, creationLog.host);
const common::dataStructures::EntryLog creationLog = pool.creationLog;
ASSERT_EQ(m_admin.username, creationLog.username);
ASSERT_EQ(m_admin.host, creationLog.host);
const common::dataStructures::EntryLog lastModificationLog =
pool.lastModificationLog;
ASSERT_EQ(creationLog, lastModificationLog);
const common::dataStructures::EntryLog lastModificationLog = pool.lastModificationLog;
ASSERT_EQ(creationLog, lastModificationLog);
}
{
const auto pool = m_catalogue->getTapePool(tapePoolName);
ASSERT_TRUE((bool)pool);
ASSERT_EQ(tapePoolName, pool->name);
ASSERT_EQ(m_vo.name, pool->vo.name);
ASSERT_EQ(nbPartialTapes, pool->nbPartialTapes);
ASSERT_EQ(isEncrypted, pool->encryption);
ASSERT_TRUE((bool)pool->supply);
ASSERT_EQ(supply.value(), pool->supply.value());
ASSERT_EQ(supply, pool->supply);
ASSERT_EQ(0, pool->nbTapes);
ASSERT_EQ(0, pool->capacityBytes);
ASSERT_EQ(0, pool->dataBytes);
ASSERT_EQ(0, pool->nbPhysicalFiles);
ASSERT_EQ(comment, pool->comment);
const common::dataStructures::EntryLog creationLog = pool->creationLog;
ASSERT_EQ(m_admin.username, creationLog.username);
ASSERT_EQ(m_admin.host, creationLog.host);
const common::dataStructures::EntryLog lastModificationLog = pool->lastModificationLog;
ASSERT_EQ(creationLog, lastModificationLog);
}
}
 
TEST_P(cta_catalogue_CatalogueTest, createTapePool_null_supply) {
......@@ -9986,8 +10024,7 @@ TEST_P(cta_catalogue_CatalogueTest, filesWrittenToTape_many_archive_files) {
ASSERT_EQ(nbArchiveFiles * archiveFileSize, pool.dataBytes);
ASSERT_EQ(nbArchiveFiles, pool.nbPhysicalFiles);
}
// I AM HERE
// tape1.vid
m_catalogue->setTapeDisabled(m_admin, tape1.vid, true);
 
{
......
......@@ -94,6 +94,7 @@ public:
std::list<common::dataStructures::StorageClass> getStorageClasses() const { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
common::dataStructures::ArchiveFileSummary getTapeFileSummary(const TapeFileSearchCriteria& searchCriteria) const { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
std::list<TapePool> getTapePools() const { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
cta::optional<TapePool> getTapePool(const std::string &tapePoolName) const override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
std::list<common::dataStructures::Tape> getTapes(const TapeSearchCriteria& searchCriteria) const { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
// getTapesByVid is implemented below (and works).
std::map<std::string, std::string> getVidToLogicalLibrary(const std::set<std::string> &vids) const override { throw exception::Exception(std::string("In ") + __PRETTY_FUNCTION__ + ": not implemented"); }
......
......@@ -2071,6 +2071,103 @@ std::list<TapePool> RdbmsCatalogue::getTapePools() const {
}
}
//------------------------------------------------------------------------------
// getTapePool
//------------------------------------------------------------------------------
cta::optional<TapePool> RdbmsCatalogue::getTapePool(const std::string &tapePoolName) const {
try {
const char *const sql =
"SELECT "
"TAPE_POOL.TAPE_POOL_NAME AS TAPE_POOL_NAME,"
"VIRTUAL_ORGANIZATION.VIRTUAL_ORGANIZATION_NAME AS VO,"
"TAPE_POOL.NB_PARTIAL_TAPES AS NB_PARTIAL_TAPES,"
"TAPE_POOL.IS_ENCRYPTED AS IS_ENCRYPTED,"
"TAPE_POOL.SUPPLY AS SUPPLY,"
"COALESCE(COUNT(TAPE.VID), 0) AS NB_TAPES,"
"COALESCE(SUM(CASE WHEN TAPE.DATA_IN_BYTES = 0 THEN 1 ELSE 0 END), 0) AS NB_EMPTY_TAPES,"
"COALESCE(SUM(CASE WHEN TAPE.IS_DISABLED <> '0' THEN 1 ELSE 0 END), 0) AS NB_DISABLED_TAPES,"
"COALESCE(SUM(CASE WHEN TAPE.IS_FULL <> '0' THEN 1 ELSE 0 END), 0) AS NB_FULL_TAPES,"
"COALESCE(SUM(CASE WHEN TAPE.IS_READ_ONLY <> '0' THEN 1 ELSE 0 END), 0) AS NB_READ_ONLY_TAPES,"
"COALESCE(SUM(MEDIA_TYPE.CAPACITY_IN_BYTES), 0) AS CAPACITY_IN_BYTES,"
"COALESCE(SUM(TAPE.DATA_IN_BYTES), 0) AS DATA_IN_BYTES,"
"COALESCE(SUM(TAPE.LAST_FSEQ), 0) AS NB_PHYSICAL_FILES,"
"TAPE_POOL.USER_COMMENT AS USER_COMMENT,"
"TAPE_POOL.CREATION_LOG_USER_NAME AS CREATION_LOG_USER_NAME,"
"TAPE_POOL.CREATION_LOG_HOST_NAME AS CREATION_LOG_HOST_NAME,"
"TAPE_POOL.CREATION_LOG_TIME AS CREATION_LOG_TIME,"
"TAPE_POOL.LAST_UPDATE_USER_NAME AS LAST_UPDATE_USER_NAME,"
"TAPE_POOL.LAST_UPDATE_HOST_NAME AS LAST_UPDATE_HOST_NAME,"
"TAPE_POOL.LAST_UPDATE_TIME AS LAST_UPDATE_TIME "
"FROM "
"TAPE_POOL "
"INNER JOIN VIRTUAL_ORGANIZATION ON "
"TAPE_POOL.VIRTUAL_ORGANIZATION_ID = VIRTUAL_ORGANIZATION.VIRTUAL_ORGANIZATION_ID "
"LEFT OUTER JOIN TAPE ON "
"TAPE_POOL.TAPE_POOL_ID = TAPE.TAPE_POOL_ID "
"LEFT OUTER JOIN MEDIA_TYPE ON "
"TAPE.MEDIA_TYPE_ID = MEDIA_TYPE.MEDIA_TYPE_ID "
"GROUP BY "
"TAPE_POOL.TAPE_POOL_NAME,"
"VIRTUAL_ORGANIZATION.VIRTUAL_ORGANIZATION_NAME,"
"TAPE_POOL.NB_PARTIAL_TAPES,"
"TAPE_POOL.IS_ENCRYPTED,"
"TAPE_POOL.SUPPLY,"
"TAPE_POOL.USER_COMMENT,"
"TAPE_POOL.CREATION_LOG_USER_NAME,"
"TAPE_POOL.CREATION_LOG_HOST_NAME,"
"TAPE_POOL.CREATION_LOG_TIME,"
"TAPE_POOL.LAST_UPDATE_USER_NAME,"
"TAPE_POOL.LAST_UPDATE_HOST_NAME,"
"TAPE_POOL.LAST_UPDATE_TIME "
"HAVING "
"TAPE_POOL.TAPE_POOL_NAME = :TAPE_POOL_NAME "
"ORDER BY "
"TAPE_POOL_NAME";
auto conn = m_connPool.getConn();
auto stmt = conn.createStmt(sql);
stmt.bindString(":TAPE_POOL_NAME", tapePoolName);
auto rset = stmt.executeQuery();
if (!rset.next()) {
return cta::nullopt;
}
TapePool pool;
pool.name = rset.columnString("TAPE_POOL_NAME");
pool.vo.name = rset.columnString("VO");
pool.nbPartialTapes = rset.columnUint64("NB_PARTIAL_TAPES");
pool.encryption = rset.columnBool("IS_ENCRYPTED");
pool.supply = rset.columnOptionalString("SUPPLY");
pool.nbTapes = rset.columnUint64("NB_TAPES");
pool.nbEmptyTapes = rset.columnUint64("NB_EMPTY_TAPES");
pool.nbDisabledTapes = rset.columnUint64("NB_DISABLED_TAPES");
pool.nbFullTapes = rset.columnUint64("NB_FULL_TAPES");
pool.nbReadOnlyTapes = rset.columnUint64("NB_READ_ONLY_TAPES");
pool.capacityBytes = rset.columnUint64("CAPACITY_IN_BYTES");
pool.dataBytes = rset.columnUint64("DATA_IN_BYTES");
pool.nbPhysicalFiles = rset.columnUint64("NB_PHYSICAL_FILES");
pool.comment = rset.columnString("USER_COMMENT");
pool.creationLog.username = rset.columnString("CREATION_LOG_USER_NAME");
pool.creationLog.host = rset.columnString("CREATION_LOG_HOST_NAME");
pool.creationLog.time = rset.columnUint64("CREATION_LOG_TIME");
pool.lastModificationLog.username = rset.columnString("LAST_UPDATE_USER_NAME");
pool.lastModificationLog.host = rset.columnString("LAST_UPDATE_HOST_NAME");
pool.lastModificationLog.time = rset.columnUint64("LAST_UPDATE_TIME");
return pool;
} catch(exception::UserError &) {
throw;
} catch(exception::Exception &ex) {
ex.getMessage().str(std::string(__FUNCTION__) + ": " + ex.getMessage().str());
throw;
}
}
//------------------------------------------------------------------------------
// modifyTapePoolVO
//------------------------------------------------------------------------------
......
......@@ -395,6 +395,13 @@ public:
void createTapePool(const common::dataStructures::SecurityIdentity &admin, const std::string &name, const std::string &vo, const uint64_t nbPartialTapes, const bool encryptionValue, const cta::optional<std::string> &supply, const std::string &comment) override;
void deleteTapePool(const std::string &name) override;
std::list<TapePool> getTapePools() const override;
/**
* @return The tape pool with the specified name.
* @param tapePoolName The name of the tape pool.
*/
cta::optional<TapePool> getTapePool(const std::string &tapePoolName) const override;
void modifyTapePoolVo(const common::dataStructures::SecurityIdentity &admin, const std::string &name, const std::string &vo) override;
void modifyTapePoolNbPartialTapes(const common::dataStructures::SecurityIdentity &admin, const std::string &name, const uint64_t nbPartialTapes) override;
void modifyTapePoolComment(const common::dataStructures::SecurityIdentity &admin, const std::string &name, const std::string &comment) override;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment