use of com.twitter.distributedlog.exceptions.DLInterruptedException in project distributedlog by twitter.
the class BKDistributedLogManager method delete.
/**
* Delete all the partitions of the specified log
*
* @throws IOException if the deletion fails
*/
@Override
public void delete() throws IOException {
BKLogWriteHandler ledgerHandler = createWriteHandler(true);
try {
ledgerHandler.deleteLog();
} finally {
Utils.closeQuietly(ledgerHandler);
}
// Delete the ZK path associated with the log stream
String zkPath = getZKPath();
// Safety check when we are using the shared zookeeper
if (zkPath.toLowerCase().contains("distributedlog")) {
try {
LOG.info("Delete the path associated with the log {}, ZK Path {}", name, zkPath);
ZKUtil.deleteRecursive(writerZKC.get(), zkPath);
} catch (InterruptedException ie) {
LOG.error("Interrupted while accessing ZK", ie);
throw new DLInterruptedException("Error initializing zk", ie);
} catch (KeeperException ke) {
LOG.error("Error accessing entry in zookeeper", ke);
throw new IOException("Error initializing zk", ke);
}
} else {
LOG.warn("Skip deletion of unrecognized ZK Path {}", zkPath);
}
}
use of com.twitter.distributedlog.exceptions.DLInterruptedException in project distributedlog by twitter.
the class BKLogWriteHandler method deleteLog.
public void deleteLog() throws IOException {
lock.checkOwnershipAndReacquire();
FutureUtils.result(purgeLogSegmentsOlderThanTxnId(-1));
try {
Utils.closeQuietly(lock);
zooKeeperClient.get().exists(logMetadata.getLogSegmentsPath(), false);
zooKeeperClient.get().exists(logMetadata.getMaxTxIdPath(), false);
if (logMetadata.getLogRootPath().toLowerCase().contains("distributedlog")) {
ZKUtil.deleteRecursive(zooKeeperClient.get(), logMetadata.getLogRootPath());
} else {
LOG.warn("Skip deletion of unrecognized ZK Path {}", logMetadata.getLogRootPath());
}
} catch (InterruptedException ie) {
LOG.error("Interrupted while deleting log znodes", ie);
throw new DLInterruptedException("Interrupted while deleting " + logMetadata.getLogRootPath(), ie);
} catch (KeeperException ke) {
LOG.error("Error deleting" + logMetadata.getLogRootPath() + " in zookeeper", ke);
}
}
use of com.twitter.distributedlog.exceptions.DLInterruptedException in project distributedlog by twitter.
the class BKSyncLogReaderDLSN method readNext.
@Override
public synchronized LogRecordWithDLSN readNext(boolean nonBlocking) throws IOException {
if (null != readerException.get()) {
throw readerException.get();
}
LogRecordWithDLSN record = null;
if (nonBlocking) {
record = readAheadRecords.poll();
} else {
try {
// reader is still catching up, waiting for next record
while (!reader.bkLedgerManager.isReadAheadCaughtUp() && null == readerException.get() && null == record) {
record = readAheadRecords.poll(maxReadAheadWaitTime, TimeUnit.MILLISECONDS);
}
// reader caught up
boolean shallWait = true;
while (shallWait && reader.bkLedgerManager.isReadAheadCaughtUp() && null == record && null == readerException.get()) {
record = readAheadRecords.poll(maxReadAheadWaitTime, TimeUnit.MILLISECONDS);
if (null != record) {
break;
}
DLSN lastDLSNSeenByReadAhead = reader.bkLedgerManager.readAheadCache.getLastReadAheadUserDLSN();
// if last seen DLSN by reader is same as the one seen by ReadAhead
// that means that reader is caught up with ReadAhead and ReadAhead
// is caught up with stream
shallWait = DLSN.InitialDLSN != lastDLSNSeenByReadAhead && lastSeenDLSN.compareTo(lastDLSNSeenByReadAhead) < 0 && startDLSN.compareTo(lastDLSNSeenByReadAhead) <= 0;
}
} catch (InterruptedException e) {
throw new DLInterruptedException("Interrupted on waiting next available log record for stream " + reader.getStreamName(), e);
}
}
if (null != readerException.get()) {
throw readerException.get();
}
if (null != record) {
if (record.isEndOfStream()) {
EndOfStreamException eos = new EndOfStreamException("End of Stream Reached for " + reader.bkLedgerManager.getFullyQualifiedName());
readerException.compareAndSet(null, eos);
throw eos;
}
invokeReadAheadCallback();
}
return record;
}
use of com.twitter.distributedlog.exceptions.DLInterruptedException in project distributedlog by twitter.
the class BKLogHandler method checkLogStreamExistsAsync.
Future<Void> checkLogStreamExistsAsync() {
final Promise<Void> promise = new Promise<Void>();
try {
final ZooKeeper zk = zooKeeperClient.get();
zk.sync(logMetadata.getLogSegmentsPath(), new AsyncCallback.VoidCallback() {
@Override
public void processResult(int syncRc, String path, Object syncCtx) {
if (KeeperException.Code.NONODE.intValue() == syncRc) {
promise.setException(new LogNotFoundException(String.format("Log %s does not exist or has been deleted", getFullyQualifiedName())));
return;
} else if (KeeperException.Code.OK.intValue() != syncRc) {
promise.setException(new ZKException("Error on checking log existence for " + getFullyQualifiedName(), KeeperException.create(KeeperException.Code.get(syncRc))));
return;
}
zk.exists(logMetadata.getLogSegmentsPath(), false, new AsyncCallback.StatCallback() {
@Override
public void processResult(int rc, String path, Object ctx, Stat stat) {
if (KeeperException.Code.OK.intValue() == rc) {
promise.setValue(null);
} else if (KeeperException.Code.NONODE.intValue() == rc) {
promise.setException(new LogNotFoundException(String.format("Log %s does not exist or has been deleted", getFullyQualifiedName())));
} else {
promise.setException(new ZKException("Error on checking log existence for " + getFullyQualifiedName(), KeeperException.create(KeeperException.Code.get(rc))));
}
}
}, null);
}
}, null);
} catch (InterruptedException ie) {
LOG.error("Interrupted while reading {}", logMetadata.getLogSegmentsPath(), ie);
promise.setException(new DLInterruptedException("Interrupted while checking " + logMetadata.getLogSegmentsPath(), ie));
} catch (ZooKeeperClient.ZooKeeperConnectionException e) {
promise.setException(e);
}
return promise;
}
use of com.twitter.distributedlog.exceptions.DLInterruptedException in project distributedlog by twitter.
the class BKLogReadHandler method ensureReadLockPathExist.
private Future<Void> ensureReadLockPathExist() {
final Promise<Void> promise = new Promise<Void>();
promise.setInterruptHandler(new com.twitter.util.Function<Throwable, BoxedUnit>() {
@Override
public BoxedUnit apply(Throwable t) {
FutureUtils.setException(promise, new LockCancelledException(readLockPath, "Could not ensure read lock path", t));
return null;
}
});
Optional<String> parentPathShouldNotCreate = Optional.of(logMetadata.getLogRootPath());
Utils.zkAsyncCreateFullPathOptimisticRecursive(zooKeeperClient, readLockPath, parentPathShouldNotCreate, new byte[0], zooKeeperClient.getDefaultACL(), CreateMode.PERSISTENT, new org.apache.zookeeper.AsyncCallback.StringCallback() {
@Override
public void processResult(final int rc, final String path, Object ctx, String name) {
scheduler.submit(new Runnable() {
@Override
public void run() {
if (KeeperException.Code.NONODE.intValue() == rc) {
FutureUtils.setException(promise, new LogNotFoundException(String.format("Log %s does not exist or has been deleted", getFullyQualifiedName())));
} else if (KeeperException.Code.OK.intValue() == rc) {
FutureUtils.setValue(promise, null);
LOG.trace("Created path {}.", path);
} else if (KeeperException.Code.NODEEXISTS.intValue() == rc) {
FutureUtils.setValue(promise, null);
LOG.trace("Path {} is already existed.", path);
} else if (DistributedLogConstants.ZK_CONNECTION_EXCEPTION_RESULT_CODE == rc) {
FutureUtils.setException(promise, new ZooKeeperClient.ZooKeeperConnectionException(path));
} else if (DistributedLogConstants.DL_INTERRUPTED_EXCEPTION_RESULT_CODE == rc) {
FutureUtils.setException(promise, new DLInterruptedException(path));
} else {
FutureUtils.setException(promise, KeeperException.create(KeeperException.Code.get(rc)));
}
}
});
}
}, null);
return promise;
}
Aggregations