Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
cbe98dc
Initial asyncio commit
yuce Sep 19, 2025
162fd17
Updates
yuce Sep 19, 2025
9931956
Updates
yuce Sep 19, 2025
856e3df
Merge branch 'master' into asyncio-module
yuce Sep 19, 2025
35384bf
Black
yuce Sep 19, 2025
fdda120
Updates
yuce Sep 19, 2025
fee5b45
Updates
yuce Sep 19, 2025
fc2c38b
Updates
yuce Sep 19, 2025
1772031
Removed docs, include HazelcastClient/Map in public API
yuce Sep 19, 2025
170cf89
Updates
yuce Sep 19, 2025
539c904
Merge branch 'master' into asyncio-module
yuce Sep 22, 2025
22449a8
black
yuce Sep 22, 2025
5406bc6
Ignore incorrect mypy errors
yuce Sep 22, 2025
a417a4a
Updates
yuce Sep 24, 2025
d00c480
Updates
yuce Sep 25, 2025
baa3bc1
Annotate optional params
yuce Sep 29, 2025
ebfc9e2
black
yuce Sep 29, 2025
6928837
Remove update to test util
yuce Sep 30, 2025
3e03cbf
black
yuce Sep 30, 2025
51ced7a
black
yuce Sep 30, 2025
e635b94
update
yuce Sep 30, 2025
4f103f6
Added support for SSL
yuce Sep 30, 2025
042cc58
Added SSL tests
yuce Sep 30, 2025
265a2b4
Added mutual authentication test
yuce Sep 30, 2025
293975d
Added hostname verification tests
yuce Oct 1, 2025
2718478
black
yuce Oct 1, 2025
58783dc
Ported more integration tests
yuce Oct 1, 2025
3cf9982
Ported hazelcast json value test
yuce Oct 2, 2025
7e97ec7
Merge branch 'master' into asyncio-module-integration-tests1
yuce Oct 2, 2025
6a558e8
Merge branch 'master' into asyncio-module-ssl
yuce Oct 2, 2025
a630706
Merge branch 'master' into asyncio-module
yuce Oct 2, 2025
c1798ea
Ported heart beat test
yuce Oct 2, 2025
e92936a
Ported more tests
yuce Oct 20, 2025
6ced889
Merge branch 'master' into asyncio-module
yuce Oct 20, 2025
c313bfa
Merge branch 'master' into asyncio-module-ssl
yuce Oct 20, 2025
6222c6b
Merge branch 'master' into asyncio-module-integration-tests1
yuce Oct 20, 2025
120a58a
black
yuce Oct 22, 2025
80880b8
Fixed type hints
yuce Oct 30, 2025
6431acc
type hints
yuce Nov 14, 2025
e9a9b5e
Ported more tests
yuce Nov 17, 2025
5334cd1
Added near cache, statistics, statistics tests
yuce Nov 17, 2025
a14290a
Black
yuce Nov 17, 2025
492ccc1
Fixed getting local address
yuce Nov 18, 2025
e8a2600
Fixed getting local address, take 2
yuce Nov 18, 2025
24eb6bf
Added nearcache tests
yuce Nov 18, 2025
6ab9365
Ported missing nearcache test
yuce Nov 18, 2025
3f3a9c5
Ported VectorCollection and its tests
yuce Nov 19, 2025
bfb805d
Black
yuce Nov 19, 2025
5f59992
Ported compact serialization tests
yuce Nov 20, 2025
91bf1d1
Addressed review comment
yuce Nov 21, 2025
ef7570f
Updates
yuce Nov 21, 2025
2128f5e
Removed unnecessary code
yuce Nov 21, 2025
62697e3
Add BETA warning
yuce Nov 21, 2025
a87a5c6
Black
yuce Nov 21, 2025
5023568
Updated test_heartbeat_stopped_and_restored test
yuce Nov 24, 2025
8d7eede
Merge branch 'asyncio-module' into asyncio-module-ssl
yuce Nov 24, 2025
00a2d12
Merge branch 'asyncio-module-ssl' into asyncio-module-integration-tests1
yuce Nov 24, 2025
539466b
Merge branch 'asyncio-module-integration-tests1' into asyncio-module-…
yuce Nov 24, 2025
2aff5e4
Merge branch 'asyncio-module-integration-tests2' into asyncio-module-…
yuce Nov 24, 2025
284de6d
Merge branch 'asyncio-module-vc-support' into asyncio-module-compact-…
yuce Nov 24, 2025
767bfd5
Fix test_map_smart_listener_local_only
yuce Nov 24, 2025
e673679
Updated test_heartbeat_stopped_and_restored
yuce Nov 25, 2025
ab4a746
Merge branch 'asyncio-module-integration-tests1' into asyncio-module-…
yuce Nov 25, 2025
319bb35
Fixed tests
yuce Nov 25, 2025
8e325ea
Linter
yuce Nov 25, 2025
eed53b3
Test updates
yuce Nov 25, 2025
a6d5949
Merge branch 'asyncio-module-integration-tests2' into asyncio-module-…
yuce Nov 26, 2025
f61ec8e
Test updates
yuce Nov 26, 2025
4446ba7
Merge branch 'asyncio-module-vc-support' into asyncio-module-compact-…
yuce Nov 26, 2025
1ca7fd6
Addressed review comment
yuce Nov 26, 2025
d9acede
updates
yuce Nov 28, 2025
bd23f41
Merge branch 'asyncio-module-ssl' into asyncio-module-integration-tests1
yuce Nov 28, 2025
76759ec
Merge branch 'asyncio-module-integration-tests1' into asyncio-module-…
yuce Nov 28, 2025
74a9aca
Merge branch 'asyncio-module-integration-tests2' into asyncio-module-…
yuce Nov 28, 2025
e33af1d
Merge branch 'asyncio-module-vc-support' into asyncio-module-compact-…
yuce Nov 28, 2025
2a2d6e8
Merge branch 'master' into asyncio-module-integration-tests1
yuce Dec 1, 2025
6da4226
Merge branch 'asyncio-module-integration-tests1' into asyncio-module-…
yuce Dec 1, 2025
0a829d4
Merge branch 'asyncio-module-integration-tests2' into asyncio-module-…
yuce Dec 2, 2025
3cf71d5
Merge branch 'asyncio-module-vc-support' into asyncio-module-compact-…
yuce Dec 2, 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
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ check:
black --check --config black.toml .

