Merge pull request #10990 from ClickHouse/odbc-bridge-wait-exp-backoff

Wait for odbc-bridge with exponential backoff
This commit is contained in:
alexey-milovidov 2020-05-18 10:17:59 +03:00 committed by GitHub
commit a316184bef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -151,16 +151,22 @@ public:
LOG_TRACE(log, BridgeHelperMixin::serviceAlias() + " is not running, will try to start it"); LOG_TRACE(log, BridgeHelperMixin::serviceAlias() + " is not running, will try to start it");
startBridge(); startBridge();
bool started = false; bool started = false;
for (size_t counter : ext::range(1, 20))
uint64_t milliseconds_to_wait = 10; /// Exponential backoff
uint64_t counter = 0;
while (milliseconds_to_wait < 10000)
{ {
++counter;
LOG_TRACE(log, "Checking " + BridgeHelperMixin::serviceAlias() + " is running, try " << counter); LOG_TRACE(log, "Checking " + BridgeHelperMixin::serviceAlias() + " is running, try " << counter);
if (checkBridgeIsRunning()) if (checkBridgeIsRunning())
{ {
started = true; started = true;
break; break;
} }
std::this_thread::sleep_for(std::chrono::milliseconds(10)); std::this_thread::sleep_for(std::chrono::milliseconds(milliseconds_to_wait));
milliseconds_to_wait *= 2;
} }
if (!started) if (!started)
throw Exception(BridgeHelperMixin::getName() + "BridgeHelper: " + BridgeHelperMixin::serviceAlias() + " is not responding", throw Exception(BridgeHelperMixin::getName() + "BridgeHelper: " + BridgeHelperMixin::serviceAlias() + " is not responding",
ErrorCodes::EXTERNAL_SERVER_IS_NOT_RESPONDING); ErrorCodes::EXTERNAL_SERVER_IS_NOT_RESPONDING);