Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[INLONG-10630][Sort] Make SQL Server source support report audit information exactly once #10631

Merged
merged 1 commit into from
Jul 16, 2024
Merged
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 @@ -314,6 +314,10 @@ public void snapshotState(FunctionSnapshotContext functionSnapshotContext) throw
snapshotOffsetState(functionSnapshotContext.getCheckpointId());
snapshotHistoryRecordsState();
}
if (deserializer instanceof RowDataDebeziumDeserializeSchema) {
((RowDataDebeziumDeserializeSchema) deserializer)
.updateCurrentCheckpointId(functionSnapshotContext.getCheckpointId());
}
}

private void snapshotOffsetState(long checkpointId) throws Exception {
Expand Down Expand Up @@ -488,6 +492,12 @@ public void notifyCheckpointComplete(long checkpointId) {
DebeziumOffset offset =
DebeziumOffsetSerializer.INSTANCE.deserialize(serializedOffsets);
changeConsumer.commitOffset(offset);

if (deserializer instanceof RowDataDebeziumDeserializeSchema) {
RowDataDebeziumDeserializeSchema schema = (RowDataDebeziumDeserializeSchema) deserializer;
schema.flushAudit();
schema.updateLastCheckpointId(checkpointId);
}
} catch (Exception e) {
// ignore exception if we are no longer running
LOG.warn("Ignore error when committing offset to database.", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import org.apache.inlong.sort.base.metric.MetricOption;
import org.apache.inlong.sort.base.metric.MetricsCollector;
import org.apache.inlong.sort.base.metric.SourceMetricData;
import org.apache.inlong.sort.base.metric.SourceExactlyMetric;

import com.ververica.cdc.debezium.table.AppendMetadataCollector;
import com.ververica.cdc.debezium.table.DebeziumChangelogMode;
Expand Down Expand Up @@ -101,7 +101,7 @@ public interface ValueValidator extends Serializable {
/** Changelog Mode to use for encoding changes in Flink internal data structure. */
private final DebeziumChangelogMode changelogMode;
private final MetricOption metricOption;
private SourceMetricData sourceMetricData;
private SourceExactlyMetric sourceExactlyMetric;

/** Returns a builder to build {@link RowDataDebeziumDeserializeSchema}. */
public static Builder newBuilder() {
Expand Down Expand Up @@ -133,7 +133,7 @@ public static Builder newBuilder() {
@Override
public void open() {
if (metricOption != null) {
sourceMetricData = new SourceMetricData(metricOption);
sourceExactlyMetric = new SourceExactlyMetric(metricOption);
}
}

Expand All @@ -146,8 +146,8 @@ public void deserialize(SourceRecord record, Collector<RowData> out) throws Exce
GenericRowData insert = extractAfterRow(value, valueSchema);
validator.validate(insert, RowKind.INSERT);
insert.setRowKind(RowKind.INSERT);
if (sourceMetricData != null) {
out = new MetricsCollector<>(out, sourceMetricData);
if (sourceExactlyMetric != null) {
out = new MetricsCollector<>(out, sourceExactlyMetric);
}
emit(record, insert, out);
} else if (op == Envelope.Operation.DELETE) {
Expand All @@ -166,8 +166,8 @@ public void deserialize(SourceRecord record, Collector<RowData> out) throws Exce
GenericRowData after = extractAfterRow(value, valueSchema);
validator.validate(after, RowKind.UPDATE_AFTER);
after.setRowKind(RowKind.UPDATE_AFTER);
if (sourceMetricData != null) {
out = new MetricsCollector<>(out, sourceMetricData);
if (sourceExactlyMetric != null) {
out = new MetricsCollector<>(out, sourceExactlyMetric);
}
emit(record, after, out);
}
Expand Down Expand Up @@ -679,4 +679,22 @@ public Object convert(Object dbzObj, Schema schema) throws Exception {
}
};
}

public void flushAudit() {
if (sourceExactlyMetric != null) {
sourceExactlyMetric.flushAudit();
}
}

public void updateCurrentCheckpointId(long checkpointId) {
if (sourceExactlyMetric != null) {
sourceExactlyMetric.updateCurrentCheckpointId(checkpointId);
}
}

public void updateLastCheckpointId(long checkpointId) {
if (sourceExactlyMetric != null) {
sourceExactlyMetric.updateLastCheckpointId(checkpointId);
}
}
}
Loading