Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
2d5bfdf
first step
slampy97 Oct 22, 2025
96c0ff1
also driver
slampy97 Oct 22, 2025
a4a292e
working coord client plus not working lock/ conenction problemsg
slampy97 Oct 22, 2025
d9de575
add wrappers, simple test is working, but problem to got structure back
slampy97 Oct 29, 2025
7701a05
several fixes plus wrappers
slampy97 Oct 29, 2025
82669fc
delete path from pr
slampy97 Oct 29, 2025
9fd7073
fix add gitmodules
slampy97 Oct 29, 2025
44a20a6
add alter node
slampy97 Oct 29, 2025
d749eb0
fix
slampy97 Oct 29, 2025
a5a36f6
fix config
slampy97 Oct 29, 2025
53ebed9
erase wrappers
slampy97 Oct 29, 2025
678598b
fix public wrappers
slampy97 Oct 31, 2025
1a6e166
fix last drivers coordination client inclusion
slampy97 Oct 31, 2025
aa8eaf9
fix tox -e style
slampy97 Oct 31, 2025
bd96246
tox -e black-format
slampy97 Oct 31, 2025
c3324cf
fix review remarks
slampy97 Nov 4, 2025
41323e6
fix review remarks
slampy97 Nov 4, 2025
65edbea
fix flake8 mistakes
slampy97 Nov 4, 2025
d2d25d4
fix review remarks plus styles checks
slampy97 Nov 5, 2025
9850b78
working async client, session_init + ping pong + lock release/acquire
slampy97 Nov 17, 2025
3f55d20
working async client, session_init + ping pong + lock release/acquire…
slampy97 Nov 17, 2025
89fe18d
some fix / redundant logic
slampy97 Nov 17, 2025
31e4fb6
fix lock logic
slampy97 Nov 17, 2025
194942f
refactor logic lock + reconnecor + stream - > lock should be resosibl…
slampy97 Nov 17, 2025
a81db7e
add describe -> start making crud lock object
slampy97 Nov 18, 2025
8defd59
crud lock object + acquire and release.
slampy97 Nov 18, 2025
53d547b
Merge branch 'coordination-service-impementation' into coordination-lock
slampy97 Nov 18, 2025
7d78387
add style checking
slampy97 Nov 18, 2025
4f66aad
fix linter
slampy97 Nov 18, 2025
45fc213
Add public wrappers for describe lock result
slampy97 Nov 18, 2025
e7a4357
rewrite stream with wrapper plus sync client
slampy97 Nov 25, 2025
c16e51e
first working version of sync and asunc client with lock api
slampy97 Nov 25, 2025
ae7f76c
refactor + reformat
slampy97 Nov 25, 2025
44a73fe
refactor + reformat
slampy97 Nov 25, 2025
82ea901
fixing format
slampy97 Nov 25, 2025
6f70b24
add NodeConfig as it was before
slampy97 Nov 25, 2025
134982a
simplify lock classes
slampy97 Nov 25, 2025
29d74b8
simplify lock classes
slampy97 Nov 25, 2025
4742860
fix common_utils.py + simplify stream.py
slampy97 Nov 26, 2025
202e4b5
simplify stream.py + correct lock.py
slampy97 Nov 26, 2025
b1a1849
fix lock delete method
slampy97 Nov 26, 2025
633f2d4
fix acquire method
slampy97 Nov 26, 2025
52f0874
get red of req_id logic and loop on every call
slampy97 Dec 10, 2025
35da8a6
test refactor, making ez for read
slampy97 Dec 10, 2025
1cafbff
test refactor, making ez for read
slampy97 Dec 10, 2025
68301b6
style refactor
slampy97 Dec 10, 2025
410c655
prep for rebase
slampy97 Dec 10, 2025
75b7b9a
Merge branch 'main' into coordination-lock
slampy97 Dec 10, 2025
ef5acef
apply req_id plus thin lock client
slampy97 Dec 11, 2025
3096a1a
simplify lock + reconnector
slampy97 Dec 11, 2025
edfc5f2
simplify lock + reconnector
slampy97 Dec 11, 2025
b8bcdb4
simplify lock + reconnector
slampy97 Dec 11, 2025
ee2c2fa
fix recconector
slampy97 Dec 11, 2025
80cd1fd
simplify reconnector.py
slampy97 Dec 11, 2025
5a4fb8c
simplify reconnector.py
slampy97 Dec 11, 2025
aaec556
simplify reconnector.py
slampy97 Dec 11, 2025
05b2c10
simplify reconnector.py
slampy97 Dec 11, 2025
bc389e0
fix style
slampy97 Dec 11, 2025
9e0ec86
fix style
slampy97 Dec 11, 2025
2dafcab
all tests passed - first time. Reconnector recconect session stream
slampy97 Dec 11, 2025
b2e4885
all tests passed - first time. Reconnector recconect session stream
slampy97 Dec 12, 2025
64491fa
all tests passed - first time. Reconnector recconect session stream
slampy97 Dec 12, 2025
fd9f4f1
all tsts passed and zero pending tasks, finally no errors
slampy97 Dec 12, 2025
f63464c
fix styles
slampy97 Dec 12, 2025
d29c9bc
fix timeout
slampy97 Dec 12, 2025
ced951f
fix test for cli
slampy97 Dec 12, 2025
df0b81e
last fixes
slampy97 Dec 12, 2025
f238d0b
last fixes + style fixing
slampy97 Dec 12, 2025
eb78713
fix and rewrite logic
slampy97 Dec 17, 2025
05355ee
some code refactor
slampy97 Dec 22, 2025
f021ddd
add example
vgvoleg Dec 22, 2025
9eede78
first working example of reconnector.py with example of how it should…
slampy97 Dec 22, 2025
84531cf
refactor of this (stable reconnector)
slampy97 Dec 23, 2025
c92f5ad
most simple and readable version of recconector.py
slampy97 Dec 23, 2025
fc69f5c
stream + reconnector, most simple version
slampy97 Dec 23, 2025
eb3db50
lock simlify
slampy97 Dec 23, 2025
55dec8f
full renaming
slampy97 Dec 23, 2025
ad962fa
rename entities
vgvoleg Dec 23, 2025
9a16069
update api
vgvoleg Dec 23, 2025
1597519
add docs and fix style
vgvoleg Dec 23, 2025
62315fc
fix warning text
vgvoleg Dec 23, 2025
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
3 changes: 2 additions & 1 deletion docs/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ Examples
:maxdepth: 3

