From e434e2ed0ea788d556921e423f9f7f33f3fff04c Mon Sep 17 00:00:00 2001
From: mvelosob <miguel.veloso.barros@cern.ch>
Date: Thu, 10 Feb 2022 13:47:27 +0100
Subject: [PATCH] update masterDataInBytes when writting to tape (#1117)

---
 ReleaseNotes.md              | 1 +
 catalogue/CatalogueTest.cpp  | 2 ++
 catalogue/RdbmsCatalogue.cpp | 5 +++--
 3 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/ReleaseNotes.md b/ReleaseNotes.md
index 25bbef3563..6225aa8c2b 100644
--- a/ReleaseNotes.md
+++ b/ReleaseNotes.md
@@ -5,6 +5,7 @@
 ### Upgrade Instructions
 
 ### Features
+- cta/CTA#1117 - Update masterDataInBytes when writting files to tape.
 
 ### Bug fixes
 
diff --git a/catalogue/CatalogueTest.cpp b/catalogue/CatalogueTest.cpp
index c521183726..1a18dd5863 100644
--- a/catalogue/CatalogueTest.cpp
+++ b/catalogue/CatalogueTest.cpp
@@ -5440,6 +5440,7 @@ TEST_P(cta_catalogue_CatalogueTest, deleteNonEmptyTape) {
     ASSERT_EQ(m_vo.name, tape.vo);
     ASSERT_EQ(m_mediaType.capacityInBytes, tape.capacityInBytes);
     ASSERT_EQ(fileSize, tape.dataOnTapeInBytes);
+    ASSERT_EQ(fileSize, tape.masterDataInBytes);
     ASSERT_EQ(m_tape1.full, tape.full);
 
     ASSERT_FALSE(tape.isFromCastor);
@@ -16229,6 +16230,7 @@ TEST_P(cta_catalogue_CatalogueTest, reclaimTape_full_lastFSeq_1_one_tape_file) {
     ASSERT_EQ(m_tape1.mediaType, tape.mediaType);
     ASSERT_EQ(m_tape1.vendor, tape.vendor);
     ASSERT_EQ(file1Written.size, tape.dataOnTapeInBytes);
+    ASSERT_EQ(file1Written.size, tape.masterDataInBytes);
     ASSERT_EQ(1, tape.lastFSeq);
     ASSERT_EQ(m_tape1.logicalLibraryName, tape.logicalLibraryName);
     ASSERT_EQ(m_tape1.tapePoolName, tape.tapePoolName);
diff --git a/catalogue/RdbmsCatalogue.cpp b/catalogue/RdbmsCatalogue.cpp
index 3b5d2d89a5..9f650a17fe 100644
--- a/catalogue/RdbmsCatalogue.cpp
+++ b/catalogue/RdbmsCatalogue.cpp
@@ -8536,15 +8536,16 @@ void RdbmsCatalogue::updateTape(
       "UPDATE TAPE SET "
         "LAST_FSEQ = :LAST_FSEQ,"
         "DATA_IN_BYTES = DATA_IN_BYTES + :DATA_IN_BYTES,"
+        "MASTER_DATA_IN_BYTES = MASTER_DATA_IN_BYTES + :MASTER_DATA_IN_BYTES,"
         "LAST_WRITE_DRIVE = :LAST_WRITE_DRIVE,"
-        "LAST_WRITE_TIME = :LAST_WRITE_TIME,"
-        "DIRTY='1' "
+        "LAST_WRITE_TIME = :LAST_WRITE_TIME "
       "WHERE "
         "VID = :VID";
     auto stmt = conn.createStmt(sql);
     stmt.bindString(":VID", vid);
     stmt.bindUint64(":LAST_FSEQ", lastFSeq);
     stmt.bindUint64(":DATA_IN_BYTES", compressedBytesWritten);
+    stmt.bindUint64(":MASTER_DATA_IN_BYTES", compressedBytesWritten);
     stmt.bindString(":LAST_WRITE_DRIVE", tapeDrive);
     stmt.bindUint64(":LAST_WRITE_TIME", now);
     stmt.executeNonQuery();
-- 
GitLab