Search in sources :

Example 11 with ShowCompactResponseElement

use of org.apache.hadoop.hive.metastore.api.ShowCompactResponseElement in project hive by apache.

the class ShowCompactionsOperation method execute.

@Override
public int execute() throws HiveException {
    SessionState sessionState = SessionState.get();
    // Call the metastore to get the status of all known compactions (completed get purged eventually)
    ShowCompactResponse rsp = context.getDb().showCompactions();
    // Write the results into the file
    try (DataOutputStream os = ShowUtils.getOutputStream(new Path(desc.getResFile()), context)) {
        // Write a header for cliDriver
        if (!sessionState.isHiveServerQuery()) {
            writeHeader(os);
        }
        if (rsp.getCompacts() != null) {
            for (ShowCompactResponseElement e : rsp.getCompacts()) {
                writeRow(os, e);
            }
        }
    } catch (IOException e) {
        LOG.warn("show compactions: ", e);
        return 1;
    }
    return 0;
}
Also used : Path(org.apache.hadoop.fs.Path) SessionState(org.apache.hadoop.hive.ql.session.SessionState) ShowCompactResponse(org.apache.hadoop.hive.metastore.api.ShowCompactResponse) DataOutputStream(java.io.DataOutputStream) IOException(java.io.IOException) ShowCompactResponseElement(org.apache.hadoop.hive.metastore.api.ShowCompactResponseElement)

Example 12 with ShowCompactResponseElement

use of org.apache.hadoop.hive.metastore.api.ShowCompactResponseElement in project hive by apache.

the class Initiator method foundCurrentOrFailedCompactions.

private boolean foundCurrentOrFailedCompactions(ShowCompactResponse compactions, CompactionInfo ci) throws MetaException {
    if (compactions.getCompacts() == null) {
        return false;
    }
    List<ShowCompactResponseElement> filteredElements = compactions.getCompacts().stream().filter(e -> e.getDbname().equals(ci.dbname) && e.getTablename().equals(ci.tableName) && (e.getPartitionname() == null && ci.partName == null || e.getPartitionname().equals(ci.partName))).collect(Collectors.toList());
    // Figure out if there are any currently running compactions on the same table or partition.
    if (filteredElements.stream().anyMatch(e -> TxnStore.WORKING_RESPONSE.equals(e.getState()) || TxnStore.INITIATED_RESPONSE.equals(e.getState()))) {
        LOG.info("Found currently initiated or working compaction for " + ci.getFullPartitionName() + " so we will not initiate another compaction");
        return true;
    }
    // Check if there is already sufficient number of consecutive failures for this table/partition
    // so that no new automatic compactions needs to be scheduled.
    int failedThreshold = MetastoreConf.getIntVar(conf, MetastoreConf.ConfVars.COMPACTOR_INITIATOR_FAILED_THRESHOLD);
    LongSummaryStatistics failedStats = filteredElements.stream().filter(e -> TxnStore.SUCCEEDED_RESPONSE.equals(e.getState()) || TxnStore.FAILED_RESPONSE.equals(e.getState())).sorted(Comparator.comparingLong(ShowCompactResponseElement::getId).reversed()).limit(failedThreshold).filter(e -> TxnStore.FAILED_RESPONSE.equals(e.getState())).collect(Collectors.summarizingLong(ShowCompactResponseElement::getEnqueueTime));
    // If the last attempt was too long ago, ignore the failed threshold and try compaction again
    long retryTime = MetastoreConf.getTimeVar(conf, MetastoreConf.ConfVars.COMPACTOR_INITIATOR_FAILED_RETRY_TIME, TimeUnit.MILLISECONDS);
    boolean needsRetry = (retryTime > 0) && (failedStats.getMax() + retryTime < System.currentTimeMillis());
    if (failedStats.getCount() == failedThreshold && !needsRetry) {
        LOG.warn("Will not initiate compaction for " + ci.getFullPartitionName() + " since last " + MetastoreConf.ConfVars.COMPACTOR_INITIATOR_FAILED_THRESHOLD + " attempts to compact it failed.");
        ci.errorMessage = "Compaction is not initiated since last " + MetastoreConf.ConfVars.COMPACTOR_INITIATOR_FAILED_THRESHOLD + " consecutive compaction attempts failed)";
        txnHandler.markFailed(ci);
        return true;
    }
    return false;
}
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) LongSummaryStatistics(java.util.LongSummaryStatistics) ShowCompactResponseElement(org.apache.hadoop.hive.metastore.api.ShowCompactResponseElement)

