-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Remove Mutation tombstones #2052
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,10 +71,10 @@ - (void)testCountBatches { | |
FSTMutationBatch *batch2 = [self addMutationBatch]; | ||
XCTAssertEqual(2, [self batchCount]); | ||
|
||
[self.mutationQueue removeMutationBatch:batch2]; | ||
[self.mutationQueue removeMutationBatch:batch1]; | ||
XCTAssertEqual(1, [self batchCount]); | ||
|
||
[self.mutationQueue removeMutationBatch:batch1]; | ||
[self.mutationQueue removeMutationBatch:batch2]; | ||
XCTAssertEqual(0, [self batchCount]); | ||
XCTAssertTrue([self.mutationQueue isEmpty]); | ||
}); | ||
|
@@ -98,10 +98,9 @@ - (void)testAcknowledgeBatchID { | |
XCTAssertEqual([self.mutationQueue highestAcknowledgedBatchID], kFSTBatchIDUnknown); | ||
|
||
[self.mutationQueue acknowledgeBatch:batch1 streamToken:nil]; | ||
[self.mutationQueue acknowledgeBatch:batch2 streamToken:nil]; | ||
XCTAssertEqual([self.mutationQueue highestAcknowledgedBatchID], batch2.batchID); | ||
|
||
[self.mutationQueue removeMutationBatch:batch1]; | ||
|
||
[self.mutationQueue acknowledgeBatch:batch2 streamToken:nil]; | ||
XCTAssertEqual([self.mutationQueue highestAcknowledgedBatchID], batch2.batchID); | ||
|
||
[self.mutationQueue removeMutationBatch:batch2]; | ||
|
@@ -139,10 +138,10 @@ - (void)testHighestAcknowledgedBatchIDNeverExceedsNextBatchID { | |
|
||
self.persistence.run("testHighestAcknowledgedBatchIDNeverExceedsNextBatchID", [&]() { | ||
[self.mutationQueue acknowledgeBatch:batch1 streamToken:nil]; | ||
[self.mutationQueue removeMutationBatch:batch1]; | ||
[self.mutationQueue acknowledgeBatch:batch2 streamToken:nil]; | ||
XCTAssertEqual([self.mutationQueue highestAcknowledgedBatchID], batch2.batchID); | ||
|
||
[self.mutationQueue removeMutationBatch:batch1]; | ||
[self.mutationQueue removeMutationBatch:batch2]; | ||
XCTAssertEqual([self.mutationQueue highestAcknowledgedBatchID], batch2.batchID); | ||
}); | ||
|
@@ -186,7 +185,7 @@ - (void)testLookupMutationBatch { | |
XCTAssertNil(notFound); | ||
|
||
NSMutableArray<FSTMutationBatch *> *batches = [self createBatches:10]; | ||
NSArray<FSTMutationBatch *> *removed = [self makeHoles:@[ @2, @6, @7 ] inBatches:batches]; | ||
NSArray<FSTMutationBatch *> *removed = [self removeFirstBatches:3 inBatches:batches]; | ||
|
||
// After removing, a batch should not be found | ||
for (NSUInteger i = 0; i < removed.count; i++) { | ||
|
@@ -211,10 +210,7 @@ - (void)testNextMutationBatchAfterBatchID { | |
|
||
self.persistence.run("testNextMutationBatchAfterBatchID", [&]() { | ||
NSMutableArray<FSTMutationBatch *> *batches = [self createBatches:10]; | ||
|
||
// This is an array of successors assuming the removals below will happen: | ||
NSArray<FSTMutationBatch *> *afters = @[ batches[3], batches[8], batches[8] ]; | ||
NSArray<FSTMutationBatch *> *removed = [self makeHoles:@[ @2, @6, @7 ] inBatches:batches]; | ||
NSArray<FSTMutationBatch *> *removed = [self removeFirstBatches:3 inBatches:batches]; | ||
|
||
for (NSUInteger i = 0; i < batches.count - 1; i++) { | ||
FSTMutationBatch *current = batches[i]; | ||
|
@@ -225,7 +221,7 @@ - (void)testNextMutationBatchAfterBatchID { | |
|
||
for (NSUInteger i = 0; i < removed.count; i++) { | ||
FSTMutationBatch *current = removed[i]; | ||
FSTMutationBatch *next = afters[i]; | ||
FSTMutationBatch *next = batches[0]; | ||
FSTMutationBatch *found = [self.mutationQueue nextMutationBatchAfterBatchID:current.batchID]; | ||
XCTAssertEqual(found.batchID, next.batchID); | ||
} | ||
|
@@ -262,26 +258,6 @@ - (void)testNextMutationBatchAfterBatchIDSkipsAcknowledgedBatches { | |
}); | ||
} | ||
|
||
- (void)testAllMutationBatchesThroughBatchID { | ||
if ([self isTestBaseClass]) return; | ||
|
||
self.persistence.run("testAllMutationBatchesThroughBatchID", [&]() { | ||
NSMutableArray<FSTMutationBatch *> *batches = [self createBatches:10]; | ||
[self makeHoles:@[ @2, @6, @7 ] inBatches:batches]; | ||
|
||
NSArray<FSTMutationBatch *> *found, *expected; | ||
|
||
found = [self.mutationQueue allMutationBatchesThroughBatchID:batches[0].batchID - 1]; | ||
XCTAssertEqualObjects(found, (@[])); | ||
|
||
for (NSUInteger i = 0; i < batches.count; i++) { | ||
found = [self.mutationQueue allMutationBatchesThroughBatchID:batches[i].batchID]; | ||
expected = [batches subarrayWithRange:NSMakeRange(0, i + 1)]; | ||
XCTAssertEqualObjects(found, expected, @"for index %lu", (unsigned long)i); | ||
} | ||
}); | ||
} | ||
|
||
- (void)testAllMutationBatchesAffectingDocumentKey { | ||
if ([self isTestBaseClass]) return; | ||
|
||
|
@@ -443,12 +419,11 @@ - (void)testRemoveMutationBatches { | |
[self.mutationQueue removeMutationBatch:batches[0]]; | ||
[batches removeObjectAtIndex:0]; | ||
|
||
FSTMutationBatch *last = batches[batches.count - 1]; | ||
XCTAssertEqual([self batchCount], 9); | ||
|
||
NSArray<FSTMutationBatch *> *found; | ||
|
||
found = [self.mutationQueue allMutationBatchesThroughBatchID:last.batchID]; | ||
found = [self.mutationQueue allMutationBatches]; | ||
XCTAssertEqualObjects(found, batches); | ||
XCTAssertEqual(found.count, 9); | ||
|
||
|
@@ -458,35 +433,35 @@ - (void)testRemoveMutationBatches { | |
[batches removeObjectsInRange:NSMakeRange(0, 3)]; | ||
XCTAssertEqual([self batchCount], 6); | ||
|
||
found = [self.mutationQueue allMutationBatchesThroughBatchID:last.batchID]; | ||
found = [self.mutationQueue allMutationBatches]; | ||
XCTAssertEqualObjects(found, batches); | ||
XCTAssertEqual(found.count, 6); | ||
|
||
[self.mutationQueue removeMutationBatch:batches[batches.count - 1]]; | ||
[batches removeObjectAtIndex:batches.count - 1]; | ||
[self.mutationQueue removeMutationBatch:batches[0]]; | ||
[batches removeObjectAtIndex:0]; | ||
XCTAssertEqual([self batchCount], 5); | ||
|
||
found = [self.mutationQueue allMutationBatchesThroughBatchID:last.batchID]; | ||
found = [self.mutationQueue allMutationBatches]; | ||
XCTAssertEqualObjects(found, batches); | ||
XCTAssertEqual(found.count, 5); | ||
|
||
[self.mutationQueue removeMutationBatch:batches[3]]; | ||
[batches removeObjectAtIndex:3]; | ||
[self.mutationQueue removeMutationBatch:batches[0]]; | ||
[batches removeObjectAtIndex:0]; | ||
XCTAssertEqual([self batchCount], 4); | ||
|
||
[self.mutationQueue removeMutationBatch:batches[1]]; | ||
[batches removeObjectAtIndex:1]; | ||
[self.mutationQueue removeMutationBatch:batches[0]]; | ||
[batches removeObjectAtIndex:0]; | ||
XCTAssertEqual([self batchCount], 3); | ||
|
||
found = [self.mutationQueue allMutationBatchesThroughBatchID:last.batchID]; | ||
found = [self.mutationQueue allMutationBatches]; | ||
XCTAssertEqualObjects(found, batches); | ||
XCTAssertEqual(found.count, 3); | ||
XCTAssertFalse([self.mutationQueue isEmpty]); | ||
|
||
for (FSTMutationBatch *batch in batches) { | ||
[self.mutationQueue removeMutationBatch:batch]; | ||
} | ||
found = [self.mutationQueue allMutationBatchesThroughBatchID:last.batchID]; | ||
found = [self.mutationQueue allMutationBatches]; | ||
XCTAssertEqualObjects(found, @[]); | ||
XCTAssertEqual(found.count, 0); | ||
XCTAssertTrue([self.mutationQueue isEmpty]); | ||
|
@@ -554,22 +529,19 @@ - (NSUInteger)batchCount { | |
} | ||
|
||
/** | ||
* Removes entries from from the given @a batches and returns them. | ||
* Removes the first n entries from the from the given batches and returns them. | ||
* | ||
* @param holes An array of indexes in the batches array; in increasing order. Indexes are relative | ||
* to the original state of the batches array, not any intermediate state that might occur. | ||
* @param n The number of batches to remove.. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: extra full stop. |
||
* @param batches The array to mutate, removing entries from it. | ||
* @return A new array containing all the entries that were removed from @a batches. | ||
*/ | ||
- (NSArray<FSTMutationBatch *> *)makeHoles:(NSArray<NSNumber *> *)holes | ||
inBatches:(NSMutableArray<FSTMutationBatch *> *)batches { | ||
- (NSArray<FSTMutationBatch *> *)removeFirstBatches:(int)n | ||
inBatches:(NSMutableArray<FSTMutationBatch *> *)batches { | ||
NSMutableArray<FSTMutationBatch *> *removed = [NSMutableArray array]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Very optional: looking at the docs, it seems like this could be expressed more clearly as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do like using the built-in tools for low level operations. I updated the method and am now using |
||
for (NSUInteger i = 0; i < holes.count; i++) { | ||
NSUInteger index = holes[i].unsignedIntegerValue - i; | ||
FSTMutationBatch *batch = batches[index]; | ||
for (int i = 0; i < n; i++) { | ||
FSTMutationBatch *batch = batches[0]; | ||
[self.mutationQueue removeMutationBatch:batch]; | ||
|
||
[batches removeObjectAtIndex:index]; | ||
[batches removeObjectAtIndex:0]; | ||
[removed addObject:batch]; | ||
} | ||
return removed; | ||
|
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/from the from the/from the
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 blame it on the original
from from
. Fixed :)