@@ -89,9 +89,9 @@ void FileBackedStorage::purgeCommon(const mqbu::StorageKey& appKey,
8989 // Update stats
9090 d_capacityMeter.clear ();
9191
92- d_queueStats_sp
92+ d_virtualStorageCatalog. stats ()
9393 ->onEvent <mqbstat::QueueStatsDomain::EventType::e_PURGE>(0 );
94- d_queueStats_sp
94+ d_virtualStorageCatalog. stats ()
9595 ->onEvent <mqbstat::QueueStatsDomain::EventType::e_UPDATE_HISTORY>(
9696 d_handles.historySize ());
9797 }
@@ -134,7 +134,6 @@ FileBackedStorage::FileBackedStorage(
134134, d_hasReceipts(!domain->config ().consistency().isStrongValue())
135135, d_currentlyAutoConfirming()
136136, d_autoConfirms(d_allocator_p)
137- , d_queueStats_sp()
138137{
139138 BSLS_ASSERT (d_store_p);
140139
@@ -147,12 +146,9 @@ FileBackedStorage::FileBackedStorage(
147146 // instance associated with it (instead of a 'mqbblp::Cluster' instance),
148147 // and domain instance will return a zero capacity meter when queries to be
149148 // passed to the 'FileBackedStorage' instance.
150-
149+ d_virtualStorageCatalog. stats ()-> initialize (queueUri, domain);
151150 d_virtualStorageCatalog.setDefaultRda (
152151 domain->config ().maxDeliveryAttempts ());
153-
154- d_queueStats_sp.createInplace (d_allocator_p, d_allocator_p);
155- d_queueStats_sp->initialize (queueUri, domain);
156152}
157153
158154FileBackedStorage::~FileBackedStorage ()
@@ -265,8 +261,6 @@ void FileBackedStorage::setQueue(mqbi::Queue* queue)
265261
266262 // Update queue stats if a queue has been associated with the storage.
267263 if (queue) {
268- queue->setStats (d_queueStats_sp);
269-
270264 const bsls::Types::Int64 numMessage = numMessages (
271265 mqbu::StorageKey::k_NULL_KEY);
272266 const bsls::Types::Int64 numByte = numBytes (
@@ -500,7 +494,7 @@ FileBackedStorage::releaseRef(const bmqt::MessageGUID& guid, bool asPrimary)
500494 if (queue ()) {
501495 queue ()->queueEngine ()->beforeMessageRemoved (guid);
502496 }
503- d_queueStats_sp
497+ d_virtualStorageCatalog. stats ()
504498 ->onEvent <mqbstat::QueueStatsDomain::EventType::e_DEL_MESSAGE>(
505499 msgLen);
506500
@@ -517,9 +511,10 @@ FileBackedStorage::releaseRef(const bmqt::MessageGUID& guid, bool asPrimary)
517511 d_capacityMeter.remove (1 , msgLen);
518512 d_handles.erase (it);
519513
520- d_queueStats_sp->onEvent <
521- mqbstat::QueueStatsDomain::EventType::e_UPDATE_HISTORY>(
522- d_handles.historySize ());
514+ d_virtualStorageCatalog.stats ()
515+ ->onEvent <
516+ mqbstat::QueueStatsDomain::EventType::e_UPDATE_HISTORY>(
517+ d_handles.historySize ());
523518 }
524519
525520 return mqbi::StorageResult::e_ZERO_REFERENCES;
@@ -622,7 +617,7 @@ FileBackedStorage::removeAll(const mqbu::StorageKey& appKey)
622617 }
623618 }
624619
625- d_queueStats_sp
620+ d_virtualStorageCatalog. stats ()
626621 ->onEvent <mqbstat::QueueStatsDomain::EventType::e_UPDATE_HISTORY>(
627622 d_handles.historySize ());
628623
@@ -751,10 +746,12 @@ int FileBackedStorage::gcExpiredMessages(
751746 int numMsgsUnreceipted = 0 ;
752747 bsls::Types::Int64 now = bmqsys::Time::highResolutionTimer ();
753748 int limit = k_GC_MESSAGES_BATCH_SIZE;
754- bsls::Types::Int64 deduplicationTimeNs =
755- queue () ? queue ()->domain ()->config ().deduplicationTimeMs () *
756- bdlt::TimeUnitRatio::k_NANOSECONDS_PER_MILLISECOND
757- : 0 ;
749+ bsls::Types::Int64 deduplicationTimeNs = 0 ;
750+ if (queue () && queue ()->domain ()) {
751+ deduplicationTimeNs =
752+ queue ()->domain ()->config ().deduplicationTimeMs () *
753+ bdlt::TimeUnitRatio::k_NANOSECONDS_PER_MILLISECOND;
754+ }
758755
759756 for (RecordHandleMapIter next = d_handles.begin (), cit;
760757 next != d_handles.end () && --limit;) {
@@ -813,7 +810,7 @@ int FileBackedStorage::gcExpiredMessages(
813810 if (queue ()) {
814811 queue ()->queueEngine ()->beforeMessageRemoved (cit->first );
815812 }
816- d_queueStats_sp
813+ d_virtualStorageCatalog. stats ()
817814 ->onEvent <mqbstat::QueueStatsDomain::EventType::e_DEL_MESSAGE>(
818815 msgLen);
819816
@@ -834,16 +831,17 @@ int FileBackedStorage::gcExpiredMessages(
834831
835832 if (numMsgsDeleted > 0 ) {
836833 if (numMsgsDeleted > numMsgsUnreceipted) {
837- d_queueStats_sp
834+ d_virtualStorageCatalog. stats ()
838835 ->onEvent <mqbstat::QueueStatsDomain::EventType::e_GC_MESSAGE>(
839836 numMsgsDeleted - numMsgsUnreceipted);
840837 }
841838 if (numMsgsUnreceipted) {
842- d_queueStats_sp->onEvent <
843- mqbstat::QueueStatsDomain::EventType::e_NO_SC_MESSAGE>(
844- numMsgsUnreceipted);
839+ d_virtualStorageCatalog.stats ()
840+ ->onEvent <
841+ mqbstat::QueueStatsDomain::EventType::e_NO_SC_MESSAGE>(
842+ numMsgsUnreceipted);
845843 }
846- d_queueStats_sp
844+ d_virtualStorageCatalog. stats ()
847845 ->onEvent <mqbstat::QueueStatsDomain::EventType::e_UPDATE_HISTORY>(
848846 d_handles.historySize ());
849847 }
@@ -859,7 +857,7 @@ int FileBackedStorage::gcHistory(bsls::Types::Int64 now)
859857{
860858 const int rc = d_handles.gc (now, k_GC_MESSAGES_BATCH_SIZE);
861859 if (0 != rc) {
862- d_queueStats_sp
860+ d_virtualStorageCatalog. stats ()
863861 ->onEvent <mqbstat::QueueStatsDomain::EventType::e_UPDATE_HISTORY>(
864862 d_handles.historySize ());
865863 }
@@ -917,7 +915,7 @@ void FileBackedStorage::processMessageRecord(
917915 // Update the messages & bytes monitors, and the stats.
918916 d_capacityMeter.forceCommit (1 , msgLen); // Return value ignored.
919917
920- d_queueStats_sp
918+ d_virtualStorageCatalog. stats ()
921919 ->onEvent <mqbstat::QueueStatsDomain::EventType::e_ADD_MESSAGE>(
922920 msgLen);
923921
@@ -1033,15 +1031,14 @@ void FileBackedStorage::processDeletionRecord(const bmqt::MessageGUID& guid)
10331031 if (queue ()) {
10341032 queue ()->queueEngine ()->beforeMessageRemoved (guid);
10351033 }
1036- d_queueStats_sp
1034+ d_virtualStorageCatalog. stats ()
10371035 ->onEvent <mqbstat::QueueStatsDomain::EventType::e_DEL_MESSAGE>(msgLen);
10381036
1039- // Delete 'guid' from all virtual storages, if any. Note that 'guid'
1040- // should have already been removed from each virtual storage when confirm
1041- // records were received earlier for each appKey, but we remove the guid
1042- // again, just in case. When the code is mature enough, we could remove
1043- // this.
1044- d_virtualStorageCatalog.remove (guid);
1037+ // Delete 'guid' from all virtual storages, if any.
1038+ // Note that we call `gc`, not `remove`, because we want to update
1039+ // message/byte counters. We don't replicate the last confirm and
1040+ // REPLICA needs to find appId that was implicitly confirmed and update it.
1041+ d_virtualStorageCatalog.gc (guid);
10451042
10461043 d_capacityMeter.remove (1 , msgLen, true /* silent mode; don't log */ );
10471044
@@ -1060,7 +1057,7 @@ void FileBackedStorage::processDeletionRecord(const bmqt::MessageGUID& guid)
10601057 d_isEmpty.storeRelaxed (1 );
10611058 }
10621059
1063- d_queueStats_sp
1060+ d_virtualStorageCatalog. stats ()
10641061 ->onEvent <mqbstat::QueueStatsDomain::EventType::e_UPDATE_HISTORY>(
10651062 d_handles.historySize ());
10661063}
@@ -1133,7 +1130,7 @@ FileBackedStorage::autoConfirm(const mqbu::StorageKey& appKey,
11331130
11341131void FileBackedStorage::setPrimary ()
11351132{
1136- d_queueStats_sp
1133+ d_virtualStorageCatalog. stats ()
11371134 ->onEvent <mqbstat::QueueStatsDomain::EventType::e_CHANGE_ROLE>(
11381135 mqbstat::QueueStatsDomain::Role::e_PRIMARY);
11391136}
0 commit comments