Search in sources :

Example 1 with PerfLogger

use of org.apache.hadoop.hive.metastore.metrics.PerfLogger in project hive by apache.

the class Cleaner method clean.

private void clean(CompactionInfo ci, long minOpenTxnGLB, boolean metricsEnabled) throws MetaException {
    LOG.info("Starting cleaning for " + ci);
    PerfLogger perfLogger = PerfLogger.getPerfLogger(false);
    String cleanerMetric = MetricsConstants.COMPACTION_CLEANER_CYCLE + "_" + (ci.type != null ? ci.type.toString().toLowerCase() : null);
    try {
        if (metricsEnabled) {
            perfLogger.perfLogBegin(CLASS_NAME, cleanerMetric);
        }
        Optional<String> location = Optional.ofNullable(ci.properties).map(StringableMap::new).map(config -> config.get("location"));
        Callable<Boolean> cleanUpTask;
        Table t = null;
        Partition p = resolvePartition(ci);
        if (!location.isPresent()) {
            t = resolveTable(ci);
            if (t == null) {
                // The table was dropped before we got around to cleaning it.
                LOG.info("Unable to find table " + ci.getFullTableName() + ", assuming it was dropped." + idWatermark(ci));
                txnHandler.markCleaned(ci);
                return;
            }
            if (MetaStoreUtils.isNoCleanUpSet(t.getParameters())) {
                // The table was marked no clean up true.
                LOG.info("Skipping table " + ci.getFullTableName() + " clean up, as NO_CLEANUP set to true");
                txnHandler.markCleaned(ci);
                return;
            }
            if (ci.partName != null) {
                if (p == null) {
                    // The partition was dropped before we got around to cleaning it.
                    LOG.info("Unable to find partition " + ci.getFullPartitionName() + ", assuming it was dropped." + idWatermark(ci));
                    txnHandler.markCleaned(ci);
                    return;
                }
                if (MetaStoreUtils.isNoCleanUpSet(p.getParameters())) {
                    // The partition was marked no clean up true.
                    LOG.info("Skipping partition " + ci.getFullPartitionName() + " clean up, as NO_CLEANUP set to true");
                    txnHandler.markCleaned(ci);
                    return;
                }
            }
        }
        txnHandler.markCleanerStart(ci);
        if (t != null) {
            StorageDescriptor sd = resolveStorageDescriptor(t, p);
            cleanUpTask = () -> removeFiles(location.orElse(sd.getLocation()), minOpenTxnGLB, ci, ci.partName != null && p == null);
        } else {
            cleanUpTask = () -> removeFiles(location.get(), ci);
        }
        Ref<Boolean> removedFiles = Ref.from(false);
        if (runJobAsSelf(ci.runAs)) {
            removedFiles.value = cleanUpTask.call();
        } else {
            LOG.info("Cleaning as user " + ci.runAs + " for " + ci.getFullPartitionName());
            UserGroupInformation ugi = UserGroupInformation.createProxyUser(ci.runAs, UserGroupInformation.getLoginUser());
            ugi.doAs((PrivilegedExceptionAction<Void>) () -> {
                removedFiles.value = cleanUpTask.call();
                return null;
            });
            try {
                FileSystem.closeAllForUGI(ugi);
            } catch (IOException exception) {
                LOG.error("Could not clean up file-system handles for UGI: " + ugi + " for " + ci.getFullPartitionName() + idWatermark(ci), exception);
            }
        }
        if (removedFiles.value || isDynPartAbort(t, ci)) {
            txnHandler.markCleaned(ci);
        } else {
            txnHandler.clearCleanerStart(ci);
            LOG.warn("No files were removed. Leaving queue entry " + ci + " in ready for cleaning state.");
        }
    } catch (Exception e) {
        LOG.error("Caught exception when cleaning, unable to complete cleaning of " + ci + " " + StringUtils.stringifyException(e));
        ci.errorMessage = e.getMessage();
        if (metricsEnabled) {
            Metrics.getOrCreateCounter(MetricsConstants.COMPACTION_CLEANER_FAILURE_COUNTER).inc();
        }
        txnHandler.markFailed(ci);
    } finally {
        if (metricsEnabled) {
            perfLogger.perfLogEnd(CLASS_NAME, cleanerMetric);
        }
    }
}
Also used : Partition(org.apache.hadoop.hive.metastore.api.Partition) Table(org.apache.hadoop.hive.metastore.api.Table) PerfLogger(org.apache.hadoop.hive.metastore.metrics.PerfLogger) StorageDescriptor(org.apache.hadoop.hive.metastore.api.StorageDescriptor) IOException(java.io.IOException) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) NoSuchTxnException(org.apache.hadoop.hive.metastore.api.NoSuchTxnException) NoSuchLockException(org.apache.hadoop.hive.metastore.api.NoSuchLockException) TxnAbortedException(org.apache.hadoop.hive.metastore.api.TxnAbortedException) TxnOpenException(org.apache.hadoop.hive.metastore.api.TxnOpenException) IOException(java.io.IOException) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation)

