You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by vi...@apache.org on 2018/08/10 16:39:20 UTC

hadoop git commit: HDFS-13795. Fix potential NPE in InMemoryLevelDBAliasMapServer.

Repository: hadoop
Updated Branches:
  refs/heads/trunk 0a71bf145 -> 15241c634


HDFS-13795. Fix potential NPE in InMemoryLevelDBAliasMapServer.


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/15241c63
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/15241c63
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/15241c63

Branch: refs/heads/trunk
Commit: 15241c6349a5245761ed43bd0d38b25f783cc96b
Parents: 0a71bf1
Author: Virajith Jalaparti <vi...@apache.org>
Authored: Fri Aug 10 09:38:40 2018 -0700
Committer: Virajith Jalaparti <vi...@apache.org>
Committed: Fri Aug 10 09:38:40 2018 -0700

----------------------------------------------------------------------
 ...yAliasMapProtocolClientSideTranslatorPB.java |  6 +++
 .../aliasmap/InMemoryLevelDBAliasMapServer.java |  8 +++-
 .../impl/TestInMemoryLevelDBAliasMapClient.java | 39 ++++++++++++++++++++
 3 files changed, 51 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/15241c63/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocolPB/InMemoryAliasMapProtocolClientSideTranslatorPB.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocolPB/InMemoryAliasMapProtocolClientSideTranslatorPB.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocolPB/InMemoryAliasMapProtocolClientSideTranslatorPB.java
index 2025c16..d9e984b 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocolPB/InMemoryAliasMapProtocolClientSideTranslatorPB.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocolPB/InMemoryAliasMapProtocolClientSideTranslatorPB.java
@@ -167,6 +167,9 @@ public class InMemoryAliasMapProtocolClientSideTranslatorPB
   public Optional<ProvidedStorageLocation> read(@Nonnull Block block)
       throws IOException {
 
+    if (block == null) {
+      throw new IOException("Block cannot be null");
+    }
     ReadRequestProto request =
         ReadRequestProto
             .newBuilder()
@@ -191,6 +194,9 @@ public class InMemoryAliasMapProtocolClientSideTranslatorPB
   public void write(@Nonnull Block block,
       @Nonnull ProvidedStorageLocation providedStorageLocation)
       throws IOException {
+    if (block == null || providedStorageLocation == null) {
+      throw new IOException("Provided block and location cannot be null");
+    }
     WriteRequestProto request =
         WriteRequestProto
             .newBuilder()

http://git-wip-us.apache.org/repos/asf/hadoop/blob/15241c63/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/aliasmap/InMemoryLevelDBAliasMapServer.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/aliasmap/InMemoryLevelDBAliasMapServer.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/aliasmap/InMemoryLevelDBAliasMapServer.java
index f201bfd..5c56736 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/aliasmap/InMemoryLevelDBAliasMapServer.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/aliasmap/InMemoryLevelDBAliasMapServer.java
@@ -150,11 +150,15 @@ public class InMemoryLevelDBAliasMapServer implements InMemoryAliasMapProtocol,
   public void close() {
     LOG.info("Stopping InMemoryLevelDBAliasMapServer");
     try {
-      aliasMap.close();
+      if (aliasMap != null) {
+        aliasMap.close();
+      }
     } catch (IOException e) {
       LOG.error(e.getMessage());
     }
-    aliasMapServer.stop();
+    if (aliasMapServer != null) {
+      aliasMapServer.stop();
+    }
   }
 
 }

http://git-wip-us.apache.org/repos/asf/hadoop/blob/15241c63/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/common/blockaliasmap/impl/TestInMemoryLevelDBAliasMapClient.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/common/blockaliasmap/impl/TestInMemoryLevelDBAliasMapClient.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/common/blockaliasmap/impl/TestInMemoryLevelDBAliasMapClient.java
index f062633..fccb6f2 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/common/blockaliasmap/impl/TestInMemoryLevelDBAliasMapClient.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/common/blockaliasmap/impl/TestInMemoryLevelDBAliasMapClient.java
@@ -28,14 +28,19 @@ import org.apache.hadoop.hdfs.server.aliasmap.InMemoryAliasMap;
 import org.apache.hadoop.hdfs.server.aliasmap.InMemoryLevelDBAliasMapServer;
 import org.apache.hadoop.hdfs.server.common.blockaliasmap.BlockAliasMap;
 import org.apache.hadoop.hdfs.server.common.FileRegion;
+import org.apache.hadoop.test.LambdaTestUtils;
 import org.junit.After;
 import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
+import org.junit.rules.ExpectedException;
 
 import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_SERVICE_RPC_BIND_HOST_KEY;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 import java.io.File;
 import java.io.IOException;
@@ -59,6 +64,9 @@ public class TestInMemoryLevelDBAliasMapClient {
   private Configuration conf;
   private final static String BPID = "BPID-0";
 
+  @Rule
+  public final ExpectedException exception = ExpectedException.none();
+
   @Before
   public void setUp() throws IOException {
     conf = new Configuration();
@@ -348,4 +356,35 @@ public class TestInMemoryLevelDBAliasMapClient {
     conf.set(DFS_NAMENODE_SERVICE_RPC_BIND_HOST_KEY, "0.0.0.0");
     writeRead();
   }
+
+  @Test
+  public void testNonExistentFile() throws Exception {
+    // delete alias map location
+    FileUtils.deleteDirectory(tempDir);
+    // expect a RuntimeException when the aliasmap is started.
+    exception.expect(RuntimeException.class);
+    levelDBAliasMapServer.setConf(conf);
+  }
+
+  @Test
+  public void testNonExistentBlock() throws Exception {
+    inMemoryLevelDBAliasMapClient.setConf(conf);
+    levelDBAliasMapServer.setConf(conf);
+    levelDBAliasMapServer.start();
+    Block block1 = new Block(100, 43, 44);
+    ProvidedStorageLocation providedStorageLocation1 = null;
+    BlockAliasMap.Writer<FileRegion> writer1 =
+        inMemoryLevelDBAliasMapClient.getWriter(null, BPID);
+    try {
+      writer1.store(new FileRegion(block1, providedStorageLocation1));
+      fail("Should fail on writing a region with null ProvidedLocation");
+    } catch (IOException | IllegalArgumentException e) {
+      assertTrue(e.getMessage().contains("not be null"));
+    }
+
+    BlockAliasMap.Reader<FileRegion> reader =
+        inMemoryLevelDBAliasMapClient.getReader(null, BPID);
+    LambdaTestUtils.assertOptionalUnset("Expected empty BlockAlias",
+        reader.resolve(block1));
+  }
 }
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org