Skip to content

Commit fc86c5f

Browse files
committed
Refactor[mqbs::FileStore]: Add setWriteHead to move the write cursor
Signed-off-by: Yuan Jing Vincent Yan <yyan82@bloomberg.net>
1 parent 9ee0a6e commit fc86c5f

2 files changed

Lines changed: 26 additions & 18 deletions

File tree

src/groups/mqb/mqbs/mqbs_filestore.cpp

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -514,8 +514,8 @@ int FileStore::openInRecoveryMode(bsl::ostream& errorDescription,
514514
BSLS_ASSERT_SAFE(0 != jit.lastRecordPosition());
515515

516516
const RecordHeader& recHeader = jit.lastRecordHeader();
517-
d_writeHeadLeaseId = recHeader.primaryLeaseId();
518-
currentSeqNumRef() = recHeader.sequenceNumber();
517+
setWriteHead(recHeader.primaryLeaseId(),
518+
recHeader.sequenceNumber());
519519
}
520520
}
521521
else {
@@ -585,8 +585,8 @@ int FileStore::openInRecoveryMode(bsl::ostream& errorDescription,
585585
// can differ in case last SyncPt was issued by new
586586
// primary on behalf of the old one, and we always use the
587587
// PSN present in the RecordHeader.
588-
d_writeHeadLeaseId = lsp.header().primaryLeaseId();
589-
currentSeqNumRef() = lsp.header().sequenceNumber();
588+
setWriteHead(lsp.header().primaryLeaseId(),
589+
lsp.header().sequenceNumber());
590590

591591
journalOffset = jit.lastSyncPointPosition() +
592592
FileStoreProtocol::k_JOURNAL_RECORD_SIZE;
@@ -615,8 +615,8 @@ int FileStore::openInRecoveryMode(bsl::ostream& errorDescription,
615615

616616
needTruncation = false;
617617
const JournalOpRecord& lsp = jit.lastSyncPoint();
618-
d_writeHeadLeaseId = lsp.header().primaryLeaseId();
619-
currentSeqNumRef() = lsp.header().sequenceNumber();
618+
setWriteHead(lsp.header().primaryLeaseId(),
619+
lsp.header().sequenceNumber());
620620
}
621621

622622
if (needTruncation) {
@@ -738,8 +738,8 @@ int FileStore::openInRecoveryMode(bsl::ostream& errorDescription,
738738
// Last record is a sync point. Extract PSN from it's header.
739739

740740
const JournalOpRecord& lsp = jit.lastSyncPoint();
741-
d_writeHeadLeaseId = lsp.header().primaryLeaseId();
742-
currentSeqNumRef() = lsp.header().sequenceNumber();
741+
setWriteHead(lsp.header().primaryLeaseId(),
742+
lsp.header().sequenceNumber());
743743
}
744744
else {
745745
// Last record is not a sync point. This is ok for a single
@@ -750,8 +750,8 @@ int FileStore::openInRecoveryMode(bsl::ostream& errorDescription,
750750

751751
appendSyncPoint = true;
752752
const RecordHeader& recHeader = jit.lastRecordHeader();
753-
d_writeHeadLeaseId = recHeader.primaryLeaseId();
754-
currentSeqNumRef() = recHeader.sequenceNumber();
753+
setWriteHead(recHeader.primaryLeaseId(),
754+
recHeader.sequenceNumber());
755755
}
756756
}
757757
}
@@ -1054,8 +1054,7 @@ int FileStore::openInRecoveryMode(bsl::ostream& errorDescription,
10541054
<< "before opening FileStore. Thus, we keep current"
10551055
<< " PSN.";
10561056

1057-
d_writeHeadLeaseId = primaryLeaseIdCurr;
1058-
currentSeqNumRef() = sequenceNumcurr;
1057+
setWriteHead(primaryLeaseIdCurr, sequenceNumcurr);
10591058
}
10601059
}
10611060

@@ -6597,8 +6596,8 @@ int FileStore::processRecoveryEvent(const bsl::shared_ptr<bdlbb::Blob>& blob)
65976596

65986597
if (!hasValidLeaseIdSeqNum) {
65996598
hasValidLeaseIdSeqNum = true;
6600-
d_writeHeadLeaseId = recHeader->primaryLeaseId();
6601-
currentSeqNumRef() = recHeader->sequenceNumber();
6599+
setWriteHead(recHeader->primaryLeaseId(),
6600+
recHeader->sequenceNumber());
66026601
}
66036602
else {
66046603
// Validate PSN
@@ -6621,8 +6620,8 @@ int FileStore::processRecoveryEvent(const bsl::shared_ptr<bdlbb::Blob>& blob)
66216620
else if (d_writeHeadLeaseId < recHeader->primaryLeaseId()) {
66226621
// LeaseId was bumped up.
66236622

6624-
d_writeHeadLeaseId = recHeader->primaryLeaseId();
6625-
currentSeqNumRef() = recHeader->sequenceNumber();
6623+
setWriteHead(recHeader->primaryLeaseId(),
6624+
recHeader->sequenceNumber());
66266625
}
66276626
else {
66286627
if (recHeader->sequenceNumber() <= sequenceNumber()) {
@@ -7156,8 +7155,7 @@ void FileStore::clearPrimary()
71567155
fs->d_journal.d_filePosition -
71577156
FileStoreProtocol::k_JOURNAL_RECORD_SIZE);
71587157

7159-
d_writeHeadLeaseId = recHeader->primaryLeaseId();
7160-
currentSeqNumRef() = recHeader->sequenceNumber();
7158+
setWriteHead(recHeader->primaryLeaseId(), recHeader->sequenceNumber());
71617159
BSLS_ASSERT_SAFE(0 != d_writeHeadLeaseId);
71627160
BSLS_ASSERT_SAFE(0 != sequenceNumber());
71637161

src/groups/mqb/mqbs/mqbs_filestore.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,9 @@ class FileStore BSLS_KEYWORD_FINAL : public DataStore {
396396
/// Note that this will insert a zero entry if one does not exist.
397397
bsls::Types::Uint64& currentSeqNumRef();
398398

399+
/// Move the internal write cursor to the specified `leaseId` and `seqNum`.
400+
void setWriteHead(unsigned int leaseId, bsls::Types::Uint64 seqNum);
401+
399402
/// Create all the relevant files names, open them for writing and
400403
/// populate the specified `fileSetSp` with relevant information.
401404
/// Return zero on success and non-zero value otherwise. Note that all
@@ -1165,6 +1168,13 @@ inline bsls::Types::Uint64& FileStore::currentSeqNumRef()
11651168
return d_highestSeqNums[d_writeHeadLeaseId];
11661169
}
11671170

1171+
inline void FileStore::setWriteHead(unsigned int leaseId,
1172+
bsls::Types::Uint64 seqNum)
1173+
{
1174+
d_writeHeadLeaseId = leaseId;
1175+
d_highestSeqNums[leaseId] = seqNum;
1176+
}
1177+
11681178
inline void FileStore::insertDataStoreRecord(RecordIterator* recordIt,
11691179
const DataStoreRecordKey& key,
11701180
const DataStoreRecord& record)

0 commit comments

Comments
 (0)