Skip to content

Implement sequence number migration #1374

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 4 commits into from
Nov 10, 2018
Merged

Conversation

gsoltis
Copy link

@gsoltis gsoltis commented Nov 9, 2018

Port of firebase/firebase-android-sdk#64

Ensures that every document in the cache has a corresponding sentinel row with a sequence number. Precursor to enabling LRU in production.

Copy link
Contributor

@schmidt-sebastian schmidt-sebastian left a comment

Choose a reason for hiding this comment

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

Basically LGTM. I think you are using the wrong Promise in one case though.

);

return getHighestListenSequenceNumber(txn).next(currentSequenceNumber => {
const writeSentinelKey = (
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 would be easier to read if a) this was declared one level higher (as a direct child of ensureSequenceNumbers) and b) if you used a normal JS function (function writeSentinelKey() {}).

Optional.

Copy link
Author

Choose a reason for hiding this comment

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

Leaving as-is.

It can't go in a higher scope as it closes over the result of getHighestListenSequenceNumber(). And typescript disallows nested function declarations, so it needs to be a lambda. I'm guessing this is because function and lambdas have different bindings for this. Nested functions make it easy to make a mistake when calling methods off of this.

.iterate((key, doc) => {
const path = new ResourcePath(key);
const docSentinelKey = sentinelKey(path);
documentTargetStore.get(docSentinelKey).next(maybeSentinel => {
Copy link
Contributor

Choose a reason for hiding this comment

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

You need to push this promise (the one returned from documentTargetStore.get) rather then the result of writeSentinelKey. With the current code, you may miss some writes if the reads don't come back fast enough.

Copy link
Author

Choose a reason for hiding this comment

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

Good catch. I restructured it a little to remove the inner call to push() and instead push every read. Reads which require an additional write return a persistence promise in the next() call.

@gsoltis gsoltis assigned schmidt-sebastian and unassigned gsoltis Nov 10, 2018
@gsoltis gsoltis merged commit fcf1f64 into master Nov 10, 2018
@gsoltis gsoltis deleted the gsoltis/ensure_sequence_numbers branch November 10, 2018 03:24
@firebase firebase locked and limited conversation to collaborators Oct 15, 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