@@ -31,6 +31,13 @@ namespace Google.Cloud.Firestore
3131 /// </summary>
3232 public sealed class FirestoreDb
3333 {
34+ private static readonly RetrySettings s_defaultBatchGetDocumentsRetrySettings = RetrySettings . FromExponentialBackoff (
35+ maxAttempts : 5 ,
36+ initialBackoff : TimeSpan . FromMilliseconds ( 100 ) ,
37+ maxBackoff : TimeSpan . FromSeconds ( 60 ) ,
38+ backoffMultiplier : 1.3 ,
39+ retryFilter : RetrySettings . FilterForStatusCodes ( StatusCode . Unavailable , StatusCode . Internal , StatusCode . DeadlineExceeded ) ) ;
40+
3441 private const string DefaultDatabaseId = "(default)" ;
3542
3643 /// <summary>
@@ -62,9 +69,11 @@ public sealed class FirestoreDb
6269
6370 internal SerializationContext SerializationContext { get ; }
6471
65- private readonly CallSettings _batchGetCallSettings ;
72+ private readonly RetrySettings _batchGetDocumentsRetrySettings ;
6673
67- private FirestoreDb ( string projectId , string databaseId , FirestoreClient client , Action < string > warningLogger , SerializationContext serializationContext )
74+ private FirestoreDb (
75+ string projectId , string databaseId , FirestoreClient client , Action < string > warningLogger ,
76+ SerializationContext serializationContext , RetrySettings batchGetDocumentsRetrySettings )
6877 {
6978 ProjectId = GaxPreconditions . CheckNotNull ( projectId , nameof ( projectId ) ) ;
7079 DatabaseId = GaxPreconditions . CheckNotNull ( databaseId , nameof ( databaseId ) ) ;
@@ -74,23 +83,10 @@ private FirestoreDb(string projectId, string databaseId, FirestoreClient client,
7483 DocumentsPath = $ "{ RootPath } /documents";
7584 WarningLogger = warningLogger ;
7685
77- // TODO: Potentially make these configurable.
78- // The retry settings are taken from firestore_grpc_service_config.json.
79- var batchGetRetry = RetrySettings . FromExponentialBackoff (
80- maxAttempts : 5 ,
81- initialBackoff : TimeSpan . FromMilliseconds ( 100 ) ,
82- maxBackoff : TimeSpan . FromSeconds ( 60 ) ,
83- backoffMultiplier : 1.3 ,
84- retryFilter : RetrySettings . FilterForStatusCodes ( StatusCode . Unavailable , StatusCode . Internal , StatusCode . DeadlineExceeded ) ) ;
85- _batchGetCallSettings = CallSettings . FromRetry ( batchGetRetry ) . WithTimeout ( TimeSpan . FromMinutes ( 10 ) ) ;
86-
8786 SerializationContext = GaxPreconditions . CheckNotNull ( serializationContext , nameof ( serializationContext ) ) ;
88- }
8987
90- // Internally, we support non-default databases. The public Create and CreateAsync methods only support the default database,
91- // as that's all the server supports at the moment. When that changes, we'll want to support non-default databases publicly,
92- // but will probably need a different method name in order to do so, to avoid it being a breaking change.
93- // We don't have a CreateAsync method accepting a database ID, as we don't use that anywhere for testing.
88+ _batchGetDocumentsRetrySettings = GaxPreconditions . CheckNotNull ( batchGetDocumentsRetrySettings , nameof ( batchGetDocumentsRetrySettings ) ) ;
89+ }
9490
9591 /// <summary>
9692 /// Creates an instance for the specified project, using the specified <see cref="FirestoreClient"/> for RPC operations.
@@ -129,20 +125,23 @@ public static async Task<FirestoreDb> CreateAsync(string projectId = null, Fires
129125 /// <param name="client">The client to use for RPC operations. Must not be null.</param>
130126 /// <param name="warningLogger">The warning logger to use, if any. May be null.</param>
131127 /// <param name="converterRegistry">A registry of custom converters. May be null.</param>
128+ /// <param name="batchGetDocumentsRetrySettings">The retry settings for batch document fetching operations. May be null.</param>
132129 /// <returns>A new instance.</returns>
133130 internal static FirestoreDb Create (
134131 // Required parameters
135132 string projectId , string databaseId , FirestoreClient client ,
136133 // Optional parameters
137134 Action < string > warningLogger = null ,
138- ConverterRegistry converterRegistry = null ) =>
135+ ConverterRegistry converterRegistry = null ,
136+ RetrySettings batchGetDocumentsRetrySettings = null ) =>
139137 // Validation is performed in the constructor.
140138 new FirestoreDb (
141139 projectId ,
142140 databaseId ?? DefaultDatabaseId ,
143141 client ,
144142 warningLogger ,
145- new SerializationContext ( converterRegistry ) ) ;
143+ new SerializationContext ( converterRegistry ) ,
144+ batchGetDocumentsRetrySettings ?? s_defaultBatchGetDocumentsRetrySettings ) ;
146145
147146 /// <summary>
148147 /// Returns a new <see cref="FirestoreDb"/> with the same project, database and client as this one,
@@ -151,7 +150,7 @@ internal static FirestoreDb Create(
151150 /// <param name="warningLogger">The logger for warnings. May be null.</param>
152151 /// <returns>A new <see cref="FirestoreDb"/> based on this one, with the given warning logger.</returns>
153152 public FirestoreDb WithWarningLogger ( Action < string > warningLogger ) =>
154- new FirestoreDb ( ProjectId , DatabaseId , Client , warningLogger , SerializationContext ) ;
153+ new FirestoreDb ( ProjectId , DatabaseId , Client , warningLogger , SerializationContext , _batchGetDocumentsRetrySettings ) ;
155154
156155 internal void LogWarning ( string message ) => WarningLogger ? . Invoke ( message ) ;
157156
@@ -295,7 +294,7 @@ internal async Task<IList<DocumentSnapshot>> GetDocumentSnapshotsAsync(IEnumerab
295294
296295 var clock = Client . Settings . Clock ?? SystemClock . Instance ;
297296 var scheduler = Client . Settings . Scheduler ?? SystemScheduler . Instance ;
298- var callSettings = _batchGetCallSettings . WithCancellationToken ( cancellationToken ) ;
297+ var callSettings = Client . Settings . BatchGetDocumentsSettings . WithCancellationToken ( cancellationToken ) ;
299298
300299 // This is the function that we'll retry. We can't use the built-in retry functionality, because it's not a unary gRPC call.
301300 // (We could potentially simulate a unary call, but it would be a little odd to do so.)
@@ -328,7 +327,7 @@ internal async Task<IList<DocumentSnapshot>> GetDocumentSnapshotsAsync(IEnumerab
328327 return snapshots ;
329328 } ;
330329
331- var retryingTask = RetryHelper . Retry ( function , request , callSettings , clock , scheduler ) ;
330+ var retryingTask = RetryHelper . Retry ( _batchGetDocumentsRetrySettings , function , request , callSettings , clock , scheduler ) ;
332331 return await retryingTask . ConfigureAwait ( false ) ;
333332
334333 string ExtractPath ( DocumentReference documentReference )
@@ -387,7 +386,6 @@ public Task RunTransactionAsync(Func<Transaction, Task> callback, TransactionOpt
387386 /// <returns>A task which completes when the transaction has committed. The result of the task then contains the result of the callback.</returns>
388387 public async Task < T > RunTransactionAsync < T > ( Func < Transaction , Task < T > > callback , TransactionOptions options = null , CancellationToken cancellationToken = default )
389388 {
390-
391389 ByteString previousTransactionId = null ;
392390 options = options ?? TransactionOptions . Default ;
393391 var attemptsLeft = options . MaxAttempts ;
0 commit comments