From c578481d802f44ab52894718cc4be96894219d83 Mon Sep 17 00:00:00 2001 From: Dmitry Yemanov Date: Sat, 27 May 2023 07:31:10 +0300 Subject: [PATCH] Fixed #7605: Disallow replication of RDB --- src/jrd/replication/Publisher.cpp | 72 ++++++++++++------------------- 1 file changed, 27 insertions(+), 45 deletions(-) diff --git a/src/jrd/replication/Publisher.cpp b/src/jrd/replication/Publisher.cpp index 6154dd68e1..12b5365ae3 100644 --- a/src/jrd/replication/Publisher.cpp +++ b/src/jrd/replication/Publisher.cpp @@ -21,6 +21,7 @@ */ #include "firebird.h" +#include "../jrd/ini.h" #include "../jrd/jrd.h" #include "../jrd/ods.h" #include "../jrd/req.h" @@ -44,10 +45,6 @@ using namespace Replication; namespace { - // Generator RDB$BACKUP_HISTORY, although defined as system, - // should be replicated similar to user-defined ones - const int BACKUP_HISTORY_GENERATOR = 9; - const char* NO_PLUGIN_ERROR = "Replication plugin %s is not found"; const char* STOP_ERROR = "Replication is stopped due to critical error(s)"; @@ -243,12 +240,27 @@ namespace return transaction->tra_replicator; } - bool matchTable(thread_db* tdbb, const MetaName& tableName) + bool checkTable(thread_db* tdbb, jrd_rel* relation) { - const auto attachment = tdbb->getAttachment(); - const auto matcher = attachment->att_repl_matcher.get(); + if (relation->isTemporary()) + return false; - return (!matcher || matcher->matchTable(tableName)); + if (!relation->isSystem()) + { + if (!relation->isReplicating(tdbb)) + return false; + + const auto attachment = tdbb->getAttachment(); + const auto matcher = attachment->att_repl_matcher.get(); + + if (matcher && !matcher->matchTable(relation->rel_name)) + return false; + } + // Do not replicate RDB$BACKUP_HISTORY as it describes physical-level things + else if (relation->rel_id == rel_backup_history) + return false; + + return true; } Record* upgradeRecord(thread_db* tdbb, jrd_rel* relation, Record* record) @@ -497,18 +509,9 @@ void REPL_store(thread_db* tdbb, const record_param* rpb, jrd_tra* transaction) const auto relation = rpb->rpb_relation; fb_assert(relation); - if (relation->isTemporary()) + if (!checkTable(tdbb, relation)) return; - if (!relation->isSystem()) - { - if (!relation->isReplicating(tdbb)) - return; - - if (!matchTable(tdbb, relation->rel_name)) - return; - } - FbLocalStatus status; const auto replicator = getReplicator(tdbb, status, transaction); if (!replicator) @@ -539,18 +542,9 @@ void REPL_modify(thread_db* tdbb, const record_param* orgRpb, const auto relation = newRpb->rpb_relation; fb_assert(relation); - if (relation->isTemporary()) + if (!checkTable(tdbb, relation)) return; - if (!relation->isSystem()) - { - if (!relation->isReplicating(tdbb)) - return; - - if (!matchTable(tdbb, relation->rel_name)) - return; - } - FbLocalStatus status; const auto replicator = getReplicator(tdbb, status, transaction); if (!replicator) @@ -597,18 +591,9 @@ void REPL_erase(thread_db* tdbb, const record_param* rpb, jrd_tra* transaction) const auto relation = rpb->rpb_relation; fb_assert(relation); - if (relation->isTemporary()) + if (!checkTable(tdbb, relation)) return; - if (!relation->isSystem()) - { - if (!relation->isReplicating(tdbb)) - return; - - if (!matchTable(tdbb, relation->rel_name)) - return; - } - FbLocalStatus status; const auto replicator = getReplicator(tdbb, status, transaction); if (!replicator) @@ -638,14 +623,11 @@ void REPL_gen_id(thread_db* tdbb, SLONG genId, SINT64 value) if (genId == 0) // special case: ignore RDB$GENERATORS return; - // Ignore other system generators, except RDB$BACKUP_HISTORY - if (genId != BACKUP_HISTORY_GENERATOR) + // Ignore other system generators + for (auto generator = generators; generator->gen_name; generator++) { - for (auto generator = generators; generator->gen_name; generator++) - { - if (generator->gen_id == genId) - return; - } + if (generator->gen_id == genId) + return; } const auto replicator = getReplicator(tdbb);