use of com.twitter.distributedlog.exceptions.DLInterruptedException in project distributedlog by twitter.
the class ZKMetadataAccessor method getMetadata.
/**
* Retrieve the metadata stored at the node
* @return byte array containing the metadata
* @throws IOException
*/
@Override
public byte[] getMetadata() throws IOException {
checkClosedOrInError("createOrUpdateMetadata");
String zkPath = getZKPath();
LOG.debug("Getting application specific metadata from {}", zkPath);
try {
Stat currentStat = readerZKC.get().exists(zkPath, false);
if (currentStat == null) {
return null;
} else {
return readerZKC.get().getData(zkPath, false, currentStat);
}
} catch (InterruptedException ie) {
throw new DLInterruptedException("Error reading the max tx id from zk", ie);
} catch (Exception e) {
throw new IOException("Error reading the max tx id from zk", e);
}
}
use of com.twitter.distributedlog.exceptions.DLInterruptedException in project distributedlog by twitter.
the class BookKeeperClient method initialize.
private synchronized void initialize() throws IOException {
if (null != this.bkc) {
return;
}
boolean registerExpirationHandler;
if (null == this.zkc) {
int zkSessionTimeout = conf.getBKClientZKSessionTimeoutMilliSeconds();
RetryPolicy retryPolicy = null;
if (conf.getBKClientZKNumRetries() > 0) {
retryPolicy = new BoundExponentialBackoffRetryPolicy(conf.getBKClientZKRetryBackoffStartMillis(), conf.getBKClientZKRetryBackoffMaxMillis(), conf.getBKClientZKNumRetries());
}
Credentials credentials = Credentials.NONE;
if (conf.getZkAclId() != null) {
credentials = new DigestCredentials(conf.getZkAclId(), conf.getZkAclId());
}
this.zkc = new ZooKeeperClient(name + ":zk", zkSessionTimeout, 2 * zkSessionTimeout, zkServers, retryPolicy, statsLogger.scope("bkc_zkc"), conf.getZKClientNumberRetryThreads(), conf.getBKClientZKRequestRateLimit(), credentials);
}
registerExpirationHandler = conf.getBKClientZKNumRetries() <= 0;
try {
commonInitialization(conf, ledgersPath, channelFactory, statsLogger, requestTimer, registerExpirationHandler);
} catch (InterruptedException e) {
throw new DLInterruptedException("Interrupted on creating bookkeeper client " + name + " : ", e);
} catch (KeeperException e) {
throw new ZKException("Error on creating bookkeeper client " + name + " : ", e);
}
if (ownZK) {
LOG.info("BookKeeper Client created {} with its own ZK Client : ledgersPath = {}, numRetries = {}, " + "sessionTimeout = {}, backoff = {}, maxBackoff = {}, dnsResolver = {}, registerExpirationHandler = {}", new Object[] { name, ledgersPath, conf.getBKClientZKNumRetries(), conf.getBKClientZKSessionTimeoutMilliSeconds(), conf.getBKClientZKRetryBackoffStartMillis(), conf.getBKClientZKRetryBackoffMaxMillis(), conf.getBkDNSResolverOverrides(), registerExpirationHandler });
} else {
LOG.info("BookKeeper Client created {} with shared zookeeper client : ledgersPath = {}, numRetries = {}, " + "sessionTimeout = {}, backoff = {}, maxBackoff = {}, dnsResolver = {}, registerExpirationHandler = {}", new Object[] { name, ledgersPath, conf.getZKNumRetries(), conf.getZKSessionTimeoutMilliseconds(), conf.getZKRetryBackoffStartMillis(), conf.getZKRetryBackoffMaxMillis(), conf.getBkDNSResolverOverrides(), registerExpirationHandler });
}
}
use of com.twitter.distributedlog.exceptions.DLInterruptedException in project distributedlog by twitter.
the class ZKSubscriptionStateStore method getLastCommitPositionFromZK.
Future<DLSN> getLastCommitPositionFromZK() {
final Promise<DLSN> result = new Promise<DLSN>();
try {
logger.debug("Reading last commit position from path {}", zkPath);
zooKeeperClient.get().getData(zkPath, false, new AsyncCallback.DataCallback() {
@Override
public void processResult(int rc, String path, Object ctx, byte[] data, Stat stat) {
logger.debug("Read last commit position from path {}: rc = {}", zkPath, rc);
if (KeeperException.Code.NONODE.intValue() == rc) {
result.setValue(DLSN.NonInclusiveLowerBound);
} else if (KeeperException.Code.OK.intValue() != rc) {
result.setException(KeeperException.create(KeeperException.Code.get(rc), path));
} else {
try {
DLSN dlsn = DLSN.deserialize(new String(data, Charsets.UTF_8));
result.setValue(dlsn);
} catch (Exception t) {
logger.warn("Invalid last commit position found from path {}", zkPath, t);
// invalid dlsn recorded in subscription state store
result.setValue(DLSN.NonInclusiveLowerBound);
}
}
}
}, null);
} catch (ZooKeeperClient.ZooKeeperConnectionException zkce) {
result.setException(zkce);
} catch (InterruptedException ie) {
result.setException(new DLInterruptedException("getLastCommitPosition was interrupted", ie));
}
return result;
}
use of com.twitter.distributedlog.exceptions.DLInterruptedException in project distributedlog by twitter.
the class Utils method sync.
/**
* Sync zookeeper client on given <i>path</i>.
*
* @param zkc
* zookeeper client
* @param path
* path to sync
* @return zookeeper client after sync
* @throws IOException
*/
public static ZooKeeper sync(ZooKeeperClient zkc, String path) throws IOException {
ZooKeeper zk;
try {
zk = zkc.get();
} catch (InterruptedException e) {
throw new DLInterruptedException("Interrupted on checking if log " + path + " exists", e);
}
final CountDownLatch syncLatch = new CountDownLatch(1);
final AtomicInteger syncResult = new AtomicInteger(0);
zk.sync(path, new AsyncCallback.VoidCallback() {
@Override
public void processResult(int rc, String path, Object ctx) {
syncResult.set(rc);
syncLatch.countDown();
}
}, null);
try {
syncLatch.await();
} catch (InterruptedException e) {
throw new DLInterruptedException("Interrupted on syncing zookeeper connection", e);
}
if (KeeperException.Code.OK.intValue() != syncResult.get()) {
throw new ZKException("Error syncing zookeeper connection ", KeeperException.Code.get(syncResult.get()));
}
return zk;
}
use of com.twitter.distributedlog.exceptions.DLInterruptedException in project distributedlog by twitter.
the class BKLogHandler method forceGetLedgerList.
/**
* Get a list of all segments in the journal.
*/
protected List<LogSegmentMetadata> forceGetLedgerList(final Comparator<LogSegmentMetadata> comparator, final LogSegmentFilter segmentFilter, boolean throwOnEmpty) throws IOException {
final List<LogSegmentMetadata> ledgers = new ArrayList<LogSegmentMetadata>();
final AtomicInteger result = new AtomicInteger(-1);
final CountDownLatch latch = new CountDownLatch(1);
Stopwatch stopwatch = Stopwatch.createStarted();
asyncGetLedgerListInternal(comparator, segmentFilter, null, new GenericCallback<List<LogSegmentMetadata>>() {
@Override
public void operationComplete(int rc, List<LogSegmentMetadata> logSegmentMetadatas) {
result.set(rc);
if (KeeperException.Code.OK.intValue() == rc) {
ledgers.addAll(logSegmentMetadatas);
} else {
LOG.error("Failed to get ledger list for {} : with error {}", getFullyQualifiedName(), rc);
}
latch.countDown();
}
}, new AtomicInteger(conf.getZKNumRetries()), new AtomicLong(conf.getZKRetryBackoffStartMillis()));
try {
latch.await();
} catch (InterruptedException e) {
forceGetListStat.registerFailedEvent(stopwatch.stop().elapsed(TimeUnit.MICROSECONDS));
throw new DLInterruptedException("Interrupted on reading ledger list from zkfor " + getFullyQualifiedName(), e);
}
long elapsedMicros = stopwatch.stop().elapsed(TimeUnit.MICROSECONDS);
KeeperException.Code rc = KeeperException.Code.get(result.get());
if (rc == KeeperException.Code.OK) {
forceGetListStat.registerSuccessfulEvent(elapsedMicros);
} else {
forceGetListStat.registerFailedEvent(elapsedMicros);
if (KeeperException.Code.NONODE == rc) {
throw new LogNotFoundException("Log " + getFullyQualifiedName() + " is not found");
} else {
throw new IOException("ZK Exception " + rc + " reading ledger list for " + getFullyQualifiedName());
}
}
if (throwOnEmpty && ledgers.isEmpty()) {
throw new LogEmptyException("Log " + getFullyQualifiedName() + " is empty");
}
return ledgers;
}
Aggregations