From 5166201498e5c23fadaf579262cfe8bbb82dd8d6 Mon Sep 17 00:00:00 2001 From: minux Date: Wed, 27 Dec 2023 16:05:47 +0900 Subject: [PATCH] Add replication log details to the exception message when replaying ZooKeeper log fails. (#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. --- .../replication/ZooKeeperCommandExecutor.java | 34 +++++++++++++------ 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/server/src/main/java/com/linecorp/centraldogma/server/internal/replication/ZooKeeperCommandExecutor.java b/server/src/main/java/com/linecorp/centraldogma/server/internal/replication/ZooKeeperCommandExecutor.java index d3b082d8ee..366171c9fc 100644 --- a/server/src/main/java/com/linecorp/centraldogma/server/internal/replication/ZooKeeperCommandExecutor.java +++ b/server/src/main/java/com/linecorp/centraldogma/server/internal/replication/ZooKeeperCommandExecutor.java @@ -715,11 +715,12 @@ private synchronized void replayLogs(long targetRevision) { } long nextRevision = info.lastReplayedRevision + 1; - try { - for (;;) { + for (;;) { + ReplicationLog l = null; + try { final Optional> 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(); @@ -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); } }