Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dynamo
Commits
9d643f1e
Unverified
Commit
9d643f1e
authored
May 05, 2025
by
Hongkuan Zhou
Committed by
GitHub
May 05, 2025
Browse files
fix: use primary lease for NixlMetadataStore (#928)
parent
960ee927
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
47 additions
and
1 deletion
+47
-1
examples/llm/utils/nixl.py
examples/llm/utils/nixl.py
+8
-1
lib/bindings/python/examples/hello_world/server.py
lib/bindings/python/examples/hello_world/server.py
+3
-0
lib/bindings/python/rust/lib.rs
lib/bindings/python/rust/lib.rs
+22
-0
lib/bindings/python/src/dynamo/_core.pyi
lib/bindings/python/src/dynamo/_core.pyi
+14
-0
No files found.
examples/llm/utils/nixl.py
View file @
9d643f1e
...
@@ -73,7 +73,14 @@ class NixlMetadataStore:
...
@@ -73,7 +73,14 @@ class NixlMetadataStore:
async
def
put
(
self
,
engine_id
,
metadata
:
NixlMetadata
):
async
def
put
(
self
,
engine_id
,
metadata
:
NixlMetadata
):
serialized_metadata
=
msgspec
.
msgpack
.
encode
(
metadata
)
serialized_metadata
=
msgspec
.
msgpack
.
encode
(
metadata
)
key
=
"/"
.
join
([
self
.
_key_prefix
,
engine_id
])
key
=
"/"
.
join
([
self
.
_key_prefix
,
engine_id
])
await
self
.
_client
.
kv_put
(
key
,
serialized_metadata
,
None
)
# create with primary lease so that the kv entry will be deleted when the worker shutdowns
try
:
# TODO: should we create a series of function in etcd client to use primary lease?
await
self
.
_client
.
kv_create_or_validate
(
key
,
serialized_metadata
,
self
.
_client
.
primary_lease_id
()
)
except
Exception
as
e
:
logger
.
warning
(
f
"A different metadata exists for engine
{
engine_id
}
:
{
e
}
"
)
self
.
_stored
.
add
(
engine_id
)
self
.
_stored
.
add
(
engine_id
)
async
def
get
(
self
,
engine_id
)
->
NixlMetadata
:
async
def
get
(
self
,
engine_id
)
->
NixlMetadata
:
...
...
lib/bindings/python/examples/hello_world/server.py
View file @
9d643f1e
...
@@ -34,6 +34,9 @@ class RequestHandler:
...
@@ -34,6 +34,9 @@ class RequestHandler:
@
dynamo_worker
(
static
=
False
)
@
dynamo_worker
(
static
=
False
)
async
def
worker
(
runtime
:
DistributedRuntime
):
async
def
worker
(
runtime
:
DistributedRuntime
):
print
(
f
"Primary lease ID:
{
runtime
.
etcd_client
().
primary_lease_id
()
}
/
{
runtime
.
etcd_client
().
primary_lease_id
():
#x
}
"
)
await
init
(
runtime
,
"dynamo"
)
await
init
(
runtime
,
"dynamo"
)
...
...
lib/bindings/python/rust/lib.rs
View file @
9d643f1e
...
@@ -481,6 +481,24 @@ impl Namespace {
...
@@ -481,6 +481,24 @@ impl Namespace {
#[pymethods]
#[pymethods]
impl
EtcdClient
{
impl
EtcdClient
{
#[pyo3(signature
=
(key,
value,
lease_id=None))]
fn
kv_create
<
'p
>
(
&
self
,
py
:
Python
<
'p
>
,
key
:
String
,
value
:
Vec
<
u8
>
,
lease_id
:
Option
<
i64
>
,
)
->
PyResult
<
Bound
<
'p
,
PyAny
>>
{
let
client
=
self
.inner
.clone
();
pyo3_async_runtimes
::
tokio
::
future_into_py
(
py
,
async
move
{
client
.kv_create
(
key
,
value
,
lease_id
)
.await
.map_err
(
to_pyerr
)
?
;
Ok
(())
})
}
#[pyo3(signature
=
(key,
value,
lease_id=None))]
#[pyo3(signature
=
(key,
value,
lease_id=None))]
fn
kv_create_or_validate
<
'p
>
(
fn
kv_create_or_validate
<
'p
>
(
&
self
,
&
self
,
...
@@ -499,6 +517,10 @@ impl EtcdClient {
...
@@ -499,6 +517,10 @@ impl EtcdClient {
})
})
}
}
fn
primary_lease_id
(
&
self
)
->
i64
{
self
.inner
.lease_id
()
}
#[pyo3(signature
=
(key,
value,
lease_id=None))]
#[pyo3(signature
=
(key,
value,
lease_id=None))]
fn
kv_put
<
'p
>
(
fn
kv_put
<
'p
>
(
&
self
,
&
self
,
...
...
lib/bindings/python/src/dynamo/_core.pyi
View file @
9d643f1e
...
@@ -79,6 +79,20 @@ class EtcdClient:
...
@@ -79,6 +79,20 @@ class EtcdClient:
Etcd is used for discovery in the DistributedRuntime
Etcd is used for discovery in the DistributedRuntime
"""
"""
def primary_lease_id(self) -> int:
"""
return the primary lease id.
"""
...
async def kv_create(
self, key: str, value: bytes, lease_id: Optional[int] = None
) -> None:
"""
Atomically create a key in etcd, fail if the key already exists.
"""
...
async def kv_create_or_validate(
async def kv_create_or_validate(
self, key: str, value: bytes, lease_id: Optional[int] = None
self, key: str, value: bytes, lease_id: Optional[int] = None
) -> None:
) -> None:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment