Skip to content

Commit 1597519

Browse files
committed
add docs and fix style
1 parent 9a16069 commit 1597519

File tree

3 files changed

+106
-4
lines changed

3 files changed

+106
-4
lines changed

docs/examples.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ Examples
55
:maxdepth: 3
66

77
examples/basic_example
8-
examples/authentication
8+
examples/authentication
9+
examples/coordination

docs/examples/coordination.rst

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
Coordination Service
2+
===================
3+
4+
.. warning::
5+
Coordination Service API is experimental and may change in future releases.
6+
7+
All examples in this section are parts of `coordination example <https://github.com/ydb-platform/ydb-python-sdk/tree/main/examples/coordination>`_.
8+
9+
10+
Create node
11+
-----------
12+
13+
.. code-block:: python
14+
15+
driver.coordination_client.create_node("/local/my_node")
16+
17+
Create node with config
18+
-----------------------
19+
20+
.. code-block:: python
21+
22+
from ydb import NodeConfig, ConsistencyMode, RateLimiterCountersMode
23+
24+
config = NodeConfig(
25+
attach_consistency_mode=ConsistencyMode.STRICT,
26+
read_consistency_mode=ConsistencyMode.STRICT,
27+
rate_limiter_counters_mode=RateLimiterCountersMode.AGGREGATED,
28+
self_check_period_millis=1000,
29+
session_grace_period_millis=10000
30+
)
31+
32+
driver.coordination_client.create_node("/local/my_node", config)
33+
34+
Describe node
35+
-------------
36+
37+
.. code-block:: python
38+
39+
config = driver.coordination_client.describe_node("/local/my_node")
40+
41+
Alter node
42+
----------
43+
44+
.. code-block:: python
45+
46+
new_config = NodeConfig(
47+
attach_consistency_mode=ConsistencyMode.RELAXED,
48+
read_consistency_mode=ConsistencyMode.RELAXED,
49+
rate_limiter_counters_mode=RateLimiterCountersMode.DETAILED,
50+
self_check_period_millis=2000,
51+
session_grace_period_millis=15000
52+
)
53+
driver.coordination_client.alter_node("/local/my_node", new_config)
54+
55+
Delete node
56+
-----------
57+
58+
.. code-block:: python
59+
60+
driver.coordination_client.delete_node("/local/my_node")
61+
62+
Create session
63+
--------------
64+
65+
.. code-block:: python
66+
67+
with driver.coordination_client.session("/local/my_node") as session:
68+
pass
69+
70+
Use semaphore manually
71+
----------------------
72+
73+
.. code-block:: python
74+
75+
with driver.coordination_client.session("/local/my_node") as session:
76+
semaphore = session.semaphore("my_semaphore", limit=2) # limit is optional, default is 1
77+
semaphore.acquire(count=2) # count is optional, default is 1
78+
try:
79+
pass
80+
finally:
81+
semaphore.release()
82+
83+
Use semaphore with context manager
84+
----------------------------------
85+
86+
.. code-block:: python
87+
88+
with driver.coordination_client.session("/local/my_node") as session:
89+
with session.semaphore("my_semaphore"):
90+
pass
91+
92+
Async usage
93+
-----------
94+
95+
.. code-block:: python
96+
97+
async with driver.coordination_client.session("/local/my_node") as session:
98+
async with session.semaphore("my_semaphore"):
99+
pass

ydb/coordination/base.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
from .._grpc.grpcwrapper.ydb_coordination_public_types import NodeConfig, DescribeResult
33
import logging
44

5+
logger = logging.getLogger(__name__)
6+
57

68
def wrapper_create_node(rpc_state, response_pb):
79
issues._process_response(response_pb.operation)
@@ -19,8 +21,6 @@ def wrapper_delete_node(rpc_state, response_pb):
1921
def wrapper_alter_node(rpc_state, response_pb):
2022
issues._process_response(response_pb.operation)
2123

22-
logger = logging.getLogger(__name__)
23-
2424

2525
class BaseCoordinationClient:
2626
def __init__(self, driver):
@@ -65,5 +65,7 @@ def _call_delete(self, request, settings=None):
6565

6666
def _log_experimental_api(self):
6767
if not self._user_warned:
68-
logger.warning("Coordination Service API is experimental, may contain bugs and may change in future releases.")
68+
logger.warning(
69+
"Coordination Service API is experimental, may contain bugs and may change in future releases."
70+
)
6971
self._user_warned = True

0 commit comments

Comments
 (0)