Example 13 with ShowCompactResponseElement

use of org.apache.hadoop.hive.metastore.api.ShowCompactResponseElement in project hive by apache.

the class TestTxnHandler method testCompactWhenAlreadyCompacting.

/**
 * Once a Compaction for a given resource is scheduled/working, we should not
 * schedule another one to prevent concurrent compactions for the same resource.
 * @throws Exception
 */
@Test
public void testCompactWhenAlreadyCompacting() throws Exception {
    CompactionRequest rqst = new CompactionRequest("foo", "bar", CompactionType.MAJOR);
    rqst.setPartitionname("ds=today");
    CompactionResponse resp = txnHandler.compact(rqst);
    Assert.assertEquals(resp, new CompactionResponse(1, TxnStore.INITIATED_RESPONSE, true));
    ShowCompactResponse rsp = txnHandler.showCompact(new ShowCompactRequest());
    List<ShowCompactResponseElement> compacts = rsp.getCompacts();
    assertEquals(1, compacts.size());
    rqst.setType(CompactionType.MINOR);
    resp = txnHandler.compact(rqst);
    Assert.assertEquals(resp, new CompactionResponse(1, TxnStore.INITIATED_RESPONSE, false));
    rsp = txnHandler.showCompact(new ShowCompactRequest());
    compacts = rsp.getCompacts();
    assertEquals(1, compacts.size());
    ShowCompactResponseElement c = compacts.get(0);
    assertEquals("foo", c.getDbname());
    assertEquals("bar", c.getTablename());
    assertEquals("ds=today", c.getPartitionname());
    assertEquals(CompactionType.MAJOR, c.getType());
    assertEquals("initiated", c.getState());
    assertEquals(0L, c.getStart());
}
Also used : ShowCompactResponse(org.apache.hadoop.hive.metastore.api.ShowCompactResponse) CompactionResponse(org.apache.hadoop.hive.metastore.api.CompactionResponse) ShowCompactRequest(org.apache.hadoop.hive.metastore.api.ShowCompactRequest) CompactionRequest(org.apache.hadoop.hive.metastore.api.CompactionRequest) ShowCompactResponseElement(org.apache.hadoop.hive.metastore.api.ShowCompactResponseElement) Test(org.junit.Test)

Example 14 with ShowCompactResponseElement

use of org.apache.hadoop.hive.metastore.api.ShowCompactResponseElement in project hive by apache.

the class TestCompactionTxnHandler method countCompactionsInHistory.

