Skip to content

Commit d12c59f

Browse files
authored
Fix[MQB]: unset queue raw pointer on config failure (#881)
1 parent e1c7ed8 commit d12c59f

10 files changed

Lines changed: 28 additions & 17 deletions

src/groups/mqb/mqbblp/mqbblp_clusterqueuehelper.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2168,13 +2168,21 @@ bsl::shared_ptr<mqbi::Queue> ClusterQueueHelper::createQueueFactory(
21682168
bdlma::LocalSequentialAllocator<1024> localAllocator(d_allocator_p);
21692169
bmqu::MemOutStream error(&localAllocator);
21702170

2171-
int rc = queueSp->configure(error,
2171+
int rc = queueSp->configure(&error,
21722172
false, // isReconfigure
21732173
true); // wait
21742174

2175+
/// `mqbi::Queue::configure` might have set a queue raw pointer in the
2176+
/// corresponding storage. Make sure we unset this if we exit the scope
2177+
/// on error.
2178+
bdlb::ScopeExitAny queuePtrGuard(
2179+
bdlf::BindUtil::bindS(d_allocator_p,
2180+
&mqbi::Storage::setQueue,
2181+
queueSp->storage(),
2182+
bsl::nullptr_t()));
2183+
21752184
if (rc != 0) {
21762185
// Queue.configure() failed.
2177-
21782186
BMQ_LOGTHROTTLE_ERROR << "Failure configuring queue '"
21792187
<< queueContext->uri() << "': " << error.str()
21802188
<< ".";
@@ -2204,6 +2212,9 @@ bsl::shared_ptr<mqbi::Queue> ClusterQueueHelper::createQueueFactory(
22042212
1);
22052213
}
22062214

2215+
/// Success: no need to unset queue raw pointer.
2216+
queuePtrGuard.release();
2217+
22072218
return queueSp;
22082219
}
22092220

src/groups/mqb/mqbblp/mqbblp_domain.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,9 +348,9 @@ int Domain::configure(bsl::ostream& errorDescription,
348348
bsl::function<int()> reconfigureQueueFn = bdlf::BindUtil::bind(
349349
&mqbi::Queue::configure,
350350
it->second.get(),
351-
bsl::ref(errorDescription),
352-
true, // isReconfigure
353-
false); // wait
351+
bsl::nullptr_t(), // errorDescription_p
352+
true, // isReconfigure
353+
false); // wait
354354
d_dispatcher_p->execute(reconfigureQueueFn, cluster());
355355
}
356356
}

src/groups/mqb/mqbblp/mqbblp_queue.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ void Queue::onReplicatedBatch()
576576
}
577577
}
578578

