From 3b601f2c0e16b84e35ebe5ecdcd06d3277eabb74 Mon Sep 17 00:00:00 2001 From: Uma Maheswara Rao G Date: Wed, 19 Jul 2017 00:55:26 -0700 Subject: [PATCH] HDFS-12152: [SPS]: Re-arrange StoragePolicySatisfyWorker stopping sequence to improve thread cleanup time. Contributed by Rakesh R. --- .../datanode/BlockStorageMovementTracker.java | 16 ++++++++++++---- .../datanode/StoragePolicySatisfyWorker.java | 5 +++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BlockStorageMovementTracker.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BlockStorageMovementTracker.java index c7e952b4dd..f3d2bb6944 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BlockStorageMovementTracker.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BlockStorageMovementTracker.java @@ -77,7 +77,8 @@ public void run() { moverTaskFutures.wait(2000); } } catch (InterruptedException ignore) { - // ignore + // Sets interrupt flag of this thread. + Thread.currentThread().interrupt(); } } try { @@ -102,12 +103,19 @@ public void run() { synchronized (moverTaskFutures) { moverTaskFutures.remove(trackId); } - // handle completed or inprogress blocks movements per trackId. - blksMovementsStatusHandler.handle(resultPerTrackIdList); + if (running) { + // handle completed or inprogress blocks movements per trackId. + blksMovementsStatusHandler.handle(resultPerTrackIdList); + } movementResults.remove(trackId); } } - } catch (ExecutionException | InterruptedException e) { + } catch (InterruptedException e) { + if (running) { + LOG.error("Exception while moving block replica to target storage" + + " type", e); + } + } catch (ExecutionException e) { // TODO: Do we need failure retries and implement the same if required. LOG.error("Exception while moving block replica to target storage type", e); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/StoragePolicySatisfyWorker.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/StoragePolicySatisfyWorker.java index 196cd58200..4e57805165 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/StoragePolicySatisfyWorker.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/StoragePolicySatisfyWorker.java @@ -137,8 +137,8 @@ void start() { * thread. */ void stop() { - movementTrackerThread.interrupt(); movementTracker.stopTracking(); + movementTrackerThread.interrupt(); } /** @@ -147,7 +147,8 @@ void stop() { void waitToFinishWorkerThread() { try { movementTrackerThread.join(3000); - } catch (InterruptedException ie) { + } catch (InterruptedException ignore) { + // ignore } }