Search in sources :

Example 1 with NoNodeException

use of org.apache.zookeeper.KeeperException.NoNodeException in project hadoop by apache.

the class ActiveStandbyElectorTestUtil method waitForActiveLockData.

public static void waitForActiveLockData(TestContext ctx, ZooKeeperServer zks, String parentDir, byte[] activeData) throws Exception {
    long st = Time.now();
    long lastPrint = st;
    while (true) {
        if (ctx != null) {
            ctx.checkException();
        }
        try {
            Stat stat = new Stat();
            byte[] data = zks.getZKDatabase().getData(parentDir + "/" + ActiveStandbyElector.LOCK_FILENAME, stat, null);
            if (activeData != null && Arrays.equals(activeData, data)) {
                return;
            }
            if (Time.now() > lastPrint + LOG_INTERVAL_MS) {
                LOG.info("Cur data: " + StringUtils.byteToHexString(data));
                lastPrint = Time.now();
            }
        } catch (NoNodeException nne) {
            if (activeData == null) {
                return;
            }
            if (Time.now() > lastPrint + LOG_INTERVAL_MS) {
                LOG.info("Cur data: no node");
                lastPrint = Time.now();
            }
        }
        Thread.sleep(50);
    }
}
Also used : Stat(org.apache.zookeeper.data.Stat) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException)

Example 2 with NoNodeException

use of org.apache.zookeeper.KeeperException.NoNodeException in project hbase by apache.

the class HRegionServer method updateRecoveringRegionLastFlushedSequenceId.

/**
   * A helper function to store the last flushed sequence Id with the previous failed RS for a
   * recovering region. The Id is used to skip wal edits which are flushed. Since the flushed
   * sequence id is only valid for each RS, we associate the Id with corresponding failed RS.
   * @throws KeeperException
   * @throws IOException
   */
private void updateRecoveringRegionLastFlushedSequenceId(Region r) throws KeeperException, IOException {
    if (!r.isRecovering()) {
        // return immdiately for non-recovering regions
        return;
    }
    HRegionInfo regionInfo = r.getRegionInfo();
    ZooKeeperWatcher zkw = getZooKeeper();
    String previousRSName = this.getLastFailedRSFromZK(regionInfo.getEncodedName());
    Map<byte[], Long> maxSeqIdInStores = r.getMaxStoreSeqId();
    long minSeqIdForLogReplay = -1;
    for (Long storeSeqIdForReplay : maxSeqIdInStores.values()) {
        if (minSeqIdForLogReplay == -1 || storeSeqIdForReplay < minSeqIdForLogReplay) {
            minSeqIdForLogReplay = storeSeqIdForReplay;
        }
    }
    try {
        long lastRecordedFlushedSequenceId = -1;
        String nodePath = ZKUtil.joinZNode(this.zooKeeper.znodePaths.recoveringRegionsZNode, regionInfo.getEncodedName());
        // recovering-region level
        byte[] data;
        try {
            data = ZKUtil.getData(zkw, nodePath);
        } catch (InterruptedException e) {
            throw new InterruptedIOException();
        }
        if (data != null) {
            lastRecordedFlushedSequenceId = ZKSplitLog.parseLastFlushedSequenceIdFrom(data);
        }
        if (data == null || lastRecordedFlushedSequenceId < minSeqIdForLogReplay) {
            ZKUtil.setData(zkw, nodePath, ZKUtil.positionToByteArray(minSeqIdForLogReplay));
        }
        if (previousRSName != null) {
            // one level deeper for the failed RS
            nodePath = ZKUtil.joinZNode(nodePath, previousRSName);
            ZKUtil.setData(zkw, nodePath, ZKUtil.regionSequenceIdsToByteArray(minSeqIdForLogReplay, maxSeqIdInStores));
            LOG.debug("Update last flushed sequence id of region " + regionInfo.getEncodedName() + " for " + previousRSName);
        } else {
            LOG.warn("Can't find failed region server for recovering region " + regionInfo.getEncodedName());
        }
    } catch (NoNodeException ignore) {
        LOG.debug("Region " + regionInfo.getEncodedName() + " must have completed recovery because its recovery znode has been removed", ignore);
    }
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) InterruptedIOException(java.io.InterruptedIOException) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) ZooKeeperWatcher(org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher)

Example 3 with NoNodeException

use of org.apache.zookeeper.KeeperException.NoNodeException in project storm by apache.

the class LocalFsBlobStore method getBlobReplication.

@Override
public int getBlobReplication(String key, Subject who) throws Exception {
    int replicationCount = 0;
    validateKey(key);
    SettableBlobMeta meta = getStoredBlobMeta(key);
    _aclHandler.hasPermissions(meta.get_acl(), READ, who, key);
    if (zkClient.checkExists().forPath(BLOBSTORE_SUBTREE + key) == null) {
        return 0;
    }
    try {
        replicationCount = zkClient.getChildren().forPath(BLOBSTORE_SUBTREE + key).size();
    } catch (NoNodeException e) {
    //Race with delete
    //If it is not here the replication is 0 
    }
    return replicationCount;
}
Also used : NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) SettableBlobMeta(org.apache.storm.generated.SettableBlobMeta)