Example 2 with PerfLogger

use of org.apache.hadoop.hive.metastore.metrics.PerfLogger in project hive by apache.

the class Initiator method run.

@Override
public void run() {
    LOG.info("Starting Initiator thread");
    // so wrap it in a big catch Throwable statement.
    try {
        recoverFailedCompactions(false);
        int abortedThreshold = HiveConf.getIntVar(conf, HiveConf.ConfVars.HIVE_COMPACTOR_ABORTEDTXN_THRESHOLD);
        long abortedTimeThreshold = HiveConf.getTimeVar(conf, HiveConf.ConfVars.HIVE_COMPACTOR_ABORTEDTXN_TIME_THRESHOLD, TimeUnit.MILLISECONDS);
        // HiveMetaStore.
        do {
            PerfLogger perfLogger = PerfLogger.getPerfLogger(false);
            long startedAt = -1;
            long prevStart;
            TxnStore.MutexAPI.LockHandle handle = null;
            // don't doom the entire thread.
            try {
                handle = txnHandler.getMutexAPI().acquireLock(TxnStore.MUTEX_KEY.Initiator.name());
                startedAt = System.currentTimeMillis();
                prevStart = handle.getLastUpdateTime();
                long compactionInterval = (prevStart <= 0) ? prevStart : (startedAt - prevStart) / 1000;
                if (metricsEnabled) {
                    perfLogger.perfLogBegin(CLASS_NAME, MetricsConstants.COMPACTION_INITIATOR_CYCLE);
                    stopCycleUpdater();
                    startCycleUpdater(HiveConf.getTimeVar(conf, HiveConf.ConfVars.HIVE_COMPACTOR_INITIATOR_DURATION_UPDATE_INTERVAL, TimeUnit.MILLISECONDS), new InitiatorCycleUpdater(MetricsConstants.COMPACTION_INITIATOR_CYCLE_DURATION, startedAt, MetastoreConf.getTimeVar(conf, MetastoreConf.ConfVars.COMPACTOR_LONG_RUNNING_INITIATOR_THRESHOLD_WARNING, TimeUnit.MILLISECONDS), MetastoreConf.getTimeVar(conf, MetastoreConf.ConfVars.COMPACTOR_LONG_RUNNING_INITIATOR_THRESHOLD_ERROR, TimeUnit.MILLISECONDS)));
                }
                final ShowCompactResponse currentCompactions = txnHandler.showCompact(new ShowCompactRequest());
                // Currently we invalidate all entries after each cycle, because the bootstrap replication is marked via
                // table property hive.repl.first.inc.pending which would be cached.
                tableCache.ifPresent(c -> c.invalidateAll());
                Set<String> skipDBs = Sets.newConcurrentHashSet();
                Set<String> skipTables = Sets.newConcurrentHashSet();
                Set<CompactionInfo> potentials = compactionExecutor.submit(() -> txnHandler.findPotentialCompactions(abortedThreshold, abortedTimeThreshold, compactionInterval).parallelStream().filter(ci -> isEligibleForCompaction(ci, currentCompactions, skipDBs, skipTables)).collect(Collectors.toSet())).get();
                LOG.debug("Found " + potentials.size() + " potential compactions, " + "checking to see if we should compact any of them");
                Map<String, String> tblNameOwners = new HashMap<>();
                List<CompletableFuture<Void>> compactionList = new ArrayList<>();
                if (!potentials.isEmpty()) {
                    ValidTxnList validTxnList = TxnCommonUtils.createValidReadTxnList(txnHandler.getOpenTxns(), 0);
                    conf.set(ValidTxnList.VALID_TXNS_KEY, validTxnList.writeToString());
                }
                for (CompactionInfo ci : potentials) {
                    try {
                        Table t = resolveTableAndCache(ci);
                        Partition p = resolvePartition(ci);
                        if (p == null && ci.partName != null) {
                            LOG.info("Can't find partition " + ci.getFullPartitionName() + ", assuming it has been dropped and moving on.");
                            continue;
                        }
                        String runAs = resolveUserToRunAs(tblNameOwners, t, p);
                        /* checkForCompaction includes many file metadata checks and may be expensive.
               * Therefore, using a thread pool here and running checkForCompactions in parallel */
                        String tableName = ci.getFullTableName();
                        String partition = ci.getFullPartitionName();
                        CompletableFuture<Void> asyncJob = CompletableFuture.runAsync(CompactorUtil.ThrowingRunnable.unchecked(() -> scheduleCompactionIfRequired(ci, t, p, runAs, metricsEnabled)), compactionExecutor).exceptionally(exc -> {
                            LOG.error("Error while running scheduling the compaction on the table {} / partition {}.", tableName, partition, exc);
                            return null;
                        });
                        compactionList.add(asyncJob);
                    } catch (Throwable t) {
                        LOG.error("Caught exception while trying to determine if we should compact {}. " + "Marking failed to avoid repeated failures, {}", ci, t);
                        ci.errorMessage = t.getMessage();
                        txnHandler.markFailed(ci);
                    }
                }
                CompletableFuture.allOf(compactionList.toArray(new CompletableFuture[0])).join();
                // Check for timed out remote workers.
                recoverFailedCompactions(true);
            } catch (Throwable t) {
                LOG.error("Initiator loop caught unexpected exception this time through the loop: " + StringUtils.stringifyException(t));
            } finally {
                if (handle != null) {
                    handle.releaseLocks(startedAt);
                }
                if (metricsEnabled) {
                    perfLogger.perfLogEnd(CLASS_NAME, MetricsConstants.COMPACTION_INITIATOR_CYCLE);
                    updateCycleDurationMetric(MetricsConstants.COMPACTION_INITIATOR_CYCLE_DURATION, startedAt);
                }
                stopCycleUpdater();
            }
            long elapsedTime = System.currentTimeMillis() - startedAt;
            if (elapsedTime < checkInterval && !stop.get()) {
                Thread.sleep(checkInterval - elapsedTime);
            }
            LOG.info("Initiator thread finished one loop.");
        } while (!stop.get());
    } catch (Throwable t) {
        LOG.error("Caught an exception in the main loop of compactor initiator, exiting " + StringUtils.stringifyException(t));
    } finally {
        if (compactionExecutor != null) {
            this.compactionExecutor.shutdownNow();
        }
    }
}
Also used : CompactionRequest(org.apache.hadoop.hive.metastore.api.CompactionRequest) ValidWriteIdList(org.apache.hadoop.hive.common.ValidWriteIdList) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) FileSystem(org.apache.hadoop.fs.FileSystem) AcidMetricService(org.apache.hadoop.hive.metastore.metrics.AcidMetricService) LoggerFactory(org.slf4j.LoggerFactory) COMPACTOR_INTIATOR_THREAD_NAME_FORMAT(org.apache.hadoop.hive.conf.Constants.COMPACTOR_INTIATOR_THREAD_NAME_FORMAT) FileStatus(org.apache.hadoop.fs.FileStatus) CompactionType(org.apache.hadoop.hive.metastore.api.CompactionType) NoSuchTxnException(org.apache.hadoop.hive.metastore.api.NoSuchTxnException) ShowCompactRequest(org.apache.hadoop.hive.metastore.api.ShowCompactRequest) AcidDirectory(org.apache.hadoop.hive.ql.io.AcidDirectory) Map(java.util.Map) Path(org.apache.hadoop.fs.Path) ShowCompactResponse(org.apache.hadoop.hive.metastore.api.ShowCompactResponse) StorageDescriptor(org.apache.hadoop.hive.metastore.api.StorageDescriptor) TxnStore(org.apache.hadoop.hive.metastore.txn.TxnStore) CompactionInfo(org.apache.hadoop.hive.metastore.txn.CompactionInfo) ParsedDirectory(org.apache.hadoop.hive.ql.io.AcidUtils.ParsedDirectory) Set(java.util.Set) GetValidWriteIdsRequest(org.apache.hadoop.hive.metastore.api.GetValidWriteIdsRequest) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) ShowCompactResponseElement(org.apache.hadoop.hive.metastore.api.ShowCompactResponseElement) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) CompactionResponse(org.apache.hadoop.hive.metastore.api.CompactionResponse) ValidReadTxnList(org.apache.hadoop.hive.common.ValidReadTxnList) TxnUtils(org.apache.hadoop.hive.metastore.txn.TxnUtils) List(java.util.List) ServerUtils(org.apache.hadoop.hive.common.ServerUtils) MetastoreConf(org.apache.hadoop.hive.metastore.conf.MetastoreConf) Optional(java.util.Optional) CacheBuilder(com.google.common.cache.CacheBuilder) AcidUtils(org.apache.hadoop.hive.ql.io.AcidUtils) HdfsFileStatusWithId(org.apache.hadoop.hive.shims.HadoopShims.HdfsFileStatusWithId) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) Partition(org.apache.hadoop.hive.metastore.api.Partition) TxnCommonUtils(org.apache.hadoop.hive.metastore.txn.TxnCommonUtils) ArrayList(java.util.ArrayList) StringUtils(org.apache.hadoop.util.StringUtils) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) MetricsConstants(org.apache.hadoop.hive.metastore.metrics.MetricsConstants) LongSummaryStatistics(java.util.LongSummaryStatistics) ExecutorService(java.util.concurrent.ExecutorService) Ref(org.apache.hive.common.util.Ref) Logger(org.slf4j.Logger) HiveConf(org.apache.hadoop.hive.conf.HiveConf) IOException(java.io.IOException) Table(org.apache.hadoop.hive.metastore.api.Table) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Metrics(org.apache.hadoop.hive.metastore.metrics.Metrics) ValidTxnList(org.apache.hadoop.hive.common.ValidTxnList) MetaStoreUtils.isNoAutoCompactSet(org.apache.hadoop.hive.metastore.utils.MetaStoreUtils.isNoAutoCompactSet) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Cache(com.google.common.cache.Cache) Comparator(java.util.Comparator) org.apache.hadoop.hive.metastore.api.hive_metastoreConstants(org.apache.hadoop.hive.metastore.api.hive_metastoreConstants) Collections(java.util.Collections) PerfLogger(org.apache.hadoop.hive.metastore.metrics.PerfLogger) Partition(org.apache.hadoop.hive.metastore.api.Partition) Table(org.apache.hadoop.hive.metastore.api.Table) HashMap(java.util.HashMap) PerfLogger(org.apache.hadoop.hive.metastore.metrics.PerfLogger) ArrayList(java.util.ArrayList) CompletableFuture(java.util.concurrent.CompletableFuture) ShowCompactResponse(org.apache.hadoop.hive.metastore.api.ShowCompactResponse) ValidTxnList(org.apache.hadoop.hive.common.ValidTxnList) ShowCompactRequest(org.apache.hadoop.hive.metastore.api.ShowCompactRequest) CompactionInfo(org.apache.hadoop.hive.metastore.txn.CompactionInfo)

Example 3 with PerfLogger

use of org.apache.hadoop.hive.metastore.metrics.PerfLogger in project hive by apache.

the class RetryingHMSHandler method invoke.

@Override
public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
    int retryCount = -1;
    int threadId = baseHandler.getThreadId();
    boolean error = true;
    PerfLogger perfLogger = PerfLogger.getPerfLogger(false);
    perfLogger.perfLogBegin(CLASS_NAME, method.getName());
    try {
        Result result = invokeInternal(proxy, method, args);
        retryCount = result.numRetries;
        error = false;
        return result.result;
    } finally {
        StringBuilder additionalInfo = new StringBuilder();
        additionalInfo.append("threadId=").append(threadId).append(" retryCount=").append(retryCount).append(" error=").append(error);
        perfLogger.perfLogEnd(CLASS_NAME, method.getName(), additionalInfo.toString());
    }
}
Also used : PerfLogger(org.apache.hadoop.hive.metastore.metrics.PerfLogger)

Aggregations

PerfLogger (org.apache.hadoop.hive.metastore.metrics.PerfLogger)3 IOException (java.io.IOException)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)2 NoSuchTxnException (org.apache.hadoop.hive.metastore.api.NoSuchTxnException)2 Partition (org.apache.hadoop.hive.metastore.api.Partition)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Cache (com.google.common.cache.Cache)1 CacheBuilder (com.google.common.cache.CacheBuilder)1 Sets (com.google.common.collect.Sets)1 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 List (java.util.List)1 LongSummaryStatistics (java.util.LongSummaryStatistics)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1