579-
int Queue::configure(bsl::ostream& errorDescription,
579+
int Queue::configure(bsl::ostream* errorDescription_p,
580580
bool isReconfigure,
581581
bool wait)
582582
{
@@ -588,7 +588,7 @@ int Queue::configure(bsl::ostream& errorDescription,
588588
bdlf::BindUtil::bind(&Queue::configureDispatched,
589589
this,
590590
(wait ? &result : NULL),
591-
(wait ? &errorDescription : NULL),
591+
(wait ? errorDescription_p : NULL),
592592
isReconfigure),
593593
this);
594594
if (!wait) {

src/groups/mqb/mqbblp/mqbblp_queue.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,16 +194,16 @@ class Queue BSLS_CPP11_FINAL : public mqbi::Queue {
194194
/// If `wait` is `true`, this method will not return until the operation
195195
/// has completed. The return value will be 0 if it succeeds, and
196196
/// nonzero if there was an error; in case of an error, the specified
197-
/// `errorDescription` stream will be populated with a human readable
197+
/// `errorDescription_p` stream will be populated with a human readable
198198
/// reason.
199199
///
200200
/// If `wait` is `false`, this method will return 0 after scheduling the
201-
/// operation on an unspecified thread, and `errorDescription` will be
201+
/// operation on an unspecified thread, and `errorDescription_p` will be
202202
/// unmodified.
203203
///
204204
/// THREAD: this method can be invoked only from cluster-dispatcher
205205
/// thread.
206-
int configure(bsl::ostream& errorDescription,
206+
int configure(bsl::ostream* errorDescription_p,
207207
bool isReconfigure,
208208
bool wait) BSLS_KEYWORD_OVERRIDE;
209209

src/groups/mqb/mqbblp/mqbblp_queueenginetester.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ void QueueEngineTester::init(const mqbconfm::Domain& domainConfig,
471471
// Register queue in domain
472472
bslma::ManagedPtr<mqbi::Queue> queueMp(d_mockQueue_sp.managedPtr());
473473

474-
rc = queueMp->configure(errorDescription,
474+
rc = queueMp->configure(&errorDescription,
475475
false, // isReconfigure
476476
true); // wait
477477
BSLS_ASSERT_OPT(rc == 0);

src/groups/mqb/mqbblp/mqbblp_storagemanager.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1172,7 +1172,6 @@ void StorageManager::setQueue(mqbi::Queue* queue,
11721172
queue));
11731173

11741174
d_fileStores[partitionId]->dispatchEvent(queueEvent);
1175-
;
11761175
}
11771176

11781177
void StorageManager::setQueueRaw(mqbi::Queue* queue,

src/groups/mqb/mqbi/mqbi_queue.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -732,15 +732,15 @@ class Queue : public DispatcherClient {
732732
/// If `wait` is `true`, this method will not return until the operation
733733
/// has completed. The return value will be 0 if it succeeds, and
734734
/// nonzero if there was an error; in case of an error, the specified
735-
/// `errorDescription` stream will be populated with a human readable
735+
/// `errorDescription_p` stream will be populated with a human readable
736736
/// reason.
737737
///
738738
/// If `wait` is `false`, this method will return 0 after scheduling the
739-
/// operation on an unspecified thread, and `errorDescription` will be
739+
/// operation on an unspecified thread, and `errorDescription_p` will be
740740
/// unmodified.
741741
///
742742
/// THREAD: this method can be called from any thread.
743-
virtual int configure(bsl::ostream& errorDescription,
743+
virtual int configure(bsl::ostream* errorDescription_p,
744744
bool isReconfigure,
745745
bool wait) = 0;
746746

src/groups/mqb/mqbmock/mqbmock_queue.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ void Queue::flush()
104104

105105
// MANIPULATORS
106106
// (virtual: mqbi::Queue)
107-
int Queue::configure(BSLA_UNUSED bsl::ostream& errorDescription,
107+
int Queue::configure(BSLA_UNUSED bsl::ostream* errorDescription_p,
108108
BSLA_UNUSED bool isReconfigure,
109109
BSLA_UNUSED bool wait)
110110
{

src/groups/mqb/mqbmock/mqbmock_queue.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ class Queue : public mqbi::Queue {
191191

192192
// MANIPULATORS
193193
// (virtual: mqbi::Queue)
194-
int configure(bsl::ostream& errorDescription,
194+
int configure(bsl::ostream* errorDescription_p,
195195
bool isReconfigure,
196196
bool wait) BSLS_KEYWORD_OVERRIDE;
197197

src/groups/mqb/mqbs/mqbs_filebackedstorage.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,7 @@ int FileBackedStorage::gcExpiredMessages(
735735
bsls::Types::Int64* configuredTtlValue,
736736
bsls::Types::Uint64 secondsFromEpoch)
737737
{
738+
// Executed by QUEUE dispatcher thread
738739
BSLS_ASSERT_SAFE(d_store_p);
739740
BSLS_ASSERT_SAFE(latestMsgTimestampEpoch);
740741
BSLS_ASSERT_SAFE(configuredTtlValue);

0 commit comments

Comments
 (0)