From 0a8c903d3f43eb4fc7c0327e04caf12f8cf5b949 Mon Sep 17 00:00:00 2001 From: Chen Liang Date: Thu, 29 Jun 2017 14:43:30 -0700 Subject: [PATCH] HDFS-12050. Ozone: StorageHandler: Implementation of close for releasing resources during shutdown. Contributed by Nandakumar. --- .../org/apache/hadoop/scm/XceiverClientManager.java | 9 +++++++++ .../hdfs/server/datanode/ObjectStoreHandler.java | 1 + .../hadoop/ozone/web/interfaces/StorageHandler.java | 5 +++++ .../ozone/web/localstorage/LocalStorageHandler.java | 5 +++++ .../ozone/web/storage/DistributedStorageHandler.java | 10 ++++++++++ 5 files changed, 30 insertions(+) diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/scm/XceiverClientManager.java b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/scm/XceiverClientManager.java index 9a5f68dceb..62e5af1eaf 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/scm/XceiverClientManager.java +++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/scm/XceiverClientManager.java @@ -154,4 +154,13 @@ public XceiverClientSpi call() throws Exception { throw new IOException("Exception getting XceiverClient.", e); } } + + /** + * Close and remove all the cached clients. + */ + public void close() { + //closing is done through RemovalListener + clientCache.invalidateAll(); + clientCache.cleanUp(); + } } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/ObjectStoreHandler.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/ObjectStoreHandler.java index 0bcb0588d4..ab89ede59b 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/ObjectStoreHandler.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/ObjectStoreHandler.java @@ -177,6 +177,7 @@ public StorageHandler getStorageHandler() { @Override public void close() { LOG.info("Closing ObjectStoreHandler."); + storageHandler.close(); if (this.storageContainerLocationClient != null) { this.storageContainerLocationClient.close(); } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/interfaces/StorageHandler.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/interfaces/StorageHandler.java index 52eb349e77..05f12e435a 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/interfaces/StorageHandler.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/interfaces/StorageHandler.java @@ -273,4 +273,9 @@ LengthInputStream newKeyReader(KeyArgs args) * @throws IOException */ ListKeys listKeys(ListArgs args) throws IOException, OzoneException; + + /** + * Closes all the opened resources. + */ + void close(); } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/localstorage/LocalStorageHandler.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/localstorage/LocalStorageHandler.java index cb8db32387..387eb16fce 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/localstorage/LocalStorageHandler.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/localstorage/LocalStorageHandler.java @@ -353,4 +353,9 @@ public ListKeys listKeys(ListArgs args) throws IOException, OzoneException { } + @Override + public void close() { + //No resource to close, do nothing. + } + } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/storage/DistributedStorageHandler.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/storage/DistributedStorageHandler.java index dfd0a96ec3..a6887fe3f1 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/storage/DistributedStorageHandler.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/storage/DistributedStorageHandler.java @@ -509,4 +509,14 @@ private static String dateToString(Date date) { sdf.setTimeZone(TimeZone.getTimeZone(OzoneConsts.OZONE_TIME_ZONE)); return sdf.format(date); } + + /** + * Closes DistributedStorageHandler. + */ + @Override + public void close() { + if(xceiverClientManager != null) { + xceiverClientManager.close(); + } + } }