FSTMutationQueueTests.m 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511
  1. /*
  2. * Copyright 2017 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import "Firestore/Example/Tests/Local/FSTMutationQueueTests.h"
  17. #import "Firestore/Source/Auth/FSTUser.h"
  18. #import "Firestore/Source/Core/FSTQuery.h"
  19. #import "Firestore/Source/Core/FSTTimestamp.h"
  20. #import "Firestore/Source/Local/FSTEagerGarbageCollector.h"
  21. #import "Firestore/Source/Local/FSTMutationQueue.h"
  22. #import "Firestore/Source/Local/FSTPersistence.h"
  23. #import "Firestore/Source/Local/FSTWriteGroup.h"
  24. #import "Firestore/Source/Model/FSTMutation.h"
  25. #import "Firestore/Source/Model/FSTMutationBatch.h"
  26. #import "Firestore/Example/Tests/Util/FSTHelpers.h"
  27. NS_ASSUME_NONNULL_BEGIN
  28. @implementation FSTMutationQueueTests
  29. - (void)tearDown {
  30. [self.mutationQueue shutdown];
  31. [self.persistence shutdown];
  32. [super tearDown];
  33. }
  34. /**
  35. * Xcode will run tests from any class that extends XCTestCase, but this doesn't work for
  36. * FSTMutationQueueTests since it is incomplete without the implementations supplied by its
  37. * subclasses.
  38. */
  39. - (BOOL)isTestBaseClass {
  40. return [self class] == [FSTMutationQueueTests class];
  41. }
  42. - (void)testCountBatches {
  43. if ([self isTestBaseClass]) return;
  44. XCTAssertEqual(0, [self batchCount]);
  45. XCTAssertTrue([self.mutationQueue isEmpty]);
  46. FSTMutationBatch *batch1 = [self addMutationBatch];
  47. XCTAssertEqual(1, [self batchCount]);
  48. XCTAssertFalse([self.mutationQueue isEmpty]);
  49. FSTMutationBatch *batch2 = [self addMutationBatch];
  50. XCTAssertEqual(2, [self batchCount]);
  51. [self removeMutationBatches:@[ batch2 ]];
  52. XCTAssertEqual(1, [self batchCount]);
  53. [self removeMutationBatches:@[ batch1 ]];
  54. XCTAssertEqual(0, [self batchCount]);
  55. XCTAssertTrue([self.mutationQueue isEmpty]);
  56. }
  57. - (void)testAcknowledgeBatchID {
  58. if ([self isTestBaseClass]) return;
  59. // Initial state of an empty queue
  60. XCTAssertEqual([self.mutationQueue highestAcknowledgedBatchID], kFSTBatchIDUnknown);
  61. // Adding mutation batches should not change the highest acked batchID.
  62. FSTMutationBatch *batch1 = [self addMutationBatch];
  63. FSTMutationBatch *batch2 = [self addMutationBatch];
  64. FSTMutationBatch *batch3 = [self addMutationBatch];
  65. XCTAssertGreaterThan(batch1.batchID, kFSTBatchIDUnknown);
  66. XCTAssertGreaterThan(batch2.batchID, batch1.batchID);
  67. XCTAssertGreaterThan(batch3.batchID, batch2.batchID);
  68. XCTAssertEqual([self.mutationQueue highestAcknowledgedBatchID], kFSTBatchIDUnknown);
  69. [self acknowledgeBatch:batch1];
  70. [self acknowledgeBatch:batch2];
  71. XCTAssertEqual([self.mutationQueue highestAcknowledgedBatchID], batch2.batchID);
  72. [self removeMutationBatches:@[ batch1 ]];
  73. XCTAssertEqual([self.mutationQueue highestAcknowledgedBatchID], batch2.batchID);
  74. [self removeMutationBatches:@[ batch2 ]];
  75. XCTAssertEqual([self.mutationQueue highestAcknowledgedBatchID], batch2.batchID);
  76. // Batch 3 never acknowledged.
  77. [self removeMutationBatches:@[ batch3 ]];
  78. XCTAssertEqual([self.mutationQueue highestAcknowledgedBatchID], batch2.batchID);
  79. }
  80. - (void)testAcknowledgeThenRemove {
  81. if ([self isTestBaseClass]) return;
  82. FSTMutationBatch *batch1 = [self addMutationBatch];
  83. FSTWriteGroup *group = [self.persistence startGroupWithAction:NSStringFromSelector(_cmd)];
  84. [self.mutationQueue acknowledgeBatch:batch1 streamToken:nil group:group];
  85. [self.mutationQueue removeMutationBatches:@[ batch1 ] group:group];
  86. [self.persistence commitGroup:group];
  87. XCTAssertEqual([self batchCount], 0);
  88. XCTAssertEqual([self.mutationQueue highestAcknowledgedBatchID], batch1.batchID);
  89. }
  90. - (void)testHighestAcknowledgedBatchIDNeverExceedsNextBatchID {
  91. if ([self isTestBaseClass]) return;
  92. FSTMutationBatch *batch1 = [self addMutationBatch];
  93. FSTMutationBatch *batch2 = [self addMutationBatch];
  94. [self acknowledgeBatch:batch1];
  95. [self acknowledgeBatch:batch2];
  96. XCTAssertEqual([self.mutationQueue highestAcknowledgedBatchID], batch2.batchID);
  97. [self removeMutationBatches:@[ batch1, batch2 ]];
  98. XCTAssertEqual([self.mutationQueue highestAcknowledgedBatchID], batch2.batchID);
  99. // Restart the queue so that nextBatchID will be reset.
  100. [self.mutationQueue shutdown];
  101. self.mutationQueue =
  102. [self.persistence mutationQueueForUser:[[FSTUser alloc] initWithUID:@"user"]];
  103. FSTWriteGroup *group = [self.persistence startGroupWithAction:@"Start MutationQueue"];
  104. [self.mutationQueue startWithGroup:group];
  105. [self.persistence commitGroup:group];
  106. // Verify that on restart with an empty queue, nextBatchID falls to a lower value.
  107. XCTAssertLessThan(self.mutationQueue.nextBatchID, batch2.batchID);
  108. // As a result highestAcknowledgedBatchID must also reset lower.
  109. XCTAssertEqual([self.mutationQueue highestAcknowledgedBatchID], kFSTBatchIDUnknown);
  110. // The mutation queue will reset the next batchID after all mutations are removed so adding
  111. // another mutation will cause a collision.
  112. FSTMutationBatch *newBatch = [self addMutationBatch];
  113. XCTAssertEqual(newBatch.batchID, batch1.batchID);
  114. // Restart the queue with one unacknowledged batch in it.
  115. group = [self.persistence startGroupWithAction:@"Start MutationQueue"];
  116. [self.mutationQueue startWithGroup:group];
  117. [self.persistence commitGroup:group];
  118. XCTAssertEqual([self.mutationQueue nextBatchID], newBatch.batchID + 1);
  119. // highestAcknowledgedBatchID must still be kFSTBatchIDUnknown.
  120. XCTAssertEqual([self.mutationQueue highestAcknowledgedBatchID], kFSTBatchIDUnknown);
  121. }
  122. - (void)testLookupMutationBatch {
  123. if ([self isTestBaseClass]) return;
  124. // Searching on an empty queue should not find a non-existent batch
  125. FSTMutationBatch *notFound = [self.mutationQueue lookupMutationBatch:42];
  126. XCTAssertNil(notFound);
  127. NSMutableArray<FSTMutationBatch *> *batches = [self createBatches:10];
  128. NSArray<FSTMutationBatch *> *removed = [self makeHoles:@[ @2, @6, @7 ] inBatches:batches];
  129. // After removing, a batch should not be found
  130. for (NSUInteger i = 0; i < removed.count; i++) {
  131. notFound = [self.mutationQueue lookupMutationBatch:removed[i].batchID];
  132. XCTAssertNil(notFound);
  133. }
  134. // Remaining entries should still be found
  135. for (FSTMutationBatch *batch in batches) {
  136. FSTMutationBatch *found = [self.mutationQueue lookupMutationBatch:batch.batchID];
  137. XCTAssertEqual(found.batchID, batch.batchID);
  138. }
  139. // Even on a nonempty queue searching should not find a non-existent batch
  140. notFound = [self.mutationQueue lookupMutationBatch:42];
  141. XCTAssertNil(notFound);
  142. }
  143. - (void)testNextMutationBatchAfterBatchID {
  144. if ([self isTestBaseClass]) return;
  145. NSMutableArray<FSTMutationBatch *> *batches = [self createBatches:10];
  146. // This is an array of successors assuming the removals below will happen:
  147. NSArray<FSTMutationBatch *> *afters = @[ batches[3], batches[8], batches[8] ];
  148. NSArray<FSTMutationBatch *> *removed = [self makeHoles:@[ @2, @6, @7 ] inBatches:batches];
  149. for (NSUInteger i = 0; i < batches.count - 1; i++) {
  150. FSTMutationBatch *current = batches[i];
  151. FSTMutationBatch *next = batches[i + 1];
  152. FSTMutationBatch *found = [self.mutationQueue nextMutationBatchAfterBatchID:current.batchID];
  153. XCTAssertEqual(found.batchID, next.batchID);
  154. }
  155. for (NSUInteger i = 0; i < removed.count; i++) {
  156. FSTMutationBatch *current = removed[i];
  157. FSTMutationBatch *next = afters[i];
  158. FSTMutationBatch *found = [self.mutationQueue nextMutationBatchAfterBatchID:current.batchID];
  159. XCTAssertEqual(found.batchID, next.batchID);
  160. }
  161. FSTMutationBatch *first = batches[0];
  162. FSTMutationBatch *found = [self.mutationQueue nextMutationBatchAfterBatchID:first.batchID - 42];
  163. XCTAssertEqual(found.batchID, first.batchID);
  164. FSTMutationBatch *last = batches[batches.count - 1];
  165. FSTMutationBatch *notFound = [self.mutationQueue nextMutationBatchAfterBatchID:last.batchID];
  166. XCTAssertNil(notFound);
  167. }
  168. - (void)testAllMutationBatchesThroughBatchID {
  169. if ([self isTestBaseClass]) return;
  170. NSMutableArray<FSTMutationBatch *> *batches = [self createBatches:10];
  171. [self makeHoles:@[ @2, @6, @7 ] inBatches:batches];
  172. NSArray<FSTMutationBatch *> *found, *expected;
  173. found = [self.mutationQueue allMutationBatchesThroughBatchID:batches[0].batchID - 1];
  174. XCTAssertEqualObjects(found, (@[]));
  175. for (NSUInteger i = 0; i < batches.count; i++) {
  176. found = [self.mutationQueue allMutationBatchesThroughBatchID:batches[i].batchID];
  177. expected = [batches subarrayWithRange:NSMakeRange(0, i + 1)];
  178. XCTAssertEqualObjects(found, expected, @"for index %lu", (unsigned long)i);
  179. }
  180. }
  181. - (void)testAllMutationBatchesAffectingDocumentKey {
  182. if ([self isTestBaseClass]) return;
  183. NSArray<FSTMutation *> *mutations = @[
  184. FSTTestSetMutation(@"fob/bar",
  185. @{ @"a" : @1 }),
  186. FSTTestSetMutation(@"foo/bar",
  187. @{ @"a" : @1 }),
  188. FSTTestPatchMutation(@"foo/bar",
  189. @{ @"b" : @1 }, nil),
  190. FSTTestSetMutation(@"foo/bar/suffix/key",
  191. @{ @"a" : @1 }),
  192. FSTTestSetMutation(@"foo/baz",
  193. @{ @"a" : @1 }),
  194. FSTTestSetMutation(@"food/bar",
  195. @{ @"a" : @1 })
  196. ];
  197. // Store all the mutations.
  198. NSMutableArray<FSTMutationBatch *> *batches = [NSMutableArray array];
  199. FSTWriteGroup *group = [self.persistence startGroupWithAction:@"New mutation batch"];
  200. for (FSTMutation *mutation in mutations) {
  201. FSTMutationBatch *batch =
  202. [self.mutationQueue addMutationBatchWithWriteTime:[FSTTimestamp timestamp]
  203. mutations:@[ mutation ]
  204. group:group];
  205. [batches addObject:batch];
  206. }
  207. [self.persistence commitGroup:group];
  208. NSArray<FSTMutationBatch *> *expected = @[ batches[1], batches[2] ];
  209. NSArray<FSTMutationBatch *> *matches =
  210. [self.mutationQueue allMutationBatchesAffectingDocumentKey:FSTTestDocKey(@"foo/bar")];
  211. XCTAssertEqualObjects(matches, expected);
  212. }
  213. - (void)testAllMutationBatchesAffectingQuery {
  214. if ([self isTestBaseClass]) return;
  215. NSArray<FSTMutation *> *mutations = @[
  216. FSTTestSetMutation(@"fob/bar",
  217. @{ @"a" : @1 }),
  218. FSTTestSetMutation(@"foo/bar",
  219. @{ @"a" : @1 }),
  220. FSTTestPatchMutation(@"foo/bar",
  221. @{ @"b" : @1 }, nil),
  222. FSTTestSetMutation(@"foo/bar/suffix/key",
  223. @{ @"a" : @1 }),
  224. FSTTestSetMutation(@"foo/baz",
  225. @{ @"a" : @1 }),
  226. FSTTestSetMutation(@"food/bar",
  227. @{ @"a" : @1 })
  228. ];
  229. // Store all the mutations.
  230. NSMutableArray<FSTMutationBatch *> *batches = [NSMutableArray array];
  231. FSTWriteGroup *group = [self.persistence startGroupWithAction:@"New mutation batch"];
  232. for (FSTMutation *mutation in mutations) {
  233. FSTMutationBatch *batch =
  234. [self.mutationQueue addMutationBatchWithWriteTime:[FSTTimestamp timestamp]
  235. mutations:@[ mutation ]
  236. group:group];
  237. [batches addObject:batch];
  238. }
  239. [self.persistence commitGroup:group];
  240. NSArray<FSTMutationBatch *> *expected = @[ batches[1], batches[2], batches[4] ];
  241. FSTQuery *query = [FSTQuery queryWithPath:FSTTestPath(@"foo")];
  242. NSArray<FSTMutationBatch *> *matches =
  243. [self.mutationQueue allMutationBatchesAffectingQuery:query];
  244. XCTAssertEqualObjects(matches, expected);
  245. }
  246. - (void)testRemoveMutationBatches {
  247. if ([self isTestBaseClass]) return;
  248. NSMutableArray<FSTMutationBatch *> *batches = [self createBatches:10];
  249. FSTMutationBatch *last = batches[batches.count - 1];
  250. [self removeMutationBatches:@[ batches[0] ]];
  251. [batches removeObjectAtIndex:0];
  252. XCTAssertEqual([self batchCount], 9);
  253. NSArray<FSTMutationBatch *> *found;
  254. found = [self.mutationQueue allMutationBatchesThroughBatchID:last.batchID];
  255. XCTAssertEqualObjects(found, batches);
  256. XCTAssertEqual(found.count, 9);
  257. [self removeMutationBatches:@[ batches[0], batches[1], batches[2] ]];
  258. [batches removeObjectsInRange:NSMakeRange(0, 3)];
  259. XCTAssertEqual([self batchCount], 6);
  260. found = [self.mutationQueue allMutationBatchesThroughBatchID:last.batchID];
  261. XCTAssertEqualObjects(found, batches);
  262. XCTAssertEqual(found.count, 6);
  263. [self removeMutationBatches:@[ batches[batches.count - 1] ]];
  264. [batches removeObjectAtIndex:batches.count - 1];
  265. XCTAssertEqual([self batchCount], 5);
  266. found = [self.mutationQueue allMutationBatchesThroughBatchID:last.batchID];
  267. XCTAssertEqualObjects(found, batches);
  268. XCTAssertEqual(found.count, 5);
  269. [self removeMutationBatches:@[ batches[3] ]];
  270. [batches removeObjectAtIndex:3];
  271. XCTAssertEqual([self batchCount], 4);
  272. [self removeMutationBatches:@[ batches[1] ]];
  273. [batches removeObjectAtIndex:1];
  274. XCTAssertEqual([self batchCount], 3);
  275. found = [self.mutationQueue allMutationBatchesThroughBatchID:last.batchID];
  276. XCTAssertEqualObjects(found, batches);
  277. XCTAssertEqual(found.count, 3);
  278. XCTAssertFalse([self.mutationQueue isEmpty]);
  279. [self removeMutationBatches:batches];
  280. found = [self.mutationQueue allMutationBatchesThroughBatchID:last.batchID];
  281. XCTAssertEqualObjects(found, @[]);
  282. XCTAssertEqual(found.count, 0);
  283. XCTAssertTrue([self.mutationQueue isEmpty]);
  284. }
  285. - (void)testRemoveMutationBatchesEmitsGarbageEvents {
  286. if ([self isTestBaseClass]) return;
  287. FSTEagerGarbageCollector *garbageCollector = [[FSTEagerGarbageCollector alloc] init];
  288. [garbageCollector addGarbageSource:self.mutationQueue];
  289. NSMutableArray<FSTMutationBatch *> *batches = [NSMutableArray array];
  290. [batches addObjectsFromArray:@[
  291. [self addMutationBatchWithKey:@"foo/bar"],
  292. [self addMutationBatchWithKey:@"foo/ba"],
  293. [self addMutationBatchWithKey:@"foo/bar2"],
  294. [self addMutationBatchWithKey:@"foo/bar"],
  295. [self addMutationBatchWithKey:@"foo/bar/suffix/baz"],
  296. [self addMutationBatchWithKey:@"bar/baz"],
  297. ]];
  298. [self removeMutationBatches:@[ batches[0] ]];
  299. NSSet<FSTDocumentKey *> *garbage = [garbageCollector collectGarbage];
  300. FSTAssertEqualSets(garbage, @[]);
  301. [self removeMutationBatches:@[ batches[1] ]];
  302. garbage = [garbageCollector collectGarbage];
  303. FSTAssertEqualSets(garbage, @[ FSTTestDocKey(@"foo/ba") ]);
  304. [self removeMutationBatches:@[ batches[5] ]];
  305. garbage = [garbageCollector collectGarbage];
  306. FSTAssertEqualSets(garbage, @[ FSTTestDocKey(@"bar/baz") ]);
  307. [self removeMutationBatches:@[ batches[2], batches[3] ]];
  308. garbage = [garbageCollector collectGarbage];
  309. FSTAssertEqualSets(garbage, (@[ FSTTestDocKey(@"foo/bar"), FSTTestDocKey(@"foo/bar2") ]));
  310. [batches addObject:[self addMutationBatchWithKey:@"foo/bar/suffix/baz"]];
  311. garbage = [garbageCollector collectGarbage];
  312. FSTAssertEqualSets(garbage, @[]);
  313. [self removeMutationBatches:@[ batches[4], batches[6] ]];
  314. garbage = [garbageCollector collectGarbage];
  315. FSTAssertEqualSets(garbage, @[ FSTTestDocKey(@"foo/bar/suffix/baz") ]);
  316. }
  317. - (void)testStreamToken {
  318. if ([self isTestBaseClass]) return;
  319. NSData *streamToken1 = [@"token1" dataUsingEncoding:NSUTF8StringEncoding];
  320. NSData *streamToken2 = [@"token2" dataUsingEncoding:NSUTF8StringEncoding];
  321. FSTWriteGroup *group = [self.persistence startGroupWithAction:@"initial stream token"];
  322. [self.mutationQueue setLastStreamToken:streamToken1 group:group];
  323. [self.persistence commitGroup:group];
  324. FSTMutationBatch *batch1 = [self addMutationBatch];
  325. [self addMutationBatch];
  326. XCTAssertEqualObjects([self.mutationQueue lastStreamToken], streamToken1);
  327. group = [self.persistence startGroupWithAction:@"acknowledgeBatchID"];
  328. [self.mutationQueue acknowledgeBatch:batch1 streamToken:streamToken2 group:group];
  329. [self.persistence commitGroup:group];
  330. XCTAssertEqual(self.mutationQueue.highestAcknowledgedBatchID, batch1.batchID);
  331. XCTAssertEqualObjects([self.mutationQueue lastStreamToken], streamToken2);
  332. }
  333. /** Creates a new FSTMutationBatch with the next batch ID and a set of dummy mutations. */
  334. - (FSTMutationBatch *)addMutationBatch {
  335. return [self addMutationBatchWithKey:@"foo/bar"];
  336. }
  337. /**
  338. * Creates a new FSTMutationBatch with the given key, the next batch ID and a set of dummy
  339. * mutations.
  340. */
  341. - (FSTMutationBatch *)addMutationBatchWithKey:(NSString *)key {
  342. FSTSetMutation *mutation = FSTTestSetMutation(key, @{ @"a" : @1 });
  343. FSTWriteGroup *group = [self.persistence startGroupWithAction:@"New mutation batch"];
  344. FSTMutationBatch *batch =
  345. [self.mutationQueue addMutationBatchWithWriteTime:[FSTTimestamp timestamp]
  346. mutations:@[ mutation ]
  347. group:group];
  348. [self.persistence commitGroup:group];
  349. return batch;
  350. }
  351. /**
  352. * Creates an array of batches containing @a number dummy FSTMutationBatches. Each has a different
  353. * batchID.
  354. */
  355. - (NSMutableArray<FSTMutationBatch *> *)createBatches:(int)number {
  356. NSMutableArray<FSTMutationBatch *> *batches = [NSMutableArray array];
  357. for (int i = 0; i < number; i++) {
  358. FSTMutationBatch *batch = [self addMutationBatch];
  359. [batches addObject:batch];
  360. }
  361. return batches;
  362. }
  363. /**
  364. * Calls -acknowledgeBatch:streamToken:group: on the mutation queue in a new group and commits the
  365. * the group.
  366. */
  367. - (void)acknowledgeBatch:(FSTMutationBatch *)batch {
  368. FSTWriteGroup *group = [self.persistence startGroupWithAction:@"Ack batchID"];
  369. [self.mutationQueue acknowledgeBatch:batch streamToken:nil group:group];
  370. [self.persistence commitGroup:group];
  371. }
  372. /**
  373. * Calls -removeMutationBatches:group: on the mutation queue in a new group and commits the group.
  374. */
  375. - (void)removeMutationBatches:(NSArray<FSTMutationBatch *> *)batches {
  376. FSTWriteGroup *group = [self.persistence startGroupWithAction:@"Remove mutation batch"];
  377. [self.mutationQueue removeMutationBatches:batches group:group];
  378. [self.persistence commitGroup:group];
  379. }
  380. /** Returns the number of mutation batches in the mutation queue. */
  381. - (NSUInteger)batchCount {
  382. return [self.mutationQueue allMutationBatches].count;
  383. }
  384. /**
  385. * Removes entries from from the given @a batches and returns them.
  386. *
  387. * @param holes An array of indexes in the batches array; in increasing order. Indexes are relative
  388. * to the original state of the batches array, not any intermediate state that might occur.
  389. * @param batches The array to mutate, removing entries from it.
  390. * @return A new array containing all the entries that were removed from @a batches.
  391. */
  392. - (NSArray<FSTMutationBatch *> *)makeHoles:(NSArray<NSNumber *> *)holes
  393. inBatches:(NSMutableArray<FSTMutationBatch *> *)batches {
  394. NSMutableArray<FSTMutationBatch *> *removed = [NSMutableArray array];
  395. for (NSUInteger i = 0; i < holes.count; i++) {
  396. NSUInteger index = holes[i].unsignedIntegerValue - i;
  397. FSTMutationBatch *batch = batches[index];
  398. [self removeMutationBatches:@[ batch ]];
  399. [batches removeObjectAtIndex:index];
  400. [removed addObject:batch];
  401. }
  402. return removed;
  403. }
  404. @end
  405. NS_ASSUME_NONNULL_END