[HUDI-1837] Add optional instant range to log record scanner for log (#2870)
This commit is contained in:
@@ -285,6 +285,12 @@ public class FlinkOptions {
|
||||
.defaultValue(128)
|
||||
.withDescription("Max log block size in MB for log file, default 128MB");
|
||||
|
||||
public static final ConfigOption<Integer> WRITE_LOG_MAX_SIZE = ConfigOptions
|
||||
.key("write.log.max.size")
|
||||
.intType()
|
||||
.defaultValue(1024)
|
||||
.withDescription("Maximum size allowed in MB for a log file before it is rolled over to the next version, default 1GB");
|
||||
|
||||
public static final ConfigOption<Integer> WRITE_MERGE_MAX_MEMORY = ConfigOptions
|
||||
.key("write.merge.max_memory")
|
||||
.intType()
|
||||
|
||||
@@ -22,6 +22,7 @@ import org.apache.hudi.common.fs.FSUtils;
|
||||
import org.apache.hudi.common.model.HoodieCommitMetadata;
|
||||
import org.apache.hudi.common.model.HoodieLogFile;
|
||||
import org.apache.hudi.common.table.HoodieTableMetaClient;
|
||||
import org.apache.hudi.common.table.log.InstantRange;
|
||||
import org.apache.hudi.common.table.timeline.HoodieInstant;
|
||||
import org.apache.hudi.common.table.timeline.HoodieTimeline;
|
||||
import org.apache.hudi.common.table.view.HoodieTableFileSystemView;
|
||||
@@ -29,7 +30,6 @@ import org.apache.hudi.common.util.Option;
|
||||
import org.apache.hudi.common.util.ValidationUtils;
|
||||
import org.apache.hudi.configuration.FlinkOptions;
|
||||
import org.apache.hudi.exception.HoodieException;
|
||||
import org.apache.hudi.table.format.mor.InstantRange;
|
||||
import org.apache.hudi.table.format.mor.MergeOnReadInputSplit;
|
||||
import org.apache.hudi.util.StreamerUtil;
|
||||
|
||||
|
||||
@@ -79,6 +79,7 @@ public class FormatUtils {
|
||||
.withSpillableMapBasePath(
|
||||
config.get(HoodieRealtimeConfig.SPILLABLE_MAP_BASE_PATH_PROP,
|
||||
HoodieRealtimeConfig.DEFAULT_SPILLABLE_MAP_BASE_PATH))
|
||||
.withInstantRange(split.getInstantRange())
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,101 +0,0 @@
|
||||
/*
|
||||
* 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.table.format.mor;
|
||||
|
||||
import org.apache.hudi.common.table.timeline.HoodieTimeline;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* A instant commits range used for incremental reader filtering.
|
||||
*/
|
||||
public abstract class InstantRange implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
protected final String startInstant;
|
||||
protected final String endInstant;
|
||||
|
||||
public InstantRange(String startInstant, String endInstant) {
|
||||
this.startInstant = Objects.requireNonNull(startInstant);
|
||||
this.endInstant = Objects.requireNonNull(endInstant);
|
||||
}
|
||||
|
||||
public static InstantRange getInstance(String startInstant, String endInstant, RangeType rangeType) {
|
||||
switch (rangeType) {
|
||||
case OPEN_CLOSE:
|
||||
return new OpenCloseRange(startInstant, endInstant);
|
||||
case CLOSE_CLOSE:
|
||||
return new CloseCloseRange(startInstant, endInstant);
|
||||
default:
|
||||
throw new AssertionError();
|
||||
}
|
||||
}
|
||||
|
||||
public String getStartInstant() {
|
||||
return startInstant;
|
||||
}
|
||||
|
||||
public String getEndInstant() {
|
||||
return endInstant;
|
||||
}
|
||||
|
||||
public abstract boolean isInRange(String instant);
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Inner Class
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Represents a range type.
|
||||
*/
|
||||
public enum RangeType {
|
||||
OPEN_CLOSE, CLOSE_CLOSE;
|
||||
}
|
||||
|
||||
private static class OpenCloseRange extends InstantRange {
|
||||
|
||||
public OpenCloseRange(String startInstant, String endInstant) {
|
||||
super(startInstant, endInstant);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInRange(String instant) {
|
||||
// No need to do comparison:
|
||||
// HoodieTimeline.compareTimestamps(instant, HoodieTimeline.LESSER_THAN_OR_EQUALS, endInstant)
|
||||
// because the logic is ensured by the log scanner
|
||||
return HoodieTimeline.compareTimestamps(instant, HoodieTimeline.GREATER_THAN, startInstant);
|
||||
}
|
||||
}
|
||||
|
||||
private static class CloseCloseRange extends InstantRange {
|
||||
|
||||
public CloseCloseRange(String startInstant, String endInstant) {
|
||||
super(startInstant, endInstant);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInRange(String instant) {
|
||||
// No need to do comparison:
|
||||
// HoodieTimeline.compareTimestamps(instant, HoodieTimeline.LESSER_THAN_OR_EQUALS, endInstant)
|
||||
// because the logic is ensured by the log scanner
|
||||
return HoodieTimeline.compareTimestamps(instant, HoodieTimeline.GREATER_THAN_OR_EQUALS, startInstant);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -64,7 +64,6 @@ import java.util.stream.IntStream;
|
||||
|
||||
import static org.apache.flink.table.data.vector.VectorizedColumnBatch.DEFAULT_SIZE;
|
||||
import static org.apache.flink.table.filesystem.RowPartitionComputer.restorePartValueFromType;
|
||||
import static org.apache.hudi.hadoop.utils.HoodieInputFormatUtils.HOODIE_COMMIT_TIME_COL_POS;
|
||||
import static org.apache.hudi.hadoop.utils.HoodieInputFormatUtils.HOODIE_RECORD_KEY_COL_POS;
|
||||
import static org.apache.hudi.table.format.FormatUtils.buildAvroRecordBySchema;
|
||||
|
||||
@@ -334,17 +333,6 @@ public class MergeOnReadInputFormat
|
||||
// skipping if the condition is unsatisfied
|
||||
// continue;
|
||||
} else {
|
||||
// should improve the code when log scanner supports
|
||||
// seeking by log blocks with commit time which is more
|
||||
// efficient.
|
||||
if (split.getInstantRange().isPresent()) {
|
||||
// based on the fact that commit time is always the first field
|
||||
String commitTime = curAvroRecord.get().get(HOODIE_COMMIT_TIME_COL_POS).toString();
|
||||
if (!split.getInstantRange().get().isInRange(commitTime)) {
|
||||
// filter out the records that are not in range
|
||||
continue;
|
||||
}
|
||||
}
|
||||
GenericRecord requiredAvroRecord = buildAvroRecordBySchema(
|
||||
curAvroRecord.get(),
|
||||
requiredSchema,
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package org.apache.hudi.table.format.mor;
|
||||
|
||||
import org.apache.hudi.common.table.log.InstantRange;
|
||||
import org.apache.hudi.common.util.Option;
|
||||
|
||||
import org.apache.flink.core.io.InputSplit;
|
||||
|
||||
@@ -213,6 +213,7 @@ public class StreamerUtil {
|
||||
.forTable(conf.getString(FlinkOptions.TABLE_NAME))
|
||||
.withStorageConfig(HoodieStorageConfig.newBuilder()
|
||||
.logFileDataBlockMaxSize(conf.getInteger(FlinkOptions.WRITE_LOG_BLOCK_SIZE) * 1024 * 1024)
|
||||
.logFileMaxSize(conf.getInteger(FlinkOptions.WRITE_LOG_MAX_SIZE) * 1024 * 1024)
|
||||
.build())
|
||||
.withAutoCommit(false)
|
||||
.withProps(flinkConf2TypedProperties(FlinkOptions.flatOptions(conf)));
|
||||
|
||||
Reference in New Issue
Block a user