From ce19f09bd09325a33124d5edb66ba8f36916baa5 Mon Sep 17 00:00:00 2001 From: Nanda kumar Date: Thu, 21 Dec 2017 18:56:30 +0530 Subject: [PATCH] HDFS-12908. Ozone: write chunk call fails because of Metrics registry exception. Contributed by Mukul Kumar Singh. --- .../main/java/org/apache/hadoop/ozone/OzoneConsts.java | 4 +++- .../ozone/container/common/helpers/ContainerUtils.java | 10 ++++++++-- .../java/org/apache/hadoop/ozone/scm/cli/SQLCLI.java | 4 ++-- .../hadoop/ozone/scm/container/ContainerMapping.java | 4 ++-- .../java/org/apache/hadoop/utils/RocksDBStore.java | 7 ++++--- .../common/impl/TestContainerPersistence.java | 2 +- .../apache/hadoop/ozone/scm/TestContainerSQLCli.java | 4 ++-- 7 files changed, 22 insertions(+), 13 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/ozone/OzoneConsts.java b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/ozone/OzoneConsts.java index 6c2966c47a..fe8319c428 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/ozone/OzoneConsts.java +++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/ozone/OzoneConsts.java @@ -76,7 +76,9 @@ public final class OzoneConsts { /** * level DB names used by SCM and data nodes. */ - public static final String CONTAINER_DB = "container.db"; + public static final String CONTAINER_DB_SUFFIX = "container.db"; + public static final String SCM_CONTAINER_DB = "scm-" + CONTAINER_DB_SUFFIX; + public static final String DN_CONTAINER_DB = "-dn-"+ CONTAINER_DB_SUFFIX; public static final String BLOCK_DB = "block.db"; public static final String NODEPOOL_DB = "nodepool.db"; public static final String OPEN_CONTAINERS_DB = "openContainers.db"; diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/container/common/helpers/ContainerUtils.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/container/common/helpers/ContainerUtils.java index d16b908517..f78e6466e1 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/container/common/helpers/ContainerUtils.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/container/common/helpers/ContainerUtils.java @@ -230,13 +230,18 @@ public static void verifyIsNewContainer(File containerFile, File metadataFile) } } + public static String getContainerDbFileName(String containerName) { + return containerName + OzoneConsts.DN_CONTAINER_DB; + } + /** * creates a Metadata DB for the specified container. * * @param containerPath - Container Path. * @throws IOException */ - public static Path createMetadata(Path containerPath, Configuration conf) + public static Path createMetadata(Path containerPath, String containerName, + Configuration conf) throws IOException { Logger log = LoggerFactory.getLogger(ContainerManagerImpl.class); Preconditions.checkNotNull(containerPath); @@ -250,7 +255,8 @@ public static Path createMetadata(Path containerPath, Configuration conf) MetadataStore store = MetadataStoreBuilder.newBuilder() .setConf(conf) .setCreateIfMissing(true) - .setDbFile(metadataPath.resolve(OzoneConsts.CONTAINER_DB).toFile()) + .setDbFile(metadataPath + .resolve(getContainerDbFileName(containerName)).toFile()) .build(); // we close since the SCM pre-creates containers. diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/cli/SQLCLI.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/cli/SQLCLI.java index 1b9777c4be..21c437d253 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/cli/SQLCLI.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/cli/SQLCLI.java @@ -60,7 +60,7 @@ import java.util.Set; import static org.apache.hadoop.ozone.OzoneConsts.BLOCK_DB; -import static org.apache.hadoop.ozone.OzoneConsts.CONTAINER_DB; +import static org.apache.hadoop.ozone.OzoneConsts.CONTAINER_DB_SUFFIX; import static org.apache.hadoop.ozone.OzoneConsts.KSM_DB_NAME; import static org.apache.hadoop.ozone.OzoneConsts.KSM_USER_PREFIX; import static org.apache.hadoop.ozone.OzoneConsts.KSM_BUCKET_PREFIX; @@ -293,7 +293,7 @@ public int run(String[] args) throws Exception { } } LOG.info("Parent path [{}] db name [{}]", parentPath, dbName); - if (dbName.toString().equals(CONTAINER_DB)) { + if (dbName.toString().endsWith(CONTAINER_DB_SUFFIX)) { LOG.info("Converting container DB"); convertContainerDB(dbPath, outPath); } else if (dbName.toString().equals(BLOCK_DB)) { diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/container/ContainerMapping.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/container/ContainerMapping.java index 3bd066cd26..2c1d3c428f 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/container/ContainerMapping.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/container/ContainerMapping.java @@ -55,7 +55,7 @@ import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; -import static org.apache.hadoop.ozone.OzoneConsts.CONTAINER_DB; +import static org.apache.hadoop.ozone.OzoneConsts.SCM_CONTAINER_DB; import static org.apache.hadoop.ozone.scm.exceptions.SCMException.ResultCodes.FAILED_TO_CHANGE_CONTAINER_STATE; /** @@ -102,7 +102,7 @@ public ContainerMapping( File metaDir = OzoneUtils.getOzoneMetaDirPath(conf); // Write the container name to pipeline mapping. - File containerDBPath = new File(metaDir, CONTAINER_DB); + File containerDBPath = new File(metaDir, SCM_CONTAINER_DB); containerStore = MetadataStoreBuilder.newBuilder() .setConf(conf) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/utils/RocksDBStore.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/utils/RocksDBStore.java index c56998902d..2f340a534b 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/utils/RocksDBStore.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/utils/RocksDBStore.java @@ -23,11 +23,8 @@ import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.hadoop.metrics2.util.MBeans; import org.apache.ratis.shaded.com.google.common.annotations.VisibleForTesting; -import org.rocksdb.DBOptions; import org.rocksdb.RocksIterator; import org.rocksdb.Options; -import org.rocksdb.Statistics; -import org.rocksdb.StatsLevel; import org.rocksdb.WriteOptions; import org.rocksdb.RocksDB; import org.rocksdb.RocksDBException; @@ -76,6 +73,10 @@ public RocksDBStore(File dbFile, Options options) jmxProperties.put("dbName", dbFile.getName()); statMBeanName = MBeans.register("Ozone", "RocksDbStore", jmxProperties, new RocksDBStoreMBean(dbOptions.statistics())); + if (statMBeanName == null) { + LOG.warn("jmx registration failed during RocksDB init, db path :{}", + dbFile.getAbsolutePath()); + } } } catch (RocksDBException e) { throw new IOException( diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/container/common/impl/TestContainerPersistence.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/container/common/impl/TestContainerPersistence.java index 06d8062e21..f114fa2bd6 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/container/common/impl/TestContainerPersistence.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/container/common/impl/TestContainerPersistence.java @@ -164,7 +164,7 @@ public void cleanupDir() throws IOException { } // Clean up SCM metadata - log.info("Deletting {}", path); + log.info("Deleting {}", path); FileUtils.deleteDirectory(new File(path)); // Clean up SCM datanode container metadata/data diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/scm/TestContainerSQLCli.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/scm/TestContainerSQLCli.java index fb852a210a..49fb261c98 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/scm/TestContainerSQLCli.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/scm/TestContainerSQLCli.java @@ -53,7 +53,7 @@ import java.util.HashMap; import static org.apache.hadoop.ozone.OzoneConsts.BLOCK_DB; -import static org.apache.hadoop.ozone.OzoneConsts.CONTAINER_DB; +import static org.apache.hadoop.ozone.OzoneConsts.SCM_CONTAINER_DB; import static org.apache.hadoop.ozone.OzoneConsts.KB; import static org.apache.hadoop.ozone.OzoneConsts.NODEPOOL_DB; //import static org.apache.hadoop.ozone.OzoneConsts.OPEN_CONTAINERS_DB; @@ -234,7 +234,7 @@ public void testConvertContainerDB() throws Exception { // TODO : the following will fail due to empty Datanode list, need to fix. //String dnUUID = cluster.getDataNodes().get(0).getDatanodeUuid(); String dbRootPath = conf.get(OzoneConfigKeys.OZONE_METADATA_DIRS); - String dbPath = dbRootPath + "/" + CONTAINER_DB; + String dbPath = dbRootPath + "/" + SCM_CONTAINER_DB; String[] args = {"-p", dbPath, "-o", dbOutPath}; Connection conn; String sql;