-
Notifications
You must be signed in to change notification settings - Fork 62
Coordination service impementation - 1 step #715
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 11 commits
2d5bfdf
96c0ff1
a4a292e
d9de575
7701a05
82669fc
9fd7073
44a20a6
d749eb0
a5a36f6
53ebed9
678598b
1a6e166
aa8eaf9
bd96246
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import ydb | ||
| from ydb import _apis | ||
|
|
||
|
|
||
| def test_coordination_alter_node(driver_sync: ydb.Driver): | ||
| client = driver_sync.coordination_client | ||
| node_path = "/local/test_alter_node" | ||
|
|
||
| try: | ||
| client.delete_node(node_path) | ||
| except ydb.SchemeError: | ||
| pass | ||
|
|
||
| client.create_node(node_path) | ||
|
|
||
| new_config = _apis.ydb_coordination.Config( | ||
vgvoleg marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| session_grace_period_millis=12345, | ||
| attach_consistency_mode=_apis.ydb_coordination.ConsistencyMode.CONSISTENCY_MODE_STRICT, | ||
| read_consistency_mode=_apis.ydb_coordination.ConsistencyMode.CONSISTENCY_MODE_RELAXED, | ||
| ) | ||
|
|
||
|
|
||
| client.alter_node(node_path, new_config) | ||
|
|
||
| node_config = client.describe_node(node_path) | ||
| assert node_config.session_grace_period_millis == 12345, "Session grace period not updated" | ||
| assert node_config.attach_consistency_mode == _apis.ydb_coordination.ConsistencyMode.CONSISTENCY_MODE_STRICT, \ | ||
| "Attach consistency mode not updated" | ||
| assert node_config.read_consistency_mode == _apis.ydb_coordination.ConsistencyMode.CONSISTENCY_MODE_RELAXED, \ | ||
| "Read consistency mode not updated" | ||
|
|
||
| client.delete_node(node_path) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import ydb | ||
|
|
||
| def test_coordination_nodes(driver_sync: ydb.Driver): | ||
| client = driver_sync.coordination_client | ||
| node_path = "/local/test_node" | ||
|
|
||
| try: | ||
| client.delete_node(node_path) | ||
| except ydb.SchemeError: | ||
| pass | ||
|
|
||
| client.create_node(node_path) | ||
|
|
||
| node_config = client.describe_node(node_path) | ||
|
|
||
| assert node_config.path == "/local/test_node" | ||
|
|
||
| client.delete_node(node_path) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| import typing | ||
| from dataclasses import dataclass | ||
|
|
||
| import ydb | ||
|
|
||
| if typing.TYPE_CHECKING: | ||
| from ..v4.protos import ydb_coordination_pb2 | ||
| else: | ||
| from ..common.protos import ydb_coordination_pb2 | ||
|
|
||
| from .common_utils import IToProto, IFromProto, ServerStatus | ||
| from . import ydb_coordination_public_types as public_types | ||
|
|
||
|
|
||
| # -------------------- Requests -------------------- | ||
|
|
||
| @dataclass | ||
| class CreateNodeRequest(IToProto): | ||
| path: str | ||
| config: typing.Optional[public_types.NodeConfig] = None | ||
| operation_params: typing.Any = None | ||
slampy97 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| def to_proto(self) -> ydb_coordination_pb2.CreateNodeRequest: | ||
| cfg_proto = self.config.to_proto() if self.config else None | ||
| return ydb_coordination_pb2.CreateNodeRequest( | ||
| path=self.path, | ||
| config=cfg_proto, | ||
| operation_params=self.operation_params, | ||
| ) | ||
|
|
||
| @dataclass | ||
| class AlterNodeRequest(IToProto): | ||
| path: str | ||
| config: typing.Optional[public_types.NodeConfig] = None | ||
| operation_params: typing.Any = None | ||
|
|
||
| def to_proto(self) -> ydb_coordination_pb2.AlterNodeRequest: | ||
| cfg_proto = self.config.to_proto() if self.config else None | ||
| return ydb_coordination_pb2.AlterNodeRequest( | ||
| path=self.path, | ||
| config=cfg_proto, | ||
| operation_params=self.operation_params, | ||
| ) | ||
|
|
||
|
|
||
|
|
||
| @dataclass | ||
| class DescribeNodeRequest(IToProto): | ||
| path: str | ||
| operation_params: typing.Any = None | ||
|
|
||
| def to_proto(self) -> ydb_coordination_pb2.DescribeNodeRequest: | ||
| return ydb_coordination_pb2.DescribeNodeRequest( | ||
| path=self.path, | ||
| operation_params=self.operation_params, | ||
| ) | ||
|
|
||
|
|
||
| @dataclass | ||
| class DropNodeRequest(IToProto): | ||
| path: str | ||
| operation_params: typing.Any = None | ||
|
|
||
| def to_proto(self) -> ydb_coordination_pb2.DropNodeRequest: | ||
| return ydb_coordination_pb2.DropNodeRequest( | ||
| path=self.path, | ||
| operation_params=self.operation_params, | ||
| ) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| from dataclasses import dataclass | ||
| from enum import Enum | ||
| import typing | ||
|
|
||
| if typing.TYPE_CHECKING: | ||
| from ..v4.protos import ydb_coordination_pb2 | ||
| else: | ||
| from ..common.protos import ydb_coordination_pb2 | ||
|
|
||
|
|
||
| @dataclass | ||
| class NodeConfig: | ||
| attach_consistency_mode: ydb_coordination_pb2.ConsistencyMode | ||
vgvoleg marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| path: str | ||
| rate_limiter_counters_mode: ydb_coordination_pb2.RateLimiterCountersMode | ||
| read_consistency_mode: ydb_coordination_pb2.ConsistencyMode | ||
| self_check_period_millis: int | ||
| session_grace_period_millis: int | ||
|
|
||
| @staticmethod | ||
| def from_proto(msg: ydb_coordination_pb2.Config) -> "NodeConfig": | ||
| return NodeConfig( | ||
| attach_consistency_mode=msg.attach_consistency_mode, | ||
| path=msg.path, | ||
| rate_limiter_counters_mode=msg.rate_limiter_counters_mode, | ||
| read_consistency_mode=msg.read_consistency_mode, | ||
| self_check_period_millis=msg.self_check_period_millis, | ||
| session_grace_period_millis=msg.session_grace_period_millis, | ||
| ) | ||
|
|
||
| def to_proto(self) -> ydb_coordination_pb2.Config: | ||
| return ydb_coordination_pb2.Config( | ||
| attach_consistency_mode=self.attach_consistency_mode.value, | ||
| path=self.path, | ||
| rate_limiter_counters_mode=self.rate_limiter_counters_mode.value, | ||
| read_consistency_mode=self.read_consistency_mode.value, | ||
| self_check_period_millis=self.self_check_period_millis, | ||
| session_grace_period_millis=self.session_grace_period_millis, | ||
| ) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| from .coordination_client import CoordinationClient | ||
|
|
||
| __all__ = [ | ||
| "CoordinationClient", | ||
vgvoleg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| import typing | ||
| from typing import Optional | ||
|
|
||
| from ydb import _apis, issues | ||
| from ydb._grpc.grpcwrapper.ydb_coordination_public_types import NodeConfig | ||
|
|
||
| if typing.TYPE_CHECKING: | ||
| import ydb | ||
|
|
||
|
|
||
| class CoordinationClient: | ||
| def __init__(self, driver: "ydb.Driver"): | ||
| self._driver = driver | ||
|
|
||
| def _call_node( | ||
vgvoleg marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| self, | ||
| request, | ||
| rpc_method, | ||
| settings: Optional["ydb.BaseRequestSettings"] = None, | ||
| ): | ||
| response = self._driver( | ||
| request, | ||
| _apis.CoordinationService.Stub, | ||
| rpc_method, | ||
| settings=settings, | ||
| ) | ||
| issues._process_response(response.operation) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. даже эту проверку стоит засунуть во враппер, тогда все что останется сделать во всех методах - return self._driver() |
||
| return response | ||
|
|
||
| def create_node( | ||
| self, | ||
| path: str, | ||
| config: Optional[_apis.ydb_coordination.Config] = None, | ||
vgvoleg marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| settings: Optional["ydb.BaseRequestSettings"] = None, | ||
| ): | ||
| request = _apis.ydb_coordination.CreateNodeRequest( | ||
| path=path, | ||
| config=config, | ||
| ) | ||
| self._call_node(request, _apis.CoordinationService.CreateNode, settings) | ||
|
|
||
| def describe_node( | ||
| self, | ||
| path: str, | ||
| settings: Optional["_apis.ydb_coordination.Config"] = None, | ||
| ) -> Optional[NodeConfig]: | ||
| request = _apis.ydb_coordination.DescribeNodeRequest(path=path) | ||
| response = self._call_node(request, _apis.CoordinationService.DescribeNode, settings) | ||
| result = _apis.ydb_coordination.DescribeNodeResult() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. на все это нужен враппер There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. враппер так и не появился |
||
| response.operation.result.Unpack(result) | ||
| result.config.path = path | ||
| return NodeConfig.from_proto(result.config) | ||
|
|
||
| def delete_node( | ||
| self, | ||
| path: str, | ||
| settings: Optional["ydb.BaseRequestSettings"] = None, | ||
| ): | ||
| request = _apis.ydb_coordination.DropNodeRequest(path=path) | ||
| self._call_node(request, _apis.CoordinationService.DropNode, settings) | ||
|
|
||
| def alter_node( | ||
| self, | ||
| path: str, | ||
| new_config: _apis.ydb_coordination.Config, | ||
| settings: Optional["ydb.BaseRequestSettings"] = None, | ||
| ): | ||
| request = _apis.ydb_coordination.AlterNodeRequest( | ||
| path=path, | ||
| config=new_config, | ||
| ) | ||
| self._call_node(request, _apis.CoordinationService.AlterNode, settings) | ||
|
|
||
| def close(self): | ||
| pass | ||
Uh oh!
There was an error while loading. Please reload this page.