Skip to content

Commit d8102f7

Browse files
committed
Merge pull request #8756 from FirebirdSQL/work/gh-8755
Fixed bug #8755 : Replicator could produce log segments with duplicated segment numbers.
1 parent 53b914c commit d8102f7

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/jrd/replication/Manager.cpp

Lines changed: 17 additions & 2 deletions
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"
@@ -132,13 +133,27 @@ Manager::Manager(const string& dbId,
132133
// Startup the journalling
133134

134135
const auto tdbb = JRD_get_thread_data();
135-
const auto* dbb = tdbb->getDatabase();
136+
const auto dbb = tdbb->getDatabase();
136137

137138
const auto& guid = dbb->dbb_guid;
138-
m_sequence = dbb->dbb_repl_sequence;
139139

140140
if (config->journalDirectory.hasData())
141141
{
142+
// At this point it is unknown if change log shared memory exists or not.
143+
// To avoid race condition with concurrent changing of current replication
144+
// sequence, take and hold shared lock on header page while creating
145+
// ChangeLog instance.
146+
147+
WIN window(HEADER_PAGE_NUMBER);
148+
CCH_FETCH(tdbb, &window, LCK_read, pag_header);
149+
150+
Cleanup releaseHeader([&] {
151+
CCH_RELEASE(tdbb, &window);
152+
});
153+
154+
// Call below will fetch header page with LCK_read lock, it is allowed and OK.
155+
m_sequence = dbb->getReplSequence(tdbb);
156+
142157
m_changeLog = FB_NEW_POOL(getPool())
143158
ChangeLog(getPool(), dbId, guid, m_sequence, config);
144159
}

0 commit comments

Comments
 (0)