Skip to content

Commit c4c3bd8

Browse files
authored
Refactor[MQB]: simplify queue creation/registration (#827)
Signed-off-by: dorjesinpo <129227380+dorjesinpo@users.noreply.github.com>
1 parent a95eb96 commit c4c3bd8

9 files changed

Lines changed: 69 additions & 97 deletions

src/groups/mqb/mqbblp/mqbblp_clusterqueuehelper.cpp

Lines changed: 47 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2039,19 +2039,12 @@ bsl::shared_ptr<mqbi::Queue> ClusterQueueHelper::createQueueFactory(
20392039
d_allocator_p),
20402040
d_allocator_p);
20412041

2042+
// Create Local/Remote queue flavor
20422043
if (!isPrimary) {
20432044
queueSp->createRemote(
20442045
openQueueResponse.deduplicationTimeMs(),
20452046
d_clusterData_p->clusterConfig().queueOperations().ackWindowSize(),
20462047
&d_clusterData_p->stateSpPool());
2047-
2048-
if (context.d_domain_p->registerQueue(errorDescription, queueSp) !=
2049-
0) {
2050-
return 0; // RETURN
2051-
}
2052-
2053-
queueContext->d_liveQInfo.d_queue_sp = queueSp;
2054-
d_queuesById[queueContext->d_liveQInfo.d_id] = queueContext;
20552048
}
20562049
else {
20572050
// This is the primary of the queue.
@@ -2084,24 +2077,62 @@ bsl::shared_ptr<mqbi::Queue> ClusterQueueHelper::createQueueFactory(
20842077
// Queue must have been registered with storage manager before
20852078
// registering it with the domain, otherwise Queue.configure() will
20862079
// fail.
2080+
}
20872081

2088-
if (context.d_domain_p->registerQueue(errorDescription, queueSp) !=
2089-
0) {
2090-
return 0; // RETURN
2091-
}
2082+
// Register this queue to the dispatcher.
2083+
if (d_cluster_p->isRemote()) {
2084+
d_cluster_p->dispatcher()->registerClient(
2085+
queueSp.get(),
2086+
mqbi::DispatcherClientType::e_QUEUE);
2087+
}
2088+
else {
2089+
d_cluster_p->dispatcher()->registerClient(
2090+
queueSp.get(),
2091+
mqbi::DispatcherClientType::e_QUEUE,
2092+
d_storageManager_p->processorForPartition(
2093+
queueContext->partitionId()));
2094+
}
2095+
2096+
// Configure the queue
2097+
bdlma::LocalSequentialAllocator<1024> localAllocator(d_allocator_p);
2098+
bmqu::MemOutStream error(&localAllocator);
20922099

2093-
queueContext->d_liveQInfo.d_queue_sp = queueSp;
2094-
// No need to insert in d_queuesById since those queues will never
2095-
// be looked up by id (and all have k_PRIMARY_QUEUE_ID id).
2100+
int rc = queueSp->configure(error,
2101+
false, // isReconfigure
2102+
true); // wait
2103+
2104+
if (rc != 0) {
2105+
// Queue.configure() failed.
2106+
2107+
BALL_LOG_ERROR << "Failure configuring queue '" << queueContext->uri()
2108+
<< "': " << error.str() << ".";
2109+
2110+
errorDescription << error.str();
2111+
2112+
// Discard the queue.
2113+
return 0; // RETURN
2114+
}
2115+
2116+
if (context.d_domain_p->registerQueue(queueSp) != 0) {
2117+
// Discard the queue.
2118+
return 0; // RETURN
2119+
}
2120+
2121+
queueContext->d_liveQInfo.d_queue_sp = queueSp;
2122+
2123+
if (!isPrimary) {
2124+
d_queuesById[queueContext->d_liveQInfo.d_id] = queueContext;
20962125
}
2126+
// else, no need to insert in d_queuesById since those queues will never
2127+
// be looked up by id (and all have k_PRIMARY_QUEUE_ID id).
20972128

20982129
if (!d_cluster_p->isRemote()) {
20992130
d_clusterState_p->updatePartitionNumActiveQueues(
21002131
queueContext->partitionId(),
21012132
1);
21022133
}
21032134

2104-
return bsl::shared_ptr<mqbi::Queue>(queueSp);
2135+
return queueSp;
21052136
}
21062137

21072138
void ClusterQueueHelper::onHandleReleased(

src/groups/mqb/mqbblp/mqbblp_domain.cpp

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -475,8 +475,7 @@ void Domain::openQueue(
475475
callback));
476476
}
477477

