Java Code Examples for org.apache.zookeeper.KeeperException.Code#NONODE

The following examples show how to use org.apache.zookeeper.KeeperException.Code#NONODE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ZooKeeperStateProvider.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Override
public void onComponentRemoved(final String componentId) throws IOException {
    try {
        ZKUtil.deleteRecursive(getZooKeeper(), getComponentPath(componentId));
    } catch (final KeeperException ke) {
        // Node doesn't exist so just ignore
        final Code exceptionCode = ke.code();
        if (Code.NONODE == exceptionCode) {
            return;
        }
        if (Code.SESSIONEXPIRED == exceptionCode) {
            invalidateClient();
            onComponentRemoved(componentId);
            return;
        }

        throw new IOException("Unable to remove state for component with ID '" + componentId + " with exception code " + exceptionCode, ke);
    } catch (final InterruptedException e) {
        Thread.currentThread().interrupt();
        throw new IOException("Failed to remove state for component with ID '" + componentId + "' from ZooKeeper due to being interrupted", e);
    }
}
 
Example 2
Source File: IntegrationTestZKAndFSPermissions.java    From hbase with Apache License 2.0 6 votes vote down vote up
private void checkZnodePermsRecursive(ZKWatcher watcher,
    RecoverableZooKeeper zk, String znode) throws KeeperException, InterruptedException {

  boolean expectedWorldReadable = watcher.getZNodePaths().isClientReadable(znode);

  assertZnodePerms(zk, znode, expectedWorldReadable);

  try {
    List<String> children = zk.getChildren(znode, false);

    for (String child : children) {
      checkZnodePermsRecursive(watcher, zk, ZNodePaths.joinZNode(znode, child));
    }
  } catch (KeeperException ke) {
    // if we are not authenticated for listChildren, it is fine.
    if (ke.code() != Code.NOAUTH && ke.code() != Code.NONODE) {
      throw ke;
    }
  }
}
 
Example 3
Source File: ZooKeeperStateProvider.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
public void onComponentRemoved(final String componentId) throws IOException {
    try {
        ZKUtil.deleteRecursive(getZooKeeper(), getComponentPath(componentId));
    } catch (final KeeperException ke) {
        // Node doesn't exist so just ignore
        final Code exceptionCode = ke.code();
        if (Code.NONODE == exceptionCode) {
            return;
        }
        if (Code.SESSIONEXPIRED == exceptionCode) {
            invalidateClient();
            onComponentRemoved(componentId);
            return;
        }

        throw new IOException("Unable to remove state for component with ID '" + componentId + " with exception code " + exceptionCode, ke);
    } catch (final InterruptedException e) {
        Thread.currentThread().interrupt();
        throw new IOException("Failed to remove state for component with ID '" + componentId + "' from ZooKeeper due to being interrupted", e);
    }
}
 
Example 4
Source File: ZooKeeperStateProvider.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Override
public StateMap getState(final String componentId) throws IOException {
    verifyEnabled();

    try {
        final Stat stat = new Stat();
        final String path = getComponentPath(componentId);
        final byte[] data = getZooKeeper().getData(path, false, stat);

        final StateMap stateMap = deserialize(data, stat.getVersion(), componentId);
        return stateMap;
    } catch (final InterruptedException e) {
        Thread.currentThread().interrupt();
        throw new IOException("Failed to obtain value from ZooKeeper for component with ID " + componentId + ", due to interruption", e);
    } catch (final KeeperException ke) {
        final Code exceptionCode = ke.code();
        if (Code.NONODE == exceptionCode) {
            return new StandardStateMap(null, -1L);
        }
        if (Code.SESSIONEXPIRED == exceptionCode) {
            invalidateClient();
            return getState(componentId);
        }

        throw new IOException("Failed to obtain value from ZooKeeper for component with ID " + componentId + " with exception code " + exceptionCode, ke);
    } catch (final IOException ioe) {
        // provide more context in the error message
        throw new IOException("Failed to obtain value from ZooKeeper for component with ID " + componentId, ioe);
    }
}
 
Example 5
Source File: ZKRMStateStore.java    From hadoop with Apache License 2.0 5 votes vote down vote up
T runWithRetries() throws Exception {
  int retry = 0;
  while (true) {
    try {
      return runWithCheck();
    } catch (KeeperException.NoAuthException nae) {
      if (HAUtil.isHAEnabled(getConfig())) {
        // NoAuthException possibly means that this store is fenced due to
        // another RM becoming active. Even if not,
        // it is safer to assume we have been fenced
        throw new StoreFencedException();
      }
    } catch (KeeperException ke) {
      if (ke.code() == Code.NODEEXISTS) {
        LOG.info("znode already exists!");
        return null;
      }
      if (hasDeleteNodeOp && ke.code() == Code.NONODE) {
        LOG.info("znode has already been deleted!");
        return null;
      }

      LOG.info("Exception while executing a ZK operation.", ke);
      if (shouldRetry(ke.code()) && ++retry < numRetries) {
        LOG.info("Retrying operation on ZK. Retry no. " + retry);
        Thread.sleep(zkRetryInterval);
        createConnection();
        continue;
      }
      LOG.info("Maxed out ZK retries. Giving up!");
      throw ke;
    }
  }
}
 
