PragmaTwice commented on code in PR #2597:
URL: https://github.com/apache/kvrocks/pull/2597#discussion_r1799423187
##########
src/storage/storage.h:
##########
@@ -430,22 +419,35 @@ struct Context {
Context &operator=(Context &&ctx) noexcept {
if (this != &ctx) {
storage = ctx.storage;
- snapshot = ctx.snapshot;
+ snapshot_ = ctx.snapshot_;
batch = std::move(ctx.batch);
ctx.storage = nullptr;
- ctx.snapshot = nullptr;
+ ctx.snapshot_ = nullptr;
}
return *this;
}
- Context(Context &&ctx) noexcept : storage(ctx.storage),
snapshot(ctx.snapshot), batch(std::move(ctx.batch)) {
+ Context(Context &&ctx) noexcept : storage(ctx.storage),
batch(std::move(ctx.batch)), snapshot_(ctx.snapshot_) {
ctx.storage = nullptr;
- ctx.snapshot = nullptr;
+ ctx.snapshot_ = nullptr;
+ }
+
+ const rocksdb::Snapshot *GetSnapshot() {
+ if (snapshot_ == nullptr) {
+ snapshot_ = storage->GetDB()->GetSnapshot(); // NOLINT
+ }
+ return snapshot_;
}
Review Comment:
I think we should state here in comments that this method is NOT thread-safe.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]