Search in sources :

Example 86 with HoodieActiveTimeline

use of org.apache.hudi.common.table.timeline.HoodieActiveTimeline in project hudi by apache.

the class CompactionCommand method compactionsAll.

@CliCommand(value = "compactions show all", help = "Shows all compactions that are in active timeline")
public String compactionsAll(@CliOption(key = { "includeExtraMetadata" }, help = "Include extra metadata", unspecifiedDefaultValue = "false") final boolean includeExtraMetadata, @CliOption(key = { "limit" }, help = "Limit commits", unspecifiedDefaultValue = "-1") final Integer limit, @CliOption(key = { "sortBy" }, help = "Sorting Field", unspecifiedDefaultValue = "") final String sortByField, @CliOption(key = { "desc" }, help = "Ordering", unspecifiedDefaultValue = "false") final boolean descending, @CliOption(key = { "headeronly" }, help = "Print Header Only", unspecifiedDefaultValue = "false") final boolean headerOnly) {
    HoodieTableMetaClient client = checkAndGetMetaClient();
    HoodieActiveTimeline activeTimeline = client.getActiveTimeline();
    return printAllCompactions(activeTimeline, compactionPlanReader(this::readCompactionPlanForActiveTimeline, activeTimeline), includeExtraMetadata, sortByField, descending, limit, headerOnly);
}
Also used : HoodieTableMetaClient(org.apache.hudi.common.table.HoodieTableMetaClient) HoodieActiveTimeline(org.apache.hudi.common.table.timeline.HoodieActiveTimeline) CliCommand(org.springframework.shell.core.annotation.CliCommand)

Example 87 with HoodieActiveTimeline

use of org.apache.hudi.common.table.timeline.HoodieActiveTimeline in project hudi by apache.

the class CompactionCommand method compactionShow.

@CliCommand(value = "compaction show", help = "Shows compaction details for a specific compaction instant")
public String compactionShow(@CliOption(key = "instant", mandatory = true, help = "Base path for the target hoodie table") final String compactionInstantTime, @CliOption(key = { "limit" }, help = "Limit commits", unspecifiedDefaultValue = "-1") final Integer limit, @CliOption(key = { "sortBy" }, help = "Sorting Field", unspecifiedDefaultValue = "") final String sortByField, @CliOption(key = { "desc" }, help = "Ordering", unspecifiedDefaultValue = "false") final boolean descending, @CliOption(key = { "headeronly" }, help = "Print Header Only", unspecifiedDefaultValue = "false") final boolean headerOnly) throws Exception {
    HoodieTableMetaClient client = checkAndGetMetaClient();
    HoodieActiveTimeline activeTimeline = client.getActiveTimeline();
    HoodieCompactionPlan compactionPlan = TimelineMetadataUtils.deserializeCompactionPlan(activeTimeline.readCompactionPlanAsBytes(HoodieTimeline.getCompactionRequestedInstant(compactionInstantTime)).get());
    return printCompaction(compactionPlan, sortByField, descending, limit, headerOnly);
}
Also used : HoodieTableMetaClient(org.apache.hudi.common.table.HoodieTableMetaClient) HoodieCompactionPlan(org.apache.hudi.avro.model.HoodieCompactionPlan) HoodieActiveTimeline(org.apache.hudi.common.table.timeline.HoodieActiveTimeline) CliCommand(org.springframework.shell.core.annotation.CliCommand)

Example 88 with HoodieActiveTimeline

use of org.apache.hudi.common.table.timeline.HoodieActiveTimeline in project hudi by apache.

the class ExportCommand method copyNonArchivedInstants.

