use of com.twitter.distributedlog.AsyncLogWriter in project distributedlog by twitter.
the class StreamImpl method handleRecoverableDLException.
/**
* Handle recoverable dl exception.
*
* @param op
* stream operation executing
* @param cause
* exception received when executing <i>op</i>
*/
private void handleRecoverableDLException(StreamOp op, final Throwable cause) {
AsyncLogWriter oldWriter = null;
boolean statusChanged = false;
synchronized (this) {
if (StreamStatus.INITIALIZED == status) {
oldWriter = setStreamStatus(StreamStatus.FAILED, StreamStatus.INITIALIZED, null, null, cause);
statusChanged = true;
}
}
if (statusChanged) {
Abortables.asyncAbort(oldWriter, false);
logger.error("Failed to write data into stream {} : ", name, cause);
scheduleTryAcquireOnce(0L);
}
op.fail(cause);
}
use of com.twitter.distributedlog.AsyncLogWriter in project distributedlog by twitter.
the class StreamImpl method handleUnknownException.
/**
* Handle unknown exception when executing <i>op</i>.
*
* @param op
* stream operation executing
* @param cause
* exception received when executing <i>op</i>
*/
private void handleUnknownException(StreamOp op, final Throwable cause) {
AsyncLogWriter oldWriter = null;
boolean statusChanged = false;
synchronized (this) {
if (StreamStatus.INITIALIZED == status) {
oldWriter = setStreamStatus(StreamStatus.FAILED, StreamStatus.INITIALIZED, null, null, cause);
statusChanged = true;
}
}
if (statusChanged) {
Abortables.asyncAbort(oldWriter, false);
logger.error("Failed to write data into stream {} : ", name, cause);
scheduleTryAcquireOnce(0L);
}
op.fail(cause);
}
use of com.twitter.distributedlog.AsyncLogWriter in project distributedlog by twitter.
the class StreamImpl method setStreamStatus.
/**
* Update the stream status. The changes are only applied when there isn't status changed.
*
* @param newStatus
* new status
* @param oldStatus
* old status
* @param writer
* new log writer
* @param owner
* new owner
* @param t
* new exception
* @return old writer if it exists
*/
synchronized AsyncLogWriter setStreamStatus(StreamStatus newStatus, StreamStatus oldStatus, AsyncLogWriter writer, String owner, Throwable t) {
if (oldStatus != this.status) {
logger.info("Stream {} status already changed from {} -> {} when trying to change it to {}", new Object[] { name, oldStatus, this.status, newStatus });
return null;
}
AsyncLogWriter oldWriter = this.writer;
this.writer = writer;
if (null != owner && owner.equals(clientId)) {
unexpectedExceptions.inc();
logger.error("I am waiting myself {} to release lock on stream {}, so have to shut myself down :", new Object[] { owner, name, t });
// I lost the ownership but left a lock over zookeeper
// I should not ask client to redirect to myself again as I can't handle it :(
// shutdown myself
fatalErrorHandler.notifyFatalError();
this.owner = null;
} else {
this.owner = owner;
}
this.lastException = t;
this.status = newStatus;
if (StreamStatus.BACKOFF == newStatus && null != owner) {
// start failure watch
this.lastAcquireFailureWatch.reset().start();
}
if (StreamStatus.INITIALIZED == newStatus) {
streamManager.notifyAcquired(this);
logger.info("Inserted acquired stream {} -> writer {}", name, this);
} else {
streamManager.notifyReleased(this);
logger.info("Removed acquired stream {} -> writer {}", name, this);
}
return oldWriter;
}
use of com.twitter.distributedlog.AsyncLogWriter in project distributedlog by twitter.
the class StreamImpl method handleOwnershipAcquireFailedException.
/**
* Handle losing ownership during executing <i>op</i>.
*
* @param op
* stream operation executing
* @param oafe
* the ownership exception received when executing <i>op</i>
*/
private void handleOwnershipAcquireFailedException(StreamOp op, final OwnershipAcquireFailedException oafe) {
logger.warn("Failed to write data into stream {} because stream is acquired by {} : {}", new Object[] { name, oafe.getCurrentOwner(), oafe.getMessage() });
AsyncLogWriter oldWriter = null;
boolean statusChanged = false;
synchronized (this) {
if (StreamStatus.INITIALIZED == status) {
oldWriter = setStreamStatus(StreamStatus.BACKOFF, StreamStatus.INITIALIZED, null, oafe.getCurrentOwner(), oafe);
statusChanged = true;
}
}
if (statusChanged) {
Abortables.asyncAbort(oldWriter, false);
scheduleTryAcquireOnce(nextAcquireWaitTimeMs);
}
op.fail(oafe);
}
Aggregations