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 @@ -1227,6 +1227,10 @@ public class Config extends ConfigBase {
@ConfField(mutable = true, masterOnly = true)
public static int streaming_task_min_timeout_sec = 300;

@ConfField(mutable = true, masterOnly = true, description = {
"Minimum interval in seconds between snapshot offset persistence operations"})
public static int streaming_job_snapshot_offset_persist_interval_sec = 300;

@ConfField(mutable = true, masterOnly = true)
public static int streaming_cdc_light_rpc_timeout_sec = 90;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class DataSourceConfigKeys {
public static final String OFFSET_LATEST = "latest";
public static final String OFFSET_SNAPSHOT = "snapshot";
public static final String SNAPSHOT_SPLIT_SIZE = "snapshot_split_size";
public static final String SNAPSHOT_SPLIT_SIZE_DEFAULT = "40960";
public static final String SNAPSHOT_SPLIT_KEY = "snapshot_split_key";
public static final String SNAPSHOT_PARALLELISM = "snapshot_parallelism";
public static final String SNAPSHOT_PARALLELISM_DEFAULT = "1";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ public class StreamingInsertJob extends AbstractJob<StreamingJobSchedulerTask, M
@SerializedName("opp")
// The value to be persisted in offsetProvider
private String offsetProviderPersist;
private transient long lastOffsetPersistTimeMs;
@Setter
@Getter
private long lastScheduleTaskTimestamp = -1L;
Expand Down Expand Up @@ -899,6 +900,7 @@ public void onStreamTaskSuccess(AbstractStreamingTask task) throws JobException
// offset provider has reached a natural end, mark job as finished
log.info("Streaming insert job {} source data fully consumed, marking job as FINISHED", getJobId());
updateJobStatus(JobStatus.FINISHED);
logUpdateOperation();
return;
}
AbstractStreamingTask nextTask = createStreamingTask();
Expand Down Expand Up @@ -1026,6 +1028,10 @@ public void replayOnUpdated(StreamingInsertJob replayJob) {
// insert TVF does not persist the running state.
// streaming multi task persists the running state when commitOffset() is called.
setJobStatus(replayJob.getJobStatus());
if (isFinalStatus()) {
setFinishTimeMs(replayJob.getFinishTimeMs());
Env.getCurrentGlobalTransactionMgr().getCallbackFactory().removeCallback(getJobId());
}
}
try {
modifyPropertiesInternal(replayJob.getProperties());
Expand Down Expand Up @@ -1059,6 +1065,8 @@ public void replayOnUpdated(StreamingInsertJob replayJob) {
setFailedTaskCount(replayJob.getFailedTaskCount());
setCanceledTaskCount(replayJob.getCanceledTaskCount());
setLastTaskSuccessTime(replayJob.getLastTaskSuccessTime());
setStartTimeMs(replayJob.getStartTimeMs());
setFailureReason(replayJob.getFailureReason());
this.boundBackendId = replayJob.boundBackendId;
}

Expand Down Expand Up @@ -1548,6 +1556,7 @@ public void commitOffset(CommitOffsetRequest offsetRequest) throws JobException
throw new JobException("Unsupported commit offset for offset provider type: "
+ offsetProvider.getClass().getSimpleName());
}
JdbcSourceOffsetProvider jdbcOffsetProvider = (JdbcSourceOffsetProvider) offsetProvider;

writeLock();
try {
Expand Down Expand Up @@ -1575,10 +1584,9 @@ public void commitOffset(CommitOffsetRequest offsetRequest) throws JobException
updateNoTxnJobStatisticAndOffset(offsetRequest);
offsetProvider.onTaskCommitted(offsetRequest.getScannedRows(), offsetRequest.getLoadBytes());
if (offsetRequest.getTableSchemas() != null) {
JdbcSourceOffsetProvider op = (JdbcSourceOffsetProvider) offsetProvider;
op.setTableSchemas(offsetRequest.getTableSchemas());
jdbcOffsetProvider.setTableSchemas(offsetRequest.getTableSchemas());
}
persistOffsetProviderIfNeed();
persistOffsetProviderIfNeed(jdbcOffsetProvider, System.currentTimeMillis());
log.info("Streaming multi table job {} task {} commit offset successfully, offset: {}",
getJobId(), offsetRequest.getTaskId(), offsetRequest.getOffset());
((StreamingMultiTblTask) this.runningStreamTask).successCallback(offsetRequest);
Expand Down Expand Up @@ -1638,12 +1646,19 @@ private void checkDataQuality(CommitOffsetRequest offsetRequest) throws JobExcep
}
}

private void persistOffsetProviderIfNeed() {
// only for jdbc
this.offsetProviderPersist = offsetProvider.getPersistInfo();
if (this.offsetProviderPersist != null) {
logUpdateOperation();
private void persistOffsetProviderIfNeed(
JdbcSourceOffsetProvider jdbcOffsetProvider, long currentTimeMs) {
this.offsetProviderPersist = jdbcOffsetProvider.getPersistInfo();
if (this.offsetProviderPersist == null) {
return;
}

if (!jdbcOffsetProvider.shouldPersistOffset(lastOffsetPersistTimeMs, currentTimeMs)) {
return;
}

logUpdateOperation();
lastOffsetPersistTimeMs = currentTimeMs;
}

public void replayOffsetProviderIfNeed() throws JobException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ private void handlePendingState() throws JobException {
// Source already fully consumed (e.g. snapshot-only mode recovered after FE restart).
// Transition directly to FINISHED without creating a new task.
streamingInsertJob.updateJobStatus(JobStatus.FINISHED);
streamingInsertJob.logUpdateOperation();
return;
}
streamingInsertJob.createStreamingTask();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Preconditions;
import com.google.gson.Gson;
import com.google.gson.annotations.SerializedName;
import lombok.Getter;
Expand Down Expand Up @@ -256,8 +257,11 @@ public void updateOffset(Offset offset) {
} else {
synchronized (splitsLock) {
BinlogSplit binlogSplit = (BinlogSplit) newOffset.getSplits().get(0);
Preconditions.checkArgument(MapUtils.isNotEmpty(binlogSplit.getStartingOffset()),
"Committed binlog offset must not be empty");
binlogOffsetPersist = new HashMap<>(binlogSplit.getStartingOffset());
binlogOffsetPersist.put(SPLIT_ID, BinlogSplit.BINLOG_SPLIT_ID);
clearSnapshotState();
currentOffset = newOffset;
hasMoreData = true;
}
Expand All @@ -266,6 +270,31 @@ public void updateOffset(Offset offset) {
this.currentOffset = newOffset;
}

protected void clearSnapshotState() {
if (MapUtils.isNotEmpty(chunkHighWatermarkMap)) {
chunkHighWatermarkMap = new HashMap<>();
}
remainingSplits.clear();
finishedSplits.clear();
if (committedSplitProgress != null) {
clearProgress(committedSplitProgress);
}
if (cdcSplitProgress != null) {
clearProgress(cdcSplitProgress);
}
}

public boolean shouldPersistOffset(long lastPersistTimeMs, long currentTimeMs) {
synchronized (splitsLock) {
if (currentOffset == null || !currentOffset.snapshotSplit()) {
return true;
}
}
long intervalMs = Math.max(1L,
(long) Config.streaming_job_snapshot_offset_persist_interval_sec) * 1000L;
return lastPersistTimeMs == 0L || currentTimeMs - lastPersistTimeMs >= intervalMs;
}

@Override
public void setBoundBackendId(long boundBackendId) {
this.boundBackendId = boundBackendId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,11 @@ public void updateOffset(Offset offset) {
synchronized (splitsLock) {
// Mirror binlog offset into bop so it survives FE checkpoint
BinlogSplit bs = (BinlogSplit) newOffset.getSplits().get(0);
if (MapUtils.isNotEmpty(bs.getStartingOffset())) {
binlogOffsetPersist = new HashMap<>(bs.getStartingOffset());
binlogOffsetPersist.put(SPLIT_ID, BinlogSplit.BINLOG_SPLIT_ID);
}
Preconditions.checkArgument(MapUtils.isNotEmpty(bs.getStartingOffset()),
"Committed binlog offset must not be empty");
binlogOffsetPersist = new HashMap<>(bs.getStartingOffset());
binlogOffsetPersist.put(SPLIT_ID, BinlogSplit.BINLOG_SPLIT_ID);
clearSnapshotState();
currentOffset = newOffset;
hasMoreData = true;
}
Expand Down
Loading
Loading