Example 4 with NoNodeException

use of org.apache.zookeeper.KeeperException.NoNodeException in project zookeeper by apache.

the class InstanceContainer method processResult.

@Override
public void processResult(int rc, String path, Object ctx, List<String> children) {
    if (rc != KeeperException.Code.OK.intValue()) {
        // try it again
        zk.getChildren(assignmentsNode, true, this, null);
        return;
    }
    HashMap<String, Instance> newList = new HashMap<String, Instance>();
    // check for differences
    Stat stat = new Stat();
    for (String child : children) {
        Instance i = instances.remove(child);
        if (i == null) {
            // Start up a new instance
            byte[] data = null;
            String myNode = assignmentsNode + '/' + child;
            while (true) {
                try {
                    data = zk.getData(myNode, true, stat);
                    break;
                } catch (NoNodeException e) {
                    // The node doesn't exist anymore, so skip it
                    break;
                } catch (KeeperException e) {
                    e.printStackTrace();
                } catch (InterruptedException e) {
                    return;
                }
            }
            if (data != null) {
                String instanceSpec = new String(data);
                int spaceIndex = instanceSpec.indexOf(' ');
                String clazz;
                String conf;
                if (spaceIndex == -1) {
                    clazz = instanceSpec;
                    conf = null;
                } else {
                    clazz = instanceSpec.substring(0, spaceIndex);
                    conf = instanceSpec.substring(spaceIndex + 1);
                }
                try {
                    Class<?> c = Class.forName(clazz);
                    i = (Instance) c.newInstance();
                    Reporter reporter = new MyReporter(child);
                    i.setReporter(reporter);
                    i.configure(conf);
                    i.start();
                    newList.put(child, i);
                    int ver = stat.getVersion();
                    Instance myInstance = i;
                    DataCallback dc = new MyDataCallback(myNode, myInstance, ver);
                    Watcher watcher = new MyWatcher(myNode, dc);
                    zk.getData(myNode, watcher, dc, watcher);
                } catch (Exception e) {
                    LOG.warn("Skipping " + child, e);
                    if (e.getCause() != null) {
                        LOG.warn("Caused by", e.getCause());
                    }
                }
            }
        } else {
            // just move it to the new list
            newList.put(child, i);
        }
    }
    // kill anything that was removed for the children
    for (Map.Entry<String, Instance> i : instances.entrySet()) {
        i.getValue().stop();
        try {
            rmnod(reportsNode + '/' + i.getKey());
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        } catch (KeeperException e) {
            e.printStackTrace();
        }
    }
    instances = newList;
}
Also used : NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) HashMap(java.util.HashMap) Reporter(org.apache.zookeeper.test.system.Instance.Reporter) Watcher(org.apache.zookeeper.Watcher) ConnectionLossException(org.apache.zookeeper.KeeperException.ConnectionLossException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) NodeExistsException(org.apache.zookeeper.KeeperException.NodeExistsException) Stat(org.apache.zookeeper.data.Stat) HashMap(java.util.HashMap) Map(java.util.Map) KeeperException(org.apache.zookeeper.KeeperException)

Example 5 with NoNodeException

use of org.apache.zookeeper.KeeperException.NoNodeException in project zookeeper by apache.

the class InstanceManager method resetStatus.

public void resetStatus(String name) throws InterruptedException, KeeperException {
    KeeperException lastException = null;
    for (int i = 0; i < maxTries; i++) {
        try {
            zk.delete(reportsNode + '/' + name, -1);
            lastException = null;
            break;
        } catch (ConnectionLossException e) {
            lastException = e;
        } catch (NoNodeException e) {
        // great this is what we want!
        }
    }
    if (lastException != null) {
        throw lastException;
    }
}
Also used : NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) ConnectionLossException(org.apache.zookeeper.KeeperException.ConnectionLossException) KeeperException(org.apache.zookeeper.KeeperException)

Aggregations

NoNodeException (org.apache.zookeeper.KeeperException.NoNodeException)44 KeeperException (org.apache.zookeeper.KeeperException)30 HeliosRuntimeException (com.spotify.helios.common.HeliosRuntimeException)16 IOException (java.io.IOException)12 Stat (org.apache.zookeeper.data.Stat)12 ZooKeeperClient (com.spotify.helios.servicescommon.coordination.ZooKeeperClient)11 ZooKeeperOperation (com.spotify.helios.servicescommon.coordination.ZooKeeperOperation)9 Job (com.spotify.helios.common.descriptors.Job)8 ConnectionLossException (org.apache.zookeeper.KeeperException.ConnectionLossException)8 JobId (com.spotify.helios.common.descriptors.JobId)6 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5 UnknownHostException (java.net.UnknownHostException)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 ZooKeeperException (org.apache.solr.common.cloud.ZooKeeperException)5 NodeExistsException (org.apache.zookeeper.KeeperException.NodeExistsException)5 SessionExpiredException (org.apache.zookeeper.KeeperException.SessionExpiredException)5 DeploymentGroup (com.spotify.helios.common.descriptors.DeploymentGroup)4 UUID (java.util.UUID)4 TimeoutException (java.util.concurrent.TimeoutException)4