Skip to content

Commit 6b9b7d5

Browse files
committed
Refactor: EngineIface to use references over gsl::not_null<>
Replace gsl::not_null<> with ref to the type This patch was created following these steps: 1. Use CLion's refactor signature functionality for each method in EngineIface. 2. Add/remove derefs or refs where needed, found by compiling the source code. 3. Reformat includes and remove gsl-light include in engine.h Change-Id: Iff5327c05d10b9fc94438231e0c09eecae063d53 Reviewed-on: http://review.couchbase.org/c/kv_engine/+/155717 Reviewed-by: Jim Walker <[email protected]> Tested-by: Build Bot <[email protected]>
1 parent f0e6533 commit 6b9b7d5

36 files changed

+898
-1037
lines changed

daemon/connection.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1440,7 +1440,7 @@ void Connection::close() {
14401440
void Connection::propagateDisconnect() const {
14411441
for (auto& cookie : cookies) {
14421442
if (cookie) {
1443-
getBucket().getEngine().disconnect(cookie.get());
1443+
getBucket().getEngine().disconnect(*cookie);
14441444
}
14451445
}
14461446
}

daemon/mcbp_validators.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ Status McbpValidator::verify_header(Cookie& cookie,
372372
} else {
373373
auto vbid = request.getVBucket();
374374
auto res = connection.getBucket().getEngine().get_scope_id(
375-
&cookie, key, vbid);
375+
cookie, key, vbid);
376376
if (res.result == cb::engine_errc::success) {
377377
manifestUid = res.getManifestId();
378378
sid = res.getScopeId();

daemon/protocol/mcbp/collections_get_collection_id_executor.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ void collections_get_collection_id_executor(Cookie& cookie) {
2828
path = std::string_view{reinterpret_cast<const char*>(value.data()),
2929
value.size()};
3030
}
31-
auto rv = connection.getBucketEngine().get_collection_id(&cookie, path);
31+
auto rv = connection.getBucketEngine().get_collection_id(cookie, path);
3232
if (rv.result == cb::engine_errc::success) {
3333
auto payload = rv.getPayload();
3434
cookie.sendResponse(cb::mcbp::Status::Success,

daemon/protocol/mcbp/collections_get_manifest_executor.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
void collections_get_manifest_executor(Cookie& cookie) {
2020
auto& connection = cookie.getConnection();
2121
const auto ret = connection.getBucketEngine().get_collection_manifest(
22-
&cookie, mcbpResponseHandlerFn);
22+
cookie, mcbpResponseHandlerFn);
2323
if (ret != cb::engine_errc::success) {
2424
Expects(ret != cb::engine_errc::would_block);
2525
handle_executor_status(cookie, ret);

daemon/protocol/mcbp/collections_get_scope_id_executor.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ void collections_get_scope_id_executor(Cookie& cookie) {
2828
path = std::string_view{reinterpret_cast<const char*>(value.data()),
2929
value.size()};
3030
}
31-
auto rv = connection.getBucketEngine().get_scope_id(&cookie, path);
31+
auto rv = connection.getBucketEngine().get_scope_id(cookie, path);
3232
if (rv.result == cb::engine_errc::success) {
3333
auto payload = rv.getPayload();
3434
cookie.sendResponse(cb::mcbp::Status::Success,

daemon/protocol/mcbp/collections_set_manifest_executor.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ void collections_set_manifest_executor(Cookie& cookie) {
3030
std::string_view jsonBuffer{reinterpret_cast<const char*>(val.data()),
3131
val.size()};
3232
auto status = connection.getBucketEngine().set_collection_manifest(
33-
&cookie, jsonBuffer);
33+
cookie, jsonBuffer);
3434
handle_executor_status(cookie, status);
3535
} else {
3636
handle_executor_status(cookie, ret);

daemon/protocol/mcbp/engine_wrapper.cc

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -40,24 +40,24 @@ cb::engine_errc bucket_unknown_command(Cookie& cookie,
4040
void bucket_item_set_cas(Connection& c,
4141
gsl::not_null<ItemIface*> it,
4242
uint64_t cas) {
43-
c.getBucketEngine().item_set_cas(it, cas);
43+
c.getBucketEngine().item_set_cas(*it, cas);
4444
}
4545

4646
void bucket_item_set_datatype(Connection& c,
4747
gsl::not_null<ItemIface*> it,
4848
protocol_binary_datatype_t datatype) {
49-
c.getBucketEngine().item_set_datatype(it, datatype);
49+
c.getBucketEngine().item_set_datatype(*it, datatype);
5050
}
5151

5252
void bucket_reset_stats(Cookie& cookie) {
5353
auto& c = cookie.getConnection();
54-
c.getBucketEngine().reset_stats(&cookie);
54+
c.getBucketEngine().reset_stats(cookie);
5555
}
5656

5757
bool bucket_get_item_info(Connection& c,
5858
gsl::not_null<const ItemIface*> item_,
5959
gsl::not_null<item_info*> item_info_) {
60-
auto ret = c.getBucketEngine().get_item_info(item_, item_info_);
60+
auto ret = c.getBucketEngine().get_item_info(*item_, *item_info_);
6161

6262
LOG_TRACE("bucket_get_item_info() item:{} -> {}", *item_, ret);
6363

@@ -74,7 +74,7 @@ cb::EngineErrorMetadataPair bucket_get_meta(Cookie& cookie,
7474
const DocKey& key,
7575
Vbid vbucket) {
7676
auto& c = cookie.getConnection();
77-
auto ret = c.getBucketEngine().get_meta(&cookie, key, vbucket);
77+
auto ret = c.getBucketEngine().get_meta(cookie, key, vbucket);
7878
if (ret.first == cb::engine_errc::disconnect) {
7979
LOG_WARNING("{}: {} bucket_get_meta return cb::engine_errc::disconnect",
8080
c.getId(),
@@ -94,8 +94,8 @@ cb::engine_errc bucket_store(
9494
DocumentState document_state,
9595
bool preserveTtl) {
9696
auto& c = cookie.getConnection();
97-
auto ret = c.getBucketEngine().store(&cookie,
98-
item_,
97+
auto ret = c.getBucketEngine().store(cookie,
98+
*item_,
9999
cas,
100100
operation,
101101
durability,
@@ -137,8 +137,8 @@ cb::EngineErrorCasPair bucket_store_if(
137137
DocumentState document_state,
138138
bool preserveTtl) {
139139
auto& c = cookie.getConnection();
140-
auto ret = c.getBucketEngine().store_if(&cookie,
141-
item_,
140+
auto ret = c.getBucketEngine().store_if(cookie,
141+
*item_,
142142
cas,
143143
operation,
144144
predicate,
@@ -169,7 +169,7 @@ cb::engine_errc bucket_remove(
169169
mutation_descr_t& mut_info) {
170170
auto& c = cookie.getConnection();
171171
auto ret = c.getBucketEngine().remove(
172-
&cookie, key, cas, vbucket, durability, mut_info);
172+
cookie, key, cas, vbucket, durability, mut_info);
173173
if (ret == cb::engine_errc::success) {
174174
cb::audit::document::add(cookie,
175175
cb::audit::document::Operation::Delete);
@@ -188,7 +188,7 @@ cb::EngineErrorItemPair bucket_get(Cookie& cookie,
188188
DocStateFilter documentStateFilter) {
189189
auto& c = cookie.getConnection();
190190
auto ret =
191-
c.getBucketEngine().get(&cookie, key, vbucket, documentStateFilter);
191+
c.getBucketEngine().get(cookie, key, vbucket, documentStateFilter);
192192
if (ret.first == cb::engine_errc::disconnect) {
193193
LOG_WARNING("{}: {} bucket_get return cb::engine_errc::disconnect",
194194
c.getId(),
@@ -220,7 +220,7 @@ cb::EngineErrorItemPair bucket_get_if(
220220
Vbid vbucket,
221221
std::function<bool(const item_info&)> filter) {
222222
auto& c = cookie.getConnection();
223-
auto ret = c.getBucketEngine().get_if(&cookie, key, vbucket, filter);
223+
auto ret = c.getBucketEngine().get_if(cookie, key, vbucket, filter);
224224

225225
if (ret.first == cb::engine_errc::disconnect) {
226226
LOG_WARNING("{}: {} bucket_get_if return cb::engine_errc::disconnect",
@@ -239,7 +239,7 @@ cb::EngineErrorItemPair bucket_get_and_touch(
239239
std::optional<cb::durability::Requirements> durability) {
240240
auto& c = cookie.getConnection();
241241
auto ret = c.getBucketEngine().get_and_touch(
242-
&cookie, key, vbucket, expiration, durability);
242+
cookie, key, vbucket, expiration, durability);
243243

244244
if (ret.first == cb::engine_errc::disconnect) {
245245
LOG_WARNING(
@@ -258,7 +258,7 @@ cb::EngineErrorItemPair bucket_get_locked(Cookie& cookie,
258258
uint32_t lock_timeout) {
259259
auto& c = cookie.getConnection();
260260
auto ret =
261-
c.getBucketEngine().get_locked(&cookie, key, vbucket, lock_timeout);
261+
c.getBucketEngine().get_locked(cookie, key, vbucket, lock_timeout);
262262

263263
if (ret.first == cb::engine_errc::success) {
264264
cb::audit::document::add(cookie, cb::audit::document::Operation::Lock);
@@ -282,7 +282,7 @@ cb::engine_errc bucket_unlock(Cookie& cookie,
282282
Vbid vbucket,
283283
uint64_t cas) {
284284
auto& c = cookie.getConnection();
285-
auto ret = c.getBucketEngine().unlock(&cookie, key, vbucket, cas);
285+
auto ret = c.getBucketEngine().unlock(cookie, key, vbucket, cas);
286286
if (ret == cb::engine_errc::disconnect) {
287287
LOG_WARNING("{}: {} bucket_unlock return cb::engine_errc::disconnect",
288288
c.getId(),
@@ -330,7 +330,7 @@ std::pair<cb::unique_item_ptr, item_info> bucket_allocate_ex(
330330
datatype,
331331
vbucket);
332332

333-
return c.getBucketEngine().allocateItem(&cookie,
333+
return c.getBucketEngine().allocateItem(cookie,
334334
key,
335335
nbytes,
336336
priv_nbytes,
@@ -353,7 +353,7 @@ std::pair<cb::unique_item_ptr, item_info> bucket_allocate_ex(
353353

354354
cb::engine_errc bucket_flush(Cookie& cookie) {
355355
auto& c = cookie.getConnection();
356-
auto ret = c.getBucketEngine().flush(&cookie);
356+
auto ret = c.getBucketEngine().flush(cookie);
357357
if (ret == cb::engine_errc::disconnect) {
358358
LOG_WARNING("{}: {} bucket_flush return cb::engine_errc::disconnect",
359359
c.getId(),
@@ -369,7 +369,7 @@ cb::engine_errc bucket_get_stats(Cookie& cookie,
369369
const AddStatFn& add_stat) {
370370
auto& c = cookie.getConnection();
371371
auto ret = c.getBucketEngine().get_stats(
372-
&cookie,
372+
cookie,
373373
key,
374374
{reinterpret_cast<const char*>(value.data()), value.size()},
375375
add_stat);
@@ -870,7 +870,7 @@ cb::engine_errc bucket_set_parameter(Cookie& cookie,
870870
Vbid vbucket) {
871871
auto& connection = cookie.getConnection();
872872
auto ret = connection.getBucket().getEngine().setParameter(
873-
&cookie, category, key, value, vbucket);
873+
cookie, category, key, value, vbucket);
874874
if (ret == cb::engine_errc::disconnect) {
875875
LOG_WARNING(
876876
"{}: {} setParameter() returned cb::engine_errc::disconnect",
@@ -891,7 +891,7 @@ cb::engine_errc bucket_compact_database(Cookie& cookie) {
891891
extras.data());
892892

893893
auto ret = connection.getBucket().getEngine().compactDatabase(
894-
&cookie,
894+
cookie,
895895
req.getVBucket(),
896896
payload->getPurgeBeforeTs(),
897897
payload->getPurgeBeforeSeq(),
@@ -909,7 +909,7 @@ cb::engine_errc bucket_compact_database(Cookie& cookie) {
909909
std::pair<cb::engine_errc, vbucket_state_t> bucket_get_vbucket(Cookie& cookie) {
910910
auto& connection = cookie.getConnection();
911911
const auto& req = cookie.getRequest();
912-
auto ret = connection.getBucket().getEngine().getVBucket(&cookie,
912+
auto ret = connection.getBucket().getEngine().getVBucket(cookie,
913913
req.getVBucket());
914914
if (ret.first == cb::engine_errc::disconnect) {
915915
LOG_WARNING("{}: {} getVBucket() returned cb::engine_errc::disconnect",
@@ -927,7 +927,7 @@ cb::engine_errc bucket_set_vbucket(Cookie& cookie,
927927
const auto& req = cookie.getRequest();
928928
auto& connection = cookie.getConnection();
929929
auto ret = connection.getBucket().getEngine().setVBucket(
930-
&cookie,
930+
cookie,
931931
req.getVBucket(),
932932
req.getCas(),
933933
state,
@@ -945,7 +945,7 @@ cb::engine_errc bucket_set_vbucket(Cookie& cookie,
945945
cb::engine_errc bucket_delete_vbucket(Cookie& cookie, Vbid vbid, bool sync) {
946946
auto& connection = cookie.getConnection();
947947
auto ret = connection.getBucket().getEngine().deleteVBucket(
948-
&cookie, vbid, sync);
948+
cookie, vbid, sync);
949949
if (ret == cb::engine_errc::disconnect) {
950950
LOG_WARNING(
951951
"{}: {} deleteVBucket() returned cb::engine_errc::disconnect",

engines/crash_engine/crash_engine.cc

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -104,19 +104,18 @@ class CrashEngine : public EngineIface {
104104
delete this;
105105
}
106106

107-
std::pair<cb::unique_item_ptr, item_info> allocateItem(
108-
gsl::not_null<const CookieIface*>,
109-
const DocKey&,
110-
size_t,
111-
size_t,
112-
int,
113-
rel_time_t,
114-
uint8_t,
115-
Vbid) override {
107+
std::pair<cb::unique_item_ptr, item_info> allocateItem(const CookieIface&,
108+
const DocKey&,
109+
size_t,
110+
size_t,
111+
int,
112+
rel_time_t,
113+
uint8_t,
114+
Vbid) override {
116115
throw cb::engine_error{cb::engine_errc::failed, "crash_engine"};
117116
}
118117

119-
cb::engine_errc remove(gsl::not_null<const CookieIface*>,
118+
cb::engine_errc remove(const CookieIface&,
120119
const DocKey&,
121120
uint64_t&,
122121
Vbid,
@@ -125,55 +124,55 @@ class CrashEngine : public EngineIface {
125124
return cb::engine_errc::failed;
126125
}
127126

128-
void release(gsl::not_null<ItemIface*> item) override {
127+
void release(ItemIface& item) override {
129128
}
130129

131-
cb::EngineErrorItemPair get(gsl::not_null<const CookieIface*>,
130+
cb::EngineErrorItemPair get(const CookieIface&,
132131
const DocKey&,
133132
Vbid,
134133
DocStateFilter) override {
135134
return cb::makeEngineErrorItemPair(cb::engine_errc::failed);
136135
}
137136

138137
cb::EngineErrorItemPair get_if(
139-
gsl::not_null<const CookieIface*>,
138+
const CookieIface&,
140139
const DocKey&,
141140
Vbid,
142141
std::function<bool(const item_info&)>) override {
143142
return cb::makeEngineErrorItemPair(cb::engine_errc::failed);
144143
}
145144

146-
cb::EngineErrorMetadataPair get_meta(gsl::not_null<const CookieIface*>,
145+
cb::EngineErrorMetadataPair get_meta(const CookieIface&,
147146
const DocKey&,
148147
Vbid) override {
149148
return {cb::engine_errc::failed, {}};
150149
}
151150

152-
cb::EngineErrorItemPair get_locked(gsl::not_null<const CookieIface*>,
151+
cb::EngineErrorItemPair get_locked(const CookieIface&,
153152
const DocKey&,
154153
Vbid,
155154
uint32_t) override {
156155
return cb::makeEngineErrorItemPair(cb::engine_errc::failed);
157156
}
158157

159-
cb::engine_errc unlock(gsl::not_null<const CookieIface*>,
158+
cb::engine_errc unlock(const CookieIface&,
160159
const DocKey&,
161160
Vbid,
162161
uint64_t) override {
163162
return cb::engine_errc::failed;
164163
}
165164

166165
cb::EngineErrorItemPair get_and_touch(
167-
gsl::not_null<const CookieIface*>,
166+
const CookieIface&,
168167
const DocKey&,
169168
Vbid,
170169
uint32_t,
171170
const std::optional<cb::durability::Requirements>&) override {
172171
return cb::makeEngineErrorItemPair(cb::engine_errc::failed);
173172
}
174173

175-
cb::engine_errc store(gsl::not_null<const CookieIface*>,
176-
gsl::not_null<ItemIface*>,
174+
cb::engine_errc store(const CookieIface&,
175+
ItemIface&,
177176
uint64_t&,
178177
StoreSemantics,
179178
const std::optional<cb::durability::Requirements>&,
@@ -182,25 +181,23 @@ class CrashEngine : public EngineIface {
182181
return cb::engine_errc::failed;
183182
}
184183

185-
cb::engine_errc get_stats(gsl::not_null<const CookieIface*>,
184+
cb::engine_errc get_stats(const CookieIface&,
186185
std::string_view,
187186
std::string_view,
188187
const AddStatFn&) override {
189188
return cb::engine_errc::failed;
190189
}
191190

192-
void reset_stats(gsl::not_null<const CookieIface*>) override {
191+
void reset_stats(const CookieIface&) override {
193192
}
194193

195-
void item_set_cas(gsl::not_null<ItemIface*>, uint64_t) override {
194+
void item_set_cas(ItemIface&, uint64_t) override {
196195
}
197196

198-
void item_set_datatype(gsl::not_null<ItemIface*>,
199-
protocol_binary_datatype_t) override {
197+
void item_set_datatype(ItemIface&, protocol_binary_datatype_t) override {
200198
}
201199

202-
bool get_item_info(gsl::not_null<const ItemIface*>,
203-
gsl::not_null<item_info*>) override {
200+
bool get_item_info(const ItemIface&, item_info&) override {
204201
return false;
205202
}
206203

0 commit comments

Comments
 (0)