Skip to content

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

Merged
merged 2 commits into from
Mar 24, 2018

Conversation

wilhuff
Copy link
Contributor

@wilhuff wilhuff commented Mar 21, 2018

No description provided.

@wilhuff
Copy link
Contributor Author

wilhuff commented Mar 21, 2018

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.

Copy link
Contributor

@var-const var-const left a 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() {
Copy link
Contributor

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() {
Copy link
Contributor

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() {
Copy link
Contributor

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() {
Copy link
Contributor

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() {
Copy link
Contributor

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.

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 nearly all the lowest-level ones could be made private if Describe were a member on the Reader. I'll attempt this next.

Copy link
Contributor Author

@wilhuff wilhuff left a 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() {
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 nearly all the lowest-level ones could be made private if Describe were a member on the Reader. I'll attempt this next.

@wilhuff wilhuff assigned wilhuff and unassigned var-const Mar 21, 2018
@wilhuff wilhuff force-pushed the wilhuff/leveldb-key branch from 3b40fa7 to e5cffe2 Compare March 22, 2018 01:00
@wilhuff wilhuff force-pushed the wilhuff/leveldb-key-experiment branch 2 times, most recently from b95b468 to 467079b Compare March 22, 2018 01:44
@googlebot
Copy link

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 cla/google commit status will not change from this state. It's up to you to confirm consent of the commit author(s) and merge this pull request when appropriate.

@wilhuff wilhuff changed the base branch from wilhuff/leveldb-key to master March 22, 2018 01:45
@wilhuff wilhuff added cla: yes and removed cla: no labels Mar 22, 2018
@wilhuff wilhuff force-pushed the wilhuff/leveldb-key-experiment branch from 467079b to 8fd20be Compare March 22, 2018 01:47
@wilhuff
Copy link
Contributor Author

wilhuff commented Mar 22, 2018

Comments updated, const applied, low-level details made private, and a few more bits of refactoring to make this all work. PTAL.

@wilhuff wilhuff assigned var-const and unassigned wilhuff Mar 22, 2018
Copy link
Contributor

@var-const var-const left a 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.
Copy link
Contributor

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".

Copy link
Contributor Author

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
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks interesting.

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 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.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: s/Rader/Reader.

Copy link
Contributor Author

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
Copy link
Contributor

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).

Copy link
Contributor Author

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".

@wilhuff wilhuff merged commit 4c3fb51 into master Mar 24, 2018
@wilhuff wilhuff deleted the wilhuff/leveldb-key-experiment branch March 24, 2018 17:23
minafarid pushed a commit to minafarid/firebase-ios-sdk that referenced this pull request Jun 6, 2018
@firebase firebase locked and limited conversation to collaborators Nov 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants