Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
* Add automatic long polling for endpoint discovery in sync and asyncio drivers
* Add `EventHandler.on_partition_session_start` to confirm topic reader partitions manually with read and commit offsets, and `EventHandler.on_partition_session_stop` to observe partition stops.
* Add `grpc_channel_shutdown_timeout` for graceful shutdown of channels removed by discovery in both drivers.

Expand Down
6 changes: 5 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ version: "3.9"
services:
ydb:
image: ydbplatform/local-ydb:trunk
command: ["--enable-feature-flag", "enable_topic_split_merge"]
command:
- --enable-feature-flag
- enable_topic_split_merge
- --enable-feature-flag
- enable_discovery_long_polling
restart: always
ports:
- 2136:2136
Expand Down
4 changes: 2 additions & 2 deletions tests/aio/test_connection_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ async def test_disconnect_by_call(endpoint, database, docker_project):
async def test_good_discovery_interval(driver):
await driver.wait(timeout=10)
mock = MagicMock(return_value=0.1)
driver._discovery._discovery_interval = mock
driver._discovery._wake_up_event.set()
driver._discovery._resolver.discovery_interval = mock
driver._discovery.notify_disconnected()
await asyncio.sleep(1)
assert mock.called
33 changes: 33 additions & 0 deletions tests/test_discovery_detect_local_dc.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# -*- coding: utf-8 -*-
import asyncio

from unittest.mock import AsyncMock, Mock, MagicMock, patch

import pytest
Expand Down Expand Up @@ -410,3 +412,34 @@ def test_driver_applies_config_and_shutdown_timeout_keyword(monkeypatch):
with pytest.raises(ValueError, match="grpc_channel_shutdown_timeout"):
driver.Driver(config, grpc_channel_shutdown_timeout=-1)
assert config.grpc_channel_shutdown_timeout == 0


@pytest.mark.asyncio
@pytest.mark.parametrize("asynchronous", [False, True], ids=["sync", "asyncio"])
async def test_long_poll_against_ydb(endpoint, database, asynchronous):
config = driver.DriverConfig(endpoint, database, discovery_request_timeout=2)
if asynchronous:
client = aio_resolver.DiscoveryEndpointsResolver(config)
resolve = client.resolve
else:
client = resolver.DiscoveryEndpointsResolver(config)

async def resolve():
return await asyncio.to_thread(client.resolve)

client._base_discovery_interval = 1
snapshot = await resolve()
assert snapshot.endpoints
assert snapshot.snapshot_hash
assert client.snapshot_hash == snapshot.snapshot_hash

# A matching hash waits for the real server's gRPC deadline.
with pytest.raises(resolver.DiscoveryUnchanged):
await resolve()
assert client.snapshot_hash == snapshot.snapshot_hash

# An out-of-date hash returns the live topology instead of timing out.
client.snapshot_hash = snapshot.snapshot_hash + b"stale"
refreshed = await resolve()
assert refreshed.snapshot_hash == snapshot.snapshot_hash
assert set(refreshed.endpoints) == set(snapshot.endpoints)
2 changes: 1 addition & 1 deletion ydb-api-protos
62 changes: 38 additions & 24 deletions ydb/_grpc/v3/protos/ydb_discovery_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1,074 changes: 761 additions & 313 deletions ydb/_grpc/v3/protos/ydb_table_pb2.py

Large diffs are not rendered by default.

Loading
Loading