Skip to content

Commit 29c15de

Browse files
added compose.yaml and throw exception on cancel first reader stream in interactive transaction
1 parent 88abe64 commit 29c15de

File tree

4 files changed

+379
-0
lines changed

4 files changed

+379
-0
lines changed

.github/compose.yaml

Lines changed: 269 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,269 @@
1+
x-runtime: &runtime
2+
hostname: localhost
3+
platform: linux/amd64
4+
privileged: true
5+
network_mode: host
6+
7+
x-ydb-node: &ydb-node
8+
image: cr.yandex/crptqonuodf51kdj7a7d/ydb:24.3.11.14
9+
restart: always
10+
<<: *runtime
11+
volumes:
12+
- ./ydb.yaml:/opt/ydb/cfg/config.yaml
13+
14+
name: ydb
15+
16+
services:
17+
static-0:
18+
<<: *ydb-node
19+
container_name: ydb-static-0
20+
command:
21+
- /opt/ydb/bin/ydbd
22+
- server
23+
- --grpc-port
24+
- "2135"
25+
- --mon-port
26+
- "8765"
27+
- --ic-port
28+
- "19001"
29+
- --yaml-config
30+
- /opt/ydb/cfg/config.yaml
31+
- --node
32+
- static
33+
- --label
34+
- deployment=docker
35+
ports:
36+
- 2135:2135
37+
- 8765:8765
38+
- 19001:19001
39+
healthcheck:
40+
test: bash -c "exec 6<> /dev/tcp/localhost/2135"
41+
interval: 10s
42+
timeout: 1s
43+
retries: 3
44+
start_period: 30s
45+
46+
static-init:
47+
<<: *ydb-node
48+
restart: on-failure
49+
container_name: ydb-static-init
50+
command:
51+
- /opt/ydb/bin/ydbd
52+
- -s
53+
- grpc://localhost:2135
54+
- admin
55+
- blobstorage
56+
- config
57+
- init
58+
- --yaml-file
59+
- /opt/ydb/cfg/config.yaml
60+
depends_on:
61+
static-0:
62+
condition: service_healthy
63+
64+
tenant-init:
65+
<<: *ydb-node
66+
restart: on-failure
67+
container_name: ydb-tenant-init
68+
command:
69+
- /opt/ydb/bin/ydbd
70+
- -s
71+
- grpc://localhost:2135
72+
- admin
73+
- database
74+
- /Root/testdb
75+
- create
76+
- ssd:1
77+
depends_on:
78+
static-init:
79+
condition: service_completed_successfully
80+
81+
database-1:
82+
<<: *ydb-node
83+
container_name: ydb-database-1
84+
command:
85+
- /opt/ydb/bin/ydbd
86+
- server
87+
- --grpc-port
88+
- "2136"
89+
- --mon-port
90+
- "8766"
91+
- --ic-port
92+
- "19002"
93+
- --yaml-config
94+
- /opt/ydb/cfg/config.yaml
95+
- --tenant
96+
- /Root/testdb
97+
- --node-broker
98+
- grpc://localhost:2135
99+
- --label
100+
- deployment=docker
101+
ports:
102+
- 2136:2136
103+
- 8766:8766
104+
- 19002:19002
105+
healthcheck:
106+
test: bash -c "exec 6<> /dev/tcp/localhost/2136"
107+
interval: 10s
108+
timeout: 1s
109+
retries: 3
110+
start_period: 30s
111+
depends_on:
112+
static-0:
113+
condition: service_healthy
114+
static-init:
115+
condition: service_completed_successfully
116+
tenant-init:
117+
condition: service_completed_successfully
118+
119+
database-2:
120+
<<: *ydb-node
121+
container_name: ydb-database-2
122+
command:
123+
- /opt/ydb/bin/ydbd
124+
- server
125+
- --grpc-port
126+
- "2137"
127+
- --mon-port
128+
- "8767"
129+
- --ic-port
130+
- "19003"
131+
- --yaml-config
132+
- /opt/ydb/cfg/config.yaml
133+
- --tenant
134+
- /Root/testdb
135+
- --node-broker
136+
- grpc://localhost:2135
137+
- --label
138+
- deployment=docker
139+
ports:
140+
- 2137:2137
141+
- 8767:8767
142+
- 19003:19003
143+
healthcheck:
144+
test: bash -c "exec 6<> /dev/tcp/localhost/2137"
145+
interval: 10s
146+
timeout: 1s
147+
retries: 3
148+
start_period: 30s
149+
depends_on:
150+
static-0:
151+
condition: service_healthy
152+
static-init:
153+
condition: service_completed_successfully
154+
tenant-init:
155+
condition: service_completed_successfully
156+
157+
database-3:
158+
<<: *ydb-node
159+
container_name: ydb-database-3
160+
command:
161+
- /opt/ydb/bin/ydbd
162+
- server
163+
- --grpc-port
164+
- "2138"
165+
- --mon-port
166+
- "8768"
167+
- --ic-port
168+
- "19004"
169+
- --yaml-config
170+
- /opt/ydb/cfg/config.yaml
171+
- --tenant
172+
- /Root/testdb
173+
- --node-broker
174+
- grpc://localhost:2135
175+
- --label
176+
- deployment=docker
177+
ports:
178+
- 2138:2138
179+
- 8768:8768
180+
- 19004:19004
181+
healthcheck:
182+
test: bash -c "exec 6<> /dev/tcp/localhost/2138"
183+
interval: 10s
184+
timeout: 1s
185+
retries: 3
186+
start_period: 30s
187+
depends_on:
188+
static-0:
189+
condition: service_healthy
190+
static-init:
191+
condition: service_completed_successfully
192+
tenant-init:
193+
condition: service_completed_successfully
194+
195+
database-4:
196+
<<: *ydb-node
197+
container_name: ydb-database-4
198+
command:
199+
- /opt/ydb/bin/ydbd
200+
- server
201+
- --grpc-port
202+
- "2139"
203+
- --mon-port
204+
- "8769"
205+
- --ic-port
206+
- "19005"
207+
- --yaml-config
208+
- /opt/ydb/cfg/config.yaml
209+
- --tenant
210+
- /Root/testdb
211+
- --node-broker
212+
- grpc://localhost:2135
213+
- --label
214+
- deployment=docker
215+
ports:
216+
- 2139:2139
217+
- 8769:8769
218+
- 19005:19005
219+
healthcheck:
220+
test: bash -c "exec 6<> /dev/tcp/localhost/2139"
221+
interval: 10s
222+
timeout: 1s
223+
retries: 3
224+
start_period: 30s
225+
depends_on:
226+
static-0:
227+
condition: service_healthy
228+
static-init:
229+
condition: service_completed_successfully
230+
tenant-init:
231+
condition: service_completed_successfully
232+
233+
database-5:
234+
<<: *ydb-node
235+
container_name: ydb-database-5
236+
command:
237+
- /opt/ydb/bin/ydbd
238+
- server
239+
- --grpc-port
240+
- "2140"
241+
- --mon-port
242+
- "8770"
243+
- --ic-port
244+
- "19006"
245+
- --yaml-config
246+
- /opt/ydb/cfg/config.yaml
247+
- --tenant
248+
- /Root/testdb
249+
- --node-broker
250+
- grpc://localhost:2135
251+
- --label
252+
- deployment=docker
253+
ports:
254+
- 2140:2140
255+
- 8770:8770
256+
- 19006:19006
257+
healthcheck:
258+
test: bash -c "exec 6<> /dev/tcp/localhost/2140"
259+
interval: 10s
260+
timeout: 1s
261+
retries: 3
262+
start_period: 30s
263+
depends_on:
264+
static-0:
265+
condition: service_healthy
266+
static-init:
267+
condition: service_completed_successfully
268+
tenant-init:
269+
condition: service_completed_successfully

