Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cherry-pick compaction enhancements and add range check function #346

Merged
merged 3 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
Comment on lines +62 to +64
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does nullptr mean? Should we return Status::InvalidArgument?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It means infinity. It's a common usage of nullptr within RocksDB codebase.

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