private void countCompactionsInHistory(String dbName, String tableName, String partition, int expectedSucceeded, int expectedFailed, int expectedDidNotInitiate) throws MetaException {
    ShowCompactResponse resp = txnHandler.showCompact(new ShowCompactRequest());
    List<ShowCompactResponseElement> filteredToPartition = resp.getCompacts().stream().filter(e -> e.getDbname().equals(dbName) && e.getTablename().equals(tableName) && (partition == null || partition.equals(e.getPartitionname()))).collect(Collectors.toList());
    assertEquals(expectedSucceeded, filteredToPartition.stream().filter(e -> e.getState().equals(TxnStore.SUCCEEDED_RESPONSE)).count());
    assertEquals(expectedFailed, filteredToPartition.stream().filter(e -> e.getState().equals(TxnStore.FAILED_RESPONSE)).count());
    assertEquals(expectedDidNotInitiate, filteredToPartition.stream().filter(e -> e.getState().equals(TxnStore.DID_NOT_INITIATE_RESPONSE)).count());
}
Also used : LockType(org.apache.hadoop.hive.metastore.api.LockType) CompactionRequest(org.apache.hadoop.hive.metastore.api.CompactionRequest) Arrays(java.util.Arrays) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) TestTxnDbUtil(org.apache.hadoop.hive.metastore.utils.TestTxnDbUtil) SortedSet(java.util.SortedSet) FindNextCompactRequest(org.apache.hadoop.hive.metastore.api.FindNextCompactRequest) OpenTxnsResponse(org.apache.hadoop.hive.metastore.api.OpenTxnsResponse) GetLatestCommittedCompactionInfoResponse(org.apache.hadoop.hive.metastore.api.GetLatestCommittedCompactionInfoResponse) LockRequest(org.apache.hadoop.hive.metastore.api.LockRequest) CompactionType(org.apache.hadoop.hive.metastore.api.CompactionType) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) AllocateTableWriteIdsRequest(org.apache.hadoop.hive.metastore.api.AllocateTableWriteIdsRequest) CommitTxnRequest(org.apache.hadoop.hive.metastore.api.CommitTxnRequest) DataOperationType(org.apache.hadoop.hive.metastore.api.DataOperationType) ShowCompactRequest(org.apache.hadoop.hive.metastore.api.ShowCompactRequest) LockLevel(org.apache.hadoop.hive.metastore.api.LockLevel) COMPACTOR_INITIATOR_FAILED_THRESHOLD(org.apache.hadoop.hive.metastore.conf.MetastoreConf.ConfVars.COMPACTOR_INITIATOR_FAILED_THRESHOLD) LockState(org.apache.hadoop.hive.metastore.api.LockState) GetOpenTxnsResponse(org.apache.hadoop.hive.metastore.api.GetOpenTxnsResponse) After(org.junit.After) LockComponent(org.apache.hadoop.hive.metastore.api.LockComponent) Assert.fail(org.junit.Assert.fail) ShowCompactResponse(org.apache.hadoop.hive.metastore.api.ShowCompactResponse) Before(org.junit.Before) AbortTxnRequest(org.apache.hadoop.hive.metastore.api.AbortTxnRequest) OpenTxnRequest(org.apache.hadoop.hive.metastore.api.OpenTxnRequest) CompactionInfoStruct(org.apache.hadoop.hive.metastore.api.CompactionInfoStruct) Assert.assertNotNull(org.junit.Assert.assertNotNull) LockResponse(org.apache.hadoop.hive.metastore.api.LockResponse) HiveConf(org.apache.hadoop.hive.conf.HiveConf) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) ShowCompactResponseElement(org.apache.hadoop.hive.metastore.api.ShowCompactResponseElement) Collectors(java.util.stream.Collectors) AllocateTableWriteIdsResponse(org.apache.hadoop.hive.metastore.api.AllocateTableWriteIdsResponse) COMPACTOR_INITIATOR_FAILED_RETRY_TIME(org.apache.hadoop.hive.metastore.conf.MetastoreConf.ConfVars.COMPACTOR_INITIATOR_FAILED_RETRY_TIME) TimeUnit(java.util.concurrent.TimeUnit) GetLatestCommittedCompactionInfoRequest(org.apache.hadoop.hive.metastore.api.GetLatestCommittedCompactionInfoRequest) List(java.util.List) MetastoreConf(org.apache.hadoop.hive.metastore.conf.MetastoreConf) Assert.assertNull(org.junit.Assert.assertNull) Assert.assertFalse(org.junit.Assert.assertFalse) AddDynamicPartitions(org.apache.hadoop.hive.metastore.api.AddDynamicPartitions) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) ShowCompactResponse(org.apache.hadoop.hive.metastore.api.ShowCompactResponse) ShowCompactRequest(org.apache.hadoop.hive.metastore.api.ShowCompactRequest) ShowCompactResponseElement(org.apache.hadoop.hive.metastore.api.ShowCompactResponseElement)

