-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Rewrite leveldb_key to use a Reader/Writer class #960
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
Conversation
Not sure this is a great idea, but it goes some ways toward alleviating some of the concerns you had in the prior PR and is relatively cheap to do. |
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.
Thanks for doing this.
In my view, this is cleaner, so unless you have concerns that the more rigid code structure can make some future refactoring harder, I'm for merging it.
The biggest improvement I see is no longer having to pass leveldb::Slice
all over the place; I think it's nice having it encapsulated in a class. Not having to create uninitialized variables and pass them by pointer also reads much better. "Read" and "write" functions are now better grouped. One potential refactoring is using optional
or StatusOr
for Read
functions, but I don't see a problem integrating that into Reader
- ok
would go away, but Reader
would still have a reason for existence, managing the string slice.
if (OrderedCode::ReadString(&tmp, result)) { | ||
*src = MakeSlice(tmp); | ||
return true; | ||
bool ok() { |
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 function could be const
.
void WriteComponentLabel(std::string *dest, ComponentLabel label) { | ||
OrderedCode::WriteSignedNumIncreasing(dest, label); | ||
} | ||
bool empty() { |
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 function could be const
.
*label = static_cast<ComponentLabel>(raw_result); | ||
return true; | ||
} | ||
leveldb::Slice source() { |
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 function could be const
.
} | ||
class Writer { | ||
public: | ||
std::string result() { |
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 function could be const
.
} | ||
|
||
/** OrderedCode::ReadSignedNumIncreasing adapted to leveldb::Slice. */ | ||
int64_t ReadSignedNumIncreasing() { |
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.
Do you think some of these lower-level functions could now be made private
? I think it's also a small improvement that using a class can bring: previously, there also was a separation between these and domain-level functions (e.g., ReadBatchId
), but it was only in the comments. Candidates for private
are:
ReadSignedNumIncreasing
;ReadString
;ReadInt32
;- (maybe)
ReadLabeledInt32
; - (maybe)
WriteLabeledInt32
.
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.
I think nearly all the lowest-level ones could be made private if Describe
were a member on the Reader. I'll attempt this next.
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.
Sorry -- I should have made it clearer that this was essentially a proof-of-concept rather than any kind of done state. Comments need to be updated, constness applied, etc. I'll reassign to you once I've gotten this cleaned up.
} | ||
|
||
/** OrderedCode::ReadSignedNumIncreasing adapted to leveldb::Slice. */ | ||
int64_t ReadSignedNumIncreasing() { |
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.
I think nearly all the lowest-level ones could be made private if Describe
were a member on the Reader. I'll attempt this next.
3b40fa7
to
e5cffe2
Compare
b95b468
to
467079b
Compare
So there's good news and bad news. 👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there. 😕 The bad news is that it appears that one or more commits were authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request. Note to project maintainer: This is a terminal state, meaning the |
467079b
to
8fd20be
Compare
Comments updated, const applied, low-level details made private, and a few more bits of refactoring to make this all work. PTAL. |
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.
LGTM, just a couple of typos.
* Reads component labels and strings from the key until it finds a component | ||
* label other that ComponentLabel::PathSegment (or the key is exhausted). | ||
* All matched path segments are assembled into a ResourcePath and wrapped in | ||
* an DocumentKey. |
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: I think it should be "a DocumentKey".
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.
Right. Sorry.
* Otherwise returns whether or not the component label is equal to the | ||
* `expected_label` and advances the Rader to the next unread byte. | ||
*/ | ||
ABSL_MUST_USE_RESULT |
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.
This looks interesting.
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.
I missed one in my early implementation and this caused me to go find this.
* If the read is unsuccessful, returns false, and fails the Reader. | ||
* | ||
* Otherwise returns whether or not the component label is equal to the | ||
* `expected_label` and advances the Rader to the next unread byte. |
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: s/Rader/Reader.
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.
Thank you for the careful review!
} | ||
|
||
/** | ||
* For each segment in the given resource path writes an |
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: I think it should be "a ComponentLabel::PathSegment", not "an" (might be wrong).
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.
You're right. This comes from the fact that the previous enumeration value here was "FSTComponentLabelPathSegment". In that case "an" worked because we spell the prefix out. Now that the prefix is gone it should be "a".
No description provided.