saihemanth-cloudera commented on code in PR #6719: URL: https://github.com/apache/hive/pull/6719#discussion_r4020747806
########## standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/tools/metatool/MetaToolTaskDedupColumns.java: ########## @@ -0,0 +1,114 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.hadoop.hive.metastore.tools.metatool; + +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicReference; + +import org.apache.hadoop.hive.metastore.Deadline; +import org.apache.hadoop.hive.metastore.api.MetaException; +import org.apache.hadoop.hive.metastore.conf.MetastoreConf; +import org.apache.hadoop.hive.metastore.tools.MetaToolObjectStore; + +class MetaToolTaskDedupColumns extends MetaToolTask { + @Override + void execute() { + String[] params = getCl().getDedupColumnsParams(); + String catalogFilter = params.length > 0 ? params[0] : null; + String dbFilter = params.length > 1 ? params[1] : null; + String tableFilter = params.length > 2 ? params[2] : null; + boolean isDryRun = getCl().isDryRun(); + boolean isVerbose = getCl().isVerbose(); + + final AtomicReference<String> progress = new AtomicReference<>(); + AtomicBoolean stopped = new AtomicBoolean(false); + Thread daemon = null; + if (isVerbose) { + daemon = new Thread(() -> { + while (!stopped.get()) { + try { + Thread.sleep(30 * 1000); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + break; + } + String message = progress.get(); + if (message != null) { + System.out.println(message); + } + } + }); + daemon.setDaemon(true); + daemon.start(); + } + MetaToolObjectStore.DedupColumnsResult result = null; + long timeoutMs = getCl().getDedupColumnsTimeoutSeconds() != null ? + getCl().getDedupColumnsTimeoutSeconds() * 1000L : + MetastoreConf.getTimeVar(getObjectStore().getConf(), MetastoreConf.ConfVars.DEDUP_COLUMNS_TIMEOUT, + TimeUnit.MILLISECONDS); + Deadline.registerIfNot(timeoutMs); + boolean timerStarted = false; + try { + timerStarted = Deadline.startTimer("dedupColumns"); + result = getObjectStore().dedupColumns(catalogFilter, dbFilter, tableFilter, progress, isDryRun, isVerbose); + } catch (MetaException ignored) { + // Deadline.check throws MetaException when timeout, ignore this exception so we can print + // the result has been done so far. + } finally { + if (daemon != null) { + stopped.set(true); + daemon.interrupt(); + } + if (timerStarted) { + try { + Deadline.stopTimer(); + } catch (MetaException ignored) { + } + } + } + + if (result != null) { + printSummary(result, isDryRun, isVerbose); + if (result.getException() != null) { + throw new IllegalStateException("HiveMetaTool: failed to de-duplicate column descriptors for all tables", + result.getException()); + } + } + } + + private void printSummary(MetaToolObjectStore.DedupColumnsResult result, boolean isDryRun, boolean isVerbose) { + System.out.println(isDryRun ? + "Dry run of -dedupColumns.." : + "De-duplicated column descriptors.."); Review Comment: typo: the CLI output has a double period here. I don't know if this intended. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
