use of com.twitter.distributedlog.exceptions.ServiceUnavailableException in project distributedlog by twitter.
the class DistributedLogClientImpl method handleServiceUnavailable.
void handleServiceUnavailable(SocketAddress addr, ProxyClient sc, Optional<StreamOp> op) {
// service is unavailable, remove it out of routing service
routingService.removeHost(addr, new ServiceUnavailableException(addr + " is unavailable now."));
onServerLeft(addr);
if (op.isPresent()) {
ownershipCache.removeOwnerFromStream(op.get().stream, addr, addr + " is unavailable now.");
// redirect the request to other host.
redirect(op.get(), null);
}
}
use of com.twitter.distributedlog.exceptions.ServiceUnavailableException in project distributedlog by twitter.
the class DistributedLogServiceImpl method executeStreamOp.
private void executeStreamOp(final StreamOp op) {
// Must attach this as early as possible--returning before this point will cause us to
// lose the status code.
op.responseHeader().addEventListener(new FutureEventListener<ResponseHeader>() {
@Override
public void onSuccess(ResponseHeader header) {
if (header.getLocation() != null || header.getCode() == StatusCode.FOUND) {
redirects.inc();
}
countStatusCode(header.getCode());
}
@Override
public void onFailure(Throwable cause) {
}
});
try {
// Apply the request limiter
limiter.apply(op);
// Execute per-op pre-exec code
op.preExecute();
} catch (TooManyStreamsException e) {
// Translate to StreamUnavailableException to ensure that the client will redirect
// to a different host. Ideally we would be able to return TooManyStreamsException,
// but the way exception handling works right now we can't control the handling in
// the client because client changes deploy very slowly.
op.fail(new StreamUnavailableException(e.getMessage()));
return;
} catch (Exception e) {
op.fail(e);
return;
}
Stream stream;
try {
stream = getLogWriter(op.streamName());
} catch (RegionUnavailableException rue) {
// redirect the requests to other region
op.fail(new RegionUnavailableException("Region " + serverRegionId + " is unavailable."));
return;
} catch (IOException e) {
op.fail(e);
return;
}
if (null == stream) {
// redirect the requests when stream is unavailable.
op.fail(new ServiceUnavailableException("Server " + clientId + " is closed."));
return;
}
if (op instanceof WriteOpWithPayload) {
WriteOpWithPayload writeOp = (WriteOpWithPayload) op;
windowedBps.add(writeOp.getPayloadSize());
windowedRps.inc();
}
stream.submit(op);
}
use of com.twitter.distributedlog.exceptions.ServiceUnavailableException in project distributedlog by twitter.
the class StreamManagerImpl method closeAndRemoveAsync.
/**
* Must be enqueued to an executor to avoid deadlocks (close and execute-op both
* try to acquire the same read-write lock).
*/
@Override
public Future<Void> closeAndRemoveAsync(final String streamName) {
final Promise<Void> releasePromise = new Promise<Void>();
java.util.concurrent.Future<?> scheduleFuture = schedule(new Runnable() {
@Override
public void run() {
releasePromise.become(doCloseAndRemoveAsync(streamName));
}
}, 0);
if (null == scheduleFuture) {
return Future.exception(new ServiceUnavailableException("Couldn't schedule a release task."));
}
return releasePromise;
}
use of com.twitter.distributedlog.exceptions.ServiceUnavailableException in project distributedlog by twitter.
the class StreamManagerImpl method deleteAndRemoveAsync.
/**
* Must be enqueued to an executor to avoid deadlocks (close and execute-op both
* try to acquire the same read-write lock).
*/
@Override
public Future<Void> deleteAndRemoveAsync(final String stream) {
final Promise<Void> result = new Promise<Void>();
java.util.concurrent.Future<?> scheduleFuture = schedule(new Runnable() {
@Override
public void run() {
result.become(doDeleteAndRemoveAsync(stream));
}
}, 0);
if (null == scheduleFuture) {
return Future.exception(new ServiceUnavailableException("Couldn't schedule a delete task."));
}
return result;
}
use of com.twitter.distributedlog.exceptions.ServiceUnavailableException in project distributedlog by twitter.
the class StreamManagerImpl method createStreamAsync.
@Override
public Future<Void> createStreamAsync(final String stream) {
final Promise<Void> createPromise = new Promise<Void>();
java.util.concurrent.Future<?> scheduleFuture = schedule(new Runnable() {
@Override
public void run() {
try {
dlNamespace.createLog(stream);
createPromise.setValue(null);
} catch (Exception e) {
createPromise.setException(e);
}
}
}, 0);
if (null == scheduleFuture) {
return Future.exception(new ServiceUnavailableException("Couldn't schedule a create task."));
}
return createPromise;
}
Aggregations