Skip to content

Commit df4f0a4

Browse files
Fix Copilot review issues for attach hint PR
Look up node connections under ConnectionsCache lock when pessimizing after NodeShutdown hints, and strip grpcio-tools version gates from v6 gRPC stubs so imports work with grpcio>=1.42.0. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 719b56e commit df4f0a4

53 files changed

Lines changed: 203 additions & 26 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
* Query session attach stream handles `NodeShutdown` and `SessionShutdown` session hints: on `NodeShutdown` the session's node connection is pessimized and the session is retired, on `SessionShutdown` the session is retired without touching the node
22
* Bumped `ydb-api-protos` and regenerated gRPC/protobuf stubs (v3–v6) to include query service session hints
33
* Fix incompatibility with protobuf 6.30–6.31.0: regenerate v6 stubs with the lowest 6.x gencode floor (6.30.0) instead of 6.31.1
4+
* Query session attach stream handles `NodeShutdown` and `SessionShutdown` session hints: on `NodeShutdown` the session's node connection is pessimized and the session is retired, on `SessionShutdown` the session is retired without touching the node
45

56
## 3.29.4 ##
67
* Fix leaked topic reader stream when close interrupts stream creation during reconnect

generate_protoc.py

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,50 @@
11
import os
22
import pathlib
3+
import re
34
import shutil
45

56
from typing import List
67
from argparse import ArgumentParser
78

8-
from grpc_tools import command
9+
_GRPC_VERSION_GATE_RE = re.compile(
10+
r"GRPC_GENERATED_VERSION = '[^']+'\n"
11+
r"GRPC_VERSION = grpc\.__version__\n"
12+
r"_version_not_supported = False\n\n"
13+
r"try:\n"
14+
r" from grpc\._utilities import first_version_is_lower\n"
15+
r" _version_not_supported = first_version_is_lower\(GRPC_VERSION, GRPC_GENERATED_VERSION\)\n"
16+
r"except ImportError:\n"
17+
r" _version_not_supported = True\n\n"
18+
r"if _version_not_supported:\n"
19+
r" raise RuntimeError\(\n"
20+
r"(?: .+\n)+"
21+
r" \)\n"
22+
)
23+
24+
25+
def strip_grpc_version_gate(content: str) -> str:
26+
"""Remove grpcio-tools version gate from generated *_grpc.py stubs."""
27+
updated = _GRPC_VERSION_GATE_RE.sub("", content)
28+
if updated != content:
29+
updated = updated.replace("import warnings\n", "")
30+
return updated
31+
32+
33+
def strip_grpc_version_gate_from_tree(rootdir: str) -> None:
34+
for dirpath, _, fnames in os.walk(rootdir):
35+
for fname in fnames:
36+
if not fname.endswith("_grpc.py"):
37+
continue
38+
39+
path = os.path.join(dirpath, fname)
40+
with open(path, "r+t") as f:
41+
content = f.read()
42+
updated = strip_grpc_version_gate(content)
43+
if updated == content:
44+
continue
45+
f.seek(0)
46+
f.write(updated)
47+
f.truncate()
948

1049

1150
def files_filter(dir, items: List[str]) -> List[str]:
@@ -56,11 +95,18 @@ def fix_file_contents(rootdir, protobuf_version: str):
5695

5796
# Add ignore style check
5897
content = content.replace("# -*- coding: utf-8 -*-", "# -*- coding: utf-8 -*-\n" + flake_ignore_line)
98+
99+
if fname.endswith("_grpc.py"):
100+
content = strip_grpc_version_gate(content)
101+
59102
f.seek(0)
60103
f.write(content)
104+
f.truncate()
61105

62106

63107
def generate_protobuf(src_proto_dir: str, dst_dir, protobuf_version: str):
108+
from grpc_tools import command
109+
64110
shutil.rmtree(dst_dir, ignore_errors=True)
65111

66112
shutil.copytree(src_proto_dir, dst_dir, ignore=files_filter)

tests/query/test_query_session_hints.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,18 @@ def test_sync_pool_pessimizes_node_connection(self):
9191
pool = ConnectionPool.__new__(ConnectionPool)
9292
connection = mock.Mock()
9393
pool._store = mock.Mock()
94-
pool._store.connections_by_node_id = {42: connection}
94+
pool._store.get_connection_by_node_id.return_value = connection
9595
pool._on_disconnected = mock.Mock()
9696

9797
pool._pessimize_node(42)
9898

99+
pool._store.get_connection_by_node_id.assert_called_once_with(42)
99100
pool._on_disconnected.assert_called_once_with(connection)
100101

101102
def test_sync_pool_ignores_missing_node_connection(self):
102103
pool = ConnectionPool.__new__(ConnectionPool)
103104
pool._store = mock.Mock()
104-
pool._store.connections_by_node_id = {}
105+
pool._store.get_connection_by_node_id.return_value = None
105106
pool._on_disconnected = mock.Mock()
106107

107108
pool._pessimize_node(42)
@@ -115,11 +116,12 @@ async def test_async_pool_pessimizes_node_connection(self):
115116
connection = mock.Mock()
116117
disconnect = mock.AsyncMock()
117118
pool._store = mock.Mock()
118-
pool._store.connections_by_node_id = {42: connection}
119+
pool._store.get_connection_by_node_id.return_value = connection
119120
pool._on_disconnected = mock.Mock(return_value=disconnect)
120121