test:
pytest -m "not enterprise"
pytest --verbose -m "not enterprise"

test-enterprise:
pytest
pytest --verbose

test-cover:
pytest --cov=hazelcast --cov-report=xml
44 changes: 38 additions & 6 deletions hazelcast/asyncio/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@

from hazelcast.internal.asyncio_cluster import ClusterService, _InternalClusterService
from hazelcast.internal.asyncio_compact import CompactSchemaService
from hazelcast.config import Config
from hazelcast.config import Config, IndexConfig
from hazelcast.internal.asyncio_connection import ConnectionManager, DefaultAddressProvider
from hazelcast.core import DistributedObjectEvent, DistributedObjectInfo
from hazelcast.cp import CPSubsystem, ProxySessionManager
from hazelcast.discovery import HazelcastCloudAddressProvider
from hazelcast.errors import IllegalStateError, InvalidConfigurationError
from hazelcast.internal.asyncio_invocation import InvocationService, Invocation
from hazelcast.internal.asyncio_proxy.vector_collection import VectorCollection
from hazelcast.lifecycle import LifecycleService, LifecycleState, _InternalLifecycleService
from hazelcast.internal.asyncio_listener import ClusterViewListenerService, ListenerService
from hazelcast.near_cache import NearCacheManager
Expand All @@ -20,17 +21,19 @@
client_add_distributed_object_listener_codec,
client_get_distributed_objects_codec,
client_remove_distributed_object_listener_codec,
dynamic_config_add_vector_collection_config_codec,
)
from hazelcast.internal.asyncio_proxy.manager import (
MAP_SERVICE,
ProxyManager,
VECTOR_SERVICE,
)
from hazelcast.internal.asyncio_proxy.base import Proxy
from hazelcast.internal.asyncio_proxy.map import Map
from hazelcast.internal.asyncio_reactor import AsyncioReactor
from hazelcast.serialization import SerializationServiceV1
from hazelcast.sql import SqlService, _InternalSqlService
from hazelcast.statistics import Statistics
from hazelcast.internal.asyncio_statistics import Statistics
from hazelcast.types import KeyType, ValueType, ItemType, MessageType
from hazelcast.util import AtomicInteger, RoundRobinLB