private int copyNonArchivedInstants(List<HoodieInstant> instants, int limit, String localFolder) throws Exception {
    int copyCount = 0;
    if (instants.isEmpty()) {
        return limit;
    }
    final Logger LOG = LogManager.getLogger(ExportCommand.class);
    final HoodieTableMetaClient metaClient = HoodieCLI.getTableMetaClient();
    final HoodieActiveTimeline timeline = metaClient.getActiveTimeline();
    for (HoodieInstant instant : instants) {
        String localPath = localFolder + Path.SEPARATOR + instant.getFileName();
        byte[] data = null;
        switch(instant.getAction()) {
            case HoodieTimeline.CLEAN_ACTION:
                {
                    HoodieCleanMetadata metadata = TimelineMetadataUtils.deserializeHoodieCleanMetadata(timeline.getInstantDetails(instant).get());
                    data = HoodieAvroUtils.avroToJson(metadata, true);
                    break;
                }
            case HoodieTimeline.DELTA_COMMIT_ACTION:
            case HoodieTimeline.COMMIT_ACTION:
            case HoodieTimeline.COMPACTION_ACTION:
                {
                    // Already in json format
                    data = timeline.getInstantDetails(instant).get();
                    break;
                }
            case HoodieTimeline.ROLLBACK_ACTION:
                {
                    HoodieRollbackMetadata metadata = TimelineMetadataUtils.deserializeHoodieRollbackMetadata(timeline.getInstantDetails(instant).get());
                    data = HoodieAvroUtils.avroToJson(metadata, true);
                    break;
                }
            case HoodieTimeline.SAVEPOINT_ACTION:
                {
                    HoodieSavepointMetadata metadata = TimelineMetadataUtils.deserializeHoodieSavepointMetadata(timeline.getInstantDetails(instant).get());
                    data = HoodieAvroUtils.avroToJson(metadata, true);
                    break;
                }
            default:
                {
                    throw new HoodieException("Unknown type of action " + instant.getAction());
                }
        }
        if (data != null) {
            writeToFile(localPath, data);
        }
    }
    return copyCount;
}
Also used : HoodieTableMetaClient(org.apache.hudi.common.table.HoodieTableMetaClient) HoodieInstant(org.apache.hudi.common.table.timeline.HoodieInstant) HoodieRollbackMetadata(org.apache.hudi.avro.model.HoodieRollbackMetadata) HoodieActiveTimeline(org.apache.hudi.common.table.timeline.HoodieActiveTimeline) HoodieCleanMetadata(org.apache.hudi.avro.model.HoodieCleanMetadata) HoodieException(org.apache.hudi.exception.HoodieException) Logger(org.apache.log4j.Logger) HoodieSavepointMetadata(org.apache.hudi.avro.model.HoodieSavepointMetadata)

Example 89 with HoodieActiveTimeline

use of org.apache.hudi.common.table.timeline.HoodieActiveTimeline in project hudi by apache.

the class RollbacksCommand method showRollbacks.

