Skip to content

Commit 048fe25

Browse files
committed
Intermediate changes
commit_hash:ac53b6445d4c78c7724d2cedae353982d0fb8332
1 parent f6feaf7 commit 048fe25

File tree

7 files changed

+66
-14
lines changed

7 files changed

+66
-14
lines changed

contrib/python/ydb/py3/.dist-info/METADATA

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Metadata-Version: 2.1
22
Name: ydb
3-
Version: 3.21.1
3+
Version: 3.21.2
44
Summary: YDB Python SDK
55
Home-page: http://github.com/ydb-platform/ydb-python-sdk
66
Author: Yandex LLC
@@ -65,3 +65,7 @@ Install YDB python sdk:
6565
```sh
6666
$ python -m pip install ydb
6767
```
68+
69+
## Development
70+
71+
Instructions on `ydb-python-sdk` development are located in [BUILD.md](BUILD.md).

contrib/python/ydb/py3/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,7 @@ Install YDB python sdk:
4242
```sh
4343
$ python -m pip install ydb
4444
```
45+
46+
## Development
47+
48+
Instructions on `ydb-python-sdk` development are located in [BUILD.md](BUILD.md).

contrib/python/ydb/py3/ya.make

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
PY3_LIBRARY()
44

5-
VERSION(3.21.1)
5+
VERSION(3.21.2)
66

77
LICENSE(Apache-2.0)
88

contrib/python/ydb/py3/ydb/aio/pool.py

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,12 +199,27 @@ def __init__(self, driver_config):
199199
self._store = ConnectionsCache(driver_config.use_all_nodes)
200200
self._grpc_init = Connection(self._driver_config.endpoint, self._driver_config)
201201
self._stopped = False
202-
self._discovery = Discovery(self._store, self._driver_config)
203202

204-
self._discovery_task = asyncio.get_event_loop().create_task(self._discovery.run())
203+
if driver_config.disable_discovery:
204+
# If discovery is disabled, just add the initial endpoint to the store
205+
async def init_connection():
206+
ready_connection = Connection(self._driver_config.endpoint, self._driver_config)
207+
await ready_connection.connection_ready(
208+
ready_timeout=getattr(self._driver_config, "discovery_request_timeout", 10)
209+
)
210+
self._store.add(ready_connection)
211+
212+
# Create and schedule the task to initialize the connection
213+
self._discovery = None
214+
self._discovery_task = asyncio.get_event_loop().create_task(init_connection())
215+
else:
216+
# Start discovery as usual
217+
self._discovery = Discovery(self._store, self._driver_config)
218+
self._discovery_task = asyncio.get_event_loop().create_task(self._discovery.run())
205219

206220
async def stop(self, timeout=10):
207-
self._discovery.stop()
221+
if self._discovery:
222+
self._discovery.stop()
208223
await self._grpc_init.close()
209224
try:
210225
await asyncio.wait_for(self._discovery_task, timeout=timeout)
@@ -215,15 +230,18 @@ async def stop(self, timeout=10):
215230
def _on_disconnected(self, connection):
216231
async def __wrapper__():
217232
await connection.close()
218-
self._discovery.notify_disconnected()
233+
if self._discovery:
234+
self._discovery.notify_disconnected()
219235

220236
return __wrapper__
221237

222238
async def wait(self, timeout=7, fail_fast=False):
223239
await self._store.get(fast_fail=fail_fast, wait_timeout=timeout)
224240

225241
def discovery_debug_details(self):
226-
return self._discovery.discovery_debug_details()
242+
if self._discovery:
243+
return self._discovery.discovery_debug_details()
244+
return "Discovery is disabled, using only the initial endpoint"
227245

