Skip to content

Commit 83ca290

Browse files
authored
Fix[MQB]: collect queue stats on replicas (#659)
1 parent 0016fd9 commit 83ca290

21 files changed

Lines changed: 707 additions & 148 deletions

src/groups/mqb/mqbblp/mqbblp_localqueue.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,18 +162,18 @@ int LocalQueue::configure(bsl::ostream& errorDescription, bool isReconfigure)
162162
d_allocator_p);
163163
}
164164

165+
// Inform the storage about the queue.
166+
d_state_p->storageManager()->setQueueRaw(queue,
167+
d_state_p->uri(),
168+
d_state_p->partitionId());
169+
165170
rc = d_queueEngine_mp->configure(errorDescription, isReconfigure);
166171
if (rc != 0) {
167172
return 10 * rc + rc_QUEUE_ENGINE_CFG_FAILURE; // RETURN
168173
}
169174

170175
d_haveStrongConsistency = domainCfg.consistency().isStrongValue();
171176

172-
// Inform the storage about the queue.
173-
d_state_p->storageManager()->setQueueRaw(queue,
174-
d_state_p->uri(),
175-
d_state_p->partitionId());
176-
177177
d_state_p->stats()
178178
->onEvent<mqbstat::QueueStatsDomain::EventType::e_CHANGE_ROLE>(
179179
mqbstat::QueueStatsDomain::Role::e_PRIMARY);

src/groups/mqb/mqbblp/mqbblp_pushstream.t.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
// mqbblp_pushstream.t.cpp -*-C++-*-
1717
#include <mqbblp_pushstream.h>
1818

19+
// MQB
20+
#include <mqbmock_cluster.h>
21+
#include <mqbmock_domain.h>
22+
1923
// BMQ
2024
#include <bmqp_messageguidgenerator.h>
2125

@@ -133,12 +137,16 @@ static void test2_iterations()
133137
0,
134138
bmqtst::TestHelperUtil::allocator());
135139
bmqt::Uri dummyUri("dummy", bmqtst::TestHelperUtil::allocator());
136-
mqbconfm::Domain dummyDomain(bmqtst::TestHelperUtil::allocator());
140+
mqbmock::Cluster dummyCluster(bmqtst::TestHelperUtil::allocator());
141+
mqbmock::Domain dummyDomain(&dummyCluster,
142+
bmqtst::TestHelperUtil::allocator());
143+
mqbconfm::Domain dummyDomainConfig(bmqtst::TestHelperUtil::allocator());
137144

138145
mqbs::InMemoryStorage dummyStorage(dummyUri,
139146
mqbu::StorageKey::k_NULL_KEY,
147+
&dummyDomain,
140148
mqbs::DataStore::k_INVALID_PARTITION_ID,
141-
dummyDomain,
149+
dummyDomainConfig,
142150
&dummyCapacityMeter,
143151
bmqtst::TestHelperUtil::allocator());
144152

