Only warn on mismatched `open_registry()` input addrs
When a new (actor) caller opens the registry there are 2 possible cases: 1. - some task already opened the registry during init and set the global superset of registrar addrs that are expected to be used, 2. - some task after the init task opens with a subset of addrs. 3. - some task after init opens with a disjoint set - should be an error? In the 2nd case we don't want to error since the may just not need to know about other registrar (multi-homed) addrs and thus only needs specific access - so only warn about the diff in that case. If the caller is requesting some disjoint set then we still runtime raise. Adjust `find_service()` to allow a null `registry_addrs` input in which case we fail over to using whatever pre-set the `Registry.addrs` has; makes it simple for actors that don't want/need to know about the global registrar set for their actor tree. Also, always set pass `tractor.find_actor(only_first=True)` (for now).distribute_dis
parent
5d081a40d5
commit
7258d57c69
|
@ -66,7 +66,13 @@ async def open_registry(
|
||||||
ensure_exists: bool = True,
|
ensure_exists: bool = True,
|
||||||
|
|
||||||
) -> list[tuple[str, int]]:
|
) -> list[tuple[str, int]]:
|
||||||
|
'''
|
||||||
|
Open the service-actor-discovery registry by returning a set of
|
||||||
|
tranport socket-addrs to registrar actors which may be
|
||||||
|
contacted and queried for similar addresses for other
|
||||||
|
non-registrar actors.
|
||||||
|
|
||||||
|
'''
|
||||||
global _tractor_kwargs
|
global _tractor_kwargs
|
||||||
actor = tractor.current_actor()
|
actor = tractor.current_actor()
|
||||||
uid = actor.uid
|
uid = actor.uid
|
||||||
|
@ -76,6 +82,14 @@ async def open_registry(
|
||||||
and addrs
|
and addrs
|
||||||
):
|
):
|
||||||
if preset_reg_addrs != addrs:
|
if preset_reg_addrs != addrs:
|
||||||
|
# if any(addr in preset_reg_addrs for addr in addrs):
|
||||||
|
diff: set[tuple[str, int]] = set(preset_reg_addrs) - set(addrs)
|
||||||
|
if diff:
|
||||||
|
log.warning(
|
||||||
|
f'`{uid}` requested only subset of registrars: {addrs}\n'
|
||||||
|
f'However there are more @{diff}'
|
||||||
|
)
|
||||||
|
else:
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
f'`{uid}` has non-matching registrar addresses?\n'
|
f'`{uid}` has non-matching registrar addresses?\n'
|
||||||
f'request: {addrs}\n'
|
f'request: {addrs}\n'
|
||||||
|
@ -122,7 +136,7 @@ async def open_registry(
|
||||||
@acm
|
@acm
|
||||||
async def find_service(
|
async def find_service(
|
||||||
service_name: str,
|
service_name: str,
|
||||||
registry_addrs: list[tuple[str, int]],
|
registry_addrs: list[tuple[str, int]] | None = None,
|
||||||
|
|
||||||
first_only: bool = True,
|
first_only: bool = True,
|
||||||
|
|
||||||
|
@ -130,22 +144,26 @@ async def find_service(
|
||||||
|
|
||||||
reg_addrs: list[tuple[str, int]]
|
reg_addrs: list[tuple[str, int]]
|
||||||
async with open_registry(
|
async with open_registry(
|
||||||
addrs=registry_addrs,
|
addrs=(
|
||||||
|
registry_addrs
|
||||||
|
# NOTE: if no addr set is passed assume the registry has
|
||||||
|
# already been opened and use the previously applied
|
||||||
|
# startup set.
|
||||||
|
or Registry.addrs
|
||||||
|
),
|
||||||
) as reg_addrs:
|
) as reg_addrs:
|
||||||
log.info(f'Scanning for service `{service_name}`')
|
log.info(f'Scanning for service `{service_name}`')
|
||||||
# attach to existing daemon by name if possible
|
# attach to existing daemon by name if possible
|
||||||
async with tractor.find_actor(
|
async with tractor.find_actor(
|
||||||
service_name,
|
service_name,
|
||||||
registry_addrs=reg_addrs,
|
registry_addrs=reg_addrs,
|
||||||
|
only_first=first_only, # if set only returns single ref
|
||||||
) as maybe_portals:
|
) as maybe_portals:
|
||||||
if not maybe_portals:
|
if not maybe_portals:
|
||||||
yield None
|
yield None
|
||||||
return
|
return
|
||||||
|
|
||||||
if first_only:
|
yield maybe_portals
|
||||||
yield maybe_portals[0]
|
|
||||||
else:
|
|
||||||
yield maybe_portals[0]
|
|
||||||
|
|
||||||
|
|
||||||
async def check_for_service(
|
async def check_for_service(
|
||||||
|
@ -156,9 +174,11 @@ async def check_for_service(
|
||||||
Service daemon "liveness" predicate.
|
Service daemon "liveness" predicate.
|
||||||
|
|
||||||
'''
|
'''
|
||||||
async with open_registry(ensure_exists=False) as reg_addr:
|
async with (
|
||||||
async with tractor.query_actor(
|
open_registry(ensure_exists=False) as reg_addr,
|
||||||
|
tractor.query_actor(
|
||||||
service_name,
|
service_name,
|
||||||
arbiter_sockaddr=reg_addr,
|
arbiter_sockaddr=reg_addr,
|
||||||
) as sockaddr:
|
) as sockaddr,
|
||||||
|
):
|
||||||
return sockaddr
|
return sockaddr
|
||||||
|
|
Loading…
Reference in New Issue