@CliCommand(value = "show rollbacks", help = "List all rollback instants")
public String showRollbacks(@CliOption(key = { "limit" }, help = "Limit #rows to be displayed", unspecifiedDefaultValue = "10") Integer limit, @CliOption(key = { "sortBy" }, help = "Sorting Field", unspecifiedDefaultValue = "") final String sortByField, @CliOption(key = { "desc" }, help = "Ordering", unspecifiedDefaultValue = "false") final boolean descending, @CliOption(key = { "headeronly" }, help = "Print Header Only", unspecifiedDefaultValue = "false") final boolean headerOnly) {
    HoodieActiveTimeline activeTimeline = new RollbackTimeline(HoodieCLI.getTableMetaClient());
    HoodieTimeline rollback = activeTimeline.getRollbackTimeline().filterCompletedInstants();
    final List<Comparable[]> rows = new ArrayList<>();
    rollback.getInstants().forEach(instant -> {
        try {
            HoodieRollbackMetadata metadata = TimelineMetadataUtils.deserializeAvroMetadata(activeTimeline.getInstantDetails(instant).get(), HoodieRollbackMetadata.class);
            metadata.getCommitsRollback().forEach(c -> {
                Comparable[] row = new Comparable[5];
                row[0] = metadata.getStartRollbackTime();
                row[1] = c;
                row[2] = metadata.getTotalFilesDeleted();
                row[3] = metadata.getTimeTakenInMillis();
                row[4] = metadata.getPartitionMetadata() != null ? metadata.getPartitionMetadata().size() : 0;
                rows.add(row);
            });
        } catch (IOException e) {
            e.printStackTrace();
        }
    });
    TableHeader header = new TableHeader().addTableHeaderField(HoodieTableHeaderFields.HEADER_INSTANT).addTableHeaderField(HoodieTableHeaderFields.HEADER_ROLLBACK_INSTANT).addTableHeaderField(HoodieTableHeaderFields.HEADER_TOTAL_FILES_DELETED).addTableHeaderField(HoodieTableHeaderFields.HEADER_TIME_TOKEN_MILLIS).addTableHeaderField(HoodieTableHeaderFields.HEADER_TOTAL_PARTITIONS);
    return HoodiePrintHelper.print(header, new HashMap<>(), sortByField, descending, limit, headerOnly, rows);
}
Also used : HoodieRollbackMetadata(org.apache.hudi.avro.model.HoodieRollbackMetadata) TableHeader(org.apache.hudi.cli.TableHeader) HoodieActiveTimeline(org.apache.hudi.common.table.timeline.HoodieActiveTimeline) HoodieTimeline(org.apache.hudi.common.table.timeline.HoodieTimeline) ArrayList(java.util.ArrayList) IOException(java.io.IOException) CliCommand(org.springframework.shell.core.annotation.CliCommand)

Example 90 with HoodieActiveTimeline

use of org.apache.hudi.common.table.timeline.HoodieActiveTimeline in project hudi by apache.

the class ITTestClusteringCommand method testScheduleClustering.

/**
 * Test case for command 'clustering schedule'.
 */
@Test
public void testScheduleClustering() throws IOException {
    // generate commits
    generateCommits();
    CommandResult cr = scheduleClustering();
    assertAll("Command run failed", () -> assertTrue(cr.isSuccess()), () -> assertTrue(cr.getResult().toString().startsWith("Succeeded to schedule clustering for")));
    // there is 1 requested clustering
    HoodieActiveTimeline timeline = HoodieCLI.getTableMetaClient().getActiveTimeline();
    assertEquals(1, timeline.filterPendingReplaceTimeline().countInstants());
}
Also used : HoodieActiveTimeline(org.apache.hudi.common.table.timeline.HoodieActiveTimeline) CommandResult(org.springframework.shell.core.CommandResult) AbstractShellIntegrationTest(org.apache.hudi.cli.testutils.AbstractShellIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

HoodieActiveTimeline (org.apache.hudi.common.table.timeline.HoodieActiveTimeline)95 HoodieInstant (org.apache.hudi.common.table.timeline.HoodieInstant)70 HoodieTimeline (org.apache.hudi.common.table.timeline.HoodieTimeline)47 Test (org.junit.jupiter.api.Test)45 HoodieCommitMetadata (org.apache.hudi.common.model.HoodieCommitMetadata)37 ArrayList (java.util.ArrayList)36 IOException (java.io.IOException)32 List (java.util.List)30 HoodieTableMetaClient (org.apache.hudi.common.table.HoodieTableMetaClient)30 HashMap (java.util.HashMap)28 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)26 Map (java.util.Map)25 Option (org.apache.hudi.common.util.Option)22 Pair (org.apache.hudi.common.util.collection.Pair)22 Collectors (java.util.stream.Collectors)21 Path (org.apache.hadoop.fs.Path)21 Logger (org.apache.log4j.Logger)21 LogManager (org.apache.log4j.LogManager)20 Stream (java.util.stream.Stream)19 HoodieWriteConfig (org.apache.hudi.config.HoodieWriteConfig)19