Skip to content

Stop persisting last acknowledged batch ID #2243

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 11 commits into from
Jan 11, 2019

Conversation

var-const
Copy link
Contributor

After #2029, acknowledged batches are always immediately removed, so persisting the last acknowledged batch ID is no longer necessary.

FSTMutationBatch *batch1 = [self addMutationBatch];
FSTMutationBatch *batch2 = [self addMutationBatch];
FSTMutationBatch *batch3 = [self addMutationBatch];
XCTAssertGreaterThan(batch1.batchID, kFSTBatchIDUnknown);
XCTAssertGreaterThan(batch2.batchID, batch1.batchID);
XCTAssertGreaterThan(batch3.batchID, batch2.batchID);

XCTAssertEqual([self.mutationQueue highestAcknowledgedBatchID], kFSTBatchIDUnknown);
XCTAssertEqual([self batchCount], 3);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Checking batchCount is the only replacement for the previous check that I could think of.

@@ -186,28 +183,6 @@ - (void)testNextMutationBatchAfterBatchID {
});
}

- (void)testNextMutationBatchAfterBatchIDSkipsAcknowledgedBatches {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test appears to be no longer relevant.

Copy link
Contributor

Choose a reason for hiding this comment

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

Right. The mutation queue now contains only unacknowledged writes now.

// the first unacknowledged batch after batchID will have a batchID larger than both of these
// values.
BatchId nextBatchID = MAX(batchID, self.metadata.lastAcknowledgedBatchId) + 1;
BatchId nextBatchID = batchID + 1;
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 presume this is fine?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes.

Copy link
Contributor

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

LGTM for the parts that are here.

What do you think of adding a migration that forces the stored value back to the unknown batch ID?

Copy link
Contributor Author

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

Took a stab at doing a migration, please take a look. Given that the effects of the migration are invisible after the changes made in this PR, I'm not sure it's worthwhile, though.

- (BatchId)highestAcknowledgedBatchID {
return self.metadata.lastAcknowledgedBatchId;
}

- (void)acknowledgeBatch:(FSTMutationBatch *)batch streamToken:(nullable NSData *)streamToken {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note that this function is now equivalent to setLastStreamToken.

Copy link
Contributor

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

Basically LGTM, though it's not clear the mutation is actually useful.

In principle, it's the right thing to do because it leaves the data in a state that's compatible with previous versions (e.g. v0.14.0, which predates the held write acks change).

In practice it's useless though because downgrading past v0.16.1 doesn't correctly record the schema downgrade so you'll end up corrupting the mutation queue anyway.

It's also not clear it's useful to maintain equivalence with the other platforms either: Web doesn't support downgrades at all and Android has problems because prior to firebase/firebase-android-sdk#149, rerunning migrations would fail.

WDYT?

Writer writer = Writer::Wrap(&bytes);
writer.WriteNanopbMessage(firestore_client_MutationQueue_fields,
&mutation_queue);
// transaction.Delete(it->key());
Copy link
Contributor

Choose a reason for hiding this comment

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

Commented out code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@@ -184,6 +189,39 @@ void RemoveAcknowledgedMutations(leveldb::DB* db) {
transaction.Commit();
}

/** Migration 6. */
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems the right way to make this work.

This is only really useful in that it leaves the data in a state that's compatible with previous versions that did use this field. This would allow developers to rollback safely to prior versions.

transaction.Commit();
}

auto get_last_acked = [&] {
Copy link
Contributor

Choose a reason for hiding this comment

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

This mechanism is not cheaply portable to Android. Consider passing the mutation_queue as a parameter to a regular function.

@var-const
Copy link
Contributor Author

it's not clear the mutation is actually useful.

I guess I'm slightly against it, because value for the user appears pretty small, but touching user data always introduces some room for corruption. So I'd probably omit the migration, but I don't feel strongly about it -- what do you think?

@var-const var-const force-pushed the varconst/eliminate-highest-ackd-batch-id branch from 3b9570b to e35b9ab Compare January 10, 2019 21:25
@wilhuff
Copy link
Contributor

wilhuff commented Jan 10, 2019

Based on your comment and the in-person discussion, let's remove it.

@var-const
Copy link
Contributor Author

Removed the migration.

* BatchId values from the local store are non-negative so this value is before
* all batches.
*/
extern const BatchId kBatchIdUnknown;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note: I originally only did this to allow leveldb_migrations.cc to remain a pure C++ file, but I guess there's no reason to revert this change.

Copy link
Contributor

Choose a reason for hiding this comment

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

Now that this is C++ couldn't this just be constexpr?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor

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

LGTM with nit.

* BatchId values from the local store are non-negative so this value is before
* all batches.
*/
extern const BatchId kBatchIdUnknown;
Copy link
Contributor

Choose a reason for hiding this comment

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

Now that this is C++ couldn't this just be constexpr?

@@ -0,0 +1,39 @@
/*
* Copyright 2018 Google
Copy link
Contributor

Choose a reason for hiding this comment

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

2019

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@var-const var-const merged commit a52abec into master Jan 11, 2019
@var-const
Copy link
Contributor Author

Should fix #2237

var-const added a commit to firebase/firebase-js-sdk that referenced this pull request Jan 14, 2019
@paulb777 paulb777 deleted the varconst/eliminate-highest-ackd-batch-id branch April 13, 2019 16:01
@firebase firebase locked and limited conversation to collaborators Oct 23, 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