From a83295e3bd5188ac567607cb3e8180f31eba72e7 Mon Sep 17 00:00:00 2001 From: Jingyu Zhou Date: Wed, 19 Apr 2023 16:55:46 -0700 Subject: [PATCH] Add backoff to lookupTenantImpl for commit_proxy_memory_limit_exceeded error --- fdbclient/NativeAPI.actor.cpp | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/fdbclient/NativeAPI.actor.cpp b/fdbclient/NativeAPI.actor.cpp index 9fe52c8570..01a22ecfa4 100644 --- a/fdbclient/NativeAPI.actor.cpp +++ b/fdbclient/NativeAPI.actor.cpp @@ -3444,16 +3444,32 @@ SpanContext generateSpanID(bool transactionTracingSample, SpanContext parentCont ACTOR Future lookupTenantImpl(DatabaseContext* cx, TenantName tenant) { loop { - ++cx->transactionTenantLookupRequests; - choose { - when(wait(cx->onProxiesChanged())) {} - when(GetTenantIdReply rep = wait(basicLoadBalance(cx->getCommitProxies(UseProvisionalProxies::False), - &CommitProxyInterface::getTenantId, - GetTenantIdRequest(tenant, latestVersion), - TaskPriority::DefaultPromiseEndpoint))) { - ++cx->transactionTenantLookupRequestsCompleted; - return rep.tenantId; + try { + double backoff = cx->getBackoff(); + if (backoff > 0.0) { + wait(delay(backoff)); } + + ++cx->transactionTenantLookupRequests; + choose { + when(wait(cx->onProxiesChanged())) {} + when(GetTenantIdReply rep = wait(basicLoadBalance(cx->getCommitProxies(UseProvisionalProxies::False), + &CommitProxyInterface::getTenantId, + GetTenantIdRequest(tenant, latestVersion), + TaskPriority::DefaultPromiseEndpoint))) { + ++cx->transactionTenantLookupRequestsCompleted; + cx->updateBackoff(success()); + return rep.tenantId; + } + } + } catch (Error& e) { + if (e.code() == error_code_commit_proxy_memory_limit_exceeded) { + // Eats commit_proxy_memory_limit_exceeded error from commit proxies + cx->updateBackoff(e); + continue; + } + + throw; } } }