examples/basic_example
examples/authentication
examples/authentication
examples/coordination
99 changes: 99 additions & 0 deletions docs/examples/coordination.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
Coordination Service
===================

.. warning::
Coordination Service API is experimental and may contain bugs and may change in future releases.

All examples in this section are parts of `coordination example <https://github.com/ydb-platform/ydb-python-sdk/tree/main/examples/coordination>`_.


Create node
-----------

.. code-block:: python

driver.coordination_client.create_node("/local/my_node")

Create node with config
-----------------------

.. code-block:: python

from ydb import NodeConfig, ConsistencyMode, RateLimiterCountersMode

config = NodeConfig(
attach_consistency_mode=ConsistencyMode.STRICT,
read_consistency_mode=ConsistencyMode.STRICT,
rate_limiter_counters_mode=RateLimiterCountersMode.AGGREGATED,
self_check_period_millis=1000,
session_grace_period_millis=10000
)

driver.coordination_client.create_node("/local/my_node", config)

Describe node
-------------

.. code-block:: python

config = driver.coordination_client.describe_node("/local/my_node")

Alter node
----------

.. code-block:: python

new_config = NodeConfig(
attach_consistency_mode=ConsistencyMode.RELAXED,
read_consistency_mode=ConsistencyMode.RELAXED,
rate_limiter_counters_mode=RateLimiterCountersMode.DETAILED,
self_check_period_millis=2000,
session_grace_period_millis=15000
)
driver.coordination_client.alter_node("/local/my_node", new_config)

Delete node
-----------

.. code-block:: python

driver.coordination_client.delete_node("/local/my_node")

Create session
--------------

.. code-block:: python

with driver.coordination_client.session("/local/my_node") as session:
pass

Use semaphore manually
----------------------

.. code-block:: python

with driver.coordination_client.session("/local/my_node") as session:
semaphore = session.semaphore("my_semaphore", limit=2) # limit is optional, default is 1
semaphore.acquire(count=2) # count is optional, default is 1
try:
pass
finally:
semaphore.release()

Use semaphore with context manager
----------------------------------

.. code-block:: python

with driver.coordination_client.session("/local/my_node") as session:
with session.semaphore("my_semaphore"):
pass