Example 15 with ShowCompactResponseElement

use of org.apache.hadoop.hive.metastore.api.ShowCompactResponseElement in project hive by apache.

the class TestCompactionTxnHandler method testFindNextToClean.

@Test
public void testFindNextToClean() throws Exception {
    CompactionRequest rqst = new CompactionRequest("foo", "bar", CompactionType.MINOR);
    rqst.setPartitionname("ds=today");
    txnHandler.compact(rqst);
    assertEquals(0, txnHandler.findReadyToClean(0, 0).size());
    CompactionInfo ci = txnHandler.findNextToCompact(aFindNextCompactRequest("fred", WORKER_VERSION));
    assertNotNull(ci);
    ci.highestWriteId = 41;
    txnHandler.updateCompactorState(ci, 0);
    txnHandler.markCompacted(ci);
    assertNull(txnHandler.findNextToCompact(aFindNextCompactRequest("fred", WORKER_VERSION)));
    List<CompactionInfo> toClean = txnHandler.findReadyToClean(0, 0);
    assertEquals(1, toClean.size());
    assertNull(txnHandler.findNextToCompact(aFindNextCompactRequest("fred", WORKER_VERSION)));
    ShowCompactResponse rsp = txnHandler.showCompact(new ShowCompactRequest());
    List<ShowCompactResponseElement> compacts = rsp.getCompacts();
    assertEquals(1, compacts.size());
    ShowCompactResponseElement c = compacts.get(0);
    assertEquals("foo", c.getDbname());
    assertEquals("bar", c.getTablename());
    assertEquals("ds=today", c.getPartitionname());
    assertEquals(CompactionType.MINOR, c.getType());
    assertEquals("ready for cleaning", c.getState());
    assertNull(c.getWorkerid());
}
Also used : ShowCompactResponse(org.apache.hadoop.hive.metastore.api.ShowCompactResponse) ShowCompactRequest(org.apache.hadoop.hive.metastore.api.ShowCompactRequest) CompactionRequest(org.apache.hadoop.hive.metastore.api.CompactionRequest) ShowCompactResponseElement(org.apache.hadoop.hive.metastore.api.ShowCompactResponseElement) Test(org.junit.Test)

Aggregations

ShowCompactResponseElement (org.apache.hadoop.hive.metastore.api.ShowCompactResponseElement)100 ShowCompactResponse (org.apache.hadoop.hive.metastore.api.ShowCompactResponse)87 Test (org.junit.Test)81 ShowCompactRequest (org.apache.hadoop.hive.metastore.api.ShowCompactRequest)79 Table (org.apache.hadoop.hive.metastore.api.Table)58 CompactionRequest (org.apache.hadoop.hive.metastore.api.CompactionRequest)46 ArrayList (java.util.ArrayList)42 Partition (org.apache.hadoop.hive.metastore.api.Partition)27 LockComponent (org.apache.hadoop.hive.metastore.api.LockComponent)26 LockRequest (org.apache.hadoop.hive.metastore.api.LockRequest)26 FileSystem (org.apache.hadoop.fs.FileSystem)25 LockResponse (org.apache.hadoop.hive.metastore.api.LockResponse)25 Path (org.apache.hadoop.fs.Path)24 FileStatus (org.apache.hadoop.fs.FileStatus)20 CommitTxnRequest (org.apache.hadoop.hive.metastore.api.CommitTxnRequest)17 TxnStore (org.apache.hadoop.hive.metastore.txn.TxnStore)16 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)11 CompactionInfo (org.apache.hadoop.hive.metastore.txn.CompactionInfo)11 IOException (java.io.IOException)9 List (java.util.List)9