Expand Down Expand Up @@ -162,10 +165,9 @@ def _init_context(self):
)

async def _start(self):
self._reactor.start()
try:
self._internal_lifecycle_service.start()
self._invocation_service.start()
await self._invocation_service.start()
membership_listeners = self._config.membership_listeners
self._internal_cluster_service.start(self._connection_manager, membership_listeners)
self._cluster_view_listener.start()
Expand All @@ -177,7 +179,7 @@ async def _start(self):
self._listener_service.start()
await self._invocation_service.add_backup_listener()
self._load_balancer.init(self._cluster_service)
self._statistics.start()
await self._statistics.start()
except Exception:
await self.shutdown()
raise
Expand All @@ -186,6 +188,37 @@ async def _start(self):
async def get_map(self, name: str) -> Map[KeyType, ValueType]:
return await self._proxy_manager.get_or_create(MAP_SERVICE, name)

async def create_vector_collection_config(
self,
name: str,
indexes: typing.List[IndexConfig],
backup_count: int = 1,
async_backup_count: int = 0,
split_brain_protection_name: typing.Optional[str] = None,
merge_policy: str = "PutIfAbsentMergePolicy",
merge_batch_size: int = 100,
) -> None:
# check that indexes have different names
if indexes:
index_names = set(index.name for index in indexes)
if len(index_names) != len(indexes):
raise AssertionError("index names must be unique")

request = dynamic_config_add_vector_collection_config_codec.encode_request(
name,
indexes,
backup_count,
async_backup_count,
split_brain_protection_name,
merge_policy,
merge_batch_size,
)
invocation = Invocation(request, response_handler=lambda m: m)
await self._invocation_service.ainvoke(invocation)

async def get_vector_collection(self, name: str) -> VectorCollection:
return await self._proxy_manager.get_or_create(VECTOR_SERVICE, name)

async def add_distributed_object_listener(
self, listener_func: typing.Callable[[DistributedObjectEvent], None]
) -> str:
Expand Down Expand Up @@ -250,7 +283,6 @@ async def shutdown(self) -> None:
await self._connection_manager.shutdown()
self._invocation_service.shutdown()
self._statistics.shutdown()
self._reactor.shutdown()
self._internal_lifecycle_service.fire_lifecycle_event(LifecycleState.SHUTDOWN)

@property
Expand Down
68 changes: 26 additions & 42 deletions hazelcast/internal/asyncio_compact.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,77 +57,61 @@ def fetch_schema(self, schema_id: int) -> asyncio.Future:
self._invocation_service.invoke(fetch_schema_invocation)
return fetch_schema_invocation.future

def send_schema_and_retry(
async def send_schema_and_retry(
self,
error: "SchemaNotReplicatedError",
func: typing.Callable[..., asyncio.Future],
*args: typing.Any,
**kwargs: typing.Any,
) -> asyncio.Future:
) -> None:
schema = error.schema
clazz = error.clazz
request = client_send_schema_codec.encode_request(schema)

def callback():
async def callback():
self._has_replicated_schemas = True
self._compact_serializer.register_schema_to_type(schema, clazz)
return func(*args, **kwargs)
return await func(*args, **kwargs)