Async usage
-----------

.. code-block:: python

async with driver.coordination_client.session("/local/my_node") as session:
async with session.semaphore("my_semaphore"):
pass
40 changes: 40 additions & 0 deletions examples/coordination/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import argparse
import asyncio
from example import run as run_sync
from example_async import run as run_async
import logging


if __name__ == "__main__":
parser = argparse.ArgumentParser(
formatter_class=argparse.RawDescriptionHelpFormatter,
description="""\033[92mYDB coordination example.\x1b[0m\n""",
)
parser.add_argument("-e", "--endpoint", help="Endpoint url to use", default="grpc://localhost:2136")
parser.add_argument("-d", "--database", help="Name of the database to use", default="/local")
parser.add_argument("-v", "--verbose", default=False, action="store_true")
parser.add_argument("-m", "--mode", default="sync", help="Mode of example: sync or async")

args = parser.parse_args()

if args.verbose:
logger = logging.getLogger("ydb")
logger.setLevel(logging.INFO)
logger.addHandler(logging.StreamHandler())

if args.mode == "sync":
print("Running sync example")
run_sync(
args.endpoint,
args.database,
)
elif args.mode == "async":
print("Running async example")
asyncio.run(
run_async(
args.endpoint,
args.database,
)
)
else:
raise ValueError(f"Unsupported mode: {args.mode}, use one of sync|async")
57 changes: 57 additions & 0 deletions examples/coordination/example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import time
import threading
import ydb

NODE_PATH = "/local/node_name1"
SEMAPHORE_NAME = "semaphore"


def linear_workload(client, text):
session = client.session(NODE_PATH)
semaphore = session.semaphore(SEMAPHORE_NAME)
for i in range(3):
semaphore.acquire()
for j in range(3):
print(f"{text} iteration {i}-{j}")
time.sleep(0.1)
semaphore.release()
time.sleep(0.05)
session.close()


def context_manager_workload(client, text):
with client.session(NODE_PATH) as session:
for i in range(3):
with session.semaphore(SEMAPHORE_NAME):
for j in range(3):
print(f"{text} iteration {i}-{j}")
time.sleep(0.1)
time.sleep(0.05)


def run(endpoint, database):
with ydb.Driver(
endpoint=endpoint,
database=database,
credentials=ydb.credentials_from_env_variables(),
root_certificates=ydb.load_ydb_root_certificate(),
) as driver:
driver.wait(timeout=5, fail_fast=True)

driver.coordination_client.create_node(NODE_PATH)

threads = []

for i in range(4):
worker_name = f"worker {i+1}"
if i < 2:
thread = threading.Thread(target=linear_workload, args=(driver.coordination_client, worker_name))
else:
thread = threading.Thread(
target=context_manager_workload, args=(driver.coordination_client, worker_name)
)
threads.append(thread)
thread.start()

for thread in threads:
thread.join()
47 changes: 47 additions & 0 deletions examples/coordination/example_async.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import asyncio
import ydb

NODE_PATH = "/local/node_name1"
SEMAPHORE_NAME = "semaphore"


async def linear_workload(client, text):
session = client.session(NODE_PATH)
semaphore = session.semaphore(SEMAPHORE_NAME)
for i in range(3):
await semaphore.acquire()
for j in range(3):
print(f"{text} iteration {i}-{j}")
await asyncio.sleep(0.1)
await semaphore.release()
await asyncio.sleep(0.05)
await session.close()


async def context_manager_workload(client, text):
async with client.session(NODE_PATH) as session:
for i in range(3):
async with session.semaphore(SEMAPHORE_NAME):
for j in range(3):
print(f"{text} iteration {i}-{j}")
await asyncio.sleep(0.1)
await asyncio.sleep(0.05)


async def run(endpoint, database):
async with ydb.aio.Driver(
endpoint=endpoint,
database=database,
credentials=ydb.credentials_from_env_variables(),
root_certificates=ydb.load_ydb_root_certificate(),
) as driver:
await driver.wait(timeout=5, fail_fast=True)

await driver.coordination_client.create_node(NODE_PATH)

await asyncio.gather(
linear_workload(driver.coordination_client, "worker 1"),
linear_workload(driver.coordination_client, "worker 2"),
context_manager_workload(driver.coordination_client, "worker 3"),
context_manager_workload(driver.coordination_client, "worker 4"),
)
Loading
Loading