From 1e8e75fbfd0ea6af174946423504733619c98d37 Mon Sep 17 00:00:00 2001 From: Vlad Khorsun Date: Sat, 27 Sep 2025 15:13:09 +0300 Subject: [PATCH] Fixed bug #8755 : Replicator could produce log segments with duplicated segment numbers. --- src/jrd/replication/Manager.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/jrd/replication/Manager.cpp b/src/jrd/replication/Manager.cpp index 31ad8d8acb9..1122ac7ba75 100644 --- a/src/jrd/replication/Manager.cpp +++ b/src/jrd/replication/Manager.cpp @@ -25,6 +25,7 @@ #include "../common/isc_proto.h" #include "../common/isc_s_proto.h" #include "../jrd/jrd.h" +#include "../jrd/cch_proto.h" #include "Manager.h" #include "Protocol.h" @@ -112,10 +113,24 @@ Manager::Manager(const string& dbId, dbb->ensureGuid(tdbb); const Guid& guid = dbb->dbb_guid; - m_sequence = dbb->dbb_repl_sequence; if (config->journalDirectory.hasData()) { + // At this point it is unknown if change log shared memory exists or not. + // To avoid race condition with concurrent changing of current replication + // sequence, take and hold shared lock on header page while creating + // ChangeLog instance. + + WIN window(HEADER_PAGE_NUMBER); + CCH_FETCH(tdbb, &window, LCK_read, pag_header); + + Cleanup releaseHeader([&] { + CCH_RELEASE(tdbb, &window); + }); + + // Call below will fetch header page with LCK_read lock, it is allowed and OK. + m_sequence = dbb->getReplSequence(tdbb); + m_changeLog = FB_NEW_POOL(getPool()) ChangeLog(getPool(), dbId, guid, m_sequence, config); }