228246
async def __aenter__(self):
229247
return self
@@ -248,7 +266,8 @@ async def __call__(
248266
try:
249267
connection = await self._store.get(preferred_endpoint, fast_fail=fast_fail, wait_timeout=wait_timeout)
250268
except BaseException:
251-
self._discovery.notify_disconnected()
269+
if self._discovery:
270+
self._discovery.notify_disconnected()
252271
raise
253272

254273
return await connection(

contrib/python/ydb/py3/ydb/driver.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ class DriverConfig(object):
9696
"grpc_lb_policy_name",
9797
"discovery_request_timeout",
9898
"compression",
99+
"disable_discovery",
99100
)
100101

101102
def __init__(
@@ -120,6 +121,7 @@ def __init__(
120121
grpc_lb_policy_name="round_robin",
121122
discovery_request_timeout=10,
122123
compression=None,
124+
disable_discovery=False,
123125
):
124126
"""
125127
A driver config to initialize a driver instance
@@ -140,6 +142,7 @@ def __init__(
140142
If tracing aio ScopeManager must be ContextVarsScopeManager
141143
:param grpc_lb_policy_name: A load balancing policy to be used for discovery channel construction. Default value is `round_round`
142144
:param discovery_request_timeout: A default timeout to complete the discovery. The default value is 10 seconds.
145+
:param disable_discovery: If True, endpoint discovery is disabled and only the start endpoint is used for all requests.
143146
144147
"""
145148
self.endpoint = endpoint
@@ -167,6 +170,7 @@ def __init__(
167170
self.grpc_lb_policy_name = grpc_lb_policy_name
168171
self.discovery_request_timeout = discovery_request_timeout
169172
self.compression = compression
173+
self.disable_discovery = disable_discovery
170174

171175
def set_database(self, database):
172176
self.database = database

contrib/python/ydb/py3/ydb/pool.py

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,21 @@ def __init__(self, driver_config):
350350
self._store = ConnectionsCache(driver_config.use_all_nodes, driver_config.tracer)
351351
self.tracer = driver_config.tracer
352352
self._grpc_init = connection_impl.Connection(self._driver_config.endpoint, self._driver_config)
353-
self._discovery_thread = Discovery(self._store, self._driver_config)
354-
self._discovery_thread.start()
353+
354+
if driver_config.disable_discovery:
355+
# If discovery is disabled, just add the initial endpoint to the store
356+
ready_connection = connection_impl.Connection.ready_factory(
357+
self._driver_config.endpoint,
358+
self._driver_config,
359+
ready_timeout=getattr(self._driver_config, "discovery_request_timeout", 10),
360+
)
361+
self._store.add(ready_connection)
362+
self._discovery_thread = None
363+
else:
364+
# Start discovery thread as usual
365+
self._discovery_thread = Discovery(self._store, self._driver_config)
366+
self._discovery_thread.start()
367+
355368
self._stopped = False
356369
self._stop_guard = threading.Lock()
357370

@@ -367,9 +380,11 @@ def stop(self, timeout=10):
367380
return
368381

369382
self._stopped = True
370-
self._discovery_thread.stop()
383+
if self._discovery_thread:
384+
self._discovery_thread.stop()
371385
self._grpc_init.close()
372-
self._discovery_thread.join(timeout)
386+
if self._discovery_thread:
387+
self._discovery_thread.join(timeout)
373388

374389
def async_wait(self, fail_fast=False):
375390
"""
@@ -404,7 +419,13 @@ def _on_disconnected(self, connection):
404419
self._discovery_thread.notify_disconnected()
405420

406421
def discovery_debug_details(self):
407-
return self._discovery_thread.discovery_debug_details()
422+
"""
423+
Returns debug string about last errors
424+
:return: str
425+
"""
426+
if self._discovery_thread:
427+
return self._discovery_thread.discovery_debug_details()
428+
return "Discovery is disabled, using only the initial endpoint"
408429

409430
@tracing.with_trace()
410431
def __call__(
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
VERSION = "3.21.1"
1+
VERSION = "3.21.2"

0 commit comments

Comments
 (0)