summaryrefslogtreecommitdiffstats
path: root/filedistribution
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2016-09-17 17:35:11 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2016-09-17 17:35:11 +0000
commit3cd17b4bd4464df0ffaf28d785e88dfa5736d7c0 (patch)
tree3edc312392764991af44312ef00de3f76bdbf9f4 /filedistribution
parenteb5caa0b486d00749fdb6154f2f48943e44a0685 (diff)
Use a guard instead of catch and rethrow.
Diffstat (limited to 'filedistribution')
-rw-r--r--filedistribution/src/vespa/filedistribution/model/zkfacade.cpp81
1 files changed, 38 insertions, 43 deletions
diff --git a/filedistribution/src/vespa/filedistribution/model/zkfacade.cpp b/filedistribution/src/vespa/filedistribution/model/zkfacade.cpp
index 89ff72e4a36..5d18deed80b 100644
--- a/filedistribution/src/vespa/filedistribution/model/zkfacade.cpp
+++ b/filedistribution/src/vespa/filedistribution/model/zkfacade.cpp
@@ -422,33 +422,31 @@ ZKFacade::hasNode(const Path& path) {
bool
ZKFacade::hasNode(const Path& path, const NodeChangedWatcherSP& watcher) {
- void* watcherContext = registerWatcher(watcher);
- try {
- RetryController retryController(this);
- do {
- Stat stat;
- retryController(
- zoo_wexists(_zhandle, path.string().c_str(),
- &ZKWatcher::watcherFn, watcherContext,
- &stat));
- } while(retryController.shouldRetry());
-
- switch(retryController._lastStatus) {
- case ZNONODE:
- return false;
- case ZOK:
- return true;
- default:
- retryController.throwIfError(path);
- //this should never happen:
- assert(false);
- return false;
- }
+ RegistrationGuard unregisterGuard(*this, watcher);
+ void* watcherContext = unregisterGuard.get();
+ RetryController retryController(this);
+ do {
+ Stat stat;
+ retryController(zoo_wexists(_zhandle, path.string().c_str(), &ZKWatcher::watcherFn, watcherContext, &stat));
+ } while (retryController.shouldRetry());
- } catch (const ZKException &e) {
- unregisterWatcher(watcherContext);
- throw;
+ bool retval(false);
+ switch(retryController._lastStatus) {
+ case ZNONODE:
+ retval = false;
+ break;
+ case ZOK:
+ retval = true;
+ break;
+ default:
+ retryController.throwIfError(path);
+ //this should never happen:
+ assert(false);
+ retval = false;
+ break;
}
+ unregisterGuard.release();
+ return retval;
}
void
@@ -529,30 +527,27 @@ ZKFacade::getChildren(const Path& path) {
std::vector< std::string >
ZKFacade::getChildren(const Path& path, const NodeChangedWatcherSP& watcher) {
- void* watcherContext = registerWatcher(watcher);
+ RegistrationGuard unregisterGuard(*this, watcher);
+ void* watcherContext = unregisterGuard.get();
- try {
- RetryController retryController(this);
- String_vector children;
- do {
- retryController( zoo_wget_children(_zhandle, path.string().c_str(), &ZKWatcher::watcherFn, watcherContext, &children));
- } while(retryController.shouldRetry());
+ RetryController retryController(this);
+ String_vector children;
+ do {
+ retryController( zoo_wget_children(_zhandle, path.string().c_str(), &ZKWatcher::watcherFn, watcherContext, &children));
+ } while (retryController.shouldRetry());
- retryController.throwIfError(path);
+ retryController.throwIfError(path);
- DeallocateZKStringVectorGuard deallocateGuard(children);
+ DeallocateZKStringVectorGuard deallocateGuard(children);
- typedef std::vector<std::string> ResultType;
- ResultType result;
- result.reserve(children.count);
+ typedef std::vector<std::string> ResultType;
+ ResultType result;
+ result.reserve(children.count);
- std::copy(children.data, children.data + children.count, std::back_inserter(result));
+ std::copy(children.data, children.data + children.count, std::back_inserter(result));
- return result;
- } catch (const ZKException & e) {
- unregisterWatcher(watcherContext);
- throw;
- }
+ unregisterGuard.release();
+ return result;
}