Skip to content

Commit

Permalink
add check in range interface
Browse files Browse the repository at this point in the history
Signed-off-by: tabokie <xy.tao@outlook.com>
  • Loading branch information
tabokie committed Aug 16, 2023
1 parent 5ae7a8d commit e7d2fc3
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions db/db_impl/db_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,7 @@ class DBImpl : public DB {

Status MergeDisjointInstances(const MergeInstanceOptions& merge_options,
const std::vector<DB*>& instances) override;
Status CheckInRange(const Slice* begin, const Slice* end) override;

static IOStatus CreateAndNewDirectory(
FileSystem* fs, const std::string& dirname,
Expand Down
26 changes: 26 additions & 0 deletions db/db_impl/db_impl_merge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,32 @@ Status DBImpl::ValidateForMerge(const MergeInstanceOptions& mopts,
return Status::OK();
}

Status DBImpl::CheckInRange(const Slice* begin, const Slice* end) {
Status s;
if (begin == nullptr && end == nullptr) {
return s;
}
for (auto cfd : *versions_->GetColumnFamilySet()) {
assert(cfd != nullptr);
auto* comparator = cfd->user_comparator();
PinnableSlice smallest, largest;
bool found = false;
s = cfd->GetUserKeyRange(&smallest, &largest, &found);
if (!s.ok()) {
return s;
}
if (!found) {
continue;
}
if (begin != nullptr && comparator->Compare(smallest, *begin) < 0) {
return Status::InvalidArgument("Has data smaller than left boundary");
} else if (end != nullptr && comparator->Compare(largest, *end) >= 0) {
return Status::InvalidArgument("Has data larger than right boundary");
}
}
return s;
}

Status DBImpl::MergeDisjointInstances(const MergeInstanceOptions& merge_options,
const std::vector<DB*>& instances) {
Status s;
Expand Down
6 changes: 6 additions & 0 deletions include/rocksdb/db.h
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,12 @@ class DB {
return Status::NotSupported("`MergeDisjointInstances` not implemented");
}

// Check all data written before this call is in the range [begin, end).
// Return InvalidArgument if not.
virtual Status CheckInRange(const Slice* /*begin*/, const Slice* /*end*/) {
return Status::NotSupported("`AssertInRange` not implemented");
}

virtual Status Resume() { return Status::NotSupported(); }

// Close the DB by releasing resources, closing files etc. This should be
Expand Down

0 comments on commit e7d2fc3

Please sign in to comment.