diff options
author | Gil <mcg@google.com> | 2018-05-24 11:00:23 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-24 11:00:23 -0700 |
commit | 8037a4bf79b8ae49162c2b6f099d62ec17a7f283 (patch) | |
tree | 5a15df8664abbcf3e63479fa3e7560fd8c2fbe9e /Firestore/Source/Local | |
parent | de4fe203525072babcdec444a06e42e77f0aa714 (diff) |
Replace Objective-C assertions with C++ assertions (#1327)
* Migrate FSTFail to HARD_FAIL
* FSTCFail -> HARD_FAIL
* FSTCAssert -> HARD_ASSERT
* FSTAssert -> HARD_ASSERT
* Replace FSTAssert with NSAssert in dead Objective-C code
* Remove FSTAssert.h
Diffstat (limited to 'Firestore/Source/Local')
-rw-r--r-- | Firestore/Source/Local/FSTLevelDB.mm | 12 | ||||
-rw-r--r-- | Firestore/Source/Local/FSTLevelDBMigrations.mm | 6 | ||||
-rw-r--r-- | Firestore/Source/Local/FSTLevelDBMutationQueue.mm | 55 | ||||
-rw-r--r-- | Firestore/Source/Local/FSTLevelDBQueryCache.mm | 26 | ||||
-rw-r--r-- | Firestore/Source/Local/FSTLevelDBRemoteDocumentCache.mm | 14 | ||||
-rw-r--r-- | Firestore/Source/Local/FSTLocalDocumentsView.mm | 4 | ||||
-rw-r--r-- | Firestore/Source/Local/FSTLocalSerializer.mm | 14 | ||||
-rw-r--r-- | Firestore/Source/Local/FSTLocalStore.mm | 31 | ||||
-rw-r--r-- | Firestore/Source/Local/FSTMemoryMutationQueue.mm | 39 | ||||
-rw-r--r-- | Firestore/Source/Local/FSTMemoryPersistence.mm | 6 | ||||
-rw-r--r-- | Firestore/Source/Local/FSTPersistence.h | 7 |
11 files changed, 106 insertions, 108 deletions
diff --git a/Firestore/Source/Local/FSTLevelDB.mm b/Firestore/Source/Local/FSTLevelDB.mm index 6d0f8af..321d47a 100644 --- a/Firestore/Source/Local/FSTLevelDB.mm +++ b/Firestore/Source/Local/FSTLevelDB.mm @@ -24,12 +24,12 @@ #import "Firestore/Source/Local/FSTLevelDBQueryCache.h" #import "Firestore/Source/Local/FSTLevelDBRemoteDocumentCache.h" #import "Firestore/Source/Remote/FSTSerializerBeta.h" -#import "Firestore/Source/Util/FSTAssert.h" #include "Firestore/core/src/firebase/firestore/auth/user.h" #include "Firestore/core/src/firebase/firestore/core/database_info.h" #include "Firestore/core/src/firebase/firestore/local/leveldb_transaction.h" #include "Firestore/core/src/firebase/firestore/model/database_id.h" +#include "Firestore/core/src/firebase/firestore/util/hard_assert.h" #include "Firestore/core/src/firebase/firestore/util/string_apple.h" #include "absl/memory/memory.h" #include "leveldb/db.h" @@ -132,7 +132,7 @@ using leveldb::WriteOptions; #pragma mark - Startup - (BOOL)start:(NSError **)error { - FSTAssert(!self.isStarted, @"FSTLevelDB double-started!"); + HARD_ASSERT(!self.isStarted, "FSTLevelDB double-started!"); self.started = YES; NSString *directory = self.directory; if (![self ensureDirectory:directory error:error]) { @@ -207,7 +207,7 @@ using leveldb::WriteOptions; } - (LevelDbTransaction *)currentTransaction { - FSTAssert(_transaction != nullptr, @"Attempting to access transaction before one has started"); + HARD_ASSERT(_transaction != nullptr, "Attempting to access transaction before one has started"); return _transaction.get(); } @@ -226,18 +226,18 @@ using leveldb::WriteOptions; } - (void)startTransaction:(absl::string_view)label { - FSTAssert(_transaction == nullptr, @"Starting a transaction while one is already outstanding"); + HARD_ASSERT(_transaction == nullptr, "Starting a transaction while one is already outstanding"); _transaction = absl::make_unique<LevelDbTransaction>(_ptr.get(), label); } - (void)commitTransaction { - FSTAssert(_transaction != nullptr, @"Committing a transaction before one is started"); + HARD_ASSERT(_transaction != nullptr, "Committing a transaction before one is started"); _transaction->Commit(); _transaction.reset(); } - (void)shutdown { - FSTAssert(self.isStarted, @"FSTLevelDB shutdown without start!"); + HARD_ASSERT(self.isStarted, "FSTLevelDB shutdown without start!"); self.started = NO; _ptr.reset(); } diff --git a/Firestore/Source/Local/FSTLevelDBMigrations.mm b/Firestore/Source/Local/FSTLevelDBMigrations.mm index fefd0f7..bd72c97 100644 --- a/Firestore/Source/Local/FSTLevelDBMigrations.mm +++ b/Firestore/Source/Local/FSTLevelDBMigrations.mm @@ -21,8 +21,8 @@ #import "Firestore/Protos/objc/firestore/local/Target.pbobjc.h" #import "Firestore/Source/Local/FSTLevelDBKey.h" #import "Firestore/Source/Local/FSTLevelDBQueryCache.h" -#import "Firestore/Source/Util/FSTAssert.h" +#include "Firestore/core/src/firebase/firestore/util/hard_assert.h" #include "absl/strings/match.h" #include "leveldb/write_batch.h" @@ -80,8 +80,8 @@ static void AddTargetCount(LevelDbTransaction *transaction) { FSTPBTargetGlobal *targetGlobal = [FSTLevelDBQueryCache readTargetMetadataWithTransaction:transaction]; - FSTCAssert(targetGlobal != nil, - @"We should have a metadata row as it was added in an earlier migration"); + HARD_ASSERT(targetGlobal != nil, + "We should have a metadata row as it was added in an earlier migration"); targetGlobal.targetCount = count; transaction->Put([FSTLevelDBTargetGlobalKey key], targetGlobal); } diff --git a/Firestore/Source/Local/FSTLevelDBMutationQueue.mm b/Firestore/Source/Local/FSTLevelDBMutationQueue.mm index 2c9f68d..3b4687c 100644 --- a/Firestore/Source/Local/FSTLevelDBMutationQueue.mm +++ b/Firestore/Source/Local/FSTLevelDBMutationQueue.mm @@ -27,12 +27,12 @@ #import "Firestore/Source/Local/FSTLocalSerializer.h" #import "Firestore/Source/Model/FSTMutation.h" #import "Firestore/Source/Model/FSTMutationBatch.h" -#import "Firestore/Source/Util/FSTAssert.h" #include "Firestore/core/src/firebase/firestore/auth/user.h" #include "Firestore/core/src/firebase/firestore/local/leveldb_transaction.h" #include "Firestore/core/src/firebase/firestore/model/document_key.h" #include "Firestore/core/src/firebase/firestore/model/resource_path.h" +#include "Firestore/core/src/firebase/firestore/util/hard_assert.h" #include "Firestore/core/src/firebase/firestore/util/string_apple.h" #include "Firestore/core/src/firebase/firestore/util/string_util.h" #include "absl/strings/match.h" @@ -120,7 +120,7 @@ using leveldb::WriteOptions; } else { FSTBatchID lastAcked = metadata.lastAcknowledgedBatchId; if (lastAcked >= nextBatchID) { - FSTAssert([self isEmpty], @"Reset nextBatchID is only possible when the queue is empty"); + HARD_ASSERT([self isEmpty], "Reset nextBatchID is only possible when the queue is empty"); lastAcked = kFSTBatchIDUnknown; metadata.lastAcknowledgedBatchId = lastAcked; @@ -184,7 +184,7 @@ using leveldb::WriteOptions; // In all the cases above there was at least one row for the current user and each case has // set things up such that iterator points to it. if (![rowKey decodeKey:it->key()]) { - FSTFail(@"There should have been a key previous to %s", userEnd.c_str()); + HARD_FAIL("There should have been a key previous to %s", userEnd); } if (rowKey.batchID > maxBatchID) { @@ -215,8 +215,8 @@ using leveldb::WriteOptions; - (void)acknowledgeBatch:(FSTMutationBatch *)batch streamToken:(nullable NSData *)streamToken { FSTBatchID batchID = batch.batchID; - FSTAssert(batchID > self.highestAcknowledgedBatchID, - @"Mutation batchIDs must be acknowledged in order"); + HARD_ASSERT(batchID > self.highestAcknowledgedBatchID, + "Mutation batchIDs must be acknowledged in order"); FSTPBMutationQueue *metadata = self.metadata; metadata.lastAcknowledgedBatchId = batchID; @@ -248,8 +248,7 @@ using leveldb::WriteOptions; } else if (status.IsNotFound()) { return nil; } else { - FSTFail(@"metadataForKey: failed loading key %s with status: %s", key.c_str(), - status.ToString().c_str()); + HARD_FAIL("metadataForKey: failed loading key %s with status: %s", key, status.ToString()); } } @@ -290,8 +289,8 @@ using leveldb::WriteOptions; if (status.IsNotFound()) { return nil; } - FSTFail(@"Lookup mutation batch (%@, %d) failed with status: %s", self.userID, batchID, - status.ToString().c_str()); + HARD_FAIL("Lookup mutation batch (%s, %s) failed with status: %s", self.userID, batchID, + status.ToString()); } return [self decodedMutationBatch:value]; @@ -318,7 +317,7 @@ using leveldb::WriteOptions; return nil; } - FSTAssert(rowKey.batchID >= nextBatchID, @"Should have found mutation after %d", nextBatchID); + HARD_ASSERT(rowKey.batchID >= nextBatchID, "Should have found mutation after %s", nextBatchID); return [self decodedMutationBatch:it->value()]; } @@ -385,9 +384,9 @@ using leveldb::WriteOptions; if (mutationIterator->Valid()) { foundKeyDescription = [FSTLevelDBKey descriptionForKey:mutationIterator->key()]; } - FSTFail( - @"Dangling document-mutation reference found: " - @"%@ points to %@; seeking there found %@", + HARD_FAIL( + "Dangling document-mutation reference found: " + "%s points to %s; seeking there found %s", [FSTLevelDBKey descriptionForKey:indexIterator->key()], [FSTLevelDBKey descriptionForKey:mutationKey], foundKeyDescription); } @@ -398,7 +397,7 @@ using leveldb::WriteOptions; } - (NSArray<FSTMutationBatch *> *)allMutationBatchesAffectingQuery:(FSTQuery *)query { - FSTAssert(![query isDocumentQuery], @"Document queries shouldn't go down this path"); + HARD_ASSERT(![query isDocumentQuery], "Document queries shouldn't go down this path"); NSString *userID = self.userID; const ResourcePath &queryPath = query.path; @@ -460,9 +459,9 @@ using leveldb::WriteOptions; if (mutationIterator->Valid()) { foundKeyDescription = [FSTLevelDBKey descriptionForKey:mutationIterator->key()]; } - FSTFail( - @"Dangling document-mutation reference found: " - @"Missing batch %@; seeking there found %@", + HARD_FAIL( + "Dangling document-mutation reference found: " + "Missing batch %s; seeking there found %s", [FSTLevelDBKey descriptionForKey:mutationKey], foundKeyDescription); } @@ -497,12 +496,12 @@ using leveldb::WriteOptions; // As a sanity check, verify that the mutation batch exists before deleting it. checkIterator->Seek(key); - FSTAssert(checkIterator->Valid(), @"Mutation batch %@ did not exist", - [FSTLevelDBKey descriptionForKey:key]); + HARD_ASSERT(checkIterator->Valid(), "Mutation batch %s did not exist", + [FSTLevelDBKey descriptionForKey:key]); - FSTAssert(key == checkIterator->key(), @"Mutation batch %@ not found; found %@", - [FSTLevelDBKey descriptionForKey:key], - [FSTLevelDBKey descriptionForKey:checkIterator->key()]); + HARD_ASSERT(key == checkIterator->key(), "Mutation batch %s not found; found %s", + [FSTLevelDBKey descriptionForKey:key], + [FSTLevelDBKey descriptionForKey:checkIterator->key()]); _db.currentTransaction->Delete(key); @@ -538,10 +537,10 @@ using leveldb::WriteOptions; [danglingMutationReferences addObject:[FSTLevelDBKey descriptionForKey:indexIterator->key()]]; } - FSTAssert(danglingMutationReferences.count == 0, - @"Document leak -- detected dangling mutation references when queue " - @"is empty. Dangling keys: %@", - danglingMutationReferences); + HARD_ASSERT(danglingMutationReferences.count == 0, + "Document leak -- detected dangling mutation references when queue " + "is empty. Dangling keys: %s", + danglingMutationReferences); } - (std::string)mutationKeyForBatch:(FSTMutationBatch *)batch { @@ -560,7 +559,7 @@ using leveldb::WriteOptions; NSError *error; FSTPBMutationQueue *proto = [FSTPBMutationQueue parseFromData:data error:&error]; if (!proto) { - FSTFail(@"FSTPBMutationQueue failed to parse: %@", error); + HARD_FAIL("FSTPBMutationQueue failed to parse: %s", error); } return proto; @@ -574,7 +573,7 @@ using leveldb::WriteOptions; NSError *error; FSTPBWriteBatch *proto = [FSTPBWriteBatch parseFromData:data error:&error]; if (!proto) { - FSTFail(@"FSTPBMutationBatch failed to parse: %@", error); + HARD_FAIL("FSTPBMutationBatch failed to parse: %s", error); } return [self.serializer decodedMutationBatch:proto]; diff --git a/Firestore/Source/Local/FSTLevelDBQueryCache.mm b/Firestore/Source/Local/FSTLevelDBQueryCache.mm index 68b6f98..f28370a 100644 --- a/Firestore/Source/Local/FSTLevelDBQueryCache.mm +++ b/Firestore/Source/Local/FSTLevelDBQueryCache.mm @@ -26,10 +26,10 @@ #import "Firestore/Source/Local/FSTLevelDBKey.h" #import "Firestore/Source/Local/FSTLocalSerializer.h" #import "Firestore/Source/Local/FSTQueryData.h" -#import "Firestore/Source/Util/FSTAssert.h" #include "Firestore/core/src/firebase/firestore/model/document_key.h" #include "Firestore/core/src/firebase/firestore/model/snapshot_version.h" +#include "Firestore/core/src/firebase/firestore/util/hard_assert.h" #include "absl/strings/match.h" NS_ASSUME_NONNULL_BEGIN @@ -70,8 +70,7 @@ using firebase::firestore::model::DocumentKeySet; if (status.IsNotFound()) { return nil; } else if (!status.ok()) { - FSTFail(@"metadataForKey: failed loading key %s with status: %s", key.c_str(), - status.ToString().c_str()); + HARD_FAIL("metadataForKey: failed loading key %s with status: %s", key, status.ToString()); } NSData *data = @@ -80,7 +79,7 @@ using firebase::firestore::model::DocumentKeySet; NSError *error; FSTPBTargetGlobal *proto = [FSTPBTargetGlobal parseFromData:data error:&error]; if (!proto) { - FSTFail(@"FSTPBTargetGlobal failed to parse: %@", error); + HARD_FAIL("FSTPBTargetGlobal failed to parse: %s", error); } return proto; @@ -93,8 +92,7 @@ using firebase::firestore::model::DocumentKeySet; if (status.IsNotFound()) { return nil; } else if (!status.ok()) { - FSTFail(@"metadataForKey: failed loading key %s with status: %s", key.c_str(), - status.ToString().c_str()); + HARD_FAIL("metadataForKey: failed loading key %s with status: %s", key, status.ToString()); } NSData *data = @@ -103,7 +101,7 @@ using firebase::firestore::model::DocumentKeySet; NSError *error; FSTPBTargetGlobal *proto = [FSTPBTargetGlobal parseFromData:data error:&error]; if (!proto) { - FSTFail(@"FSTPBTargetGlobal failed to parse: %@", error); + HARD_FAIL("FSTPBTargetGlobal failed to parse: %s", error); } return proto; @@ -111,7 +109,7 @@ using firebase::firestore::model::DocumentKeySet; - (instancetype)initWithDB:(FSTLevelDB *)db serializer:(FSTLocalSerializer *)serializer { if (self = [super init]) { - FSTAssert(db, @"db must not be NULL"); + HARD_ASSERT(db, "db must not be NULL"); _db = db; _serializer = serializer; } @@ -121,9 +119,9 @@ using firebase::firestore::model::DocumentKeySet; - (void)start { // TODO(gsoltis): switch this usage of ptr to currentTransaction FSTPBTargetGlobal *metadata = [FSTLevelDBQueryCache readTargetMetadataFromDB:_db.ptr]; - FSTAssert( + HARD_ASSERT( metadata != nil, - @"Found nil metadata, expected schema to be at version 0 which ensures metadata existence"); + "Found nil metadata, expected schema to be at version 0 which ensures metadata existence"); _lastRemoteSnapshotVersion = [self.serializer decodedVersion:metadata.lastRemoteSnapshotVersion]; self.metadata = metadata; @@ -224,7 +222,7 @@ using firebase::firestore::model::DocumentKeySet; NSError *error; FSTPBTarget *proto = [FSTPBTarget parseFromData:data error:&error]; if (!proto) { - FSTFail(@"FSTPBTarget failed to parse: %@", error); + HARD_FAIL("FSTPBTarget failed to parse: %s", error); } return [self.serializer decodedQueryData:proto]; @@ -263,9 +261,9 @@ using firebase::firestore::model::DocumentKeySet; if (targetIterator->Valid()) { foundKeyDescription = [FSTLevelDBKey descriptionForKey:targetIterator->key()]; } - FSTFail( - @"Dangling query-target reference found: " - @"%@ points to %@; seeking there found %@", + HARD_FAIL( + "Dangling query-target reference found: " + "%s points to %s; seeking there found %s", [FSTLevelDBKey descriptionForKey:indexItererator->key()], [FSTLevelDBKey descriptionForKey:targetKey], foundKeyDescription); } diff --git a/Firestore/Source/Local/FSTLevelDBRemoteDocumentCache.mm b/Firestore/Source/Local/FSTLevelDBRemoteDocumentCache.mm index f655e3a..534d2a4 100644 --- a/Firestore/Source/Local/FSTLevelDBRemoteDocumentCache.mm +++ b/Firestore/Source/Local/FSTLevelDBRemoteDocumentCache.mm @@ -26,10 +26,10 @@ #import "Firestore/Source/Model/FSTDocument.h" #import "Firestore/Source/Model/FSTDocumentDictionary.h" #import "Firestore/Source/Model/FSTDocumentSet.h" -#import "Firestore/Source/Util/FSTAssert.h" #include "Firestore/core/src/firebase/firestore/local/leveldb_transaction.h" #include "Firestore/core/src/firebase/firestore/model/document_key.h" +#include "Firestore/core/src/firebase/firestore/util/hard_assert.h" #include "leveldb/db.h" #include "leveldb/write_batch.h" @@ -77,8 +77,8 @@ using leveldb::Status; } else if (status.ok()) { return [self decodeMaybeDocument:value withKey:documentKey]; } else { - FSTFail(@"Fetch document for key (%s) failed with status: %s", documentKey.ToString().c_str(), - status.ToString().c_str()); + HARD_FAIL("Fetch document for key (%s) failed with status: %s", documentKey.ToString(), + status.ToString()); } } @@ -118,13 +118,13 @@ using leveldb::Status; NSError *error; FSTPBMaybeDocument *proto = [FSTPBMaybeDocument parseFromData:data error:&error]; if (!proto) { - FSTFail(@"FSTPBMaybeDocument failed to parse: %@", error); + HARD_FAIL("FSTPBMaybeDocument failed to parse: %s", error); } FSTMaybeDocument *maybeDocument = [self.serializer decodedMaybeDocument:proto]; - FSTAssert([maybeDocument.key isEqualToKey:documentKey], - @"Read document has key (%s) instead of expected key (%s).", - maybeDocument.key.ToString().c_str(), documentKey.ToString().c_str()); + HARD_ASSERT([maybeDocument.key isEqualToKey:documentKey], + "Read document has key (%s) instead of expected key (%s).", + maybeDocument.key.ToString(), documentKey.ToString()); return maybeDocument; } diff --git a/Firestore/Source/Local/FSTLocalDocumentsView.mm b/Firestore/Source/Local/FSTLocalDocumentsView.mm index 471840a..48c963e 100644 --- a/Firestore/Source/Local/FSTLocalDocumentsView.mm +++ b/Firestore/Source/Local/FSTLocalDocumentsView.mm @@ -23,11 +23,11 @@ #import "Firestore/Source/Model/FSTDocumentDictionary.h" #import "Firestore/Source/Model/FSTMutation.h" #import "Firestore/Source/Model/FSTMutationBatch.h" -#import "Firestore/Source/Util/FSTAssert.h" #include "Firestore/core/src/firebase/firestore/model/document_key.h" #include "Firestore/core/src/firebase/firestore/model/resource_path.h" #include "Firestore/core/src/firebase/firestore/model/snapshot_version.h" +#include "Firestore/core/src/firebase/firestore/util/hard_assert.h" using firebase::firestore::model::DocumentKey; using firebase::firestore::model::ResourcePath; @@ -178,7 +178,7 @@ NS_ASSUME_NONNULL_BEGIN } else if ([mutatedDoc isKindOfClass:[FSTDocument class]]) { result = [result dictionaryBySettingObject:(FSTDocument *)mutatedDoc forKey:key]; } else { - FSTFail(@"Unknown document: %@", mutatedDoc); + HARD_FAIL("Unknown document: %s", mutatedDoc); } }]; return result; diff --git a/Firestore/Source/Local/FSTLocalSerializer.mm b/Firestore/Source/Local/FSTLocalSerializer.mm index 2c5ab4d..662419a 100644 --- a/Firestore/Source/Local/FSTLocalSerializer.mm +++ b/Firestore/Source/Local/FSTLocalSerializer.mm @@ -29,11 +29,11 @@ #import "Firestore/Source/Model/FSTFieldValue.h" #import "Firestore/Source/Model/FSTMutationBatch.h" #import "Firestore/Source/Remote/FSTSerializerBeta.h" -#import "Firestore/Source/Util/FSTAssert.h" #include "Firestore/core/include/firebase/firestore/timestamp.h" #include "Firestore/core/src/firebase/firestore/model/document_key.h" #include "Firestore/core/src/firebase/firestore/model/snapshot_version.h" +#include "Firestore/core/src/firebase/firestore/util/hard_assert.h" using firebase::Timestamp; using firebase::firestore::model::DocumentKey; @@ -64,7 +64,7 @@ using firebase::firestore::model::SnapshotVersion; } else if ([document isKindOfClass:[FSTDocument class]]) { proto.document = [self encodedDocument:(FSTDocument *)document]; } else { - FSTFail(@"Unknown document type %@", NSStringFromClass([document class])); + HARD_FAIL("Unknown document type %s", NSStringFromClass([document class])); } return proto; @@ -79,7 +79,7 @@ using firebase::firestore::model::SnapshotVersion; return [self decodedDeletedDocument:proto.noDocument]; default: - FSTFail(@"Unknown MaybeDocument %@", proto); + HARD_FAIL("Unknown MaybeDocument %s", proto); } } @@ -164,9 +164,9 @@ using firebase::firestore::model::SnapshotVersion; - (FSTPBTarget *)encodedQueryData:(FSTQueryData *)queryData { FSTSerializerBeta *remoteSerializer = self.remoteSerializer; - FSTAssert(queryData.purpose == FSTQueryPurposeListen, - @"only queries with purpose %lu may be stored, got %lu", - (unsigned long)FSTQueryPurposeListen, (unsigned long)queryData.purpose); + HARD_ASSERT(queryData.purpose == FSTQueryPurposeListen, + "only queries with purpose %s may be stored, got %s", FSTQueryPurposeListen, + queryData.purpose); FSTPBTarget *proto = [FSTPBTarget message]; proto.targetId = queryData.targetID; @@ -203,7 +203,7 @@ using firebase::firestore::model::SnapshotVersion; break; default: - FSTFail(@"Unknown Target.targetType %" PRId32, target.targetTypeOneOfCase); + HARD_FAIL("Unknown Target.targetType %s", target.targetTypeOneOfCase); } return [[FSTQueryData alloc] initWithQuery:query diff --git a/Firestore/Source/Local/FSTLocalStore.mm b/Firestore/Source/Local/FSTLocalStore.mm index 245dd62..7469c71 100644 --- a/Firestore/Source/Local/FSTLocalStore.mm +++ b/Firestore/Source/Local/FSTLocalStore.mm @@ -36,12 +36,12 @@ #import "Firestore/Source/Model/FSTMutation.h" #import "Firestore/Source/Model/FSTMutationBatch.h" #import "Firestore/Source/Remote/FSTRemoteEvent.h" -#import "Firestore/Source/Util/FSTAssert.h" #include "Firestore/core/src/firebase/firestore/auth/user.h" #include "Firestore/core/src/firebase/firestore/core/target_id_generator.h" #include "Firestore/core/src/firebase/firestore/model/document_key.h" #include "Firestore/core/src/firebase/firestore/model/snapshot_version.h" +#include "Firestore/core/src/firebase/firestore/util/hard_assert.h" #include "Firestore/core/src/firebase/firestore/util/log.h" using firebase::firestore::auth::User; @@ -236,10 +236,10 @@ NS_ASSUME_NONNULL_BEGIN - (FSTMaybeDocumentDictionary *)rejectBatchID:(FSTBatchID)batchID { return self.persistence.run("Reject batch", [&]() -> FSTMaybeDocumentDictionary * { FSTMutationBatch *toReject = [self.mutationQueue lookupMutationBatch:batchID]; - FSTAssert(toReject, @"Attempt to reject nonexistent batch!"); + HARD_ASSERT(toReject, "Attempt to reject nonexistent batch!"); FSTBatchID lastAcked = [self.mutationQueue highestAcknowledgedBatchID]; - FSTAssert(batchID > lastAcked, @"Acknowledged batches can't be rejected."); + HARD_ASSERT(batchID > lastAcked, "Acknowledged batches can't be rejected."); DocumentKeySet affected = [self removeMutationBatch:toReject]; @@ -304,7 +304,7 @@ NS_ASSUME_NONNULL_BEGIN [queryCache addMatchingKeys:update.addedDocuments forTargetID:targetID]; } else { - FSTFail(@"Unknown mapping type: %@", mapping); + HARD_FAIL("Unknown mapping type: %s", mapping); } } }]; @@ -345,10 +345,9 @@ NS_ASSUME_NONNULL_BEGIN const SnapshotVersion &lastRemoteVersion = [self.queryCache lastRemoteSnapshotVersion]; const SnapshotVersion &remoteVersion = remoteEvent.snapshotVersion; if (remoteVersion != SnapshotVersion::None()) { - FSTAssert(remoteVersion >= lastRemoteVersion, - @"Watch stream reverted to previous snapshot?? (%s < %s)", - remoteVersion.timestamp().ToString().c_str(), - lastRemoteVersion.timestamp().ToString().c_str()); + HARD_ASSERT(remoteVersion >= lastRemoteVersion, + "Watch stream reverted to previous snapshot?? (%s < %s)", + remoteVersion.timestamp().ToString(), lastRemoteVersion.timestamp().ToString()); [self.queryCache setLastRemoteSnapshotVersion:remoteVersion]; } @@ -369,7 +368,7 @@ NS_ASSUME_NONNULL_BEGIN FSTReferenceSet *localViewReferences = self.localViewReferences; for (FSTLocalViewChanges *view in viewChanges) { FSTQueryData *queryData = [self.queryCache queryDataForQuery:view.query]; - FSTAssert(queryData, @"Local view changes contain unallocated query."); + HARD_ASSERT(queryData, "Local view changes contain unallocated query."); FSTTargetID targetID = queryData.targetID; for (const DocumentKey &key : view.removedKeys) { [self->_persistence.referenceDelegate removeReference:key target:targetID]; @@ -409,8 +408,8 @@ NS_ASSUME_NONNULL_BEGIN }); // Sanity check to ensure that even when resuming a query it's not currently active. FSTBoxedTargetID *boxedTargetID = @(queryData.targetID); - FSTAssert(!self.targetIDs[boxedTargetID], @"Tried to allocate an already allocated query: %@", - query); + HARD_ASSERT(!self.targetIDs[boxedTargetID], "Tried to allocate an already allocated query: %s", + query); self.targetIDs[boxedTargetID] = queryData; return queryData; } @@ -418,7 +417,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)releaseQuery:(FSTQuery *)query { self.persistence.run("Release query", [&]() { FSTQueryData *queryData = [self.queryCache queryDataForQuery:query]; - FSTAssert(queryData, @"Tried to release nonexistent query: %@", query); + HARD_ASSERT(queryData, "Tried to release nonexistent query: %s", query); [self.localViewReferences removeReferencesForID:queryData.targetID]; if (self.garbageCollector.isEager) { @@ -530,14 +529,14 @@ NS_ASSUME_NONNULL_BEGIN FSTMaybeDocument *_Nullable doc = remoteDoc; auto ackVersionIter = versions.find(docKey); - FSTAssert(ackVersionIter != versions.end(), - @"docVersions should contain every doc in the write."); + HARD_ASSERT(ackVersionIter != versions.end(), + "docVersions should contain every doc in the write."); const SnapshotVersion &ackVersion = ackVersionIter->second; if (!doc || doc.version < ackVersion) { doc = [batch applyTo:doc documentKey:docKey mutationBatchResult:batchResult]; if (!doc) { - FSTAssert(!remoteDoc, @"Mutation batch %@ applied to document %@ resulted in nil.", batch, - remoteDoc); + HARD_ASSERT(!remoteDoc, "Mutation batch %s applied to document %s resulted in nil.", batch, + remoteDoc); } else { [self.remoteDocumentCache addEntry:doc]; } diff --git a/Firestore/Source/Local/FSTMemoryMutationQueue.mm b/Firestore/Source/Local/FSTMemoryMutationQueue.mm index e05ee64..8faf893 100644 --- a/Firestore/Source/Local/FSTMemoryMutationQueue.mm +++ b/Firestore/Source/Local/FSTMemoryMutationQueue.mm @@ -21,11 +21,11 @@ #import "Firestore/Source/Local/FSTMemoryPersistence.h" #import "Firestore/Source/Model/FSTMutation.h" #import "Firestore/Source/Model/FSTMutationBatch.h" -#import "Firestore/Source/Util/FSTAssert.h" #import "Firestore/third_party/Immutable/FSTImmutableSortedSet.h" #include "Firestore/core/src/firebase/firestore/model/document_key.h" #include "Firestore/core/src/firebase/firestore/model/resource_path.h" +#include "Firestore/core/src/firebase/firestore/util/hard_assert.h" using firebase::firestore::model::DocumentKey; using firebase::firestore::model::ResourcePath; @@ -102,8 +102,8 @@ static const NSComparator NumberComparator = ^NSComparisonResult(NSNumber *left, self.nextBatchID = 1; self.highestAcknowledgedBatchID = kFSTBatchIDUnknown; } - FSTAssert(self.highestAcknowledgedBatchID < self.nextBatchID, - @"highestAcknowledgedBatchID must be less than the nextBatchID"); + HARD_ASSERT(self.highestAcknowledgedBatchID < self.nextBatchID, + "highestAcknowledgedBatchID must be less than the nextBatchID"); } - (BOOL)isEmpty { @@ -120,16 +120,16 @@ static const NSComparator NumberComparator = ^NSComparisonResult(NSNumber *left, NSMutableArray<FSTMutationBatch *> *queue = self.queue; FSTBatchID batchID = batch.batchID; - FSTAssert(batchID > self.highestAcknowledgedBatchID, - @"Mutation batchIDs must be acknowledged in order"); + HARD_ASSERT(batchID > self.highestAcknowledgedBatchID, + "Mutation batchIDs must be acknowledged in order"); NSInteger batchIndex = [self indexOfExistingBatchID:batchID action:@"acknowledged"]; // Verify that the batch in the queue is the one to be acknowledged. FSTMutationBatch *check = queue[(NSUInteger)batchIndex]; - FSTAssert(batchID == check.batchID, @"Queue ordering failure: expected batch %d, got batch %d", - batchID, check.batchID); - FSTAssert(![check isTombstone], @"Can't acknowledge a previously removed batch"); + HARD_ASSERT(batchID == check.batchID, "Queue ordering failure: expected batch %s, got batch %s", + batchID, check.batchID); + HARD_ASSERT(![check isTombstone], "Can't acknowledge a previously removed batch"); self.highestAcknowledgedBatchID = batchID; self.lastStreamToken = streamToken; @@ -137,7 +137,7 @@ static const NSComparator NumberComparator = ^NSComparisonResult(NSNumber *left, - (FSTMutationBatch *)addMutationBatchWithWriteTime:(FIRTimestamp *)localWriteTime mutations:(NSArray<FSTMutation *> *)mutations { - FSTAssert(mutations.count > 0, @"Mutation batches should not be empty"); + HARD_ASSERT(mutations.count > 0, "Mutation batches should not be empty"); FSTBatchID batchID = self.nextBatchID; self.nextBatchID += 1; @@ -145,7 +145,8 @@ static const NSComparator NumberComparator = ^NSComparisonResult(NSNumber *left, NSMutableArray<FSTMutationBatch *> *queue = self.queue; if (queue.count > 0) { FSTMutationBatch *prior = queue[queue.count - 1]; - FSTAssert(prior.batchID < batchID, @"Mutation batchIDs must be monotonically increasing order"); + HARD_ASSERT(prior.batchID < batchID, + "Mutation batchIDs must be monotonically increasing order"); } FSTMutationBatch *batch = [[FSTMutationBatch alloc] initWithBatchID:batchID @@ -173,7 +174,7 @@ static const NSComparator NumberComparator = ^NSComparisonResult(NSNumber *left, } FSTMutationBatch *batch = queue[(NSUInteger)index]; - FSTAssert(batch.batchID == batchID, @"If found batch must match"); + HARD_ASSERT(batch.batchID == batchID, "If found batch must match"); return [batch isTombstone] ? nil : batch; } @@ -233,7 +234,7 @@ static const NSComparator NumberComparator = ^NSComparisonResult(NSNumber *left, } FSTMutationBatch *batch = [self lookupMutationBatch:reference.ID]; - FSTAssert(batch, @"Batches in the index must exist in the main table"); + HARD_ASSERT(batch, "Batches in the index must exist in the main table"); [result addObject:batch]; }; @@ -292,7 +293,7 @@ static const NSComparator NumberComparator = ^NSComparisonResult(NSNumber *left, - (void)removeMutationBatches:(NSArray<FSTMutationBatch *> *)batches { NSUInteger batchCount = batches.count; - FSTAssert(batchCount > 0, @"Should not remove mutations when none exist."); + HARD_ASSERT(batchCount > 0, "Should not remove mutations when none exist."); FSTBatchID firstBatchID = batches[0].batchID; @@ -302,7 +303,7 @@ static const NSComparator NumberComparator = ^NSComparisonResult(NSNumber *left, // Find the position of the first batch for removal. This need not be the first entry in the // queue. NSUInteger startIndex = [self indexOfExistingBatchID:firstBatchID action:@"removed"]; - FSTAssert(queue[startIndex].batchID == firstBatchID, @"Removed batches must exist in the queue"); + HARD_ASSERT(queue[startIndex].batchID == firstBatchID, "Removed batches must exist in the queue"); // Check that removed batches are contiguous (while excluding tombstones). NSUInteger batchIndex = 1; @@ -314,8 +315,8 @@ static const NSComparator NumberComparator = ^NSComparisonResult(NSNumber *left, continue; } - FSTAssert(batch.batchID == batches[batchIndex].batchID, - @"Removed batches must be contiguous in the queue"); + HARD_ASSERT(batch.batchID == batches[batchIndex].batchID, + "Removed batches must be contiguous in the queue"); batchIndex++; queueIndex++; } @@ -359,8 +360,8 @@ static const NSComparator NumberComparator = ^NSComparisonResult(NSNumber *left, - (void)performConsistencyCheck { if (self.queue.count == 0) { - FSTAssert([self.batchesByDocumentKey isEmpty], - @"Document leak -- detected dangling mutation references when queue is empty."); + HARD_ASSERT([self.batchesByDocumentKey isEmpty], + "Document leak -- detected dangling mutation references when queue is empty."); } } @@ -431,7 +432,7 @@ static const NSComparator NumberComparator = ^NSComparisonResult(NSNumber *left, */ - (NSUInteger)indexOfExistingBatchID:(FSTBatchID)batchID action:(NSString *)action { NSInteger index = [self indexOfBatchID:batchID]; - FSTAssert(index >= 0 && index < self.queue.count, @"Batches must exist to be %@", action); + HARD_ASSERT(index >= 0 && index < self.queue.count, "Batches must exist to be %s", action); return (NSUInteger)index; } diff --git a/Firestore/Source/Local/FSTMemoryPersistence.mm b/Firestore/Source/Local/FSTMemoryPersistence.mm index 3466f3e..5e35aa4 100644 --- a/Firestore/Source/Local/FSTMemoryPersistence.mm +++ b/Firestore/Source/Local/FSTMemoryPersistence.mm @@ -21,9 +21,9 @@ #import "Firestore/Source/Local/FSTMemoryMutationQueue.h" #import "Firestore/Source/Local/FSTMemoryQueryCache.h" #import "Firestore/Source/Local/FSTMemoryRemoteDocumentCache.h" -#import "Firestore/Source/Util/FSTAssert.h" #include "Firestore/core/src/firebase/firestore/auth/user.h" +#include "Firestore/core/src/firebase/firestore/util/hard_assert.h" using firebase::firestore::auth::HashUser; using firebase::firestore::auth::User; @@ -67,14 +67,14 @@ NS_ASSUME_NONNULL_BEGIN - (BOOL)start:(NSError **)error { // No durable state to read on startup. - FSTAssert(!self.isStarted, @"FSTMemoryPersistence double-started!"); + HARD_ASSERT(!self.isStarted, "FSTMemoryPersistence double-started!"); self.started = YES; return YES; } - (void)shutdown { // No durable state to ensure is closed on shutdown. - FSTAssert(self.isStarted, @"FSTMemoryPersistence shutdown without start!"); + HARD_ASSERT(self.isStarted, "FSTMemoryPersistence shutdown without start!"); self.started = NO; } diff --git a/Firestore/Source/Local/FSTPersistence.h b/Firestore/Source/Local/FSTPersistence.h index 417ff3f..a2ce76f 100644 --- a/Firestore/Source/Local/FSTPersistence.h +++ b/Firestore/Source/Local/FSTPersistence.h @@ -17,8 +17,9 @@ #import <Foundation/Foundation.h> #import "Firestore/Source/Core/FSTTypes.h" -#import "Firestore/Source/Util/FSTAssert.h" + #include "Firestore/core/src/firebase/firestore/auth/user.h" +#include "Firestore/core/src/firebase/firestore/util/hard_assert.h" @class FSTDocumentKey; @protocol FSTMutationQueue; @@ -181,7 +182,7 @@ struct FSTTransactionRunner { typename std::enable_if<std::is_void<decltype(block())>::value, void>::type { __strong id<FSTTransactional> strongDb = _db; if (!strongDb && _expect_db) { - FSTCFail(@"Transaction runner accessed without underlying db when it expected one"); + HARD_FAIL("Transaction runner accessed without underlying db when it expected one"); } if (strongDb) { [strongDb startTransaction:label]; @@ -198,7 +199,7 @@ struct FSTTransactionRunner { using ReturnT = decltype(block()); __strong id<FSTTransactional> strongDb = _db; if (!strongDb && _expect_db) { - FSTCFail(@"Transaction runner accessed without underlying db when it expected one"); + HARD_FAIL("Transaction runner accessed without underlying db when it expected one"); } if (strongDb) { [strongDb startTransaction:label]; |