Skip to content

Commit

Permalink
[HUDI-6539] New LSM tree style archived timeline
Browse files Browse the repository at this point in the history
* Maintain only one version pointer file, add file size limination to compaction strategy
* write the manifest as JSON, move the timeline write path to separate class for convenient review
  • Loading branch information
danny0405 committed Aug 25, 2023
1 parent e9376ba commit 1739fa3
Show file tree
Hide file tree
Showing 46 changed files with 2,450 additions and 883 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ public String compactionShowArchived(
HoodieTimeline.COMPACTION_ACTION, compactionInstantTime);
try {
archivedTimeline.loadCompactionDetailsInMemory(compactionInstantTime);
HoodieCompactionPlan compactionPlan = TimelineMetadataUtils.deserializeAvroRecordMetadata(
archivedTimeline.getInstantDetails(instant).get(), HoodieCompactionPlan.getClassSchema());
HoodieCompactionPlan compactionPlan =
TimelineMetadataUtils.deserializeCompactionPlan(archivedTimeline.getInstantDetails(instant).get());
return printCompaction(compactionPlan, sortByField, descending, limit, headerOnly, partition);
} finally {
archivedTimeline.clearInstantDetailsFromMemory(compactionInstantTime);
Expand Down Expand Up @@ -365,17 +365,10 @@ Function<HoodieInstant, HoodieCompactionPlan> compactionPlanReader(

private HoodieCompactionPlan readCompactionPlanForArchivedTimeline(HoodieArchivedTimeline archivedTimeline,
HoodieInstant instant) {
// filter inflight compaction
if (HoodieTimeline.COMPACTION_ACTION.equals(instant.getAction())
&& HoodieInstant.State.INFLIGHT.equals(instant.getState())) {
try {
return TimelineMetadataUtils.deserializeAvroRecordMetadata(archivedTimeline.getInstantDetails(instant).get(),
HoodieCompactionPlan.getClassSchema());
} catch (Exception e) {
throw new HoodieException(e.getMessage(), e);
}
} else {
return null;
try {
return TimelineMetadataUtils.deserializeCompactionPlan(archivedTimeline.getInstantDetails(instant).get());
} catch (Exception e) {
throw new HoodieException(e.getMessage(), e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@

import org.apache.hudi.DataSourceWriteOptions;
import org.apache.hudi.cli.utils.SparkUtil;
import org.apache.hudi.client.HoodieTimelineArchiver;
import org.apache.hudi.client.SparkRDDWriteClient;
import org.apache.hudi.client.common.HoodieSparkEngineContext;
import org.apache.hudi.client.timeline.HoodieTimelineArchiver;
import org.apache.hudi.common.config.HoodieMetadataConfig;
import org.apache.hudi.common.config.TypedProperties;
import org.apache.hudi.common.engine.HoodieEngineContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import org.apache.hudi.cli.testutils.HoodieTestCommitMetadataGenerator;
import org.apache.hudi.cli.testutils.HoodieTestCommitUtilities;
import org.apache.hudi.cli.testutils.ShellEvaluationResultUtil;
import org.apache.hudi.client.HoodieTimelineArchiver;
import org.apache.hudi.client.timeline.HoodieTimelineArchiver;
import org.apache.hudi.common.model.HoodieCommitMetadata;
import org.apache.hudi.common.table.HoodieTableMetaClient;
import org.apache.hudi.common.table.timeline.HoodieInstant;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import org.apache.hudi.cli.testutils.HoodieTestCommitMetadataGenerator;
import org.apache.hudi.cli.testutils.HoodieTestReplaceCommitMetadataGenerator;
import org.apache.hudi.cli.testutils.ShellEvaluationResultUtil;
import org.apache.hudi.client.HoodieTimelineArchiver;
import org.apache.hudi.client.timeline.HoodieTimelineArchiver;
import org.apache.hudi.common.config.HoodieMetadataConfig;
import org.apache.hudi.common.fs.FSUtils;
import org.apache.hudi.common.model.HoodieTableType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.apache.hudi.cli.TableHeader;
import org.apache.hudi.cli.functional.CLIFunctionalTestHarness;
import org.apache.hudi.cli.testutils.HoodieTestCommitMetadataGenerator;
import org.apache.hudi.client.HoodieTimelineArchiver;
import org.apache.hudi.client.timeline.HoodieTimelineArchiver;
import org.apache.hudi.common.fs.FSUtils;
import org.apache.hudi.common.fs.HoodieWrapperFileSystem;
import org.apache.hudi.common.fs.NoOpConsistencyGuard;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.apache.hudi.avro.model.HoodieRollbackPlan;
import org.apache.hudi.client.embedded.EmbeddedTimelineService;
import org.apache.hudi.client.heartbeat.HeartbeatUtils;
import org.apache.hudi.client.timeline.HoodieTimelineArchiver;
import org.apache.hudi.common.HoodiePendingRollbackInfo;
import org.apache.hudi.common.data.HoodieData;
import org.apache.hudi.common.engine.HoodieEngineContext;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.hudi.client.timeline;

import org.apache.hudi.common.table.HoodieTableMetaClient;
import org.apache.hudi.common.table.timeline.HoodieInstant;
import org.apache.hudi.common.table.timeline.HoodieTimeline;
import org.apache.hudi.common.util.Option;
import org.apache.hudi.common.util.ValidationUtils;

import javax.annotation.Nullable;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
* A combination of instants covering action states: requested, inflight, completed.
*/
public class ActiveAction implements Serializable, Comparable<ActiveAction> {
private final HoodieInstant requested;
private final HoodieInstant inflight;
private final HoodieInstant completed;

/**
* The constructor.
*/
protected ActiveAction(@Nullable HoodieInstant requested, @Nullable HoodieInstant inflight, HoodieInstant completed) {
this.requested = requested;
this.inflight = inflight;
this.completed = completed;
}

public static ActiveAction fromInstants(List<HoodieInstant> instants) {
ValidationUtils.checkArgument(instants.size() <= 3);
HoodieInstant requested = null;
HoodieInstant inflight = null;
HoodieInstant completed = null;
for (HoodieInstant instant : instants) {
if (instant.isRequested()) {
requested = instant;
} else if (instant.isInflight()) {
inflight = instant;
} else {
completed = instant;
}
}
return new ActiveAction(requested, inflight, Objects.requireNonNull(completed));
}

public List<HoodieInstant> getPendingInstants() {
List<HoodieInstant> instants = new ArrayList<>(2);
if (this.requested != null) {
instants.add(this.requested);
}
if (this.inflight != null) {
instants.add(this.inflight);
}
return instants;
}

public HoodieInstant getCompleted() {
return completed;
}

public String getAction() {
return this.completed.getAction();
}

/**
* A COMPACTION action eventually becomes COMMIT when completed.
*/
public String getPendingAction() {
return getPendingInstant().getAction();
}

public String getInstantTime() {
return this.completed.getTimestamp();
}

public String getCompletionTime() {
return this.completed.getStateTransitionTime();
}

public Option<byte[]> getCommitMetadata(HoodieTableMetaClient metaClient) {
Option<byte[]> content = metaClient.getActiveTimeline().getInstantDetails(this.completed);
if (content.isPresent() && content.get().length == 0) {
return Option.empty();
}
return content;
}

public Option<byte[]> getRequestedCommitMetadata(HoodieTableMetaClient metaClient) {
if (this.requested != null) {
Option<byte[]> requestedContent = metaClient.getActiveTimeline().getInstantDetails(this.requested);
if (!requestedContent.isPresent() || requestedContent.get().length == 0) {
return Option.empty();
} else {
return requestedContent;
}
} else {
return Option.empty();
}
}

public Option<byte[]> getInflightCommitMetadata(HoodieTableMetaClient metaClient) {
if (this.inflight != null) {
Option<byte[]> inflightContent = metaClient.getActiveTimeline().getInstantDetails(this.inflight);
if (!inflightContent.isPresent() || inflightContent.get().length == 0) {
return Option.empty();
} else {
return inflightContent;
}
} else {
return Option.empty();
}
}

public byte[] getCleanPlan(HoodieTableMetaClient metaClient) {
return metaClient.getActiveTimeline().readCleanerInfoAsBytes(getPendingInstant()).get();
}

public byte[] getCompactionPlan(HoodieTableMetaClient metaClient) {
return metaClient.getActiveTimeline().readCompactionPlanAsBytes(HoodieTimeline.getCompactionRequestedInstant(getInstantTime())).get();
}

public byte[] getLogCompactionPlan(HoodieTableMetaClient metaClient) {
return metaClient.getActiveTimeline().readCompactionPlanAsBytes(HoodieTimeline.getLogCompactionRequestedInstant(getInstantTime())).get();
}

protected HoodieInstant getPendingInstant() {
if (requested != null) {
return requested;
} else if (inflight != null) {
return inflight;
} else {
throw new AssertionError("Pending instant does not exist.");
}
}

@Override
public int compareTo(ActiveAction other) {
return this.completed.getTimestamp().compareTo(other.completed.getTimestamp());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.hudi.client.timeline;

import org.apache.hudi.common.table.HoodieTableMetaClient;
import org.apache.hudi.common.table.timeline.HoodieInstant;
import org.apache.hudi.common.util.Option;
import org.apache.hudi.common.util.ValidationUtils;
import org.apache.hudi.common.util.collection.Pair;

import javax.annotation.Nullable;

import java.util.List;
import java.util.Objects;

/**
* A combination of instants covering action states: requested, inflight, completed.
*
* <p>It holds all the instant details besides the instants.
*/
public class ActiveActionWithDetails extends ActiveAction {
private final Option<byte[]> requestedDetails;
private final Option<byte[]> inflightDetails;
private final Option<byte[]> completedDetails;

/**
* The constructor.
*/
protected ActiveActionWithDetails(
@Nullable HoodieInstant requested,
Option<byte[]> requestedDetails,
@Nullable HoodieInstant inflight,
Option<byte[]> inflightDetails,
HoodieInstant completed,
Option<byte[]> completedDetails) {
super(requested, inflight, completed);
this.requestedDetails = requestedDetails;
this.inflightDetails = inflightDetails;
this.completedDetails = completedDetails;
}

public static ActiveActionWithDetails fromInstantAndDetails(List<Pair<HoodieInstant, Option<byte[]>>> instantAndDetails) {
ValidationUtils.checkArgument(instantAndDetails.size() <= 3);

HoodieInstant requested = null;
HoodieInstant inflight = null;
HoodieInstant completed = null;

Option<byte[]> requestedDetails = Option.empty();
Option<byte[]> inflightDetails = Option.empty();
Option<byte[]> completedDetails = Option.empty();

for (Pair<HoodieInstant, Option<byte[]>> instantAndDetail : instantAndDetails) {
HoodieInstant instant = instantAndDetail.getKey();
Option<byte[]> details = instantAndDetail.getRight();
if (instant.isRequested()) {
requested = instant;
requestedDetails = details;
} else if (instant.isInflight()) {
inflight = instant;
inflightDetails = details;
} else {
completed = instant;
completedDetails = details;
}
}
return new ActiveActionWithDetails(requested, requestedDetails, inflight, inflightDetails, Objects.requireNonNull(completed), completedDetails);
}

public Option<byte[]> getCommitMetadata(HoodieTableMetaClient metaClient) {
return this.completedDetails;
}

public Option<byte[]> getRequestedCommitMetadata(HoodieTableMetaClient metaClient) {
return this.requestedDetails;
}

public Option<byte[]> getInflightCommitMetadata(HoodieTableMetaClient metaClient) {
return this.inflightDetails;
}

public byte[] getCleanPlan(HoodieTableMetaClient metaClient) {
ValidationUtils.checkState(this.requestedDetails.isPresent(), "clean plan does not exist");
return this.requestedDetails.get();
}

public byte[] getCompactionPlan(HoodieTableMetaClient metaClient) {
ValidationUtils.checkState(this.requestedDetails.isPresent(), "compaction plan does not exist");
return this.requestedDetails.get();
}

public byte[] getLogCompactionPlan(HoodieTableMetaClient metaClient) {
ValidationUtils.checkState(this.requestedDetails.isPresent(), "log compaction plan does not exist");
return this.requestedDetails.get();
}
}
Loading

0 comments on commit 1739fa3

Please sign in to comment.