Skip to content

Commit 42cf2d1

Browse files
authored
Merge pull request #8756 from FirebirdSQL/work/gh-8755
Fixed bug #8755 : Replicator could produce log segments with duplicated segment numbers.
2 parents 7984160 + 1e8e75f commit 42cf2d1

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/jrd/replication/Manager.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "../common/isc_proto.h"
2626
#include "../common/isc_s_proto.h"
2727
#include "../jrd/jrd.h"
28+
#include "../jrd/cch_proto.h"
2829

2930
#include "Manager.h"
3031
#include "Protocol.h"
@@ -112,10 +113,24 @@ Manager::Manager(const string& dbId,
112113

113114
dbb->ensureGuid(tdbb);
114115
const Guid& guid = dbb->dbb_guid;
115-
m_sequence = dbb->dbb_repl_sequence;
116116

117117
if (config->journalDirectory.hasData())
118118
{
119+
// At this point it is unknown if change log shared memory exists or not.
120+
// To avoid race condition with concurrent changing of current replication
121+
// sequence, take and hold shared lock on header page while creating
122+
// ChangeLog instance.
123+
124+
WIN window(HEADER_PAGE_NUMBER);
125+
CCH_FETCH(tdbb, &window, LCK_read, pag_header);
126+
127+
Cleanup releaseHeader([&] {
128+
CCH_RELEASE(tdbb, &window);
129+
});
130+
131+
// Call below will fetch header page with LCK_read lock, it is allowed and OK.
132+
m_sequence = dbb->getReplSequence(tdbb);
133+
119134
m_changeLog = FB_NEW_POOL(getPool())
120135
ChangeLog(getPool(), dbId, guid, m_sequence, config);
121136
}

0 commit comments

Comments
 (0)