Skip to content

Commit

Permalink
Add replication log details to the exception message when replaying Z…
Browse files Browse the repository at this point in the history
…ooKeeper log fails. (line#900)

Motivation:
Currently, it is challenging to identify the specific replication log that fails during replay.

Modifications:
- Enhanced exception messages by including details of the replication log that encountered failure.

Result:
- You can now easily identify the failing replication log.
  • Loading branch information
minwoox authored Dec 27, 2023
1 parent 49a71fd commit 5166201
Showing 1 changed file with 24 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -715,11 +715,12 @@ private synchronized void replayLogs(long targetRevision) {
}

long nextRevision = info.lastReplayedRevision + 1;
try {
for (;;) {
for (;;) {
ReplicationLog<?> l = null;
try {
final Optional<ReplicationLog<?>> log = loadLog(nextRevision, true);
if (log.isPresent()) {
final ReplicationLog<?> l = log.get();
l = log.get();
final Command<?> command = l.command();
final Object expectedResult = l.result();
final Object actualResult = delegate.execute(command).get();
Expand All @@ -744,15 +745,28 @@ private synchronized void replayLogs(long targetRevision) {
} else {
nextRevision++;
}
}
} catch (Throwable t) {
logger.error("Failed to replay a log at revision {}; entering read-only mode", nextRevision, t);
stopLater();
} catch (Throwable t) {
if (l != null) {
logger.error(
"Failed to replay a log at revision {}; entering read-only mode. replay log: {}",
nextRevision, l, t);
} else {
logger.error("Failed to replay a log at revision {}; entering read-only mode.",
nextRevision, t);
}

stopLater();

if (t instanceof ReplicationException) {
throw (ReplicationException) t;
if (t instanceof ReplicationException) {
throw (ReplicationException) t;
}
final StringBuilder sb = new StringBuilder();
sb.append("failed to replay a log at revision " + nextRevision);
if (l != null) {
sb.append(". replay log: ").append(l);
}
throw new ReplicationException(sb.toString(), t);
}
throw new ReplicationException("failed to replay a log at revision " + nextRevision, t);
}
}

Expand Down

0 comments on commit 5166201

Please sign in to comment.