Skip to content

Commit 1ee3e86

Browse files
authored
impl(spanner): heed any google.rpc.RetryInfo in transaction re-run loop (#13761)
If the service returned a `google.rpc.RetryInfo.retry_delay` in the failing operation that caused `Commit()` to re-run the transaction, use its value instead of the delay provided by the backoff policy. Not tested as we do not (yet) have a mechanism to inject/mock the "sleeper" behavior in the re-run loop.
1 parent 0f71367 commit 1ee3e86

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

google/cloud/spanner/client.cc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,14 @@
2121
#include "google/cloud/spanner/transaction.h"
2222
#include "google/cloud/backoff_policy.h"
2323
#include "google/cloud/credentials.h"
24+
#include "google/cloud/grpc_options.h"
2425
#include "google/cloud/internal/getenv.h"
2526
#include "google/cloud/internal/retry_loop.h"
2627
#include "google/cloud/log.h"
28+
#include "google/cloud/status.h"
2729
#include "absl/types/optional.h"
2830
#include <grpcpp/grpcpp.h>
31+
#include <chrono>
2932
#include <thread>
3033

3134
namespace google {
@@ -293,7 +296,14 @@ StatusOr<CommitResult> Client::Commit(
293296
// so that we have a slightly better chance of avoiding another abort.
294297
txn = MakeReadWriteTransaction(txn, txn_opts);
295298
}
296-
std::this_thread::sleep_for(backoff_policy->OnCompletion());
299+
std::chrono::nanoseconds delay = backoff_policy->OnCompletion();
300+
if (internal::CurrentOptions().get<EnableServerRetriesOption>()) {
301+
if (auto retry_info = internal::GetRetryInfo(status)) {
302+
// Heed the `RetryInfo` from the service.
303+
delay = retry_info->retry_delay();
304+
}
305+
}
306+
std::this_thread::sleep_for(delay);
297307
}
298308
}
299309

0 commit comments

Comments
 (0)