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);
}
}
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);
}
}
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;
}
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;
}
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;
}
}
Aggregations