478-
int Domain::registerQueue(bsl::ostream& errorDescription,
479-
const bsl::shared_ptr<mqbi::Queue>& queueSp)
478+
int Domain::registerQueue(const bsl::shared_ptr<mqbi::Queue>& queueSp)
480479
{
481480
// executed by the associated CLUSTER's DISPATCHER thread
482481

@@ -486,9 +485,8 @@ int Domain::registerQueue(bsl::ostream& errorDescription,
486485

487486
enum RcEnum {
488487
// Value for the various RC error categories
489-
rc_SUCCESS = 0,
490-
rc_ALREADY_REGISTERED = -1,
491-
rc_CONFIGURATION_FAILED = -2
488+
rc_SUCCESS = 0,
489+
rc_ALREADY_REGISTERED = -1
492490
};
493491

494492
// As part of registering the 'queue' with the domain, 'queue' will also be
@@ -519,30 +517,6 @@ int Domain::registerQueue(bsl::ostream& errorDescription,
519517

520518
d_queues[queueSp->uri().queue()] = queueSp;
521519
}
522-
bdlma::LocalSequentialAllocator<1024> localAllocator(d_allocator_p);
523-
bmqu::MemOutStream error(&localAllocator);
524-
525-
int rc = queueSp->configure(error,
526-
false, // isReconfigure
527-
true); // wait
528-
if (rc != 0) {
529-
// Queue.configure() failed, need to rollback.
530-
531-
BALL_LOG_ERROR << "Failure configuring queue in the domain '" << d_name
532-
<< "' "
533-
<< "[canonicalURI: " << queueSp->uri().canonical()
534-
<< ", qId: " << bmqp::QueueId::QueueIdInt(queueSp->id())
535-
<< "]: " << error.str() << ".";
536-
537-
errorDescription << error.str();
538-
539-
bslmt::LockGuard<bslmt::Mutex> guard(&d_mutex); // LOCK
540-
QueueMap::const_iterator it = d_queues.find(queueSp->uri().queue());
541-
BSLS_ASSERT_SAFE(it != d_queues.end());
542-
d_queues.erase(it);
543-
544-
return rc * 10 + rc_CONFIGURATION_FAILED; // RETURN
545-
}
546520

547521
BALL_LOG_INFO << "Registered queue to domain '" << d_name << "' "
548522
<< "[canonicalURI: " << queueSp->uri().canonical()

src/groups/mqb/mqbblp/mqbblp_domain.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -267,11 +267,9 @@ class Domain BSLS_KEYWORD_FINAL : public mqbi::Domain {
267267
const mqbi::Domain::OpenQueueCallback& callback)
268268
BSLS_KEYWORD_OVERRIDE;
269269

270-
/// Take ownership of and configure the specified `queue`. Return 0 on
271-
/// success, or a non-zero return code otherwise, populating the
272-
/// specified `errorDescription` with a description of the failure.
273-
int registerQueue(bsl::ostream& errorDescription,
274-
const bsl::shared_ptr<mqbi::Queue>& queueSp)
270+
/// Take ownership of the specified `queue`. Return 0 on success, or a
271+
/// non-zero return code otherwise.
272+
int registerQueue(const bsl::shared_ptr<mqbi::Queue>& queueSp)
275273
BSLS_KEYWORD_OVERRIDE;
276274

277275
/// Reverse method of `registerQueue`, invoked when the last

src/groups/mqb/mqbblp/mqbblp_queue.cpp

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -448,10 +448,6 @@ Queue::Queue(const bmqt::Uri& uri,
448448
.setMiscWorkThreadPool(threadPool)
449449
.setRoutingConfig(routingCfg)
450450
.setMessageThrottleConfig(messageThrottleConfig);
451-
452-
// Have to set up dispatcher in constructor so we can check if we are
453-
// in the correct thread in `mqbblp::Queue::configure()`.
454-
dispatcherClientData().setDispatcher(domain->cluster()->dispatcher());
455451
}
456452

457453
Queue::~Queue()
@@ -584,26 +580,7 @@ int Queue::configure(bsl::ostream& errorDescription,
584580
bool isReconfigure,
585581
bool wait)
586582
{
587-
// executed by the cluster *DISPATCHER* thread
588-
589-
// PRECONDITIONS
590-
BSLS_ASSERT_SAFE(
591-
dispatcher()->inDispatcherThread(d_state.domain()->cluster()));
592-
593-
if (!isReconfigure) {
594-
// Register this queue to the dispatcher.
595-
if (d_state.domain()->cluster()->isRemote()) {
596-
dispatcher()->registerClient(this,
597-
mqbi::DispatcherClientType::e_QUEUE);
598-
}
599-
else {
600-
dispatcher()->registerClient(
601-
this,
602-
mqbi::DispatcherClientType::e_QUEUE,
603-
d_state.storageManager()->processorForPartition(
604-
d_state.partitionId()));
605-
}
606-
}
583+
// executed by *ANY* thread
607584

608585
// Enqueue a configure callback in the queue-dispatcher thread.
609586
int result = 0;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ Test::Test()
246246
bslma::ManagedPtr<mqbi::Queue> queueMp(&d_queue,
247247
0,
248248
bslma::ManagedPtrUtil::noOpDeleter);
249-
d_domain.registerQueue(errorDescription, queueMp);
249+
d_domain.registerQueue(queueMp);
250250

251251
mqbconfm::Storage config;
252252
mqbconfm::Limits limits;

src/groups/mqb/mqbblp/mqbblp_queueenginetester.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,13 @@ void QueueEngineTester::init(const mqbconfm::Domain& domainConfig,
470470

471471
// Register queue in domain
472472
bslma::ManagedPtr<mqbi::Queue> queueMp(d_mockQueue_sp.managedPtr());
473-
rc = d_mockDomain_mp->registerQueue(errorDescription, queueMp);
473+
474+
rc = queueMp->configure(errorDescription,
475+
false, // isReconfigure
476+
true); // wait
477+
BSLS_ASSERT_OPT(rc == 0);
478+
479+
rc = d_mockDomain_mp->registerQueue(queueMp);
474480
BSLS_ASSERT_OPT(rc == 0);
475481

476482
// VALIDATION

src/groups/mqb/mqbi/mqbi_domain.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,9 @@ class Domain {
163163
const bmqp_ctrlmsg::QueueHandleParameters& handleParameters,
164164
const OpenQueueCallback& callback) = 0;
165165

166-
/// Take ownership of the specified `queue`, and eventually configure
167-
/// it. Return 0 on success, or a non-zero return code otherwise,
168-
/// populating the specified `errorDescription` with a description of
169-
/// the failure.
170-
virtual int registerQueue(bsl::ostream& errorDescription,
171-
const bsl::shared_ptr<Queue>& queueSp) = 0;
166+
/// Take ownership of the specified `queue`. Return 0 on success, or a
167+
/// non-zero return code otherwise.
168+
virtual int registerQueue(const bsl::shared_ptr<Queue>& queueSp) = 0;
172169

173170
/// Reverse method of `registerQueue`, invoked when the last
174171
/// `QueueHandle` associated to the specified `queue` has been deleted

src/groups/mqb/mqbmock/mqbmock_domain.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,21 +99,13 @@ void Domain::openQueue(
9999
// NOTHING
100100
}
101101

102-
int Domain::registerQueue(bsl::ostream& errorDescription,
103-
const bsl::shared_ptr<mqbi::Queue>& queueSp)
102+
int Domain::registerQueue(const bsl::shared_ptr<mqbi::Queue>& queueSp)
104103
{
105104
// PRECONDITIONS
106105
BSLS_ASSERT_SAFE(queueSp && "'queue' must not be null");
107106
BSLS_ASSERT_SAFE(lookupQueue(0, queueSp->uri()) != 0 &&
108107
"'queue' already registered with the domain");
109108

110-
int rc = queueSp->configure(errorDescription,
111-
false, // isReconfigure
112-
true); // wait
113-
if (rc != 0) {
114-
return rc; // RETURN
115-
}
116-
117109
d_queues[queueSp->uri().queue()] = queueSp;
118110

119111
return 0;

src/groups/mqb/mqbmock/mqbmock_domain.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,9 @@ class Domain : public mqbi::Domain {
182182
const mqbi::Domain::OpenQueueCallback& callback)
183183
BSLS_KEYWORD_OVERRIDE;
184184

185-
/// Take ownership of the specified `queue`, and eventually configure
186-
/// it. Return 0 on success, or a non-zero return code otherwise,
187-
/// populating the specified `errorDescription` with a description of
188-
/// the failure.
189-
int registerQueue(bsl::ostream& errorDescription,
190-
const bsl::shared_ptr<mqbi::Queue>& queueSp)
185+
/// Take ownership of the specified `queue`. Return 0 on success, or a
186+
/// non-zero return code otherwise.
187+
int registerQueue(const bsl::shared_ptr<mqbi::Queue>& queueSp)
191188
BSLS_KEYWORD_OVERRIDE;
192189

193190
/// Reverse method of `registerQueue`, invoked when the last

0 commit comments

Comments
 (0)