Search in sources :

Example 21 with HoodieCompactionOperation

use of org.apache.hudi.avro.model.HoodieCompactionOperation in project hudi by apache.

the class TestCompactionUtil method generateCompactionPlan.

/**
 * Generates a compaction plan on the timeline and returns its instant time.
 */
private String generateCompactionPlan() {
    HoodieCompactionOperation operation = new HoodieCompactionOperation();
    HoodieCompactionPlan plan = new HoodieCompactionPlan(Collections.singletonList(operation), Collections.emptyMap(), 1);
    String instantTime = HoodieActiveTimeline.createNewInstantTime();
    HoodieInstant compactionInstant = new HoodieInstant(HoodieInstant.State.REQUESTED, HoodieTimeline.COMPACTION_ACTION, instantTime);
    try {
        metaClient.getActiveTimeline().saveToCompactionRequested(compactionInstant, TimelineMetadataUtils.serializeCompactionPlan(plan));
        table.getActiveTimeline().transitionCompactionRequestedToInflight(compactionInstant);
    } catch (IOException ioe) {
        throw new HoodieIOException("Exception scheduling compaction", ioe);
    }
    metaClient.reloadActiveTimeline();
    return instantTime;
}
Also used : HoodieInstant(org.apache.hudi.common.table.timeline.HoodieInstant) HoodieIOException(org.apache.hudi.exception.HoodieIOException) HoodieCompactionPlan(org.apache.hudi.avro.model.HoodieCompactionPlan) HoodieCompactionOperation(org.apache.hudi.avro.model.HoodieCompactionOperation) IOException(java.io.IOException) HoodieIOException(org.apache.hudi.exception.HoodieIOException)

Aggregations

HoodieCompactionOperation (org.apache.hudi.avro.model.HoodieCompactionOperation)21 ArrayList (java.util.ArrayList)16 List (java.util.List)13 HashMap (java.util.HashMap)11 Test (org.junit.jupiter.api.Test)10 HoodieCompactionPlan (org.apache.hudi.avro.model.HoodieCompactionPlan)9 FileSlice (org.apache.hudi.common.model.FileSlice)9 HoodieWriteConfig (org.apache.hudi.config.HoodieWriteConfig)9 Map (java.util.Map)7 Collectors (java.util.stream.Collectors)7 Path (org.apache.hadoop.fs.Path)7 HoodieFileGroupId (org.apache.hudi.common.model.HoodieFileGroupId)7 HoodieLogFile (org.apache.hudi.common.model.HoodieLogFile)7 Pair (org.apache.hudi.common.util.collection.Pair)7 HoodieBaseFile (org.apache.hudi.common.model.HoodieBaseFile)6 IOException (java.io.IOException)5 SimpleDateFormat (java.text.SimpleDateFormat)5 Date (java.util.Date)5 HoodieTableMetaClient (org.apache.hudi.common.table.HoodieTableMetaClient)5 HoodieInstant (org.apache.hudi.common.table.timeline.HoodieInstant)5