src/groups/mqb/mqbblp/mqbblp_queueconsumptionmonitor.t.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ Test::Test()
232232
d_allocator_p)
233233
, d_storage(d_queue.uri(),
234234
mqbu::StorageKey::k_NULL_KEY,
235+
&d_domain,
235236
mqbs::DataStore::k_INVALID_PARTITION_ID,
236237
getDomainConfig(),
237238
d_domain.capacityMeter(),

src/groups/mqb/mqbblp/mqbblp_queueenginetester.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,7 @@ void QueueEngineTester::init(const mqbconfm::Domain& domainConfig,
534534
mqbi::Storage* storage_p = new (*d_allocator_p)
535535
mqbs::InMemoryStorage(d_mockQueue_sp->uri(),
536536
k_NULL_QUEUE_KEY,
537+
d_mockDomain_mp.get(),
537538
k_PARTITION_ID,
538539
domainConfig,
539540
d_mockDomain_mp->capacityMeter(),

src/groups/mqb/mqbblp/mqbblp_remotequeue.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ int RemoteQueue::configureAsProxy(bsl::ostream& errorDescription,
116116
storageSp.load(new (*d_allocator_p) mqbs::InMemoryStorage(
117117
d_state_p->uri(),
118118
d_state_p->key(),
119+
d_state_p->domain(),
119120
mqbs::DataStore::k_INVALID_PARTITION_ID,
120121
domainCfg,
121122
d_state_p->domain()->capacityMeter(),

src/groups/mqb/mqbblp/mqbblp_rootqueueengine.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,19 @@ int RootQueueEngine::initializeAppId(const bsl::string& appId,
462462

463463
d_consumptionMonitor.registerSubStream(appId);
464464

465+
const bsls::Types::Int64 appNumMessages =
466+
d_queueState_p->storage()->numMessages(appKey);
467+
const bsls::Types::Int64 appNumBytes =
468+
d_queueState_p->storage()->numBytes(appKey);
469+
470+
d_queueState_p->queue()->stats()->setOutstandingData(appNumMessages,
471+
appNumBytes,
472+
appId);
473+
BALL_LOG_INFO << "Set outstanding data for appId[" << appId
474+
<< "], queue [" << d_queueState_p->uri() << "]: ("
475+
<< appNumMessages << " msgs, " << appNumBytes
476+
<< " bytes)";
477+
465478
BALL_LOG_INFO << "Found virtual storage for appId [" << appId
466479
<< "], queue [" << d_queueState_p->uri() << "], appKey ["
467480
<< appKey << "], ordinal [" << ordinal << "]";

src/groups/mqb/mqbblp/mqbblp_routers.t.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
// MQB
2828
#include <mqbcfg_brokerconfig.h>
29+
#include <mqbmock_cluster.h>
30+
#include <mqbmock_domain.h>
2931
#include <mqbmock_queue.h>
3032
#include <mqbmock_queuehandle.h>
3133
#include <mqbs_inmemorystorage.h>
@@ -57,6 +59,8 @@ struct TestStorage {
5759
mqbconfm::Domain d_domainCfg;
5860
mqbu::CapacityMeter d_capacityMeter;
5961
mqbu::StorageKey d_storageKey;
62+
mqbmock::Cluster d_cluster;
63+
mqbmock::Domain d_domain;
6064
mqbs::InMemoryStorage d_storage;
6165
bslma::ManagedPtr<mqbi::StorageIterator> d_iterator;
6266
bdlbb::PooledBlobBufferFactory d_bufferFactory;
@@ -69,8 +73,12 @@ struct TestStorage {
6973
, d_domainCfg(d_allocator_p)
7074
, d_capacityMeter(bsl::string("cm", d_allocator_p), 0, d_allocator_p)
7175
, d_storageKey(d_subQueueId)
76+
, d_cluster(d_allocator_p)
77+
, d_domain(&d_cluster,
78+
d_allocator_p) // Use domain only to hold mqbstat::StatContext
7279
, d_storage(bmqt::Uri("uri", d_allocator_p),
7380
d_storageKey,
81+
&d_domain,
7482
1,
7583
d_domainCfg,
7684
&d_capacityMeter,

src/groups/mqb/mqbs/mqbs_filebackedstorage.cpp

Lines changed: 32 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -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

158154
FileBackedStorage::~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

11341131
void 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
}

src/groups/mqb/mqbs/mqbs_filebackedstorage.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,6 @@ class FileBackedStorage BSLS_KEYWORD_FINAL : public ReplicatedStorage {
211211
AutoConfirms d_autoConfirms;
212212
// Auto CONFIRMs waiting for 'put' or 'processMessageRecord'
213213

214-
bsl::shared_ptr<mqbstat::QueueStatsDomain> d_queueStats_sp;
215-
// Statistics of the queue associated to this storage.
216-
217214
private:
218215
// NOT IMPLEMENTED
219216
FileBackedStorage(const FileBackedStorage&) BSLS_KEYWORD_DELETED;

src/groups/mqb/mqbs/mqbs_filestore.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5266,6 +5266,7 @@ void FileStore::createStorage(bsl::shared_ptr<ReplicatedStorage>* storageSp,
52665266
storageSp->reset(new (*storageAlloc)
52675267
InMemoryStorage(queueUri,
52685268
queueKey,
5269+
domain,
52695270
config().partitionId(),
52705271
domain->config(),
52715272
domain->capacityMeter(),

0 commit comments

Comments
 (0)