Skip to content

Commit 15d3b46

Browse files
author
Илья
committed
Added timeout and canceled params
1 parent e614381 commit 15d3b46

File tree

3 files changed

+63
-1
lines changed

3 files changed

+63
-1
lines changed

slo-workload/Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@ FROM ilyakharev/php-grpc:7.2
33
COPY . /src
44
WORKDIR /src/slo-workload
55
RUN composer update
6-
RUN apt instll bmon
76
#RUN apt update; apt install htop
87
ENTRYPOINT ["php", "application.php"]

src/Session.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
use Closure;
66
use Exception;
7+
use Google\Protobuf\Duration;
8+
use Ydb\Operations\OperationParams;
79
use Ydb\Table\Query;
810
use Ydb\Table\QueryCachePolicy;
911
// use Ydb\Table\StaleModeSettings;
@@ -366,6 +368,18 @@ public function query($yql, array $parameters = null, array $options = [])
366368
if(isset($options['collectStats'])){
367369
$query->collectStats($options['collectStats']);
368370
}
371+
$operationParams = new OperationParams();
372+
if(isset($options['operation_timeout_ms'])){
373+
$operationParams->setOperationTimeout(new Duration([
374+
'nanos' => $options['operation_timeout_ms'] * 1000000 // convert ms to ns
375+
]));
376+
}
377+
if(isset($options['cancel_after_ms'])){
378+
$operationParams->setCancelAfter(new Duration([
379+
'nanos' => $options['cancel_after_ms'] * 1000000 // convert ms to ns
380+
]));
381+
}
382+
$query->operationParams($operationParams);
369383

370384
return $this->executeQuery($query);
371385
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
namespace YdbPlatform\Ydb\Test;
4+
5+
use PHPUnit\Framework\TestCase;
6+
use YdbPlatform\Ydb\Auth\Implement\AnonymousAuthentication;
7+
use YdbPlatform\Ydb\Logger\SimpleStdLogger;
8+
use YdbPlatform\Ydb\Session;
9+
use YdbPlatform\Ydb\Ydb;
10+
11+
class CheckTimeoutAndDurationParamsTest extends TestCase
12+
{
13+
public function testTimeoutAndDurationParams(){
14+
$config = [
15+
16+
// Database path
17+
'database' => '/local',
18+
19+
// Database endpoint
20+
'endpoint' => 'localhost:2136',
21+
22+
// Auto discovery (dedicated server only)
23+
'discovery' => false,
24+
25+
// IAM config
26+
'iam_config' => [
27+
'insecure' => true,
28+
],
29+
'credentials' => new AnonymousAuthentication()
30+
];
31+
32+
$ydb = new Ydb($config, new SimpleStdLogger(7));
33+
$table = $ydb->table();
34+
35+
$this->expectException('YdbPlatform\Ydb\Exceptions\Ydb\TimeoutException');
36+
$table->retrySession(function (Session $session){
37+
$session->query('SELECT 1;', null, [
38+
'operation_timeout_ms' => 1e-5
39+
]);
40+
});
41+
42+
$this->expectException('YdbPlatform\Ydb\Exceptions\Ydb\CancelledException');
43+
$table->retrySession(function (Session $session){
44+
$session->query('SELECT 1;', null, [
45+
'cancel_after_ms' => 1e-5
46+
]);
47+
});
48+
}
49+
}

0 commit comments

Comments
 (0)