.github/ydb.yaml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
actor_system_config:
2+
cpu_count: 1
3+
node_type: STORAGE
4+
use_auto_config: true
5+
blob_storage_config:
6+
service_set:
7+
groups:
8+
- erasure_species: none
9+
rings:
10+
- fail_domains:
11+
- vdisk_locations:
12+
- node_id: 1
13+
path: SectorMap:1:64
14+
pdisk_category: SSD
15+
channel_profile_config:
16+
profile:
17+
- channel:
18+
- erasure_species: none
19+
pdisk_category: 0
20+
storage_pool_kind: ssd
21+
- erasure_species: none
22+
pdisk_category: 0
23+
storage_pool_kind: ssd
24+
- erasure_species: none
25+
pdisk_category: 0
26+
storage_pool_kind: ssd
27+
profile_id: 0
28+
domains_config:
29+
domain:
30+
- name: local
31+
storage_pool_types:
32+
- kind: ssd
33+
pool_config:
34+
box_id: 1
35+
erasure_species: none
36+
kind: ssd
37+
pdisk_filter:
38+
- property:
39+
- type: SSD
40+
vdisk_kind: Default
41+
state_storage:
42+
- ring:
43+
node: [1]
44+
nto_select: 1
45+
ssid: 1
46+
host_configs:
47+
- drive:
48+
- path: SectorMap:1:64
49+
type: SSD
50+
host_config_id: 1
51+
hosts:
52+
- host: localhost
53+
host_config_id: 1
54+
node_id: 1
55+
port: 19001
56+
walle_location:
57+
body: 1
58+
data_center: az-1
59+
rack: "0"
60+
static_erasure: none

