Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1811,6 +1811,23 @@ public class ConfigOptions {
+ ConfigOptions.TABLE_DATALAKE_AUTO_EXPIRE_SNAPSHOT
+ " is false.");

public static final ConfigOption<Duration> LAKE_TIERING_TABLE_DURATION_MAX =
key("lake.tiering.table.duration.max")
.durationType()
.defaultValue(Duration.ofMinutes(30))
.withDescription(
"The maximum duration for tiering a single table. If tiering a table exceeds this duration, "
+ "it will be force completed: the tiering will be finalized and committed to the data lake "
+ "(e.g., Paimon) immediately, even if they haven't reached their desired stopping offsets.");

public static final ConfigOption<Duration> LAKE_TIERING_TABLE_DURATION_DETECT_INTERVAL =
key("lake.tiering.table.duration.detect-interval")
.durationType()
.defaultValue(Duration.ofSeconds(30))
.withDescription(
"The interval to check if a table tiering operation has reached the maximum duration. "
+ "The enumerator will periodically check tiering tables and force complete those that exceed the maximum duration.");

// ------------------------------------------------------------------------
// ConfigOptions for fluss kafka
// ------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.sink.v2.DiscardingSink;

import static org.apache.fluss.config.ConfigOptions.LAKE_TIERING_TABLE_DURATION_DETECT_INTERVAL;
import static org.apache.fluss.config.ConfigOptions.LAKE_TIERING_TABLE_DURATION_MAX;
import static org.apache.fluss.flink.tiering.source.TieringSource.TIERING_SOURCE_TRANSFORMATION_UID;
import static org.apache.fluss.flink.tiering.source.TieringSourceOptions.POLL_TIERING_TABLE_INTERVAL;
import static org.apache.fluss.utils.Preconditions.checkNotNull;
Expand Down Expand Up @@ -89,6 +91,17 @@ public JobClient build() throws Exception {
tieringSourceBuilder.withPollTieringTableIntervalMs(
flussConfig.get(POLL_TIERING_TABLE_INTERVAL).toMillis());
}

if (lakeTieringConfig.get(LAKE_TIERING_TABLE_DURATION_MAX) != null) {
tieringSourceBuilder.withTieringTableDurationMax(
lakeTieringConfig.get(LAKE_TIERING_TABLE_DURATION_MAX).toMillis());
}

if (lakeTieringConfig.get(LAKE_TIERING_TABLE_DURATION_DETECT_INTERVAL) != null) {
tieringSourceBuilder.withTieringTableDurationDetectInterval(
lakeTieringConfig.get(LAKE_TIERING_TABLE_DURATION_DETECT_INTERVAL).toMillis());
}

TieringSource<?> tieringSource = tieringSourceBuilder.build();
DataStreamSource<?> source =
env.fromSource(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* 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.fluss.flink.tiering.event;

import org.apache.flink.api.connector.source.SourceEvent;

import java.util.Objects;

/**
* SourceEvent used to notify TieringSourceReader that a table has reached the maximum tiering
* duration and should be force completed.
*/
public class TieringReachMaxDurationEvent implements SourceEvent {

private static final long serialVersionUID = 1L;

private final long tableId;

public TieringReachMaxDurationEvent(long tableId) {
this.tableId = tableId;
}

public long getTableId() {
return tableId;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof TieringReachMaxDurationEvent)) {
return false;
}
TieringReachMaxDurationEvent that = (TieringReachMaxDurationEvent) o;
return tableId == that.tableId;
}

@Override
public int hashCode() {
return Objects.hashCode(tableId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,16 @@
import org.apache.flink.api.connector.source.SourceReaderContext;
import org.apache.flink.api.connector.source.SplitEnumerator;
import org.apache.flink.api.connector.source.SplitEnumeratorContext;
import org.apache.flink.connector.base.source.reader.RecordsWithSplitIds;
import org.apache.flink.connector.base.source.reader.synchronization.FutureCompletingBlockingQueue;
import org.apache.flink.core.io.SimpleVersionedSerializer;
import org.apache.flink.runtime.jobgraph.OperatorID;
import org.apache.flink.streaming.api.graph.StreamGraphHasherV2;

import java.nio.charset.StandardCharsets;

import static org.apache.fluss.config.ConfigOptions.LAKE_TIERING_TABLE_DURATION_DETECT_INTERVAL;
import static org.apache.fluss.config.ConfigOptions.LAKE_TIERING_TABLE_DURATION_MAX;
import static org.apache.fluss.flink.tiering.source.TieringSourceOptions.POLL_TIERING_TABLE_INTERVAL;

/**
Expand All @@ -61,14 +65,20 @@ public class TieringSource<WriteResult>
private final Configuration flussConf;
private final LakeTieringFactory<WriteResult, ?> lakeTieringFactory;
private final long pollTieringTableIntervalMs;
private final long tieringTableDurationMaxMs;
private final long tieringTableDurationDetectIntervalMs;

public TieringSource(
Configuration flussConf,
LakeTieringFactory<WriteResult, ?> lakeTieringFactory,
long pollTieringTableIntervalMs) {
long pollTieringTableIntervalMs,
long tieringTableDurationMaxMs,
long tieringTableDurationDetectIntervalMs) {
this.flussConf = flussConf;
this.lakeTieringFactory = lakeTieringFactory;
this.pollTieringTableIntervalMs = pollTieringTableIntervalMs;
this.tieringTableDurationMaxMs = tieringTableDurationMaxMs;
this.tieringTableDurationDetectIntervalMs = tieringTableDurationDetectIntervalMs;
}

@Override
Expand All @@ -78,19 +88,26 @@ public Boundedness getBoundedness() {

@Override
public SplitEnumerator<TieringSplit, TieringSourceEnumeratorState> createEnumerator(
SplitEnumeratorContext<TieringSplit> splitEnumeratorContext) throws Exception {
SplitEnumeratorContext<TieringSplit> splitEnumeratorContext) {
return new TieringSourceEnumerator(
flussConf, splitEnumeratorContext, pollTieringTableIntervalMs);
flussConf,
splitEnumeratorContext,
pollTieringTableIntervalMs,
tieringTableDurationMaxMs,
tieringTableDurationDetectIntervalMs);
}

@Override
public SplitEnumerator<TieringSplit, TieringSourceEnumeratorState> restoreEnumerator(
SplitEnumeratorContext<TieringSplit> splitEnumeratorContext,
TieringSourceEnumeratorState tieringSourceEnumeratorState)
throws Exception {
TieringSourceEnumeratorState tieringSourceEnumeratorState) {
// stateless operator
return new TieringSourceEnumerator(
flussConf, splitEnumeratorContext, pollTieringTableIntervalMs);
flussConf,
splitEnumeratorContext,
pollTieringTableIntervalMs,
tieringTableDurationMaxMs,
tieringTableDurationDetectIntervalMs);
}

@Override
Expand All @@ -107,8 +124,11 @@ public SimpleVersionedSerializer<TieringSplit> getSplitSerializer() {
@Override
public SourceReader<TableBucketWriteResult<WriteResult>, TieringSplit> createReader(
SourceReaderContext sourceReaderContext) {
FutureCompletingBlockingQueue<RecordsWithSplitIds<TableBucketWriteResult<WriteResult>>>
elementsQueue = new FutureCompletingBlockingQueue<>();
Connection connection = ConnectionFactory.createConnection(flussConf);
return new TieringSourceReader<>(sourceReaderContext, connection, lakeTieringFactory);
return new TieringSourceReader<>(
elementsQueue, sourceReaderContext, connection, lakeTieringFactory);
}

/** This follows the operator uid hash generation logic of flink {@link StreamGraphHasherV2}. */
Expand All @@ -126,6 +146,10 @@ public static class Builder<WriteResult> {
private final LakeTieringFactory<WriteResult, ?> lakeTieringFactory;
private long pollTieringTableIntervalMs =
POLL_TIERING_TABLE_INTERVAL.defaultValue().toMillis();
private long tieringTableDurationMaxMs =
LAKE_TIERING_TABLE_DURATION_MAX.defaultValue().toMillis();
private long tieringTableDurationDetectIntervalMs =
LAKE_TIERING_TABLE_DURATION_DETECT_INTERVAL.defaultValue().toMillis();

public Builder(
Configuration flussConf, LakeTieringFactory<WriteResult, ?> lakeTieringFactory) {
Expand All @@ -138,8 +162,24 @@ public Builder<WriteResult> withPollTieringTableIntervalMs(long pollTieringTable
return this;
}

public Builder<WriteResult> withTieringTableDurationMax(long tieringTableDurationMaxMs) {
this.tieringTableDurationMaxMs = tieringTableDurationMaxMs;
return this;
}

public Builder<WriteResult> withTieringTableDurationDetectInterval(
long tieringTableDurationDetectIntervalMs) {
this.tieringTableDurationDetectIntervalMs = tieringTableDurationDetectIntervalMs;
return this;
}

public TieringSource<WriteResult> build() {
return new TieringSource<>(flussConf, lakeTieringFactory, pollTieringTableIntervalMs);
return new TieringSource<>(
flussConf,
lakeTieringFactory,
pollTieringTableIntervalMs,
tieringTableDurationMaxMs,
tieringTableDurationDetectIntervalMs);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* 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.fluss.flink.tiering.source;

import org.apache.fluss.flink.adapter.SingleThreadFetcherManagerAdapter;
import org.apache.fluss.flink.tiering.source.split.TieringSplit;

import org.apache.flink.configuration.Configuration;
import org.apache.flink.connector.base.source.reader.RecordsWithSplitIds;
import org.apache.flink.connector.base.source.reader.fetcher.SplitFetcher;
import org.apache.flink.connector.base.source.reader.fetcher.SplitFetcherTask;
import org.apache.flink.connector.base.source.reader.splitreader.SplitReader;
import org.apache.flink.connector.base.source.reader.synchronization.FutureCompletingBlockingQueue;

import java.util.Collection;
import java.util.function.Consumer;
import java.util.function.Supplier;

/**
* The SplitFetcherManager for tiering source. This class is needed to help notify a table reaches
* to deadline of tiering to {@link TieringSplitReader}.
*/
public class TieringSourceFetcherManager<WriteResult>
extends SingleThreadFetcherManagerAdapter<
TableBucketWriteResult<WriteResult>, TieringSplit> {

public TieringSourceFetcherManager(
FutureCompletingBlockingQueue<RecordsWithSplitIds<TableBucketWriteResult<WriteResult>>>
elementsQueue,
Supplier<SplitReader<TableBucketWriteResult<WriteResult>, TieringSplit>>
splitReaderSupplier,
Configuration configuration,
Consumer<Collection<String>> splitFinishedHook) {
super(elementsQueue, splitReaderSupplier, configuration, splitFinishedHook);
}

public void markTableReachTieringMaxDuration(long tableId) {
if (!fetchers.isEmpty()) {
// The fetcher thread is still running. This should be the majority of the cases.
fetchers.values()
.forEach(
splitFetcher ->
enqueueMarkTableReachTieringMaxDurationTask(
splitFetcher, tableId));
} else {
SplitFetcher<TableBucketWriteResult<WriteResult>, TieringSplit> splitFetcher =
createSplitFetcher();
enqueueMarkTableReachTieringMaxDurationTask(splitFetcher, tableId);
startFetcher(splitFetcher);
}
}

private void enqueueMarkTableReachTieringMaxDurationTask(
SplitFetcher<TableBucketWriteResult<WriteResult>, TieringSplit> splitFetcher,
long reachTieringDeadlineTable) {
splitFetcher.enqueueTask(
new SplitFetcherTask() {
@Override
public boolean run() {
((TieringSplitReader<WriteResult>) splitFetcher.getSplitReader())
.handleTableReachTieringMaxDuration(reachTieringDeadlineTable);
return true;
}

@Override
public void wakeUp() {
// do nothing
}
});
}
}
Loading