pkuwm commented on a change in pull request #845: Async write operation should
not throw Exception for serializing error
URL: https://github.com/apache/helix/pull/845#discussion_r386800263
##########
File path:
zookeeper-api/src/main/java/org/apache/helix/zookeeper/zkclient/ZkClient.java
##########
@@ -1720,33 +1721,43 @@ public Stat writeDataGetStat(final String path, Object
datat, final int expected
public void asyncCreate(final String path, Object datat, final CreateMode
mode,
final ZkAsyncCallbacks.CreateCallbackHandler cb) {
final long startT = System.currentTimeMillis();
- final byte[] data = (datat == null ? null : serialize(datat, path));
- retryUntilConnected(new Callable<Object>() {
- @Override
- public Object call() throws Exception {
- ((ZkConnection) getConnection()).getZookeeper()
- .create(path, data, ZooDefs.Ids.OPEN_ACL_UNSAFE,
- // Arrays.asList(DEFAULT_ACL),
- mode, cb, new ZkAsyncCallbacks.ZkAsyncCallContext(_monitor,
startT,
- data == null ? 0 : data.length, false));
- return null;
- }
+ byte[] data = null;
+ try {
+ data = (datat == null ? null : serialize(datat, path));
+ } catch (ZkMarshallingError e) {
+ cb.processResult(KeeperException.Code.MARSHALLINGERROR.intValue(), path,
+ new ZkAsyncCallbacks.ZkAsyncCallContext(_monitor, startT, 0, false),
null);
+ return;
+ }
+ final byte[] finalData = data;
+ retryUntilConnected(() -> {
+ ((ZkConnection) getConnection()).getZookeeper()
+ .create(path, finalData, ZooDefs.Ids.OPEN_ACL_UNSAFE,
+ // Arrays.asList(DEFAULT_ACL),
+ mode, cb, new ZkAsyncCallbacks.ZkAsyncCallContext(_monitor,
startT,
+ finalData == null ? 0 : finalData.length, false));
+ return null;
});
}
// Async Data Accessors
public void asyncSetData(final String path, Object datat, final int version,
final ZkAsyncCallbacks.SetDataCallbackHandler cb) {
final long startT = System.currentTimeMillis();
- final byte[] data = serialize(datat, path);
- retryUntilConnected(new Callable<Object>() {
- @Override
- public Object call() throws Exception {
- ((ZkConnection) getConnection()).getZookeeper().setData(path, data,
version, cb,
- new ZkAsyncCallbacks.ZkAsyncCallContext(_monitor, startT,
- data == null ? 0 : data.length, false));
- return null;
- }
+ byte[] data = null;
+ try {
+ data = serialize(datat, path);
+ } catch (ZkMarshallingError e) {
+ cb.processResult(KeeperException.Code.MARSHALLINGERROR.intValue(), path,
+ new ZkAsyncCallbacks.ZkAsyncCallContext(_monitor, startT, 0, false),
null);
+ return;
+ }
+ final byte[] finalData = data;
Review comment:
I think it is possible:
```
final byte[] data;
try {
data = serialize(datat, path);
} catch (ZkMarshallingError e) {
cb.processResult(KeeperException.Code.MARSHALLINGERROR.intValue(), path,
new ZkAsyncCallbacks.ZkAsyncCallContext(_monitor, startT, 0, false),
null);
return;
}
retryUntilConnected();
```
----------------------------------------------------------------
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]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]