Skip to content

Commit 7a7141d

Browse files
authored
Merge pull request #264 from ydb-platform/fix-discovery
log failed discovery, fix discovery rate on failure
2 parents 5bce112 + 646aa0a commit 7a7141d

3 files changed

Lines changed: 36 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
* logged failed discovery refresh in `checkDiscovery` instead of silently swallowing the exception
2+
* fixed discovery retry rate after a failure: a separate `lastDiscoveryAttempt` timer gates retries by `discoveryInterval()`, so a broken discovery no longer triggers `discover()` on every API request
3+
14
## 1.16.1
25
* added resilient internal endpoint discovery (`YdbPlatform\Ydb\Internal\Discovery`) that always targets the original bootstrap endpoint and recreates the gRPC channel with `force_new` on retries to bust the c-core DNS cache and survive bootstrap IP changes
36
* added discovery tuning config keys: `discoveryTimeoutMs` (default 1000), `discoveryAttemptTimeoutMs` (default 300), `discoveryInitialTimeoutMs` (default 5000; set to `PHP_INT_MAX` to wait indefinitely on startup)

src/Table.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
use YdbPlatform\Ydb\Retry\Retry;
2121
use YdbPlatform\Ydb\Retry\RetryParams;
2222

23-
class Table
23+
class Table
2424
{
2525
use Traits\RequestTrait;
2626
use Traits\ParseResultTrait;

src/Traits/RequestTrait.php

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,19 @@ trait RequestTrait
3737
protected $ydb;
3838

3939
/**
40-
* @var int
40+
* @var int Timestamp of the last SUCCESSFUL discovery. Drives the regular
41+
* refresh schedule via discoveryInterval().
4142
*/
4243
protected $lastDiscovery = 0;
4344

45+
/**
46+
* @var int Timestamp of the last FAILED discovery attempt. Used to avoid
47+
* calling discover() on every API request while it is down — under
48+
* load each request would otherwise pay ~discoveryTimeoutMs on top
49+
* until discovery recovers.
50+
*/
51+
protected $lastDiscoveryAttempt = 0;
52+
4453

4554

4655
/**
@@ -315,13 +324,29 @@ protected function resetLastRequest()
315324
}
316325

317326
protected function checkDiscovery(){
318-
if ($this->ydb->needDiscovery() && time()-$this->lastDiscovery>$this->ydb->discoveryInterval()){
319-
try{
320-
$this->lastDiscovery = time();
321-
$this->ydb->discover();
322-
} catch (\Exception $e){
327+
if (!$this->ydb->needDiscovery()) {
328+
return;
329+
}
330+
$now = time();
331+
$interval = $this->ydb->discoveryInterval();
332+
333+
// Scheduled refresh is gated by the last success; retries after a
334+
// failure are gated by lastDiscoveryAttempt so a broken discovery
335+
// does not get called on every single API request.
336+
if ($now - $this->lastDiscovery <= $interval) {
337+
return;
338+
}
339+
if ($now - $this->lastDiscoveryAttempt <= $interval) {
340+
return;
341+
}
323342

324-
}
343+
$this->lastDiscoveryAttempt = $now;
344+
try {
345+
$this->logger()->debug('YDB: discovery for update ydb nodes list.');
346+
$this->ydb->discover();
347+
$this->lastDiscovery = $now;
348+
} catch (\Exception $e) {
349+
$this->logger()->warning('YDB: discovery refresh failed: ' . $e->getMessage());
325350
}
326351
}
327352

0 commit comments

Comments
 (0)