From 11615631360ba49c1e9d256ed4f65119d99fd67d Mon Sep 17 00:00:00 2001 From: Arpit Agarwal Date: Thu, 25 May 2017 14:01:53 -0700 Subject: [PATCH] HDFS-11879. Fix JN sync interval in case of exception. Contributed by Hanisha Koneru. --- .../qjournal/server/JournalNodeSyncer.java | 40 ++++++++++++------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/qjournal/server/JournalNodeSyncer.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/qjournal/server/JournalNodeSyncer.java index 99bd499082..479f6a00e2 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/qjournal/server/JournalNodeSyncer.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/qjournal/server/JournalNodeSyncer.java @@ -172,7 +172,6 @@ private void startSyncJournalsDaemon() { } else { syncJournals(); } - Thread.sleep(journalSyncInterval); } catch (Throwable t) { if (!shouldSync) { if (t instanceof InterruptedException) { @@ -194,6 +193,17 @@ private void startSyncJournalsDaemon() { LOG.error( "JournalNodeSyncer daemon received Runtime exception. ", t); } + try { + Thread.sleep(journalSyncInterval); + } catch (InterruptedException e) { + if (!shouldSync) { + LOG.info("Stopping JournalNode Sync."); + } else { + LOG.warn("JournalNodeSyncer interrupted", e); + } + Thread.currentThread().interrupt(); + return; + } } }); syncJournalDaemon.start(); @@ -320,30 +330,30 @@ private List getMissingLogList( List missingEditLogs = Lists.newArrayList(); - int thisJnIndex = 0, otherJnIndex = 0; - int thisJnNumLogs = thisJournalEditLogs.size(); - int otherJnNumLogs = otherJournalEditLogs.size(); + int localJnIndex = 0, remoteJnIndex = 0; + int localJnNumLogs = thisJournalEditLogs.size(); + int remoteJnNumLogs = otherJournalEditLogs.size(); - while (thisJnIndex < thisJnNumLogs && otherJnIndex < otherJnNumLogs) { - long localJNstartTxId = thisJournalEditLogs.get(thisJnIndex) + while (localJnIndex < localJnNumLogs && remoteJnIndex < remoteJnNumLogs) { + long localJNstartTxId = thisJournalEditLogs.get(localJnIndex) .getStartTxId(); - long remoteJNstartTxId = otherJournalEditLogs.get(otherJnIndex) + long remoteJNstartTxId = otherJournalEditLogs.get(remoteJnIndex) .getStartTxId(); if (localJNstartTxId == remoteJNstartTxId) { - thisJnIndex++; - otherJnIndex++; + localJnIndex++; + remoteJnIndex++; } else if (localJNstartTxId > remoteJNstartTxId) { - missingEditLogs.add(otherJournalEditLogs.get(otherJnIndex)); - otherJnIndex++; + missingEditLogs.add(otherJournalEditLogs.get(remoteJnIndex)); + remoteJnIndex++; } else { - thisJnIndex++; + localJnIndex++; } } - if (otherJnIndex < otherJnNumLogs) { - for (; otherJnIndex < otherJnNumLogs; otherJnIndex++) { - missingEditLogs.add(otherJournalEditLogs.get(otherJnIndex)); + if (remoteJnIndex < remoteJnNumLogs) { + for (; remoteJnIndex < remoteJnNumLogs; remoteJnIndex++) { + missingEditLogs.add(otherJournalEditLogs.get(remoteJnIndex)); } }