Browse Source

HDFS-11338: [SPS]: Fix timeout issue in unit tests caused by longger NN down time. Contributed by Wei Zhou and Rakesh R

Uma Maheswara Rao G 8 years ago
parent
commit
11a08a7e8f

+ 11 - 2
hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java

@@ -726,7 +726,7 @@ public class BlockManager implements BlockStatsMXBean {
 
 
   public void close() {
   public void close() {
     if (sps != null) {
     if (sps != null) {
-      sps.stop(false);
+      sps.deactivate(false);
     }
     }
     bmSafeMode.close();
     bmSafeMode.close();
     try {
     try {
@@ -741,6 +741,7 @@ public class BlockManager implements BlockStatsMXBean {
     datanodeManager.close();
     datanodeManager.close();
     pendingReconstruction.stop();
     pendingReconstruction.stop();
     blocksMap.close();
     blocksMap.close();
+    stopSPSGracefully();
   }
   }
 
 
   /** @return the datanodeManager */
   /** @return the datanodeManager */
@@ -5067,9 +5068,17 @@ public class BlockManager implements BlockStatsMXBean {
       LOG.info("Storage policy satisfier is already stopped.");
       LOG.info("Storage policy satisfier is already stopped.");
       return;
       return;
     }
     }
-    sps.stop(true);
+    sps.deactivate(true);
   }
   }
 
 
+  /**
+   * Timed wait to stop storage policy satisfier daemon threads.
+   */
+  public void stopSPSGracefully() {
+    if (sps != null) {
+      sps.stopGracefully();
+    }
+  }
   /**
   /**
    * @return True if storage policy satisfier running.
    * @return True if storage policy satisfier running.
    */
    */

+ 19 - 6
hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/BlockStorageMovementAttemptedItems.java

@@ -130,20 +130,33 @@ public class BlockStorageMovementAttemptedItems {
   }
   }
 
 
   /**
   /**
-   * Stops the monitor thread.
+   * Sets running flag to false. Also, this will interrupt monitor thread and
+   * clear all the queued up tasks.
    */
    */
-  public synchronized void stop() {
+  public synchronized void deactivate() {
     monitorRunning = false;
     monitorRunning = false;
     if (timerThread != null) {
     if (timerThread != null) {
       timerThread.interrupt();
       timerThread.interrupt();
-      try {
-        timerThread.join(3000);
-      } catch (InterruptedException ie) {
-      }
     }
     }
     this.clearQueues();
     this.clearQueues();
   }
   }
 
 
+  /**
+   * Timed wait to stop monitor thread.
+   */
+  synchronized void stopGracefully() {
+    if (timerThread == null) {
+      return;
+    }
+    if (monitorRunning) {
+      deactivate();
+    }
+    try {
+      timerThread.join(3000);
+    } catch (InterruptedException ie) {
+    }
+  }
+
   /**
   /**
    * This class contains information of an attempted trackID. Information such
    * This class contains information of an attempted trackID. Information such
    * as, (a)last attempted time stamp, (b)whether all the blocks in the trackID
    * as, (a)last attempted time stamp, (b)whether all the blocks in the trackID

+ 1 - 1
hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java

@@ -1324,7 +1324,6 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
       if (blockManager != null) {
       if (blockManager != null) {
         blockManager.deactivateSPS();
         blockManager.deactivateSPS();
       }
       }
-
       stopSecretManager();
       stopSecretManager();
       leaseManager.stopMonitor();
       leaseManager.stopMonitor();
       if (nnrmthread != null) {
       if (nnrmthread != null) {
@@ -1363,6 +1362,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
         // Don't want to keep replication queues when not in Active.
         // Don't want to keep replication queues when not in Active.
         blockManager.clearQueues();
         blockManager.clearQueues();
         blockManager.setInitializedReplQueues(false);
         blockManager.setInitializedReplQueues(false);
+        blockManager.stopSPSGracefully();
       }
       }
     } finally {
     } finally {
       writeUnlock("stopActiveServices");
       writeUnlock("stopActiveServices");

+ 27 - 11
hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/StoragePolicySatisfier.java

@@ -115,22 +115,21 @@ public class StoragePolicySatisfier implements Runnable {
   }
   }
 
 
   /**
   /**
-   * Stop storage policy satisfier demon thread.
+   * Deactivates storage policy satisfier by stopping its services.
    *
    *
-   * @param reconfigStop
+   * @param reconfig
+   *          true represents deactivating SPS service as requested by admin,
+   *          false otherwise
    */
    */
