lordcheng10 commented on code in PR #7418:
URL: https://github.com/apache/inlong/pull/7418#discussion_r1116689276
##########
inlong-sort/sort-connectors/iceberg/src/main/java/org/apache/inlong/sort/iceberg/sink/multiple/IcebergSingleStreamWriter.java:
##########
@@ -84,11 +135,60 @@ public void prepareSnapshotPreBarrier(long checkpointId)
throws Exception {
@Override
public void processElement(T value) throws Exception {
- writer.write(value);
+ try {
+ writer.write(value);
+ } catch (Exception e) {
+ if (multipleSink) {
+ throw e;
+ }
+
+ LOGGER.error(String.format("write error, raw data: %s", value), e);
+ if (!dirtyOptions.ignoreDirty()) {
+ throw e;
+ }
+ if (dirtySink != null) {
+ DirtyData.Builder<Object> builder = DirtyData.builder();
+ try {
+ builder.setData(value)
+ .setLabels(dirtyOptions.getLabels())
+ .setLogTag(dirtyOptions.getLogTag())
+ .setIdentifier(dirtyOptions.getIdentifier())
+ .setRowType(flinkRowType)
+ .setDirtyMessage(e.getMessage());
+ dirtySink.invoke(builder.build());
+ if (metricData != null) {
+ metricData.invokeDirtyWithEstimate(value);
+ }
+ } catch (Exception ex) {
+ if (!dirtyOptions.ignoreSideOutputErrors()) {
+ throw new RuntimeException(ex);
+ }
+ LOGGER.warn("Dirty sink failed", ex);
+ }
+ }
+ }
+ if (metricData != null) {
+ metricData.invokeWithEstimate(value == null ? "" : value);
+ }
}
@Override
public void initializeState(FunctionInitializationContext context) throws
Exception {
+ // init metric state
+ if(multipleSink){
+ return;
+ }
+ if (this.inlongMetric != null) {
+ this.metricStateListState =
context.getOperatorStateStore().getUnionListState(
+ new ListStateDescriptor<>(
+ String.format("Iceberg(%s)-" +
INLONG_METRIC_STATE_NAME, fullTableName),
Review Comment:
Fixed
##########
inlong-sort/sort-connectors/iceberg/src/main/java/org/apache/inlong/sort/iceberg/sink/multiple/IcebergMultipleStreamWriter.java:
##########
@@ -201,7 +239,56 @@ public void processElement(RecordWithSchema
recordWithSchema) throws Exception {
if (multipleWriters.get(tableId) != null) {
for (RowData data : recordWithSchema.getData()) {
- multipleWriters.get(tableId).processElement(data);
+ try {
+ multipleWriters.get(tableId).processElement(data);
+ } catch (Exception e) {
+ LOG.error(String.format("write error, raw data: %s",
data), e);
+ if (!dirtyOptions.ignoreDirty()) {
+ throw e;
+ }
+ if (dirtySink != null) {
+ DirtyData.Builder<Object> builder =
DirtyData.builder();
+ try {
+ String dataBaseName =
tableId.namespace().toString();
+ String tableName = tableId.name();
+ String dirtyLabel =
DirtySinkHelper.regexReplace(dirtyOptions.getLabels(),
+ DirtyType.BATCH_LOAD_ERROR, null,
+ dataBaseName, tableName, null);
+ String dirtyLogTag =
+
DirtySinkHelper.regexReplace(dirtyOptions.getLogTag(),
+ DirtyType.BATCH_LOAD_ERROR, null,
+ dataBaseName, tableName, null);
+ String dirtyIdentifier =
+
DirtySinkHelper.regexReplace(dirtyOptions.getIdentifier(),
+ DirtyType.BATCH_LOAD_ERROR, null,
+ dataBaseName, tableName, null);
+ builder.setData(data)
+ .setLabels(dirtyLabel)
+ .setLogTag(dirtyLogTag)
+ .setIdentifier(dirtyIdentifier)
+
.setRowType(multipleWriters.get(tableId).getFlinkRowType())
+ .setDirtyMessage(e.getMessage());
+ dirtySink.invoke(builder.build());
+ if (sinkMetricData != null) {
+ long size =
data.toString().getBytes(StandardCharsets.UTF_8).length;
+
sinkMetricData.outputDirtyMetricsWithEstimate(dataBaseName,
+ tableName, 1, size);
+ }
+ } catch (Exception ex) {
+ if (!dirtyOptions.ignoreSideOutputErrors()) {
+ throw new RuntimeException(ex);
+ }
+ LOG.warn("Dirty sink failed", ex);
+ }
+ }
+ }
+
+ if (sinkMetricData != null) {
+ String dataBaseName = tableId.namespace().toString();
+ String tableName = tableId.name();
+ long size =
data.toString().getBytes(StandardCharsets.UTF_8).length;
+ sinkMetricData.outputMetrics(dataBaseName, tableName, 1,
size);
Review Comment:
Fixed
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]