Skip to content

Commit 3ec79fc

Browse files
author
Илья
committed
Added snapshot tx
1 parent 528dbd6 commit 3ec79fc

File tree

4 files changed

+82
-0
lines changed

4 files changed

+82
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
* added snapshot tx
2+
13
## 1.12.0
24
* added StaticAuthentication
35
* added query timeout and canceled params

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,7 @@ Methods of the query builder:
542542
- online
543543
- online_inconsistent
544544
- serializable
545+
- snapshot
545546
- `txControl(\Ydb\Table\TransactionControl $tx_control)` - transaction control with custom settings
546547

547548
You can chain these methods for convenience.

src/YdbQuery.php

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

55
use Ydb\Table\Query;
66
use Ydb\Table\QueryCachePolicy;
7+
use Ydb\Table\SnapshotModeSettings;
78
use Ydb\Table\StaleModeSettings;
89
use Ydb\Table\OnlineModeSettings;
910
use Ydb\Table\TransactionControl;
@@ -170,6 +171,11 @@ public function beginTx($mode)
170171
]);
171172
break;
172173

174+
case 'snapshot':
175+
case 'snapshot_read_only':
176+
$tx_settings['snapshot_read_only'] = new SnapshotModeSettings;
177+
break;
178+
173179
case 'serializable':
174180
case 'serializable_read_write':
175181
default:

tests/CheckTxSettingsTest.php

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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\Ydb;
9+
use YdbPlatform\Ydb\YdbQuery;
10+
11+
class CheckTxSettingsTest extends TestCase
12+
{
13+
14+
/**
15+
* @var Ydb
16+
*/
17+
protected $ydb;
18+
/**
19+
* @var \YdbPlatform\Ydb\Table
20+
*/
21+
protected $table;
22+
/**
23+
* @var \YdbPlatform\Ydb\Session|null
24+
*/
25+
protected $session;
26+
protected $yql = "SELECT 1;";
27+
28+
public function __construct(?string $name = null, array $data = [], $dataName = '')
29+
{
30+
parent::__construct($name, $data, $dataName);
31+
$config = [
32+
33+
// Database path
34+
'database' => '/local',
35+
36+
// Database endpoint
37+
'endpoint' => 'localhost:2136',
38+
39+
// Auto discovery (dedicated server only)
40+
'discovery' => false,
41+
42+
// IAM config
43+
'iam_config' => [
44+
'insecure' => true,
45+
],
46+
'credentials' => new AnonymousAuthentication()
47+
];
48+
$this->ydb = new Ydb($config, new SimpleStdLogger(SimpleStdLogger::DEBUG));
49+
$this->table = $this->ydb->table();
50+
$this->session = $this->table->session();
51+
}
52+
53+
public function testSerializableTxConfig(){
54+
$this->checkTx('serializable', 'serializable_read_write');
55+
}
56+
57+
public function testSnapshotTxConfig(){
58+
$this->checkTx('snapshot', 'snapshot_read_only');
59+
}
60+
public function testStaleTxConfig(){
61+
$this->checkTx('stale', 'stale_read_only');
62+
}
63+
public function testOnlineTxConfig(){
64+
$this->checkTx('online', 'online_read_only');
65+
}
66+
67+
protected function checkTx(string $mode, string $value)
68+
{
69+
$query= $this->session->newQuery($this->yql)
70+
->beginTx($mode);
71+
self::assertEquals($value, $query->getRequestData()['tx_control']->getBeginTx()->getTxMode());
72+
}
73+
}

0 commit comments

Comments
 (0)