Example 6
Source File: ZKRMStateStore.java    From big-c with Apache License 2.0 5 votes vote down vote up
T runWithRetries() throws Exception {
  int retry = 0;
  while (true) {
    try {
      return runWithCheck();
    } catch (KeeperException.NoAuthException nae) {
      if (HAUtil.isHAEnabled(getConfig())) {
        // NoAuthException possibly means that this store is fenced due to
        // another RM becoming active. Even if not,
        // it is safer to assume we have been fenced
        throw new StoreFencedException();
      }
    } catch (KeeperException ke) {
      if (ke.code() == Code.NODEEXISTS) {
        LOG.info("znode already exists!");
        return null;
      }
      if (hasDeleteNodeOp && ke.code() == Code.NONODE) {
        LOG.info("znode has already been deleted!");
        return null;
      }

      LOG.info("Exception while executing a ZK operation.", ke);
      if (shouldRetry(ke.code()) && ++retry < numRetries) {
        LOG.info("Retrying operation on ZK. Retry no. " + retry);
        Thread.sleep(zkRetryInterval);
        createConnection();
        continue;
      }
      LOG.info("Maxed out ZK retries. Giving up!");
      throw ke;
    }
  }
}
 
Example 7
Source File: ZooKeeperStateProvider.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public StateMap getState(final String componentId) throws IOException {
    verifyEnabled();

    try {
        final Stat stat = new Stat();
        final String path = getComponentPath(componentId);
        final byte[] data = getZooKeeper().getData(path, false, stat);

        final StateMap stateMap = deserialize(data, stat.getVersion(), componentId);
        return stateMap;
    } catch (final InterruptedException e) {
        Thread.currentThread().interrupt();
        throw new IOException("Failed to obtain value from ZooKeeper for component with ID " + componentId + ", due to interruption", e);
    } catch (final KeeperException ke) {
        final Code exceptionCode = ke.code();
        if (Code.NONODE == exceptionCode) {
            return new StandardStateMap(null, -1L);
        }
        if (Code.SESSIONEXPIRED == exceptionCode) {
            invalidateClient();
            return getState(componentId);
        }

        throw new IOException("Failed to obtain value from ZooKeeper for component with ID " + componentId + " with exception code " + exceptionCode, ke);
    } catch (final IOException ioe) {
        // provide more context in the error message
        throw new IOException("Failed to obtain value from ZooKeeper for component with ID " + componentId, ioe);
    }
}
 
Example 8
Source File: ActiveStandbyElector.java    From hadoop with Apache License 2.0 4 votes vote down vote up
private static boolean isNodeDoesNotExist(Code code) {
  return (code == Code.NONODE);
}
 
Example 9
Source File: ActiveStandbyElector.java    From big-c with Apache License 2.0 4 votes vote down vote up
private static boolean isNodeDoesNotExist(Code code) {
  return (code == Code.NONODE);
}
 
Example 10
Source File: WatchChildren.java    From incubator-retired-blur with Apache License 2.0 4 votes vote down vote up
public WatchChildren watch(final OnChange onChange, long fireAnywayTime, TimeUnit timeUnit) {
  if (_debug) {
    StringWriter writer = new StringWriter();
    PrintWriter printWriter = new PrintWriter(writer);
    new Throwable().printStackTrace(printWriter);
    printWriter.close();
    _debugStackTrace = writer.toString();
  }
  final long timeToFireAnywayTime = TimeUnit.MILLISECONDS.convert(fireAnywayTime, timeUnit);
  _watchThread = new Thread(new Runnable() {
    @Override
    public void run() {
      Watcher watcher = new Watcher() {
        @Override
        public void process(WatchedEvent event) {
          synchronized (_lock) {
            _lock.notify();
          }
        }
      };
      startDoubleCheckThread();
      while (_running.get()) {
        synchronized (_lock) {
          try {
            List<String> children = _zooKeeper.getChildren(_path, watcher);
            try {
              onChange.action(children);
              _children = children;
            } catch (Throwable t) {
              LOG.error("Unknown error during onchange action [" + this + "].", t);
            }
            _lock.wait(timeToFireAnywayTime);
          } catch (KeeperException e) {
            if (!_running.get()) {
              LOG.info("Error [{0}]", e.getMessage());
              return;
            }
            if (e.code() == Code.NONODE) {
              if (_debug) {
                LOG.debug("Path for watching not found [{0}], no longer watching, debug [{1}].", _path,
                    _debugStackTrace);
              } else {
                LOG.debug("Path for watching not found [{0}], no longer watching.", _path);
              }
              close();
              return;
            }
            if (_debug) {
              LOG.error("Unknown error [{0}]", e, _debugStackTrace);
            } else {
              LOG.error("Unknown error", e);
            }
            throw new RuntimeException(e);
          } catch (InterruptedException e) {
            return;
          }
        }
      }
      _running.set(false);
    }
  });
  _watchThread.setName("Watch Children [" + _path + "][" + instance + "]");
  _watchThread.setDaemon(true);
  _watchThread.start();
  return this;
}