-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Conversation
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); |
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.
Checking batchCount
is the only replacement for the previous check that I could think of.
@@ -186,28 +183,6 @@ - (void)testNextMutationBatchAfterBatchID { | |||
}); | |||
} | |||
|
|||
- (void)testNextMutationBatchAfterBatchIDSkipsAcknowledgedBatches { |
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 test appears to be no longer relevant.
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. 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; |
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 presume this is fine?
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.
Yes.
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 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?
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.
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 { |
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.
Note that this function is now equivalent to setLastStreamToken
.
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.
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()); |
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.
Commented out code?
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.
Done.
@@ -184,6 +189,39 @@ void RemoveAcknowledgedMutations(leveldb::DB* db) { | |||
transaction.Commit(); | |||
} | |||
|
|||
/** Migration 6. */ |
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 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 = [&] { |
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 mechanism is not cheaply portable to Android. Consider passing the mutation_queue as a parameter to a regular function.
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? |
3b9570b
to
e35b9ab
Compare
Based on your comment and the in-person discussion, let's remove it. |
Removed the migration. |
* BatchId values from the local store are non-negative so this value is before | ||
* all batches. | ||
*/ | ||
extern const BatchId kBatchIdUnknown; |
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.
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.
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.
Now that this is C++ couldn't this just be constexpr?
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.
Done.
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 with nit.
* BatchId values from the local store are non-negative so this value is before | ||
* all batches. | ||
*/ | ||
extern const BatchId kBatchIdUnknown; |
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.
Now that this is C++ couldn't this just be constexpr?
@@ -0,0 +1,39 @@ | |||
/* | |||
* Copyright 2018 Google |
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.
2019
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.
Done.
Should fix #2237 |
A straightforward port of firebase/firebase-ios-sdk#2243.
After #2029, acknowledged batches are always immediately removed, so persisting the last acknowledged batch ID is no longer necessary.