-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
Make InternalKeyComparator not configurable #10342
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,22 @@ namespace ROCKSDB_NAMESPACE { | |
|
||
class Slice; | ||
|
||
// The general interface for comparing two Slices are defined for both of | ||
// Comparator and some internal data structures. | ||
class CompareInterface { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There should be a comment for why this exists, such as "used internally" |
||
public: | ||
virtual ~CompareInterface() {} | ||
|
||
// Three-way comparison. Returns value: | ||
// < 0 iff "a" < "b", | ||
// == 0 iff "a" == "b", | ||
// > 0 iff "a" > "b" | ||
// Note that Compare(a, b) also compares timestamp if timestamp size is | ||
// non-zero. For the same user key with different timestamps, larger (newer) | ||
// timestamp comes first. | ||
virtual int Compare(const Slice& a, const Slice& b) const = 0; | ||
}; | ||
|
||
// A Comparator object provides a total order across slices that are | ||
// used as keys in an sstable or a database. A Comparator implementation | ||
// must be thread-safe since rocksdb may invoke its methods concurrently | ||
|
@@ -25,7 +41,7 @@ class Slice; | |
// Exceptions MUST NOT propagate out of overridden functions into RocksDB, | ||
// because RocksDB is not exception-safe. This could cause undefined behavior | ||
// including data loss, unreported corruption, deadlocks, and more. | ||
class Comparator : public Customizable { | ||
class Comparator : public Customizable, public CompareInterface { | ||
public: | ||
Comparator() : timestamp_size_(0) {} | ||
|
||
|
@@ -47,24 +63,6 @@ class Comparator : public Customizable { | |
const Comparator** comp); | ||
static const char* Type() { return "Comparator"; } | ||
|
||
// Three-way comparison. Returns value: | ||
// < 0 iff "a" < "b", | ||
// == 0 iff "a" == "b", | ||
// > 0 iff "a" > "b" | ||
// Note that Compare(a, b) also compares timestamp if timestamp size is | ||
// non-zero. For the same user key with different timestamps, larger (newer) | ||
// timestamp comes first. | ||
virtual int Compare(const Slice& a, const Slice& b) const = 0; | ||
|
||
// Compares two slices for equality. The following invariant should always | ||
// hold (and is the default implementation): | ||
// Equal(a, b) iff Compare(a, b) == 0 | ||
// Overwrite only if equality comparisons can be done more efficiently than | ||
// three-way comparisons. | ||
virtual bool Equal(const Slice& a, const Slice& b) const { | ||
return Compare(a, b) == 0; | ||
} | ||
|
||
// The name of the comparator. Used to check for comparator | ||
// mismatches (i.e., a DB created with one comparator is | ||
// accessed using a different comparator. | ||
|
@@ -77,6 +75,15 @@ class Comparator : public Customizable { | |
// by any clients of this package. | ||
const char* Name() const override = 0; | ||
|
||
// Compares two slices for equality. The following invariant should always | ||
// hold (and is the default implementation): | ||
// Equal(a, b) iff Compare(a, b) == 0 | ||
// Overwrite only if equality comparisons can be done more efficiently than | ||
// three-way comparisons. | ||
virtual bool Equal(const Slice& a, const Slice& b) const { | ||
return Compare(a, b) == 0; | ||
} | ||
|
||
// Advanced functions: these are used to reduce the space requirements | ||
// for internal data structures like index blocks. | ||
|
||
|
@@ -91,10 +98,6 @@ class Comparator : public Customizable { | |
// i.e., an implementation of this method that does nothing is correct. | ||
virtual void FindShortSuccessor(std::string* key) const = 0; | ||
|
||
// if it is a wrapped comparator, may return the root one. | ||
// return itself it is not wrapped. | ||
virtual const Comparator* GetRootComparator() const { return this; } | ||
|
||
// given two keys, determine if t is the successor of s | ||
// BUG: only return true if no other keys starting with `t` are ordered | ||
// before `t`. Otherwise, the auto_prefix_mode can omit entries within | ||
|
@@ -111,6 +114,10 @@ class Comparator : public Customizable { | |
// with the customized comparator. | ||
virtual bool CanKeysWithDifferentByteContentsBeEqual() const { return true; } | ||
|
||
// if it is a wrapped comparator, may return the root one. | ||
// return itself it is not wrapped. | ||
virtual const Comparator* GetRootComparator() const { return this; } | ||
|
||
inline size_t timestamp_size() const { return timestamp_size_; } | ||
|
||
int CompareWithoutTimestamp(const Slice& a, const Slice& b) const { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: This should probably include compaator.h as well.