ivandasch commented on a change in pull request #2:
URL:
https://github.com/apache/ignite-python-thin-client/pull/2#discussion_r560832291
##########
File path: pyignite/cache.py
##########
@@ -185,10 +214,128 @@ def destroy(self):
"""
Destroys cache with a given name.
"""
- return cache_destroy(self._client, self._cache_id)
+ return cache_destroy(self.get_best_node(), self._cache_id)
@status_to_exception(CacheError)
- def get(self, key, key_hint: object=None) -> Any:
+ def _get_affinity(self, conn: 'Connection') -> Dict:
+ """
+ Queries server for affinity mappings. Retries in case
+ of an intermittent error (most probably “Getting affinity for topology
+ version earlier than affinity is calculated”).
+
+ :param conn: connection to Igneite server,
+ :return: OP_CACHE_PARTITIONS operation result value.
+ """
+ for _ in range(AFFINITY_RETRIES or 1):
+ result = cache_get_node_partitions(conn, self._cache_id)
+ if result.status == 0 and result.value['partition_mapping']:
+ break
+ time.sleep(AFFINITY_DELAY)
+
+ return result
+
+ @select_version
+ def get_best_node(
+ self, key: Any = None, key_hint: 'IgniteDataType' = None,
+ ) -> 'Connection':
+ """
+ Returns the node from the list of the nodes, opened by client, that
+ most probably contains the needed key-value pair. See IEP-23.
+
+ This method is not a part of the public API. Unless you wish to
+ extend the `pyignite` capabilities (with additional testing, logging,
+ examining connections, et c.) you probably should not use it.
+
+ :param key: (optional) pythonic key,
+ :param key_hint: (optional) Ignite data type, for which the given key
+ should be converted,
+ :return: Ignite connection object.
+ """
+ conn = self._client.random_node
+
+ if self.client.partition_aware and key is not None:
+ if key_hint is None:
+ key_hint = AnyDataObject.map_python_type(key)
+
+ parts = -1
Review comment:
not needed here, you define parts in both branches below
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]