From dcac7311de35c07080a8fd91665b60c14034b263 Mon Sep 17 00:00:00 2001 From: Peter Slawski Date: Mon, 20 Jun 2016 10:18:25 -0700 Subject: [PATCH] HIVE-14290: Refactor HIVE-14054 to use Collections#newSetFromMap This refactors HIVE-14054 to cleanly create and use a set backed by a Map implementation, that is, a ConcurrentHashMap. --- .../hadoop/hive/ql/metadata/HiveMetaStoreChecker.java | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/ql/src/java/org/apache/hadoop/hive/ql/metadata/HiveMetaStoreChecker.java b/ql/src/java/org/apache/hadoop/hive/ql/metadata/HiveMetaStoreChecker.java index a164b12..7f1a9ee 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/metadata/HiveMetaStoreChecker.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/metadata/HiveMetaStoreChecker.java @@ -375,9 +375,7 @@ private String getPartitionName(Path tablePath, Path partitionPath) { private void getAllLeafDirs(Path basePath, Set allDirs) throws IOException, HiveException { ConcurrentLinkedQueue basePaths = new ConcurrentLinkedQueue<>(); basePaths.add(basePath); - // we only use the keySet of ConcurrentHashMap - // Neither the key nor the value can be null. - Map dirSet = new ConcurrentHashMap<>(); + Set dirSet = Collections.newSetFromMap(new ConcurrentHashMap()); // Here we just reuse the THREAD_COUNT configuration for // HIVE_MOVE_FILES_THREAD_COUNT final ExecutorService pool = conf.getInt(ConfVars.HIVE_MOVE_FILES_THREAD_COUNT.varname, 25) > 0 ? Executors @@ -392,12 +390,12 @@ private void getAllLeafDirs(Path basePath, Set allDirs) throws IOException } getAllLeafDirs(pool, basePaths, dirSet, basePath.getFileSystem(conf)); pool.shutdown(); - allDirs.addAll(dirSet.keySet()); + allDirs.addAll(dirSet); } // process the basePaths in parallel and then the next level of basePaths private void getAllLeafDirs(final ExecutorService pool, final ConcurrentLinkedQueue basePaths, - final Map allDirs, final FileSystem fs) throws IOException, HiveException { + final Set allDirs, final FileSystem fs) throws IOException, HiveException { final ConcurrentLinkedQueue nextLevel = new ConcurrentLinkedQueue<>(); if (null == pool) { for (final Path path : basePaths) { @@ -411,8 +409,7 @@ private void getAllLeafDirs(final ExecutorService pool, final ConcurrentLinkedQu } if (!directoryFound) { - // true is just a boolean object place holder because neither the key nor the value can be null. - allDirs.put(path, true); + allDirs.add(path); } if (!nextLevel.isEmpty()) { getAllLeafDirs(pool, nextLevel, allDirs, fs); @@ -435,7 +432,7 @@ public Void call() throws Exception { } if (!directoryFound) { - allDirs.put(path, true); + allDirs.add(path); } return null; } -- 2.5.4 (Apple Git-61)