From eb8def71d1c05f6ff690eac5c898ae327c2dd905 Mon Sep 17 00:00:00 2001
From: Steven Murray <Steven.Murray@cern.ch>
Date: Tue, 30 Jan 2018 23:03:31 +0100
Subject: [PATCH] cta/CTA#186 CTA should cope with idle database connections
 being dropped by the database server

OracleCatalogue::deleteArchiveFileByDiskFileId()  should re-connect to database if connection lost.
---
 catalogue/OracleCatalogue.cpp | 11 ++++++++++-
 catalogue/OracleCatalogue.hpp | 24 ++++++++++++++++++++++++
 2 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/catalogue/OracleCatalogue.cpp b/catalogue/OracleCatalogue.cpp
index 8f043e147e..84cf04faf8 100644
--- a/catalogue/OracleCatalogue.cpp
+++ b/catalogue/OracleCatalogue.cpp
@@ -340,8 +340,17 @@ void OracleCatalogue::deleteArchiveFileInternal(const std::string &diskInstanceN
 //------------------------------------------------------------------------------
 void OracleCatalogue::deleteArchiveFileByDiskFileId(const std::string &diskInstanceName, const std::string &diskFileId,
   log::LogContext &lc) {
+  return retryOnLostConnection(m_log, [&]{return deleteArchiveFileByDiskFileIdInternal(diskInstanceName, diskFileId,
+    lc);}, m_maxTriesToConnect);
+}
+
+//------------------------------------------------------------------------------
+// deleteArchiveFileByDiskFileIdInternal
+//------------------------------------------------------------------------------
+void OracleCatalogue::deleteArchiveFileByDiskFileIdInternal(const std::string &diskInstanceName,
+  const std::string &diskFileId, log::LogContext &lc) {
   try {
-    const char *selectSql =
+    const char *const selectSql =
       "SELECT "
         "ARCHIVE_FILE.ARCHIVE_FILE_ID AS ARCHIVE_FILE_ID,"
         "ARCHIVE_FILE.DISK_INSTANCE_NAME AS DISK_INSTANCE_NAME,"
diff --git a/catalogue/OracleCatalogue.hpp b/catalogue/OracleCatalogue.hpp
index 3c31406bed..3823ce0b42 100644
--- a/catalogue/OracleCatalogue.hpp
+++ b/catalogue/OracleCatalogue.hpp
@@ -150,6 +150,30 @@ private:
   void deleteArchiveFileInternal(const std::string &diskInstanceName, const uint64_t archiveFileId,
     log::LogContext &lc);
 
+  /**
+   * Deletes the specified archive file and its associated tape copies from the
+   * catalogue.
+   *
+   * Please note that this method is idempotent.  If the file to be deleted does
+   * not exist in the CTA catalogue then this method returns without error.
+   *
+   * This internal method can be re-tried if it throws a LostDatabaseConnection
+   * exception.
+   *
+   * @param diskInstanceName The name of the instance from where the deletion
+   * request originated
+   * @param diskFileId 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 diskInstanceName and
+   * diskFileId must be globally unique, in other words unique within the CTA
+   * catalogue.
+   * @param lc The log context.
+   * @return The metadata of the deleted archive file including the metadata of
+   * the associated and also deleted tape copies.
+   */
+  void deleteArchiveFileByDiskFileIdInternal(const std::string &diskInstanceName, const std::string &diskFileId,
+    log::LogContext &lc);
+
   /**
    * Notifies the catalogue that the specified files have been written to tape.
    *
-- 
GitLab