Search in sources :

Example 91 with HoodieActiveTimeline

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

the class ITTestClusteringCommand method testClustering.

/**
 * Test case for command 'clustering run'.
 */
@Test
public void testClustering() throws IOException {
    // generate commits
    generateCommits();
    CommandResult cr1 = scheduleClustering();
    assertTrue(cr1.isSuccess());
    // get clustering instance
    HoodieActiveTimeline timeline = HoodieCLI.getTableMetaClient().getActiveTimeline();
    Option<String> instance = timeline.filterPendingReplaceTimeline().firstInstant().map(HoodieInstant::getTimestamp);
    assertTrue(instance.isPresent(), "Must have pending clustering.");
    CommandResult cr2 = getShell().executeCommand(String.format("clustering run --parallelism %s --clusteringInstant %s --sparkMaster %s", 2, instance, "local"));
    assertAll("Command run failed", () -> assertTrue(cr2.isSuccess()), () -> assertTrue(cr2.getResult().toString().startsWith("Succeeded to run clustering for ")));
    // assert clustering complete
    assertTrue(HoodieCLI.getTableMetaClient().getActiveTimeline().reload().filterCompletedInstants().getInstants().map(HoodieInstant::getTimestamp).collect(Collectors.toList()).contains(instance), "Pending clustering must be completed");
    assertTrue(HoodieCLI.getTableMetaClient().getActiveTimeline().reload().getCompletedReplaceTimeline().getInstants().map(HoodieInstant::getTimestamp).collect(Collectors.toList()).contains(instance), "Pending clustering must be completed");
}
Also used : HoodieInstant(org.apache.hudi.common.table.timeline.HoodieInstant) 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)

Example 92 with HoodieActiveTimeline

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

the class ITTestCommitsCommand method testRollbackCommit.

/**
 * Test case of 'commit rollback' command.
 */
@Test
public void testRollbackCommit() throws Exception {
    // Create some commits files and base files
    Map<String, String> partitionAndFileId = new HashMap<String, String>() {

        {
            put(DEFAULT_FIRST_PARTITION_PATH, "file-1");
            put(DEFAULT_SECOND_PARTITION_PATH, "file-2");
            put(DEFAULT_THIRD_PARTITION_PATH, "file-3");
        }
    };
    final String rollbackCommit = "102";
    HoodieTestTable.of(metaClient).withPartitionMetaFiles(DEFAULT_PARTITION_PATHS).addCommit("100").withBaseFilesInPartitions(partitionAndFileId).addCommit("101").withBaseFilesInPartitions(partitionAndFileId).addCommit(rollbackCommit).withBaseFilesInPartitions(partitionAndFileId);
    CommandResult cr = getShell().executeCommand(String.format("commit rollback --commit %s --sparkMaster %s --sparkMemory %s", rollbackCommit, "local", "4G"));
    assertTrue(cr.isSuccess());
    metaClient = HoodieTableMetaClient.reload(HoodieCLI.getTableMetaClient());
    HoodieActiveTimeline rollbackTimeline = new RollbacksCommand.RollbackTimeline(metaClient);
    assertEquals(1, rollbackTimeline.getRollbackTimeline().countInstants(), "There should have 1 rollback instant.");
    HoodieActiveTimeline timeline = metaClient.reloadActiveTimeline();
    assertEquals(2, timeline.getCommitsTimeline().countInstants(), "There should have 2 instants.");
    // rollback complete commit
    CommandResult cr2 = getShell().executeCommand(String.format("commit rollback --commit %s --sparkMaster %s --sparkMemory %s", "101", "local", "4G"));
    assertTrue(cr2.isSuccess());
    metaClient = HoodieTableMetaClient.reload(HoodieCLI.getTableMetaClient());
    HoodieActiveTimeline rollbackTimeline2 = new RollbacksCommand.RollbackTimeline(metaClient);
    assertEquals(1, rollbackTimeline2.getRollbackTimeline().countInstants(), "There should have 2 rollback instant.");
    HoodieActiveTimeline timeline2 = metaClient.reloadActiveTimeline();
    assertEquals(2, timeline2.getCommitsTimeline().countInstants(), "There should have 1 instants.");
}
Also used : HashMap(java.util.HashMap) 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)

