Skip to content

Commit 9f06169

Browse files
authored
fix Getting rid of raw pointer to storage (#608)
* Getting rid of raw pointer to storage Signed-off-by: dorjesinpo <[email protected]> * also in configureAsProxy Signed-off-by: dorjesinpo <[email protected]> --------- Signed-off-by: dorjesinpo <[email protected]>
1 parent b67faa9 commit 9f06169

13 files changed

+76
-76
lines changed

src/groups/mqb/mqbblp/mqbblp_localqueue.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,10 @@ int LocalQueue::configure(bsl::ostream& errorDescription, bool isReconfigure)
109109

110110
// Only create a storage if this is the initial configure; reconfigure
111111
// should reuse the previously created storage.
112-
bslma::ManagedPtr<mqbi::Storage> storageMp;
112+
bsl::shared_ptr<mqbi::Storage> storageSp;
113113
rc = d_state_p->storageManager()->makeStorage(
114114
errorDescription,
115-
&storageMp,
115+
&storageSp,
116116
d_state_p->uri(),
117117
d_state_p->key(),
118118
d_state_p->partitionId(),
@@ -124,10 +124,10 @@ int LocalQueue::configure(bsl::ostream& errorDescription, bool isReconfigure)
124124
}
125125

126126
if (d_state_p->isAtMostOnce()) {
127-
storageMp->capacityMeter()->disable();
127+
storageSp->capacityMeter()->disable();
128128
}
129129

130-
if (!d_state_p->isStorageCompatible(storageMp)) {
130+
if (!d_state_p->isStorageCompatible(storageSp)) {
131131
errorDescription << "Incompatible storage type for LocalQueue "
132132
<< "[uri: " << d_state_p->uri() << ", key: '"
133133
<< d_state_p->key()
@@ -136,7 +136,7 @@ int LocalQueue::configure(bsl::ostream& errorDescription, bool isReconfigure)
136136
return rc_INCOMPATIBLE_STORAGE; // RETURN
137137
}
138138

139-
d_state_p->setStorage(storageMp);
139+
d_state_p->setStorage(storageSp);
140140
}
141141
else {
142142
d_state_p->storage()->setConsistency(domainCfg.consistency());

src/groups/mqb/mqbblp/mqbblp_queuestate.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ QueueState::QueueState(mqbi::Queue* queue,
6565
, d_storageManager_p(0)
6666
, d_resources(resources)
6767
, d_miscWorkThreadPool_p(0)
68-
, d_storage_mp(0)
68+
, d_storage_sp(0)
6969
, d_stats_sp(0)
7070
, d_messageThrottleConfig()
7171
, d_handleCatalog(queue, allocator)
@@ -162,13 +162,14 @@ mqbi::QueueCounts QueueState::consumerAndProducerCounts(
162162
return mqbi::QueueCounts(0, 0);
163163
}
164164

165-
bool QueueState::isStorageCompatible(const StorageMp& storageMp) const
165+
bool QueueState::isStorageCompatible(
166+
const bsl::shared_ptr<mqbi::Storage>& storageSp) const
166167
{
167168
// executed by either the *QUEUE* or *CLUSTER* thread
168169

169170
// If persistent, then there are no validation rules at the moment.
170171
// If no persistence, then the storage should be in-memory.
171-
return !isAtMostOnce() || !storageMp->isPersistent();
172+
return !isAtMostOnce() || !storageSp->isPersistent();
172173
}
173174

174175
bool QueueState::isAtMostOnce() const
@@ -222,18 +223,18 @@ void QueueState::loadInternals(mqbcmd::QueueState* out) const
222223
out->key() = os.str();
223224
out->partitionId() = d_partitionId;
224225

225-
if (d_storage_mp) {
226+
if (d_storage_sp) {
226227
mqbcmd::QueueStorage& queueStorage = out->storage().makeValue();
227-
queueStorage.numMessages() = d_storage_mp->numMessages(
228+
queueStorage.numMessages() = d_storage_sp->numMessages(
228229
mqbu::StorageKey::k_NULL_KEY);
229-
queueStorage.numBytes() = d_storage_mp->numBytes(
230+
queueStorage.numBytes() = d_storage_sp->numBytes(
230231
mqbu::StorageKey::k_NULL_KEY);
231-
if (d_storage_mp->numVirtualStorages()) {
232+
if (d_storage_sp->numVirtualStorages()) {
232233
mqbi::Storage::AppInfos appIdKeyPairs;
233-
d_storage_mp->loadVirtualStorageDetails(&appIdKeyPairs);
234+
d_storage_sp->loadVirtualStorageDetails(&appIdKeyPairs);
234235
BSLS_ASSERT_SAFE(
235236
appIdKeyPairs.size() ==
236-
static_cast<size_t>(d_storage_mp->numVirtualStorages()));
237+
static_cast<size_t>(d_storage_sp->numVirtualStorages()));
237238

238239
bsl::vector<mqbcmd::VirtualStorage>& virtualStorages =
239240
queueStorage.virtualStorages();
@@ -248,17 +249,17 @@ void QueueState::loadInternals(mqbcmd::QueueState* out) const
248249
os.reset();
249250
os << cit->second;
250251
virtualStorages[i].appKey() = os.str();
251-
virtualStorages[i].numMessages() = d_storage_mp->numMessages(
252+
virtualStorages[i].numMessages() = d_storage_sp->numMessages(
252253
cit->second);
253254
}
254255
}
255256
}
256257

257-
if (d_storage_mp) {
258+
if (d_storage_sp) {
258259
mqbcmd::CapacityMeter& capacityMeter =
259260
out->capacityMeter().makeValue();
260261
mqbu::CapacityMeterUtil::loadState(&capacityMeter,
261-
*d_storage_mp->capacityMeter());
262+
*d_storage_sp->capacityMeter());
262263
}
263264

264265
d_handleCatalog.loadInternals(&out->handles());

src/groups/mqb/mqbblp/mqbblp_queuestate.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ namespace mqbblp {
7979
class QueueState {
8080
public:
8181
// TYPES
82-
typedef bslma::ManagedPtr<mqbi::Storage> StorageMp;
8382

8483
/// `SubQueuesParameters` is an alias for a map of QueueStreamParameters
8584
/// (subQueueId) -> queueStreamParameters
@@ -145,7 +144,7 @@ class QueueState {
145144
bdlmt::FixedThreadPool* d_miscWorkThreadPool_p;
146145

147146
/// Storage used by the queue associated to this state.
148-
StorageMp d_storage_mp;
147+
bsl::shared_ptr<mqbi::Storage> d_storage_sp;
149148

150149
/// Dispatcher Client Data of the queue associated to this state.
151150
mqbi::DispatcherClientData d_dispatcherClientData;
@@ -200,7 +199,7 @@ class QueueState {
200199
QueueState& setId(unsigned int value);
201200
QueueState& setKey(const mqbu::StorageKey& key);
202201
QueueState& setPartitionId(int value);
203-
QueueState& setStorage(StorageMp& value);
202+
QueueState& setStorage(const bsl::shared_ptr<mqbi::Storage>& value);
204203
QueueState& setStorageManager(mqbi::StorageManager* value);
205204
QueueState&
206205
setRoutingConfig(const bmqp_ctrlmsg::RoutingConfiguration& routingConfig);
@@ -303,7 +302,8 @@ class QueueState {
303302

304303
/// Return `true` if the specified `storage` is compatible with the
305304
/// current configuration, or `false` otherwise.
306-
bool isStorageCompatible(const StorageMp& storageMp) const;
305+
bool
306+
isStorageCompatible(const bsl::shared_ptr<mqbi::Storage>& storageSp) const;
307307

308308
/// Return `true` if the configuration for this queue requires
309309
/// at-most-once semantics or `false` otherwise.
@@ -373,9 +373,10 @@ inline QueueState& QueueState::setPartitionId(int value)
373373
return *this;
374374
}
375375

376-
inline QueueState& QueueState::setStorage(StorageMp& value)
376+
inline QueueState&
377+
QueueState::setStorage(const bsl::shared_ptr<mqbi::Storage>& value)
377378
{
378-
d_storage_mp = value;
379+
d_storage_sp = value;
379380
return *this;
380381
}
381382

@@ -566,7 +567,7 @@ inline mqbi::Queue* QueueState::queue() const
566567

567568
inline mqbi::Storage* QueueState::storage() const
568569
{
569-
return d_storage_mp.get();
570+
return d_storage_sp.get();
570571
}
571572

572573
inline mqbi::StorageManager* QueueState::storageManager() const

src/groups/mqb/mqbblp/mqbblp_remotequeue.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ int RemoteQueue::configureAsProxy(bsl::ostream& errorDescription,
109109
// TTL is not applicable at proxy
110110

111111
// Create the associated storage.
112-
bslma::ManagedPtr<mqbi::Storage> storageMp;
113-
storageMp.load(new (*d_allocator_p) mqbs::InMemoryStorage(
112+
bsl::shared_ptr<mqbi::Storage> storageSp;
113+
storageSp.load(new (*d_allocator_p) mqbs::InMemoryStorage(
114114
d_state_p->uri(),
115115
d_state_p->key(),
116116
mqbs::DataStore::k_INVALID_PARTITION_ID,
@@ -125,8 +125,8 @@ int RemoteQueue::configureAsProxy(bsl::ostream& errorDescription,
125125
limits.messages() = bsl::numeric_limits<bsls::Types::Int64>::max();
126126
limits.bytes() = bsl::numeric_limits<bsls::Types::Int64>::max();
127127

128-
storageMp->setConsistency(domainCfg.consistency());
129-
int rc = storageMp->configure(errorDescription,
128+
storageSp->setConsistency(domainCfg.consistency());
129+
int rc = storageSp->configure(errorDescription,
130130
config,
131131
limits,
132132
domainCfg.messageTtl(),
@@ -135,18 +135,18 @@ int RemoteQueue::configureAsProxy(bsl::ostream& errorDescription,
135135
return 10 * rc + rc_STORAGE_CFG_FAILURE; // RETURN
136136
}
137137

138-
storageMp->capacityMeter()->disable();
138+
storageSp->capacityMeter()->disable();
139139
// In a remote queue, we don't care about monitoring, so disable it for
140140
// efficiency performance.
141141

142-
if (!d_state_p->isStorageCompatible(storageMp)) {
142+
if (!d_state_p->isStorageCompatible(storageSp)) {
143143
errorDescription << "Incompatible storage type for ProxyRemoteQueue "
144144
<< "[uri: " << d_state_p->uri()
145145
<< ", id: " << d_state_p->id() << "]";
146146
return rc_INCOMPATIBLE_STORAGE; // RETURN
147147
}
148148

149-
d_state_p->setStorage(storageMp);
149+
d_state_p->setStorage(storageSp);
150150

151151
// Create the queueEngine.
152152
d_queueEngine_mp.load(
@@ -195,12 +195,12 @@ int RemoteQueue::configureAsClusterMember(bsl::ostream& errorDescription,
195195
// Only create a storage if this is the initial configure; reconfigure
196196
// (which happens during conversion to local/remote) should reuse the
197197
// previously created storage.
198-
bslma::ManagedPtr<mqbi::Storage> storageMp;
198+
bsl::shared_ptr<mqbi::Storage> storageSp;
199199
bdlma::LocalSequentialAllocator<1024> localAllocator(d_allocator_p);
200200
bmqu::MemOutStream errorDesc(&localAllocator);
201201
rc = d_state_p->storageManager()->makeStorage(
202202
errorDesc,
203-
&storageMp,
203+
&storageSp,
204204
d_state_p->uri(),
205205
d_state_p->key(),
206206
d_state_p->partitionId(),
@@ -223,10 +223,10 @@ int RemoteQueue::configureAsClusterMember(bsl::ostream& errorDescription,
223223
}
224224

225225
if (d_state_p->isAtMostOnce()) {
226-
storageMp->capacityMeter()->disable();
226+
storageSp->capacityMeter()->disable();
227227
}
228228

229-
if (!d_state_p->isStorageCompatible(storageMp)) {
229+
if (!d_state_p->isStorageCompatible(storageSp)) {
230230
BMQTSK_ALARMLOG_ALARM("CLUSTER_STATE")
231231
<< d_state_p->domain()->cluster()->name() << ": Partition ["
232232
<< d_state_p->partitionId()
@@ -236,7 +236,7 @@ int RemoteQueue::configureAsClusterMember(bsl::ostream& errorDescription,
236236
return 10 * rc + rc_QUEUE_CONFIGURE_FAILURE; // RETURN
237237
}
238238

239-
d_state_p->setStorage(storageMp);
239+
d_state_p->setStorage(storageSp);
240240

241241
// Create the queueEngine.
242242
d_queueEngine_mp.load(

src/groups/mqb/mqbblp/mqbblp_storagemanager.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1645,11 +1645,11 @@ void StorageManager::processReplicaDataRequest(
16451645
}
16461646

16471647
int StorageManager::makeStorage(bsl::ostream& errorDescription,
1648-
bslma::ManagedPtr<mqbi::Storage>* out,
1649-
const bmqt::Uri& uri,
1650-
const mqbu::StorageKey& queueKey,
1651-
int partitionId,
1652-
const bsls::Types::Int64 messageTtl,
1648+
bsl::shared_ptr<mqbi::Storage>* out,
1649+
const bmqt::Uri& uri,
1650+
const mqbu::StorageKey& queueKey,
1651+
int partitionId,
1652+
const bsls::Types::Int64 messageTtl,
16531653
const int maxDeliveryAttempts,
16541654
const mqbconfm::StorageDefinition& storageDef)
16551655
{

src/groups/mqb/mqbblp/mqbblp_storagemanager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ class StorageManager BSLS_KEYWORD_FINAL : public mqbi::StorageManager {
555555
BSLS_KEYWORD_OVERRIDE;
556556

557557
int makeStorage(bsl::ostream& errorDescription,
558-
bslma::ManagedPtr<mqbi::Storage>* out,
558+
bsl::shared_ptr<mqbi::Storage>* out,
559559
const bmqt::Uri& uri,
560560
const mqbu::StorageKey& queueKey,
561561
int partitionId,

src/groups/mqb/mqbc/mqbc_storagemanager.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4177,11 +4177,11 @@ void StorageManager::processReplicaDataRequest(
41774177
}
41784178

41794179
int StorageManager::makeStorage(bsl::ostream& errorDescription,
4180-
bslma::ManagedPtr<mqbi::Storage>* out,
4181-
const bmqt::Uri& uri,
4182-
const mqbu::StorageKey& queueKey,
4183-
int partitionId,
4184-
const bsls::Types::Int64 messageTtl,
4180+
bsl::shared_ptr<mqbi::Storage>* out,
4181+
const bmqt::Uri& uri,
4182+
const mqbu::StorageKey& queueKey,
4183+
int partitionId,
4184+
const bsls::Types::Int64 messageTtl,
41854185
int maxDeliveryAttempts,
41864186
const mqbconfm::StorageDefinition& storageDef)
41874187
{

src/groups/mqb/mqbc/mqbc_storagemanager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,7 @@ class StorageManager BSLS_KEYWORD_FINAL
918918
BSLS_KEYWORD_OVERRIDE;
919919

920920
int makeStorage(bsl::ostream& errorDescription,
921-
bslma::ManagedPtr<mqbi::Storage>* out,
921+
bsl::shared_ptr<mqbi::Storage>* out,
922922
const bmqt::Uri& uri,
923923
const mqbu::StorageKey& queueKey,
924924
int partitionId,

src/groups/mqb/mqbc/mqbc_storageutil.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3203,14 +3203,14 @@ void StorageUtil::setQueueDispatched(
32033203
it->second->setQueue(queue);
32043204
}
32053205

3206-
int StorageUtil::makeStorage(bsl::ostream& errorDescription,
3207-
bslma::ManagedPtr<mqbi::Storage>* out,
3208-
StorageSpMap* storageMap,
3209-
bslmt::Mutex* storagesLock,
3210-
const bmqt::Uri& uri,
3211-
const mqbu::StorageKey& queueKey,
3212-
int partitionId,
3213-
const bsls::Types::Int64 messageTtl,
3206+
int StorageUtil::makeStorage(bsl::ostream& errorDescription,
3207+
bsl::shared_ptr<mqbi::Storage>* out,
3208+
StorageSpMap* storageMap,
3209+
bslmt::Mutex* storagesLock,
3210+
const bmqt::Uri& uri,
3211+
const mqbu::StorageKey& queueKey,
3212+
int partitionId,
3213+
const bsls::Types::Int64 messageTtl,
32143214
const int maxDeliveryAttempts,
32153215
const mqbconfm::StorageDefinition& storageDef)
32163216
{
@@ -3267,9 +3267,7 @@ int StorageUtil::makeStorage(bsl::ostream& errorDescription,
32673267
return 10 * rc + rc_STORAGE_CFG_FAILURE; // RETURN
32683268
}
32693269

3270-
out->load(storageSp.get(),
3271-
0, // cookie
3272-
bslma::ManagedPtrUtil::noOpDeleter);
3270+
*out = storageSp;
32733271

32743272
static_cast<void>(queueKey);
32753273

src/groups/mqb/mqbc/mqbc_storageutil.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -724,15 +724,15 @@ struct StorageUtil {
724724
const bmqt::Uri& uri,
725725
mqbi::Queue* queue);
726726

727-
static int makeStorage(bsl::ostream& errorDescription,
728-
bslma::ManagedPtr<mqbi::Storage>* out,
729-
StorageSpMap* storageMap,
730-
bslmt::Mutex* storagesLock,
731-
const bmqt::Uri& uri,
732-
const mqbu::StorageKey& queueKey,
733-
int partitionId,
734-
const bsls::Types::Int64 messageTtl,
735-
const int maxDeliveryAttempts,
727+
static int makeStorage(bsl::ostream& errorDescription,
728+
bsl::shared_ptr<mqbi::Storage>* out,
729+
StorageSpMap* storageMap,
730+
bslmt::Mutex* storagesLock,
731+
const bmqt::Uri& uri,
732+
const mqbu::StorageKey& queueKey,
733+
int partitionId,
734+
const bsls::Types::Int64 messageTtl,
735+
const int maxDeliveryAttempts,
736736
const mqbconfm::StorageDefinition& storageDef);
737737

738738
/// THREAD: Executed by the queue dispatcher thread associated with

0 commit comments

Comments
 (0)