return self._replicate_schema(
schema, request, CompactSchemaService._SEND_SCHEMA_RETRY_COUNT, callback
return await self._replicate_schema(
schema, request, CompactSchemaService._SEND_SCHEMA_RETRY_COUNT, callback()
)

def _replicate_schema(
async def _replicate_schema(
self,
schema: "Schema",
request: "OutboundMessage",
remaining_retries: int,
callback: typing.Callable[..., asyncio.Future],
) -> asyncio.Future:
def continuation(future: asyncio.Future):
replicated_members = future.result()
callback: typing.Coroutine[typing.Any, typing.Any, typing.Any],
) -> None:
while remaining_retries >= 2:
replicated_members = await self._send_schema_replication_request(request)
members = self._cluster_service.get_members()
for member in members:
if member.uuid not in replicated_members:
break
else:
# Loop completed normally.
# All members in our member list all known to have the schema
return callback()
return await callback

# There is a member in our member list that the schema
# is not known to be replicated yet. We should retry
# sending it in a random member.
if remaining_retries <= 1:
# We tried to send it a couple of times, but the member list
# in our local and the member list returned by the initiator
# nodes did not match.
raise IllegalStateError(
f"The schema {schema} cannot be replicated in the cluster, "
f"after {CompactSchemaService._SEND_SCHEMA_RETRY_COUNT} retries. "
f"It might be the case that the client is connected to the two "
f"halves of the cluster that is experiencing a split-brain, "
f"and continue putting the data associated with that schema "
f"might result in data loss. It might be possible to replicate "
f"the schema after some time, when the cluster is healed."
)

delayed_future: asyncio.Future = asyncio.get_running_loop().create_future()
self._reactor.add_timer(
self._invocation_retry_pause,
lambda: delayed_future.set_result(None),
)

def retry(_):
return self._replicate_schema(
schema, request.copy(), remaining_retries - 1, callback
)

return delayed_future.add_done_callback(retry)

fut = self._send_schema_replication_request(request)
fut.add_done_callback(continuation)
return fut
await asyncio.sleep(self._invocation_retry_pause)

# We tried to send it a couple of times, but the member list
# in our local and the member list returned by the initiator
# nodes did not match.
raise IllegalStateError(
f"The schema {schema} cannot be replicated in the cluster, "
f"after {CompactSchemaService._SEND_SCHEMA_RETRY_COUNT} retries. "
f"It might be the case that the client is connected to the two "
f"halves of the cluster that is experiencing a split-brain, "
f"and continue putting the data associated with that schema "
f"might result in data loss. It might be possible to replicate "
f"the schema after some time, when the cluster is healed."
)

def _send_schema_replication_request(self, request: "OutboundMessage") -> asyncio.Future:
invocation = Invocation(request, response_handler=client_send_schema_codec.decode_response)
Expand Down
39 changes: 23 additions & 16 deletions hazelcast/internal/asyncio_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ def __init__(
self._use_public_ip = (
isinstance(address_provider, DefaultAddressProvider) and config.use_public_ip
)
# asyncio tasks are weakly referenced
# storing tasks here in order not to lose them midway
self._tasks = set()

def add_listener(self, on_connection_opened=None, on_connection_closed=None):
"""Registers a ConnectionListener.
Expand Down Expand Up @@ -315,22 +318,21 @@ async def on_connection_close(self, closed_connection):
disconnected = False
removed = False
trigger_reconnection = False
async with self._lock:
connection = self.active_connections.get(remote_uuid, None)
if connection == closed_connection:
self.active_connections.pop(remote_uuid, None)
removed = True
_logger.info(
"Removed connection to %s:%s, connection: %s",
remote_address,
remote_uuid,
connection,
)
connection = self.active_connections.get(remote_uuid, None)
if connection == closed_connection:
self.active_connections.pop(remote_uuid, None)
removed = True
_logger.info(
"Removed connection to %s:%s, connection: %s",
remote_address,
remote_uuid,
connection,
)

if not self.active_connections:
trigger_reconnection = True
if self._client_state == ClientState.INITIALIZED_ON_CLUSTER:
disconnected = True
if not self.active_connections:
trigger_reconnection = True
if self._client_state == ClientState.INITIALIZED_ON_CLUSTER:
disconnected = True

if disconnected:
self._lifecycle_service.fire_lifecycle_event(LifecycleState.DISCONNECTED)
Expand Down Expand Up @@ -809,6 +811,9 @@ def __init__(self, connection_manager, client, config, reactor, invocation_servi
self._heartbeat_timeout = config.heartbeat_timeout
self._heartbeat_interval = config.heartbeat_interval
self._heartbeat_task: asyncio.Task | None = None
# asyncio tasks are weakly referenced
# storing tasks here in order not to lose them midway
self._tasks = set()

def start(self):
"""Starts sending periodic HeartBeat operations."""
Expand Down Expand Up @@ -848,7 +853,9 @@ async def _check_connection(self, now, connection):
if (now - connection.last_write_time) > self._heartbeat_interval:
request = client_ping_codec.encode_request()
invocation = Invocation(request, connection=connection, urgent=True)
asyncio.create_task(self._invocation_service.ainvoke(invocation))
task = asyncio.create_task(self._invocation_service.ainvoke(invocation))
self._tasks.add(task)
task.add_done_callback(self._tasks.discard)


_frame_header = struct.Struct("<iH")
Expand Down
19 changes: 10 additions & 9 deletions hazelcast/internal/asyncio_invocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def __init__(self, client, config, reactor):
self._backup_ack_to_client_enabled = smart_routing and config.backup_ack_to_client_enabled
self._fail_on_indeterminate_state = config.fail_on_indeterminate_operation_state
self._backup_timeout = config.operation_backup_timeout
self._clean_resources_timer = None
self._clean_resources_task = None
self._shutdown = False
self._compact_schema_service = None

Expand All @@ -107,8 +107,8 @@ def init(self, partition_service, connection_manager, listener_service, compact_
self._check_invocation_allowed_fn = connection_manager.check_invocation_allowed
self._compact_schema_service = compact_schema_service

def start(self):
self._start_clean_resources_timer()
async def start(self):
await self._start_clean_resources_timer()

async def add_backup_listener(self):
if self._backup_ack_to_client_enabled:
Expand Down Expand Up @@ -152,8 +152,8 @@ def shutdown(self):
return

self._shutdown = True
if self._clean_resources_timer:
self._clean_resources_timer.cancel()
if self._clean_resources_task:
self._clean_resources_task.cancel()
for invocation in list(self._pending.values()):
self._notify_error(invocation, HazelcastClientNotActiveError())

Expand Down Expand Up @@ -400,8 +400,9 @@ def _notify_backup_complete(self, invocation):

self._complete(invocation, invocation.pending_response)

def _start_clean_resources_timer(self):
def run():
async def _start_clean_resources_timer(self):
async def run():
await asyncio.sleep(self._CLEAN_RESOURCES_PERIOD)
if self._shutdown:
return

Expand All @@ -419,9 +420,9 @@ def run():
if self._backup_ack_to_client_enabled:
self._detect_and_handle_backup_timeout(invocation, now)

self._clean_resources_timer = self._reactor.add_timer(self._CLEAN_RESOURCES_PERIOD, run)
self._clean_resources_task = asyncio.create_task(run())

self._clean_resources_timer = self._reactor.add_timer(self._CLEAN_RESOURCES_PERIOD, run)
self._clean_resources_task = asyncio.create_task(run())

def _detect_and_handle_backup_timeout(self, invocation, now):
if not invocation.pending_response:
Expand Down
36 changes: 14 additions & 22 deletions hazelcast/internal/asyncio_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,8 @@ async def _register_on_connection(
self, user_registration_id, listener_registration, connection
):
registration_map = listener_registration.connection_registrations

if connection in registration_map:
return

registration_request = listener_registration.registration_request.copy()
invocation = Invocation(
registration_request,
Expand All @@ -187,26 +185,20 @@ async def _register_on_connection(
response_handler=lambda m: m,
urgent=True,
)
self._invocation_service.invoke(invocation)

def callback(f):
try:
response = f.result()
server_registration_id = listener_registration.decode_register_response(response)
correlation_id = registration_request.get_correlation_id()
registration = _EventRegistration(server_registration_id, correlation_id)
registration_map[connection] = registration
except Exception as e:
if connection.live:
_logger.exception(
"Listener %s can not be added to a new connection: %s",
user_registration_id,
connection,
)
raise e

invocation.future.add_done_callback(callback)
return await invocation.future
response = await self._invocation_service.ainvoke(invocation)
try:
server_registration_id = listener_registration.decode_register_response(response)
correlation_id = registration_request.get_correlation_id()
registration = _EventRegistration(server_registration_id, correlation_id)
registration_map[connection] = registration
except Exception as e:
if connection.live:
_logger.exception(
"Listener %s can not be added to a new connection: %s",
user_registration_id,
connection,
)
raise e

async def _connection_added(self, connection):
async with self._registration_lock:
Expand Down
Loading