src/Ydb.Sdk/src/Ado/YdbDataReader.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,15 @@ public override async Task CloseAsync()
437437
ReaderState = State.Closed;
438438

439439
await _stream.DisposeAsync();
440+
441+
if (_ydbTransaction is { TxId: null })
442+
{
443+
_ydbTransaction.Failed = true;
444+
445+
throw new YdbException(
446+
"YdbDataReader was closed before receiving the transaction id. Transaction is broken!"
447+
);
448+
}
440449
}
441450

442451
public override void Close()

src/Ydb.Sdk/tests/Ado/YdbTransactionTests.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,47 @@ public void CommitAndRollback_WhenDoubleCommit_ThrowException()
120120
Assert.Throws<InvalidOperationException>(() => ydbTransaction.Rollback()).Message);
121121
}
122122

123+
[Fact]
124+
public void BeginTransaction_WhenYdbDataReaderIsClosed_ThrowExceptionTransactionIsBroken()
125+
{
126+
using var connection = new YdbConnection();
127+
connection.Open();
128+
129+
using var ydbTransaction = connection.BeginTransaction();
130+
var ydbCommand = connection.CreateCommand();
131+
ydbCommand.CommandText = "SELECT 1; SELECT 2; SELECT 3";
132+
var dbDataReader = ydbCommand.ExecuteReader();
133+
dbDataReader.Read();
134+
Assert.Equal("YdbDataReader was closed before receiving the transaction id. Transaction is broken!",
135+
Assert.Throws<YdbException>(() => dbDataReader.Close()).Message);
136+
Assert.Equal("This YdbTransaction has completed; it is no longer usable",
137+
Assert.Throws<InvalidOperationException>(() => ydbTransaction.Commit()).Message);
138+
ydbTransaction.Rollback();
139+
Assert.Equal("This YdbTransaction has completed; it is no longer usable",
140+
Assert.Throws<InvalidOperationException>(() => ydbTransaction.Commit()).Message);
141+
Assert.Equal("This YdbTransaction has completed; it is no longer usable",
142+
Assert.Throws<InvalidOperationException>(() => ydbTransaction.Rollback()).Message);
143+
}
144+
145+
[Fact]
146+
public void BeginTransaction_WhenTxIdIsReceivedThenYdbDataReaderIsClosed_SuccessCommit()
147+
{
148+
using var connection = new YdbConnection();
149+
connection.Open();
150+
151+
var tx = connection.BeginTransaction();
152+
var ydbCommand1 = connection.CreateCommand();
153+
ydbCommand1.CommandText = "SELECT 1";
154+
Assert.Equal(1, ydbCommand1.ExecuteScalar());
155+
var ydbCommand2 = connection.CreateCommand();
156+
ydbCommand2.CommandText = "SELECT 1; SELECT 2; SELECT 3";
157+
var dbDataReader = ydbCommand2.ExecuteReader();
158+
dbDataReader.Read();
159+
dbDataReader.Read();
160+
dbDataReader.Close();
161+
tx.Commit();
162+
}
163+
123164
[Fact]
124165
public void CommitAndRollback_WhenStreamIsOpened_ThrowException()
125166
{

0 commit comments

Comments
 (0)