Skip to content

Commit 295d29b

Browse files
WIP Write Stream recovery with stream token
This is just a proof of concept. DO NOT MERGE.
1 parent b9b5a43 commit 295d29b

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

packages/firestore/src/remote/remote_store.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,11 @@ export class RemoteStore implements TargetMetadataProvider {
199199

200200
private async enableNetworkInternal(): Promise<void> {
201201
if (this.canUseNetwork()) {
202-
this.writeStream.lastStreamToken = await this.localStore.getLastStreamToken();
202+
try {
203+
this.writeStream.lastStreamToken = await this.localStore.getLastStreamToken();
204+
} catch (e) {
205+
return this.disableNetworkUntilRecovery(e);
206+
}
203207

204208
if (this.shouldStartWatchStream()) {
205209
this.startWatchStream();
@@ -667,7 +671,12 @@ export class RemoteStore implements TargetMetadataProvider {
667671
this.writeStream.writeMutations(batch.mutations);
668672
}
669673
})
670-
.catch(ignoreIfPrimaryLeaseLoss);
674+
.catch(ignoreIfPrimaryLeaseLoss)
675+
.catch(e =>
676+
this.disableNetworkUntilRecovery(e, () =>
677+
this.localStore.setLastStreamToken(this.writeStream.lastStreamToken)
678+
)
679+
);
671680
}
672681

673682
private async onMutationResult(
@@ -744,7 +753,12 @@ export class RemoteStore implements TargetMetadataProvider {
744753

745754
return this.localStore
746755
.setLastStreamToken(ByteString.EMPTY_BYTE_STRING)
747-
.catch(ignoreIfPrimaryLeaseLoss);
756+
.catch(ignoreIfPrimaryLeaseLoss)
757+
.catch(e =>
758+
this.disableNetworkUntilRecovery(e, () =>
759+
this.localStore.setLastStreamToken(ByteString.EMPTY_BYTE_STRING)
760+
)
761+
);
748762
} else {
749763
// Some other error, don't reset stream token. Our stream logic will
750764
// just retry with exponential backoff.

0 commit comments

Comments
 (0)