Fix Zookeeper Issues

- `tryLock()` didn't throw `InterruptedException`
- `putIfAbsent()` use `get()` for current value
1
This commit is contained in:
Gary Russell
2019-03-08 12:36:57 -05:00
parent d886733c26
commit d8ec8352ff
3 changed files with 12 additions and 11 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2017 the original author or authors.
* Copyright 2015-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -301,9 +301,15 @@ public class ZookeeperLockRegistry implements ExpirableLockRegistry, DisposableB
}
}
catch (TimeoutException e) {
future.cancel(true);
if (future != null) {
future.cancel(true);
}
return false;
}
catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw e;
}
catch (Exception e) {
throw new MessagingException("Failed to acquire mutex at " + this.path, e);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2018 the original author or authors.
* Copyright 2015-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -122,13 +122,7 @@ public class ZookeeperMetadataStore implements ListenableMetadataStore, SmartLif
}
catch (KeeperException.NodeExistsException e) {
// so the data actually exists, we can read it
try {
byte[] bytes = this.client.getData().forPath(getPath(key));
return IntegrationUtils.bytesToString(bytes, this.encoding);
}
catch (Exception exceptionDuringGet) {
throw new ZookeeperMetadataStoreException("Exception while reading node with key '" + key + "':", e);
}
return get(key);
}
catch (Exception e) {
throw new ZookeeperMetadataStoreException("Error while trying to set '" + key + "':", e);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2018 the original author or authors.
* Copyright 2015-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -288,6 +288,7 @@ public class ZookeeperMetadataStoreTests extends ZookeeperTestSupport {
CuratorFramework otherClient = createNewClient();
ZookeeperMetadataStore otherMetadataStore = new ZookeeperMetadataStore(otherClient);
otherMetadataStore.start();
// register listeners
final List<List<String>> notifiedChanges = new ArrayList<List<String>>();