You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@helix.apache.org by xy...@apache.org on 2023/02/14 22:36:40 UTC
[helix] branch metaclient updated: Update async API for MetaClient.
This is an automated email from the ASF dual-hosted git repository.
xyuanlu pushed a commit to branch metaclient
in repository https://gitbox.apache.org/repos/asf/helix.git
The following commit(s) were added to refs/heads/metaclient by this push:
new d445de488 Update async API for MetaClient.
d445de488 is described below
commit d445de488bf836dc1e51ac4b95caa3e4bcf0bc4d
Author: xyuanlu <xy...@gmail.com>
AuthorDate: Tue Feb 14 14:36:34 2023 -0800
Update async API for MetaClient.
Update async API for MetaClient.
---
.../org/apache/helix/metaclient/api/AsyncCallback.java | 17 ++++++++---------
.../helix/metaclient/api/MetaClientInterface.java | 4 ++--
.../apache/helix/metaclient/impl/zk/ZkMetaClient.java | 16 +++++++++++-----
3 files changed, 21 insertions(+), 16 deletions(-)
diff --git a/meta-client/src/main/java/org/apache/helix/metaclient/api/AsyncCallback.java b/meta-client/src/main/java/org/apache/helix/metaclient/api/AsyncCallback.java
index 88ae31623..1e7c1eb75 100644
--- a/meta-client/src/main/java/org/apache/helix/metaclient/api/AsyncCallback.java
+++ b/meta-client/src/main/java/org/apache/helix/metaclient/api/AsyncCallback.java
@@ -20,6 +20,8 @@ package org.apache.helix.metaclient.api;
*/
import java.util.List;
+import javax.annotation.Nullable;
+
/**
* An asynchronous callback is deferred to invoke after an async CRUD operation finish and return.
@@ -34,10 +36,10 @@ public interface AsyncCallback {
* Process the result of asynchronous calls that returns a stat object.
* @param returnCode The return code of the call.
* @param key the key that passed to asynchronous calls.
- * @param context context object that passed to asynchronous calls.
* @param stat the stats of the entry of the given key, returned from the async call.
+ * Could be null if the entry did not exist.
*/
- void processResult(int returnCode, String key, Object context, MetaClientInterface.Stat stat);
+ void processResult(int returnCode, String key, @Nullable MetaClientInterface.Stat stat);
}
//This callback is used when data is returned from the operation.
@@ -46,11 +48,10 @@ public interface AsyncCallback {
* Process the result of asynchronous calls that returns entry data.
* @param returnCode The return code of the call.
* @param key The key that passed to asynchronous calls.
- * @param context context object that passed to asynchronous calls.
* @param data returned entry data from the call.
- * @param stat the stats of the entry of the given key.
+ * @param stat the stats of the entry of the given key. Could be null if the entry did not exist.
*/
- void processResult(int returnCode, String key, Object context, byte[] data, MetaClientInterface.Stat stat);
+ void processResult(int returnCode, String key, byte[] data, @Nullable MetaClientInterface.Stat stat);
}
//This callback is used when nothing is returned from the operation.
@@ -59,9 +60,8 @@ public interface AsyncCallback {
* Process the result of asynchronous calls that has no return value.
* @param returnCode The return code of the call.
* @param key he key that passed to asynchronous calls.
- * @param context context object that passed to asynchronous calls.
*/
- void processResult(int returnCode, String key, Object context);
+ void processResult(int returnCode, String key);
}
//This callback is used to process the list if OpResults from a single transactional call.
@@ -70,10 +70,9 @@ public interface AsyncCallback {
* Process the result of asynchronous transactional calls.
* @param returnCode The return code of the transaction call.
* @param keys List of keys passed to the async transactional call.
- * @param context context object that passed to asynchronous calls.
* @param opResults The list of transactional results.
*/
- void processResult(int returnCode, List<String> keys, Object context, List<OpResult> opResults);
+ void processResult(int returnCode, List<String> keys, List<OpResult> opResults);
}
}
\ No newline at end of file
diff --git a/meta-client/src/main/java/org/apache/helix/metaclient/api/MetaClientInterface.java b/meta-client/src/main/java/org/apache/helix/metaclient/api/MetaClientInterface.java
index 46fb59cb7..dc310b0ef 100644
--- a/meta-client/src/main/java/org/apache/helix/metaclient/api/MetaClientInterface.java
+++ b/meta-client/src/main/java/org/apache/helix/metaclient/api/MetaClientInterface.java
@@ -223,9 +223,9 @@ public interface MetaClientInterface<T> {
* @param data new data of the entry
* @param version expected version if the entry. -1 matched any version
* @param cb An user defined VoidCallback implementation that will be invoked when async create return.
- * @see org.apache.helix.metaclient.api.AsyncCallback.VoidCallback
+ * @see org.apache.helix.metaclient.api.AsyncCallback.StatCallback
*/
- void asyncSet(final String key, final T data, final int version, AsyncCallback.VoidCallback cb);
+ void asyncSet(final String key, final T data, final int version, AsyncCallback.StatCallback cb);
/**
* The asynchronous version of update.
diff --git a/meta-client/src/main/java/org/apache/helix/metaclient/impl/zk/ZkMetaClient.java b/meta-client/src/main/java/org/apache/helix/metaclient/impl/zk/ZkMetaClient.java
index fbca7ce5c..fea40bcde 100644
--- a/meta-client/src/main/java/org/apache/helix/metaclient/impl/zk/ZkMetaClient.java
+++ b/meta-client/src/main/java/org/apache/helix/metaclient/impl/zk/ZkMetaClient.java
@@ -166,10 +166,16 @@ public class ZkMetaClient<T> implements MetaClientInterface<T>, AutoCloseable {
return true;
}
- // Zookeeper execute async callbacks at zookeeper server side. In our first version of
- // implementation, we will keep this behavior.
- // In later version, we may consider creating a thread pool to execute registered callbacks.
- // However, this will change metaclient from stateless to stateful.
+ // In Current ZkClient, Async CRUD do auto retry when connection lost or session mismatch using
+ // existing retry handling logic in zkClient. (defined in ZkAsyncCallbacks)
+ // ZkClient execute async callbacks at zkClient main thead, retry is handles in a separate retry
+ // thread. In our first version of implementation, we will keep similar behavior and have
+ // callbacks executed in ZkClient event thread, and reuse zkclient retry logic.
+
+ // It is highly recommended NOT to perform any blocking operation inside the callbacks.
+ // If you block the thread the meta client won't process other events.
+
+ // corresponding callbacks for each operation are invoked in order.
@Override
public void setAsyncExecPoolSize(int poolSize) {
@@ -181,7 +187,7 @@ public class ZkMetaClient<T> implements MetaClientInterface<T>, AutoCloseable {
}
@Override
- public void asyncSet(String key, T data, int version, AsyncCallback.VoidCallback cb) {
+ public void asyncSet(String key, T data, int version, AsyncCallback.StatCallback cb) {
}