diff --git a/catalogue/MysqlCatalogue.cpp b/catalogue/MysqlCatalogue.cpp index 0ad64512d700d2d181f138f9b0b5d5709ee87a25..8702631ec2de83d83acb99d1b39cf474f2134d75 100644 --- a/catalogue/MysqlCatalogue.cpp +++ b/catalogue/MysqlCatalogue.cpp @@ -322,8 +322,6 @@ void MysqlCatalogue::fileWrittenToTape(rdbms::Conn &conn, const TapeFileWritten insertArchiveFile(conn, row); } catch(exception::DatabasePrimaryKeyError &) { // Ignore this error - } catch(...) { - throw; } const time_t now = time(nullptr); diff --git a/catalogue/PostgresCatalogue.cpp b/catalogue/PostgresCatalogue.cpp index 4d941d36f62ac1f25a7d0b543ae18e925377d654..485fa07f78eb3c2e76d1d103ba2618aa1b95ea0e 100644 --- a/catalogue/PostgresCatalogue.cpp +++ b/catalogue/PostgresCatalogue.cpp @@ -495,6 +495,16 @@ void PostgresCatalogue::idempotentBatchInsertArchiveFiles(rdbms::Conn &conn, archiveFileBatch.diskFileGroup.setFieldValue(i, event.diskFileGid); archiveFileBatch.size.setFieldValue(i, event.size); archiveFileBatch.checksumBlob.setFieldByteA(conn, i, event.checksumBlob.serialize()); + // Keep transition ADLER32 checksum up-to-date if it exists + std::string adler32str; + try { + std::string adler32hex = checksum::ChecksumBlob::ByteArrayToHex(event.checksumBlob.at(checksum::ADLER32)); + uint32_t adler32 = strtoul(adler32hex.c_str(), 0, 16); + adler32str = std::to_string(adler32); + } catch(exception::ChecksumTypeMismatch &ex) { + adler32str = "0"; + } + archiveFileBatch.checksumAdler32.setFieldValue(i, adler32str); archiveFileBatch.storageClassName.setFieldValue(i, event.storageClassName); archiveFileBatch.creationTime.setFieldValue(i, now); archiveFileBatch.reconciliationTime.setFieldValue(i, now); @@ -540,6 +550,7 @@ void PostgresCatalogue::idempotentBatchInsertArchiveFiles(rdbms::Conn &conn, postgresStmt.setColumn(archiveFileBatch.diskFileGroup); postgresStmt.setColumn(archiveFileBatch.size); postgresStmt.setColumn(archiveFileBatch.checksumBlob); + postgresStmt.setColumn(archiveFileBatch.checksumAdler32); postgresStmt.setColumn(archiveFileBatch.storageClassName); postgresStmt.setColumn(archiveFileBatch.creationTime); postgresStmt.setColumn(archiveFileBatch.reconciliationTime); diff --git a/catalogue/RdbmsCatalogue.cpp b/catalogue/RdbmsCatalogue.cpp index 8334552f1805b3060d04f39f1f6c27e6e78b30c9..00faa087a67a2a0f8085b41f4bd4af4d98a96ab9 100644 --- a/catalogue/RdbmsCatalogue.cpp +++ b/catalogue/RdbmsCatalogue.cpp @@ -4086,7 +4086,7 @@ void RdbmsCatalogue::createActivitiesFairShareWeight(const common::dataStructure const time_t now = time(nullptr); const char *const sql = - "INSERT INTO ACTIVITIES_WEIGHTS (" + "INSERT INTO ACTIVITIES_WEIGHTS(" "DISK_INSTANCE_NAME," "ACTIVITY," "WEIGHT," @@ -4330,13 +4330,14 @@ void RdbmsCatalogue::insertArchiveFile(rdbms::Conn &conn, const ArchiveFileRow & stmt.bindUint64(":SIZE_IN_BYTES", row.size); stmt.bindBlob (":CHECKSUM_BLOB", row.checksumBlob.serialize()); // Keep transition ADLER32 checksum up-to-date if it exists - std::string adler32str; + uint32_t adler32; try { - adler32str = checksum::ChecksumBlob::ByteArrayToHex(row.checksumBlob.at(checksum::ADLER32)); + std::string adler32hex = checksum::ChecksumBlob::ByteArrayToHex(row.checksumBlob.at(checksum::ADLER32)); + adler32 = strtoul(adler32hex.c_str(), 0, 16); } catch(exception::ChecksumTypeMismatch &ex) { - adler32str = "0"; + adler32 = 0; } - stmt.bindBlob (":CHECKSUM_ADLER32", "0x" + adler32str); + stmt.bindUint64(":CHECKSUM_ADLER32", adler32); stmt.bindString(":STORAGE_CLASS_NAME", row.storageClassName); stmt.bindUint64(":CREATION_TIME", now); stmt.bindUint64(":RECONCILIATION_TIME", now); diff --git a/rdbms/wrapper/MysqlStmt.cpp b/rdbms/wrapper/MysqlStmt.cpp index d4d2246369baffc184965c2a8d5b4f632b34e279..d007cf8e109a91c8112488a4abd81b0af087026c 100644 --- a/rdbms/wrapper/MysqlStmt.cpp +++ b/rdbms/wrapper/MysqlStmt.cpp @@ -315,7 +315,8 @@ void MysqlStmt::bindOptionalString(const std::string ¶mName, const optional< // reset memory holder->reset(); - snprintf(holder->val, holder->get_buffer_length(), paramValue.value().c_str()); + // need to use memcpy for VARBINARY strings, which are not null-terminated + memcpy(holder->val, paramValue.value().c_str(), holder->get_buffer_length()); } else { holder->length = 0; } @@ -325,7 +326,6 @@ void MysqlStmt::bindOptionalString(const std::string ¶mName, const optional< // delete m_placeholder[idx]; // remove the previous placeholder m_placeholder[idx] = holder; - } catch(exception::Exception &ex) { throw exception::Exception(std::string(__FUNCTION__) + " failed for SQL statement " + getSqlForException() + ": " + ex.getMessage().str());