@@ -62,7 +62,7 @@ bool TipCache::GlobalTpcInitializer::initialize(SharedMemoryBase* sm, bool initF
62
62
}
63
63
64
64
thread_db* tdbb = JRD_get_thread_data ();
65
- Database* dbb = tdbb->getDatabase ();
65
+ const Database* dbb = tdbb->getDatabase ();
66
66
67
67
// Initialize the shared data header
68
68
initHeader (header);
@@ -198,18 +198,18 @@ void TipCache::finalizeTpc(thread_db* tdbb)
198
198
CommitNumber TipCache::cacheState (TraNumber number)
199
199
{
200
200
fb_assert (m_tpcHeader);
201
- GlobalTpcHeader* header = m_tpcHeader->getHeader ();
201
+ const GlobalTpcHeader* header = m_tpcHeader->getHeader ();
202
202
203
- TraNumber oldest = header->oldest_transaction .load (std::memory_order_relaxed);
203
+ const TraNumber oldest = header->oldest_transaction .load (std::memory_order_relaxed);
204
204
205
205
if (number < oldest)
206
206
return CN_PREHISTORIC;
207
207
208
- TpcBlockNumber blockNumber = number / m_transactionsPerBlock;
209
- ULONG offset = number % m_transactionsPerBlock;
208
+ const TpcBlockNumber blockNumber = number / m_transactionsPerBlock;
209
+ const ULONG offset = number % m_transactionsPerBlock;
210
210
211
211
Sync sync (&m_sync_status, FB_FUNCTION);
212
- TransactionStatusBlock* block = getTransactionStatusBlock (header, blockNumber, sync);
212
+ const TransactionStatusBlock* block = getTransactionStatusBlock (header, blockNumber, sync);
213
213
214
214
// This should not really happen ever
215
215
fb_assert (block);
@@ -281,12 +281,12 @@ void TipCache::initializeTpc(thread_db *tdbb)
281
281
LCK_convert (tdbb, m_lock, LCK_SR, LCK_WAIT); // never fails
282
282
}
283
283
284
- void TipCache::initTransactionsPerBlock (ULONG blockSize)
284
+ void TipCache::initTransactionsPerBlock (ULONG blockSize) noexcept
285
285
{
286
286
if (m_transactionsPerBlock)
287
287
return ;
288
288
289
- const ULONG dataOffset = static_cast <ULONG>(offsetof (TransactionStatusBlock, data[0 ]));
289
+ constexpr ULONG dataOffset = static_cast <ULONG>(offsetof (TransactionStatusBlock, data[0 ]));
290
290
m_transactionsPerBlock = (blockSize - dataOffset) / sizeof (CommitNumber);
291
291
}
292
292
@@ -300,7 +300,7 @@ void TipCache::loadInventoryPages(thread_db* tdbb, GlobalTpcHeader* header)
300
300
const TraNumber hdr_oldest = dbb->dbb_oldest_transaction ;
301
301
#else
302
302
WIN window (HEADER_PAGE_NUMBER);
303
- const auto header_page = (Ods::header_page*) CCH_FETCH (tdbb, &window, LCK_read, pag_header);
303
+ const auto * header_page = (Ods::header_page*) CCH_FETCH (tdbb, &window, LCK_read, pag_header);
304
304
const TraNumber hdr_next_transaction = header_page->hdr_next_transaction ;
305
305
const TraNumber hdr_oldest_transaction = header_page->hdr_oldest_transaction ;
306
306
const AttNumber hdr_attachment_id = header_page->hdr_attachment_id ;
@@ -319,7 +319,7 @@ void TipCache::loadInventoryPages(thread_db* tdbb, GlobalTpcHeader* header)
319
319
320
320
// Round down the oldest to a multiple of four, which puts the
321
321
// transaction in temporary buffer on a byte boundary
322
- TraNumber base = hdr_oldest_transaction & ~TRA_MASK;
322
+ const TraNumber base = hdr_oldest_transaction & ~TRA_MASK;
323
323
324
324
const FB_SIZE_T buffer_length = (hdr_next_transaction + 1 - base + TRA_MASK) / 4 ;
325
325
Array<UCHAR> transactions (buffer_length);
@@ -337,8 +337,8 @@ void TipCache::loadInventoryPages(thread_db* tdbb, GlobalTpcHeader* header)
337
337
338
338
for (TraNumber t = hdr_oldest_transaction; ; )
339
339
{
340
- int state = TRA_state (buffer, base, t);
341
- CommitNumber cn = init_state_mapping[state];
340
+ const int state = TRA_state (buffer, base, t);
341
+ const CommitNumber cn = init_state_mapping[state];
342
342
343
343
// Barrier is not needed as our thread is the only one here.
344
344
// At the same time, simple write to a volatile variable is not good
@@ -357,7 +357,7 @@ void TipCache::loadInventoryPages(thread_db* tdbb, GlobalTpcHeader* header)
357
357
}
358
358
}
359
359
360
- void TipCache::mapInventoryPages (GlobalTpcHeader* header)
360
+ void TipCache::mapInventoryPages (const GlobalTpcHeader* header)
361
361
{
362
362
TpcBlockNumber blockNumber = header->oldest_transaction / m_transactionsPerBlock;
363
363
const TpcBlockNumber lastNumber = header->latest_transaction_id / m_transactionsPerBlock;
@@ -443,13 +443,13 @@ void TipCache::StatusBlockData::clear(thread_db* tdbb)
443
443
oldest = cache->m_tpcHeader ->getHeader ()->oldest_transaction .load (std::memory_order_relaxed);
444
444
else
445
445
{
446
- Database* dbb = tdbb->getDatabase ();
446
+ const Database* dbb = tdbb->getDatabase ();
447
447
if (dbb->dbb_flags & DBB_shared)
448
448
oldest = dbb->dbb_oldest_transaction ;
449
449
else
450
450
{
451
451
WIN window (HEADER_PAGE_NUMBER);
452
- const auto header_page = (Ods::header_page*) CCH_FETCH (tdbb, &window, LCK_read, pag_header);
452
+ const auto * header_page = (Ods::header_page*) CCH_FETCH (tdbb, &window, LCK_read, pag_header);
453
453
oldest = header_page->hdr_oldest_transaction ;
454
454
CCH_RELEASE (tdbb, &window);
455
455
}
@@ -500,7 +500,7 @@ TipCache::TransactionStatusBlock* TipCache::createTransactionStatusBlock(ULONG b
500
500
return blockData->memory ->getHeader ();
501
501
}
502
502
503
- TipCache::TransactionStatusBlock* TipCache::getTransactionStatusBlock (GlobalTpcHeader* header, TpcBlockNumber blockNumber, Sync& sync)
503
+ TipCache::TransactionStatusBlock* TipCache::getTransactionStatusBlock (const GlobalTpcHeader* header, TpcBlockNumber blockNumber, Sync& sync)
504
504
{
505
505
fb_assert (sync.getState () == SYNC_NONE);
506
506
@@ -524,7 +524,7 @@ TipCache::TransactionStatusBlock* TipCache::getTransactionStatusBlock(GlobalTpcH
524
524
else
525
525
{
526
526
// Check if block might be too old to be created.
527
- TraNumber oldest = header->oldest_transaction .load (std::memory_order_relaxed);
527
+ const TraNumber oldest = header->oldest_transaction .load (std::memory_order_relaxed);
528
528
if (blockNumber >= oldest / m_transactionsPerBlock)
529
529
block = createTransactionStatusBlock (header->tpc_block_size , blockNumber);
530
530
else
@@ -538,7 +538,7 @@ TraNumber TipCache::findStates(TraNumber minNumber, TraNumber maxNumber, ULONG m
538
538
{
539
539
// Can only be called on initialized TipCache
540
540
fb_assert (m_tpcHeader);
541
- GlobalTpcHeader* header = m_tpcHeader->getHeader ();
541
+ const GlobalTpcHeader* header = m_tpcHeader->getHeader ();
542
542
543
543
TransactionStatusBlock* statusBlock = nullptr ;
544
544
ULONG transOffset = 0 ;
@@ -574,7 +574,7 @@ TraNumber TipCache::findStates(TraNumber minNumber, TraNumber maxNumber, ULONG m
574
574
// Such transaction shall already be considered active by our caller.
575
575
// TODO: check if this assumption is indeed correct.
576
576
577
- CommitNumber cn = (statusBlock->data + transOffset)->load (std::memory_order_relaxed);
577
+ const CommitNumber cn = (statusBlock->data + transOffset)->load (std::memory_order_relaxed);
578
578
switch (cn)
579
579
{
580
580
case CN_ACTIVE:
@@ -590,7 +590,8 @@ TraNumber TipCache::findStates(TraNumber minNumber, TraNumber maxNumber, ULONG m
590
590
break ;
591
591
592
592
case CN_MAX_NUMBER:
593
- fb_assert (false ); // fall thru
593
+ fb_assert (false );
594
+ [[fallthrough]];
594
595
595
596
default :
596
597
state = tra_committed;
@@ -610,7 +611,7 @@ CommitNumber TipCache::setState(TraNumber number, int state)
610
611
fb_assert (m_tpcHeader);
611
612
GlobalTpcHeader* header = m_tpcHeader->getHeader ();
612
613
613
- TpcBlockNumber blockNumber = number / m_transactionsPerBlock;
614
+ const TpcBlockNumber blockNumber = number / m_transactionsPerBlock;
614
615
ULONG offset = number % m_transactionsPerBlock;
615
616
616
617
Sync sync (&m_sync_status, FB_FUNCTION);
@@ -621,7 +622,7 @@ CommitNumber TipCache::setState(TraNumber number, int state)
621
622
ERR_bugcheck_msg (" TPC: Attempt to change state of old transaction" );
622
623
623
624
std::atomic<CommitNumber>* statePtr = block->data + offset;
624
- CommitNumber oldStateCn = statePtr->load (std::memory_order_relaxed);
625
+ const CommitNumber oldStateCn = statePtr->load (std::memory_order_relaxed);
625
626
switch (state)
626
627
{
627
628
case tra_committed:
@@ -702,7 +703,7 @@ CommitNumber TipCache::snapshotState(thread_db* tdbb, TraNumber number)
702
703
return CN_ACTIVE;
703
704
704
705
// Go to disk, and obtain state of our transaction from TIP
705
- int state = TRA_fetch_state (tdbb, number);
706
+ const int state = TRA_fetch_state (tdbb, number);
706
707
707
708
// We already know for sure that this transaction cannot be active, so mark it dead now
708
709
// to avoid more work in the future
@@ -724,8 +725,8 @@ void TipCache::updateOldestTransaction(thread_db *tdbb, TraNumber oldest, TraNum
724
725
fb_assert (m_tpcHeader);
725
726
GlobalTpcHeader* header = m_tpcHeader->getHeader ();
726
727
727
- TraNumber oldestNew = MIN (oldest, oldestSnapshot);
728
- TraNumber oldestNow = header->oldest_transaction .load (std::memory_order_relaxed);
728
+ const TraNumber oldestNew = MIN (oldest, oldestSnapshot);
729
+ const TraNumber oldestNow = header->oldest_transaction .load (std::memory_order_relaxed);
729
730
if (oldestNew > oldestNow)
730
731
{
731
732
header->oldest_transaction .store (oldestNew, std::memory_order_relaxed);
@@ -747,7 +748,7 @@ int TipCache::tpc_block_blocking_ast(void* arg)
747
748
return 0 ;
748
749
749
750
TipCache* cache = data->cache ;
750
- TraNumber oldest =
751
+ const TraNumber oldest =
751
752
cache->m_tpcHeader ->getHeader ()->oldest_transaction .load (std::memory_order_relaxed);
752
753
753
754
// Is data block really old?
@@ -775,7 +776,7 @@ void TipCache::releaseSharedMemory(thread_db* tdbb, TraNumber oldest_old, TraNum
775
776
{
776
777
Database* dbb = tdbb->getDatabase ();
777
778
778
- TpcBlockNumber lastInterestingBlockNumber = oldest_new / m_transactionsPerBlock;
779
+ const TpcBlockNumber lastInterestingBlockNumber = oldest_new / m_transactionsPerBlock;
779
780
780
781
// If we didn't cross block boundary - there is nothing to do.
781
782
// Note that due to the fuzziness of our caller's memory access to variables
@@ -787,13 +788,12 @@ void TipCache::releaseSharedMemory(thread_db* tdbb, TraNumber oldest_old, TraNum
787
788
// Populate array of blocks that might be unmapped and deleted.
788
789
// We scan for blocks to clean up in descending order, but delete them in
789
790
// ascending order to ensure for robust operation.
790
- PathName fileName;
791
791
HalfStaticArray<TpcBlockNumber, 16 > blocksToCleanup;
792
792
793
793
for (TpcBlockNumber cleanupCounter = lastInterestingBlockNumber - SAFETY_GAP_BLOCKS;
794
794
cleanupCounter; cleanupCounter--)
795
795
{
796
- TpcBlockNumber blockNumber = cleanupCounter - 1 ;
796
+ const TpcBlockNumber blockNumber = cleanupCounter - 1 ;
797
797
PathName fileName = StatusBlockData::makeSharedMemoryFileName (dbb, blockNumber, true );
798
798
799
799
struct stat st;
@@ -810,7 +810,7 @@ void TipCache::releaseSharedMemory(thread_db* tdbb, TraNumber oldest_old, TraNum
810
810
SyncLockGuard sync (&m_sync_status, SYNC_EXCLUSIVE, FB_FUNCTION);
811
811
while (blocksToCleanup.hasData ())
812
812
{
813
- TpcBlockNumber blockNumber = blocksToCleanup.pop ();
813
+ const TpcBlockNumber blockNumber = blocksToCleanup.pop ();
814
814
815
815
if (m_blocks_memory.locate (blockNumber))
816
816
{
@@ -845,7 +845,7 @@ SnapshotHandle TipCache::allocateSnapshotSlot()
845
845
// Scan previously used slots first
846
846
SnapshotHandle slotNumber;
847
847
848
- ULONG slots_used = snapshots->slots_used .load (std::memory_order_relaxed);
848
+ const ULONG slots_used = snapshots->slots_used .load (std::memory_order_relaxed);
849
849
for (slotNumber = snapshots->min_free_slot ; slotNumber < slots_used; slotNumber++)
850
850
{
851
851
if (!snapshots->slots [slotNumber].attachment_id .load (std::memory_order_relaxed))
@@ -890,7 +890,7 @@ void TipCache::remapSnapshots(bool sync)
890
890
// Can only be called on initialized TipCache
891
891
fb_assert (m_tpcHeader);
892
892
893
- SnapshotList* snapshots = m_snapshots->getHeader ();
893
+ const SnapshotList* snapshots = m_snapshots->getHeader ();
894
894
895
895
if (snapshots->slots_allocated .load (std::memory_order_acquire) !=
896
896
(m_snapshots->sh_mem_length_mapped - offsetof (SnapshotList, slots[0 ])) / sizeof (SnapshotData))
@@ -916,7 +916,7 @@ SnapshotHandle TipCache::beginSnapshot(thread_db* tdbb, AttNumber attachmentId,
916
916
{
917
917
// Can only be called on initialized TipCache
918
918
fb_assert (m_tpcHeader);
919
- GlobalTpcHeader* header = m_tpcHeader->getHeader ();
919
+ const GlobalTpcHeader* header = m_tpcHeader->getHeader ();
920
920
921
921
fb_assert (attachmentId);
922
922
@@ -930,7 +930,7 @@ SnapshotHandle TipCache::beginSnapshot(thread_db* tdbb, AttNumber attachmentId,
930
930
931
931
if (commitNumber != 0 )
932
932
{
933
- ULONG slotsUsed = snapshots->slots_used .load (std::memory_order_relaxed);
933
+ const ULONG slotsUsed = snapshots->slots_used .load (std::memory_order_relaxed);
934
934
bool found = false ;
935
935
936
936
for (SnapshotHandle slotNumber = 0 ; slotNumber < slotsUsed; ++slotNumber)
@@ -1010,8 +1010,8 @@ void TipCache::endSnapshot(thread_db* tdbb, SnapshotHandle handle, AttNumber att
1010
1010
// deallocation.
1011
1011
1012
1012
// Perform some sanity checks on a handle
1013
- SnapshotList* snapshots = m_snapshots->getHeader ();
1014
- SnapshotData* slot = snapshots->slots + handle;
1013
+ const SnapshotList* snapshots = m_snapshots->getHeader ();
1014
+ const SnapshotData* slot = snapshots->slots + handle;
1015
1015
1016
1016
if (handle >= snapshots->slots_used .load (std::memory_order_relaxed))
1017
1017
ERR_bugcheck_msg (" Incorrect snapshot deallocation - too few slots" );
@@ -1030,7 +1030,7 @@ void TipCache::updateActiveSnapshots(thread_db* tdbb, ActiveSnapshots* activeSna
1030
1030
{
1031
1031
// Can only be called on initialized TipCache
1032
1032
fb_assert (m_tpcHeader);
1033
- GlobalTpcHeader* header = m_tpcHeader->getHeader ();
1033
+ const GlobalTpcHeader* header = m_tpcHeader->getHeader ();
1034
1034
1035
1035
fb_assert (activeSnapshots);
1036
1036
@@ -1048,7 +1048,7 @@ void TipCache::updateActiveSnapshots(thread_db* tdbb, ActiveSnapshots* activeSna
1048
1048
// If new slots are allocated past this value - we don't care as we preserved
1049
1049
// lastCommit and new snapshots will have numbers >= lastCommit and we don't
1050
1050
// GC them anyways
1051
- ULONG slots_used_org = snapshots->slots_used .load (std::memory_order_acquire);
1051
+ const ULONG slots_used_org = snapshots->slots_used .load (std::memory_order_acquire);
1052
1052
1053
1053
// Remap snapshot list if it has been grown by someone else
1054
1054
remapSnapshots (true );
@@ -1063,8 +1063,8 @@ void TipCache::updateActiveSnapshots(thread_db* tdbb, ActiveSnapshots* activeSna
1063
1063
activeSnapshots->m_snapshots .clear ();
1064
1064
for (ULONG slotNumber = 0 ; slotNumber < slots_used_org; slotNumber++)
1065
1065
{
1066
- SnapshotData* slot = snapshots->slots + slotNumber;
1067
- AttNumber slot_attachment_id = slot->attachment_id .load (std::memory_order_acquire);
1066
+ const SnapshotData* slot = snapshots->slots + slotNumber;
1067
+ const AttNumber slot_attachment_id = slot->attachment_id .load (std::memory_order_acquire);
1068
1068
if (slot_attachment_id)
1069
1069
{
1070
1070
bool isAttachmentDead;
@@ -1085,7 +1085,7 @@ void TipCache::updateActiveSnapshots(thread_db* tdbb, ActiveSnapshots* activeSna
1085
1085
guard.lock ();
1086
1086
1087
1087
// Check if slot was reused while we waited for the mutex
1088
- AttNumber slot_attachment_id2 = slot->attachment_id .load (std::memory_order_acquire);
1088
+ const AttNumber slot_attachment_id2 = slot->attachment_id .load (std::memory_order_acquire);
1089
1089
if (slot_attachment_id != slot_attachment_id2)
1090
1090
{
1091
1091
slotNumber--;
@@ -1097,7 +1097,7 @@ void TipCache::updateActiveSnapshots(thread_db* tdbb, ActiveSnapshots* activeSna
1097
1097
}
1098
1098
else
1099
1099
{
1100
- CommitNumber slot_snapshot = slot->snapshot .load (std::memory_order_acquire);
1100
+ const CommitNumber slot_snapshot = slot->snapshot .load (std::memory_order_acquire);
1101
1101
if (slot_snapshot)
1102
1102
activeSnapshots->m_snapshots .set (slot_snapshot);
1103
1103
}
@@ -1118,7 +1118,7 @@ void TipCache::updateActiveSnapshots(thread_db* tdbb, ActiveSnapshots* activeSna
1118
1118
1119
1119
activeSnapshots->m_lastCommit = header->latest_commit_number .load (std::memory_order_acquire);
1120
1120
ULONG slots_used_org = snapshots->slots_used .load (std::memory_order_acquire);
1121
- ULONG release_count = header->snapshot_release_count .load (std::memory_order_relaxed);
1121
+ const ULONG release_count = header->snapshot_release_count .load (std::memory_order_relaxed);
1122
1122
1123
1123
// If no snapshots were released since we were last called - do nothing
1124
1124
// Do not care about race issues here, because worst-case consequences are benign
@@ -1144,7 +1144,7 @@ void TipCache::updateActiveSnapshots(thread_db* tdbb, ActiveSnapshots* activeSna
1144
1144
{
1145
1145
if (slot->attachment_id .load (std::memory_order_acquire))
1146
1146
{
1147
- CommitNumber slot_snapshot = slot->snapshot .load (std::memory_order_acquire);
1147
+ const CommitNumber slot_snapshot = slot->snapshot .load (std::memory_order_acquire);
1148
1148
if (slot_snapshot)
1149
1149
activeSnapshots->m_snapshots .set (slot_snapshot);
1150
1150
}
@@ -1206,7 +1206,7 @@ AttNumber TipCache::getLatestAttachmentId() const
1206
1206
{
1207
1207
// Can only be called on initialized TipCache
1208
1208
fb_assert (m_tpcHeader);
1209
- GlobalTpcHeader* header = m_tpcHeader->getHeader ();
1209
+ const GlobalTpcHeader* header = m_tpcHeader->getHeader ();
1210
1210
1211
1211
return header->latest_attachment_id ;
1212
1212
}
@@ -1215,7 +1215,7 @@ StmtNumber TipCache::getLatestStatementId() const
1215
1215
{
1216
1216
// Can only be called on initialized TipCache
1217
1217
fb_assert (m_tpcHeader);
1218
- GlobalTpcHeader* header = m_tpcHeader->getHeader ();
1218
+ const GlobalTpcHeader* header = m_tpcHeader->getHeader ();
1219
1219
1220
1220
return header->latest_statement_id ;
1221
1221
}
@@ -1229,7 +1229,7 @@ int TPC_snapshot_state(thread_db* tdbb, TraNumber number)
1229
1229
if (!cache)
1230
1230
return TRA_fetch_state (tdbb, number);
1231
1231
1232
- CommitNumber stateCn = cache->snapshotState (tdbb, number);
1232
+ const CommitNumber stateCn = cache->snapshotState (tdbb, number);
1233
1233
switch (stateCn)
1234
1234
{
1235
1235
case CN_ACTIVE:
0 commit comments