Example 93 with HoodieActiveTimeline

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

the class ITTestCompactionCommand method testScheduleCompact.

/**
 * Test case for command 'compaction schedule'.
 */
@Test
public void testScheduleCompact() throws IOException {
    // generate commits
    generateCommits();
    CommandResult cr = getShell().executeCommand(String.format("compaction schedule --hoodieConfigs hoodie.compact.inline.max.delta.commits=1 --sparkMaster %s", "local"));
    assertAll("Command run failed", () -> assertTrue(cr.isSuccess()), () -> assertTrue(cr.getResult().toString().startsWith("Attempted to schedule compaction for")));
    // there is 1 requested compaction
    HoodieActiveTimeline timeline = HoodieCLI.getTableMetaClient().getActiveTimeline();
    assertEquals(1, timeline.filterPendingCompactionTimeline().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)

Example 94 with HoodieActiveTimeline

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

the class TestCleansCommand method getLatestCleanTimeTakenInMillis.

/**
 * Get time taken of latest instant.
 */
private Long getLatestCleanTimeTakenInMillis() throws IOException {
    HoodieActiveTimeline activeTimeline = HoodieCLI.getTableMetaClient().getActiveTimeline();
    HoodieTimeline timeline = activeTimeline.getCleanerTimeline().filterCompletedInstants();
    HoodieInstant clean = timeline.getReverseOrderedInstants().findFirst().orElse(null);
    if (clean != null) {
        HoodieCleanMetadata cleanMetadata = TimelineMetadataUtils.deserializeHoodieCleanMetadata(timeline.getInstantDetails(clean).get());
        return cleanMetadata.getTimeTakenInMillis();
    }
    return -1L;
}
Also used : HoodieInstant(org.apache.hudi.common.table.timeline.HoodieInstant) HoodieActiveTimeline(org.apache.hudi.common.table.timeline.HoodieActiveTimeline) HoodieTimeline(org.apache.hudi.common.table.timeline.HoodieTimeline) HoodieCleanMetadata(org.apache.hudi.avro.model.HoodieCleanMetadata)

Example 95 with HoodieActiveTimeline

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

the class CleansCommand method showCleans.

@CliCommand(value = "cleans show", help = "Show the cleans")
public String showCleans(@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 IOException {
    HoodieActiveTimeline activeTimeline = HoodieCLI.getTableMetaClient().getActiveTimeline();
    HoodieTimeline timeline = activeTimeline.getCleanerTimeline().filterCompletedInstants();
    List<HoodieInstant> cleans = timeline.getReverseOrderedInstants().collect(Collectors.toList());
    List<Comparable[]> rows = new ArrayList<>();
    for (HoodieInstant clean : cleans) {
        HoodieCleanMetadata cleanMetadata = TimelineMetadataUtils.deserializeHoodieCleanMetadata(timeline.getInstantDetails(clean).get());
        rows.add(new Comparable[] { clean.getTimestamp(), cleanMetadata.getEarliestCommitToRetain(), cleanMetadata.getTotalFilesDeleted(), cleanMetadata.getTimeTakenInMillis() });
    }
    TableHeader header = new TableHeader().addTableHeaderField(HoodieTableHeaderFields.HEADER_CLEAN_TIME).addTableHeaderField(HoodieTableHeaderFields.HEADER_EARLIEST_COMMAND_RETAINED).addTableHeaderField(HoodieTableHeaderFields.HEADER_TOTAL_FILES_DELETED).addTableHeaderField(HoodieTableHeaderFields.HEADER_TOTAL_TIME_TAKEN);
    return HoodiePrintHelper.print(header, new HashMap<>(), sortByField, descending, limit, headerOnly, rows);
}
Also used : HoodieInstant(org.apache.hudi.common.table.timeline.HoodieInstant) 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) HoodieCleanMetadata(org.apache.hudi.avro.model.HoodieCleanMetadata) CliCommand(org.springframework.shell.core.annotation.CliCommand)

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