121122
pool._pessimize_node(42)
122123
await asyncio.sleep(0)
123124

125+
pool._store.get_connection_by_node_id.assert_called_once_with(42)
124126
pool._on_disconnected.assert_called_once_with(connection)
125127
disconnect.assert_awaited_once_with()

ydb/_grpc/v6/draft/protos/ydb_dynamic_config_pb2_grpc.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
22
"""Client and server classes corresponding to protobuf-defined services."""
33
import grpc
4+
<<<<<<< HEAD
45
import warnings
56

67

@@ -22,3 +23,5 @@
2223
+ f' Please upgrade your grpc module to grpcio>={GRPC_GENERATED_VERSION}'
2324
+ f' or downgrade your generated code using grpcio-tools<={GRPC_VERSION}.'
2425
)
26+
=======
27+
>>>>>>> 989b70e (Fix Copilot review issues for attach hint PR)

ydb/_grpc/v6/draft/protos/ydb_federated_query_pb2_grpc.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
22
"""Client and server classes corresponding to protobuf-defined services."""
33
import grpc
4+
<<<<<<< HEAD
45
import warnings
56

67

@@ -22,3 +23,5 @@
2223
+ f' Please upgrade your grpc module to grpcio>={GRPC_GENERATED_VERSION}'
2324
+ f' or downgrade your generated code using grpcio-tools<={GRPC_VERSION}.'
2425
)
26+
=======
27+
>>>>>>> 989b70e (Fix Copilot review issues for attach hint PR)

ydb/_grpc/v6/draft/protos/ydb_keyvalue_pb2_grpc.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
22
"""Client and server classes corresponding to protobuf-defined services."""
33
import grpc
4+
<<<<<<< HEAD
45
import warnings
56

67

@@ -22,3 +23,5 @@
2223
+ f' Please upgrade your grpc module to grpcio>={GRPC_GENERATED_VERSION}'
2324
+ f' or downgrade your generated code using grpcio-tools<={GRPC_VERSION}.'
2425
)
26+
=======
27+
>>>>>>> 989b70e (Fix Copilot review issues for attach hint PR)

ydb/_grpc/v6/draft/protos/ydb_maintenance_pb2_grpc.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
22
"""Client and server classes corresponding to protobuf-defined services."""
33
import grpc
4+
<<<<<<< HEAD
45
import warnings
56

67

@@ -22,3 +23,5 @@
2223
+ f' Please upgrade your grpc module to grpcio>={GRPC_GENERATED_VERSION}'
2324
+ f' or downgrade your generated code using grpcio-tools<={GRPC_VERSION}.'
2425
)
26+
=======
27+
>>>>>>> 989b70e (Fix Copilot review issues for attach hint PR)

ydb/_grpc/v6/draft/protos/ydb_object_storage_pb2_grpc.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
22
"""Client and server classes corresponding to protobuf-defined services."""
33
import grpc
4+
<<<<<<< HEAD
45
import warnings
56

67

@@ -22,3 +23,5 @@
2223
+ f' Please upgrade your grpc module to grpcio>={GRPC_GENERATED_VERSION}'
2324
+ f' or downgrade your generated code using grpcio-tools<={GRPC_VERSION}.'
2425
)
26+
=======
27+
>>>>>>> 989b70e (Fix Copilot review issues for attach hint PR)

ydb/_grpc/v6/draft/ydb_dynamic_config_v1_pb2_grpc.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
22
"""Client and server classes corresponding to protobuf-defined services."""
33
import grpc
4-
import warnings
54

65
from ydb._grpc.v6.draft.protos import ydb_dynamic_config_pb2 as draft_dot_protos_dot_ydb__dynamic__config__pb2
76

7+
<<<<<<< HEAD
88
GRPC_GENERATED_VERSION = '1.72.1'
99
GRPC_VERSION = grpc.__version__
1010
_version_not_supported = False
@@ -23,6 +23,8 @@
2323
+ f' Please upgrade your grpc module to grpcio>={GRPC_GENERATED_VERSION}'
2424
+ f' or downgrade your generated code using grpcio-tools<={GRPC_VERSION}.'
2525
)
26+
=======
27+
>>>>>>> 989b70e (Fix Copilot review issues for attach hint PR)
2628

2729

2830
class DynamicConfigServiceStub(object):

ydb/_grpc/v6/draft/ydb_federated_query_v1_pb2_grpc.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
22
"""Client and server classes corresponding to protobuf-defined services."""
33
import grpc
4-
import warnings
54

65
from ydb._grpc.v6.draft.protos import ydb_federated_query_pb2 as draft_dot_protos_dot_ydb__federated__query__pb2
76

7+
<<<<<<< HEAD
88
GRPC_GENERATED_VERSION = '1.72.1'
99
GRPC_VERSION = grpc.__version__
1010
_version_not_supported = False
@@ -23,6 +23,8 @@
2323
+ f' Please upgrade your grpc module to grpcio>={GRPC_GENERATED_VERSION}'
2424
+ f' or downgrade your generated code using grpcio-tools<={GRPC_VERSION}.'
2525
)
26+
=======
27+
>>>>>>> 989b70e (Fix Copilot review issues for attach hint PR)
2628

2729

2830
class FederatedQueryServiceStub(object):

0 commit comments

Comments
 (0)