-
Notifications
You must be signed in to change notification settings - Fork 16
Added retry function #63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
||
namespace YdbPlatform\Ydb\Exceptions; | ||
|
||
class FastBackoffRetryableException extends RetryableException |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need Fast/Slow backoff in exceptions hierarchy.
Because it will difficult to change backoff type in future.
It may be property of exception, or (better) some function, which detect retry delay
src/Traits/RequestTrait.php
Outdated
* @return mixed|void|null | ||
* @throws \Exception | ||
*/ | ||
public function makeRequest(Closure $closure, bool $retryable){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the function need?
src/Traits/RetryTrait.php
Outdated
|
||
namespace YdbPlatform\Ydb\Traits; | ||
|
||
trait RetryTrait |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is empty trait need?
src/Session.php
Outdated
$result = $closure($this); | ||
$this->commitTransaction(); | ||
return $result; | ||
return $this->makeRequest(function ($session) use ($closure) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need the changes, retry only in retry function
src/Table.php
Outdated
@@ -421,4 +424,54 @@ protected function streamRequest($method, array $data = []) | |||
return $this->doStreamRequest('Table', $method, $data); | |||
} | |||
|
|||
/** | |||
* @param Closure $closure пользовательская функция, которую должен выполнить sdk. | |||
* Функция принимает новую сессию |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need example:
retrySession(function($session){...})
src/Table.php
Outdated
* Функция принимает новую сессию | ||
* @return mixed результат выполнения функции | ||
*/ | ||
public function retrySession(Closure $closure, int $waitTime = 100, bool $independent = false){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What unit of waitTime?
independent -> idempotent
src/Table.php
Outdated
$waitBefore = microtime(true)+$waitTime/1000; | ||
$requestCount = 0; | ||
$session = $this->session(); | ||
while ($waitBefore>microtime(true)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it will good to reuse $Ydb->retry in the session instead of copy paste code.
src/Ydb.php
Outdated
return $this->scripting; | ||
} | ||
|
||
public function retry(Closure $closure, int $waitTime = 100, bool $independent = false){ | ||
$waitBefore = microtime(true)+$waitTime*1e-3; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$waitTime*1e-3 - difficult to read and parse by human:
- science form is unusual in programs
- is that "($waitTime1e)-3" or "$waitTime(1e-3)"?
tests/classes/FakeCredentials.php
Outdated
use YdbPlatform\Ydb\Auth\Auth; | ||
use YdbPlatform\Ydb\Auth\TokenInfo; | ||
|
||
class FakeCredentials extends Auth { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the file need in the PR?
$output->writeln('Table ' . $table_name . ' has been created.'); | ||
|
||
$session->transaction(function($session) use ($table_name, $columns) { | ||
$session->query('upsert into `' . $table_name . '` (`' . implode('`, `', array_keys($columns)) . '`) values (' . implode('), (', $this->getData()) . ');'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
insert data in text of query id bad example.
I don't see is it your changes or original code.
src/Table.php
Outdated
$sessionId = $session->id(); | ||
$session->beginTransaction(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about use transaction function?
->primaryKey(['series_id', 'season_id']) | ||
); | ||
|
||
$this->print('Table `seasons` has been created.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here and in other places:
print should be out of retry
|
||
$output->writeln('Table ' . $table_name . ' has been created.'); | ||
$output->writeln('Table ' . $table_name . ' has been created.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$output->writeln mat be called multiply times if transaction will retry.
need separate create tables from requests to the tables.
{ | ||
$output->writeln('Empty directory'); | ||
} | ||
$ydb->retry(function (Ydb $ydb) use ($output, $dirname) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
retry should include only logic for work with ydb, for prevent bad examples.
prepare
retry (func (){work with database})
show/return result, render, etc.
|
||
class AbortedException extends RetryableException | ||
{ | ||
public function isFastBackoff(): bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the function need?
src/Retry/Retry.php
Outdated
} | ||
|
||
/** | ||
* @throws NonRetryableException |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
may be simpler - ydb/Exception?
src/Traits/RequestTrait.php
Outdated
@@ -158,9 +151,13 @@ protected function doStreamRequest($service, $method, $data = []) | |||
*/ | |||
protected function checkStatus($service, $method, $status) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better rename to checkGrpcStatus, for prevent mistakes with check server status code.
); | ||
|
||
$this->print('Table `episodes` has been created.'); | ||
$this->ydb->table()->retrySession(function (Session $session) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need set idempotend = true for this and other idempotent operations
I hereby agree to the terms of the CLA available at: https://yandex.ru/legal/cla/?lang=en
Pull request type
Please check the type of change your PR introduces:
Issue numbers: #61, #62