Skip to content

Commit 754ec3e

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 a6dec5f commit 754ec3e

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/jrd/replication/Manager.cpp

Lines changed: 17 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"
@@ -102,6 +103,7 @@ Manager::Manager(const string& dbId,
102103
m_buffers(getPool()),
103104
m_queue(getPool()),
104105
m_queueSize(0),
106+
m_sequence(0),
105107
m_shutdown(false),
106108
m_signalled(false)
107109
{
@@ -112,10 +114,24 @@ Manager::Manager(const string& dbId,
112114

113115
dbb->ensureGuid(tdbb);
114116
const Guid& guid = dbb->dbb_guid;
115-
m_sequence = dbb->dbb_repl_sequence;
116117

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

0 commit comments

Comments
 (0)