Skip to content

Commit

Permalink
Adding more logs around mutations and acks
Browse files Browse the repository at this point in the history
  • Loading branch information
wu-hui committed May 17, 2024
1 parent 61c10bc commit 6bab86f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
11 changes: 11 additions & 0 deletions Firestore/Swift/Tests/Integration/QueryIntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,17 @@ class QueryIntegrationTests: FSTIntegrationTestCase {
matchesResult: ["doc2"])
}

func testFailedWriteBatch() throws {
let batch = db.batch()
.updateData(["a": 1, "b": 0], forDocument: documentRef())
let a = expectation(description: "wait for mutation")
batch.commit { [weak self] err in
XCTAssert(err != nil)
a.fulfill()
}
awaitExpectation(a)
}

func testOrQueriesWithIn() throws {
let collRef = collectionRef(
withDocuments: ["doc1": ["a": 1, "b": 0],
Expand Down
4 changes: 4 additions & 0 deletions Firestore/core/src/core/firestore_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -523,13 +523,17 @@ void FirestoreClient::WriteMutations(std::vector<Mutation>&& mutations,
if (mutations.empty()) {
if (callback) {
user_executor_->Execute([=] { callback(Status::OK()); });
} else {
LOG_WARN("Skipping callback due to empty mutations");
}
} else {
sync_engine_->WriteMutations(
std::move(mutations), [this, callback](Status error) {
// Dispatch the result back onto the user dispatch queue.
if (callback) {
user_executor_->Execute([=] { callback(std::move(error)); });
} else {
LOG_WARN("Skipping callback due to null call back");
}
});
}
Expand Down
11 changes: 9 additions & 2 deletions Firestore/core/src/core/sync_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -408,9 +408,9 @@ void SyncEngine::HandleRejectedWrite(

DocumentMap changes = local_store_->RejectBatch(batch_id);

if (!changes.empty() && ErrorIsInteresting(error)) {
if (!changes.empty()) {
const DocumentKey& min_key = changes.min()->first;
LOG_WARN("Write at %s failed: %s", min_key.ToString(),
LOG_WARN("Write batch %s at %s failed: %s", batch_id, min_key.ToString(),
error.error_message());
}

Expand Down Expand Up @@ -469,6 +469,10 @@ void SyncEngine::NotifyUser(BatchId batch_id, Status status) {
// NOTE: Mutations restored from persistence won't have callbacks, so
// it's okay for this (or the callback below) to not exist.
if (it == mutation_callbacks_.end()) {
if (!status.ok()) {
LOG_WARN("Could not find mutation callback queue for user %s",
current_user_.uid());
}
return;
}

Expand All @@ -477,6 +481,9 @@ void SyncEngine::NotifyUser(BatchId batch_id, Status status) {
if (callback_it != callbacks.end()) {
callback_it->second(std::move(status));
callbacks.erase(callback_it);
} else if (!status.ok()) {
LOG_WARN("Could not find mutation callback for user %s and batch %s",
current_user_.uid(), batch_id);
}
}

Expand Down

0 comments on commit 6bab86f

Please sign in to comment.