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

Compaction filter support for (new) BlobDB #7974

Closed

Conversation

riversand963
Copy link
Contributor

Allow applications to implement a custom compaction filter and pass it to BlobDB.

The compaction filter's custom logic can operate on blobs.
To do so, application needs to subclass CompactionFilter abstract class and implement FilterV2() method.
Optionally, a method called ShouldFilterBlobByKey() can be implemented if application's custom logic rely solely
on the key to make a decision without reading the blob, thus saving extra IO. Examples can be found in
db/blob/db_blob_compaction_test.cc.

Test plan:
make check

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@riversand963 has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Copy link
Contributor

@ltamasi ltamasi left a comment

Choose a reason for hiding this comment

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

Thanks a lot for the PR @riversand963 ! Could you also update db_bench and db_stress / db_crashtest.py so they allow using compaction filters with the new BlobDB?

HISTORY.md Outdated Show resolved Hide resolved
include/rocksdb/compaction_filter.h Outdated Show resolved Hide resolved
include/rocksdb/compaction_filter.h Outdated Show resolved Hide resolved
db/column_family.cc Outdated Show resolved Hide resolved
db/compaction/compaction_iterator.cc Outdated Show resolved Hide resolved
db/compaction/compaction_iterator.cc Outdated Show resolved Hide resolved
}
if (CompactionFilter::Decision::kUndetermined == filter) {
filter = CompactionFilter::Decision::kKeep;
} else if (CompactionFilter::Decision::kChangeBlobIndex == filter &&
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

The same holds for kIOError as well (i.e. only the stacked BlobDB's internal filter could potentially return it).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that's added already.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I might be missing something; where is it checked? I can see an assertion further down but not a check like this...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh I see you are referring to returning an error. Just added.

Copy link
Contributor

Choose a reason for hiding this comment

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

Again, maybe I'm misreading the code but now I think we have two checks for CompactionFilter::Decision::kChangeBlobIndex == filter && !compaction_filter_->IsStackedBlobDbInternalCompactionFilter() ? If so, we could remove this one (line 282-283)

db/compaction/compaction_iterator.cc Outdated Show resolved Hide resolved
db/blob/db_blob_compaction_test.cc Outdated Show resolved Hide resolved
db/blob/db_blob_compaction_test.cc Outdated Show resolved Hide resolved
@riversand963
Copy link
Contributor Author

Thanks a lot for the PR @riversand963 ! Could you also update db_bench and db_stress / db_crashtest.py so they allow using compaction filters with the new BlobDB?

Thanks @ltamasi for the review.

Can this be in a separate PR?

@ltamasi
Copy link
Contributor

ltamasi commented Feb 22, 2021

Thanks a lot for the PR @riversand963 ! Could you also update db_bench and db_stress / db_crashtest.py so they allow using compaction filters with the new BlobDB?

Thanks @ltamasi for the review.

Can this be in a separate PR?

Sure, absolutely! Thanks!

@facebook-github-bot
Copy link
Contributor

@riversand963 has updated the pull request. You must reimport the pull request before landing.

@facebook-github-bot
Copy link
Contributor

@riversand963 has updated the pull request. You must reimport the pull request before landing.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@riversand963 has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@riversand963
Copy link
Contributor Author

Thanks @ltamasi for the detailed review!

@facebook-github-bot
Copy link
Contributor

@riversand963 has updated the pull request. You must reimport the pull request before landing.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@riversand963 has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@riversand963 has updated the pull request. You must reimport the pull request before landing.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@riversand963 has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@riversand963 has updated the pull request. You must reimport the pull request before landing.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@riversand963 has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Copy link
Contributor

@ltamasi ltamasi left a comment

Choose a reason for hiding this comment

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

Thanks once again for the change @riversand963 !


namespace ROCKSDB_NAMESPACE {

class DBBlobCompactionTest : public DBTestBase {
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the really comprehensive unit tests! This is awesome :)

Comment on lines 48 to 55
class DummyStackedBlobDbCompactionFilter : public CompactionFilter {
public:
explicit DummyStackedBlobDbCompactionFilter() = default;
const char* Name() const override {
return "rocksdb.compaction.filter.dummy.stacked.blobdb";
}
bool IsStackedBlobDbInternalCompactionFilter() const override { return true; }
};
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is no longer in use

}
if (CompactionFilter::Decision::kUndetermined == filter) {
filter = CompactionFilter::Decision::kKeep;
} else if (CompactionFilter::Decision::kChangeBlobIndex == filter &&
Copy link
Contributor

Choose a reason for hiding this comment

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

Again, maybe I'm misreading the code but now I think we have two checks for CompactionFilter::Decision::kChangeBlobIndex == filter && !compaction_filter_->IsStackedBlobDbInternalCompactionFilter() ? If so, we could remove this one (line 282-283)

@facebook-github-bot
Copy link
Contributor

@riversand963 has updated the pull request. You must reimport the pull request before landing.

@riversand963
Copy link
Contributor Author

Thanks @ltamasi for the review!

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@riversand963 has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@riversand963 merged this pull request in cef4a6c.

@riversand963 riversand963 deleted the blob-compaction-filter branch February 26, 2021 01:01
codingrhythm pushed a commit to SafetyCulture/rocksdb that referenced this pull request Mar 5, 2021
Summary:
Allow applications to implement a custom compaction filter and pass it to BlobDB.

The compaction filter's custom logic can operate on blobs.
To do so, application needs to subclass `CompactionFilter` abstract class and implement `FilterV2()` method.
Optionally, a method called `ShouldFilterBlobByKey()` can be implemented if application's custom logic rely solely
on the key to make a decision without reading the blob, thus saving extra IO. Examples can be found in
db/blob/db_blob_compaction_test.cc.

Pull Request resolved: facebook#7974

Test Plan: make check

Reviewed By: ltamasi

Differential Revision: D26509280

Pulled By: riversand963

fbshipit-source-id: 59f9ae5614c4359de32f4f2b16684193cc537b39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants