Skip to content

Commit 1a578f1

Browse files
authored
Merge pull request #476 from ydb-platform/new_session_pool
Query Session Pool redesign
2 parents 683d5b0 + 4bb2566 commit 1a578f1

24 files changed

+479
-185
lines changed

examples/basic_example_v2/basic_example.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def select_with_parameters(pool: ydb.QuerySessionPool, series_id, season_id, epi
140140
# calls instead to avoid additional hops to YDB cluster and allow more efficient
141141
# execution of queries.
142142
def explicit_transaction_control(pool: ydb.QuerySessionPool, series_id, season_id, episode_id):
143-
def callee(session: ydb.QuerySessionSync):
143+
def callee(session: ydb.QuerySession):
144144
query = """
145145
DECLARE $seriesId AS Int64;
146146
DECLARE $seasonId AS Int64;
@@ -175,7 +175,7 @@ def callee(session: ydb.QuerySessionSync):
175175

176176

177177
def huge_select(pool: ydb.QuerySessionPool):
178-
def callee(session: ydb.QuerySessionSync):
178+
def callee(session: ydb.QuerySession):
179179
query = """SELECT * from episodes;"""
180180

181181
with session.transaction().execute(

examples/basic_example_v2/basic_example_async.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
"""
5959

6060

61-
async def fill_tables_with_data(pool: ydb.aio.QuerySessionPoolAsync):
61+
async def fill_tables_with_data(pool: ydb.aio.QuerySessionPool):
6262
print("\nFilling tables with data...")
6363
await pool.execute_with_retries(
6464
FillDataQuery,
@@ -70,7 +70,7 @@ async def fill_tables_with_data(pool: ydb.aio.QuerySessionPoolAsync):
7070
)
7171

7272

73-
async def select_simple(pool: ydb.aio.QuerySessionPoolAsync):
73+
async def select_simple(pool: ydb.aio.QuerySessionPool):
7474
print("\nCheck series table...")
7575
result_sets = await pool.execute_with_retries(
7676
"""
@@ -96,7 +96,7 @@ async def select_simple(pool: ydb.aio.QuerySessionPoolAsync):
9696
return first_set
9797

9898

99-
async def upsert_simple(pool: ydb.aio.QuerySessionPoolAsync):
99+
async def upsert_simple(pool: ydb.aio.QuerySessionPool):
100100
print("\nPerforming UPSERT into episodes...")
101101

102102
await pool.execute_with_retries(
@@ -106,7 +106,7 @@ async def upsert_simple(pool: ydb.aio.QuerySessionPoolAsync):
106106
)
107107

108108

109-
async def select_with_parameters(pool: ydb.aio.QuerySessionPoolAsync, series_id, season_id, episode_id):
109+
async def select_with_parameters(pool: ydb.aio.QuerySessionPool, series_id, season_id, episode_id):
110110
result_sets = await pool.execute_with_retries(
111111
"""
112112
DECLARE $seriesId AS Int64;
@@ -138,8 +138,8 @@ async def select_with_parameters(pool: ydb.aio.QuerySessionPoolAsync, series_id,
138138
# In most cases it's better to use transaction control settings in session.transaction
139139
# calls instead to avoid additional hops to YDB cluster and allow more efficient
140140
# execution of queries.
141-
async def explicit_transaction_control(pool: ydb.aio.QuerySessionPoolAsync, series_id, season_id, episode_id):
142-
async def callee(session: ydb.aio.QuerySessionAsync):
141+
async def explicit_transaction_control(pool: ydb.aio.QuerySessionPool, series_id, season_id, episode_id):
142+
async def callee(session: ydb.aio.QuerySession):
143143
query = """
144144
DECLARE $seriesId AS Int64;
145145
DECLARE $seasonId AS Int64;
@@ -173,8 +173,8 @@ async def callee(session: ydb.aio.QuerySessionAsync):
173173
return await pool.retry_operation_async(callee)
174174

175175

176-
async def huge_select(pool: ydb.aio.QuerySessionPoolAsync):
177-
async def callee(session: ydb.aio.QuerySessionAsync):
176+
async def huge_select(pool: ydb.aio.QuerySessionPool):
177+
async def callee(session: ydb.aio.QuerySession):
178178
query = """SELECT * from episodes;"""
179179

180180
async with await session.transaction().execute(
@@ -189,12 +189,12 @@ async def callee(session: ydb.aio.QuerySessionAsync):
189189
return await pool.retry_operation_async(callee)
190190

191191

192-
async def drop_tables(pool: ydb.aio.QuerySessionPoolAsync):
192+
async def drop_tables(pool: ydb.aio.QuerySessionPool):
193193
print("\nCleaning up existing tables...")
194194
await pool.execute_with_retries(DropTablesQuery)
195195

196196

197-
async def create_tables(pool: ydb.aio.QuerySessionPoolAsync):
197+
async def create_tables(pool: ydb.aio.QuerySessionPool):
198198
print("\nCreating table series...")
199199
await pool.execute_with_retries(
200200
"""
@@ -246,7 +246,7 @@ async def run(endpoint, database):
246246
) as driver:
247247
await driver.wait(timeout=5, fail_fast=True)
248248

249-
async with ydb.aio.QuerySessionPoolAsync(driver) as pool:
249+
async with ydb.aio.QuerySessionPool(driver) as pool:
250250
await drop_tables(pool)
251251

252252
await create_tables(pool)

examples/query-service/basic_example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def callee(session):
8282

8383
pool.retry_operation_sync(callee)
8484

85-
def callee(session: ydb.QuerySessionSync):
85+
def callee(session: ydb.QuerySession):
8686
query_print = """select $a"""
8787

8888
print("=" * 50)

examples/query-service/basic_example_asyncio.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ async def main():
1515
except TimeoutError:
1616
raise RuntimeError("Connect failed to YDB")
1717

18-
pool = ydb.aio.QuerySessionPoolAsync(driver)
18+
pool = ydb.aio.QuerySessionPool(driver)
1919

2020
print("=" * 50)
2121
print("DELETE TABLE IF EXISTS")
@@ -83,7 +83,7 @@ async def callee(session):
8383

8484
await pool.retry_operation_async(callee)
8585

86-
async def callee(session: ydb.aio.QuerySessionAsync):
86+
async def callee(session: ydb.aio.QuerySession):
8787
query_print = """select $a"""
8888

8989
print("=" * 50)

test-requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pyjwt==2.0.0
3434
requests==2.31.0
3535
texttable==1.6.4
3636
toml==0.10.2
37-
typing-extensions==3.10.0.0
37+
typing-extensions==4.12.2
3838
urllib3==1.26.6
3939
websocket-client==0.59.0
4040
zipp==3.19.1

tests/aio/query/conftest.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import pytest
2-
from ydb.aio.query.session import QuerySessionAsync
3-
from ydb.aio.query.pool import QuerySessionPoolAsync
2+
from ydb.aio.query.session import QuerySession
3+
from ydb.aio.query.pool import QuerySessionPool
44

55

66
@pytest.fixture
77
async def session(driver):
8-
session = QuerySessionAsync(driver)
8+
session = QuerySession(driver)
99

1010
yield session
1111

@@ -29,6 +29,6 @@ async def tx(session):
2929

3030

3131
@pytest.fixture
32-
def pool(driver):
33-
pool = QuerySessionPoolAsync(driver)
34-
yield pool
32+
async def pool(driver):
33+
async with QuerySessionPool(driver) as pool:
34+
yield pool

tests/aio/query/test_query_session.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
import pytest
2-
from ydb.aio.query.session import QuerySessionAsync
2+
from ydb.aio.query.session import QuerySession
33

44

5-
def _check_session_state_empty(session: QuerySessionAsync):
5+
def _check_session_state_empty(session: QuerySession):
66
assert session._state.session_id is None
77
assert session._state.node_id is None
88
assert not session._state.attached
99

1010

11-
def _check_session_state_full(session: QuerySessionAsync):
11+
def _check_session_state_full(session: QuerySession):
1212
assert session._state.session_id is not None
1313
assert session._state.node_id is not None
1414
assert session._state.attached
1515

1616

1717
class TestAsyncQuerySession:
1818
@pytest.mark.asyncio
19-
async def test_session_normal_lifecycle(self, session: QuerySessionAsync):
19+
async def test_session_normal_lifecycle(self, session: QuerySession):
2020
_check_session_state_empty(session)
2121

2222
await session.create()
@@ -26,7 +26,7 @@ async def test_session_normal_lifecycle(self, session: QuerySessionAsync):
2626
_check_session_state_empty(session)
2727

2828
@pytest.mark.asyncio
29-
async def test_second_create_do_nothing(self, session: QuerySessionAsync):
29+
async def test_second_create_do_nothing(self, session: QuerySession):
3030
await session.create()
3131
_check_session_state_full(session)
3232

@@ -40,30 +40,30 @@ async def test_second_create_do_nothing(self, session: QuerySessionAsync):
4040
assert session._state.node_id == node_id_before
4141

4242
@pytest.mark.asyncio
43-
async def test_second_delete_do_nothing(self, session: QuerySessionAsync):
43+
async def test_second_delete_do_nothing(self, session: QuerySession):
4444
await session.create()
4545

4646
await session.delete()
4747
await session.delete()
4848

4949
@pytest.mark.asyncio
50-
async def test_delete_before_create_not_possible(self, session: QuerySessionAsync):
50+
async def test_delete_before_create_not_possible(self, session: QuerySession):
5151
with pytest.raises(RuntimeError):
5252
await session.delete()
5353

5454
@pytest.mark.asyncio
55-
async def test_create_after_delete_not_possible(self, session: QuerySessionAsync):
55+
async def test_create_after_delete_not_possible(self, session: QuerySession):
5656
await session.create()
5757
await session.delete()
5858
with pytest.raises(RuntimeError):
5959
await session.create()
6060

61-
def test_transaction_before_create_raises(self, session: QuerySessionAsync):
61+
def test_transaction_before_create_raises(self, session: QuerySession):
6262
with pytest.raises(RuntimeError):
6363
session.transaction()
6464

6565
@pytest.mark.asyncio
66-
async def test_transaction_after_delete_raises(self, session: QuerySessionAsync):
66+
async def test_transaction_after_delete_raises(self, session: QuerySession):
6767
await session.create()
6868

6969
await session.delete()
@@ -72,24 +72,24 @@ async def test_transaction_after_delete_raises(self, session: QuerySessionAsync)
7272
session.transaction()
7373

7474
@pytest.mark.asyncio
75-
async def test_transaction_after_create_not_raises(self, session: QuerySessionAsync):
75+
async def test_transaction_after_create_not_raises(self, session: QuerySession):
7676
await session.create()
7777
session.transaction()
7878

7979
@pytest.mark.asyncio
80-
async def test_execute_before_create_raises(self, session: QuerySessionAsync):
80+
async def test_execute_before_create_raises(self, session: QuerySession):
8181
with pytest.raises(RuntimeError):
8282
await session.execute("select 1;")
8383

8484
@pytest.mark.asyncio
85-
async def test_execute_after_delete_raises(self, session: QuerySessionAsync):
85+
async def test_execute_after_delete_raises(self, session: QuerySession):
8686
await session.create()
8787
await session.delete()
8888
with pytest.raises(RuntimeError):
8989
await session.execute("select 1;")
9090

9191
@pytest.mark.asyncio
92-
async def test_basic_execute(self, session: QuerySessionAsync):
92+
async def test_basic_execute(self, session: QuerySession):
9393
await session.create()
9494
it = await session.execute("select 1;")
9595
result_sets = [result_set async for result_set in it]
@@ -100,7 +100,7 @@ async def test_basic_execute(self, session: QuerySessionAsync):
100100
assert list(result_sets[0].rows[0].values()) == [1]
101101

102102
@pytest.mark.asyncio
103-
async def test_two_results(self, session: QuerySessionAsync):
103+
async def test_two_results(self, session: QuerySession):
104104
await session.create()
105105
res = []
106106

0 commit comments

Comments
 (0)