-  public synchronized void stop(boolean reconfigStop) {
+  public synchronized void deactivate(boolean reconfig) {
     isRunning = false;
     isRunning = false;
     if (storagePolicySatisfierThread == null) {
     if (storagePolicySatisfierThread == null) {
       return;
       return;
     }
     }
+
     storagePolicySatisfierThread.interrupt();
     storagePolicySatisfierThread.interrupt();
-    try {
-      storagePolicySatisfierThread.join(3000);
-    } catch (InterruptedException ie) {
-    }
-    this.storageMovementsMonitor.stop();
-    if (reconfigStop) {
+    this.storageMovementsMonitor.deactivate();
+    if (reconfig) {
       LOG.info("Stopping StoragePolicySatisfier, as admin requested to "
       LOG.info("Stopping StoragePolicySatisfier, as admin requested to "
           + "deactivate it.");
           + "deactivate it.");
       this.clearQueuesWithNotification();
       this.clearQueuesWithNotification();
@@ -140,6 +139,23 @@ public class StoragePolicySatisfier implements Runnable {
     }
     }
   }
   }
 
 
+  /**
+   * Timed wait to stop storage policy satisfier daemon threads.
+   */
+  public synchronized void stopGracefully() {
+    if (isRunning) {
+      deactivate(true);
+    }
+    this.storageMovementsMonitor.stopGracefully();
+    if (storagePolicySatisfierThread == null) {
+      return;
+    }
+    try {
+      storagePolicySatisfierThread.join(3000);
+    } catch (InterruptedException ie) {
+    }
+  }
+
   /**
   /**
    * Check whether StoragePolicySatisfier is running.
    * Check whether StoragePolicySatisfier is running.
    * @return true if running
    * @return true if running
@@ -162,7 +178,7 @@ public class StoragePolicySatisfier implements Runnable {
       if (!isRunning) {
       if (!isRunning) {
         // Stopping monitor thread and clearing queues as well
         // Stopping monitor thread and clearing queues as well
         this.clearQueues();
         this.clearQueues();
-        this.storageMovementsMonitor.stop();
+        this.storageMovementsMonitor.stopGracefully();
         LOG.error(
         LOG.error(
             "Stopping StoragePolicySatisfier thread " + "as Mover ID file "
             "Stopping StoragePolicySatisfier thread " + "as Mover ID file "
                 + HdfsServerConstants.MOVER_ID_PATH.toString()
                 + HdfsServerConstants.MOVER_ID_PATH.toString()
@@ -194,7 +210,7 @@ public class StoragePolicySatisfier implements Runnable {
           isRunning = false;
           isRunning = false;
           // Stopping monitor thread and clearing queues as well
           // Stopping monitor thread and clearing queues as well
           this.clearQueues();
           this.clearQueues();
-          this.storageMovementsMonitor.stop();
+          this.storageMovementsMonitor.stopGracefully();
         }
         }
         if (!namesystem.isRunning()) {
         if (!namesystem.isRunning()) {
           LOG.info("Stopping StoragePolicySatisfier.");
           LOG.info("Stopping StoragePolicySatisfier.");

+ 2 - 1
hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestBlockStorageMovementAttemptedItems.java

@@ -47,7 +47,8 @@ public class TestBlockStorageMovementAttemptedItems {
   @After
   @After
   public void teardown() {
   public void teardown() {
     if (bsmAttemptedItems != null) {
     if (bsmAttemptedItems != null) {
-      bsmAttemptedItems.stop();
+      bsmAttemptedItems.deactivate();
+      bsmAttemptedItems.stopGracefully();
     }
     }
   }
   }