nzw921rx commented on code in PR #10306: URL: https://github.com/apache/seatunnel/pull/10306#discussion_r3511325409
########## seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/task/error/ErrorHandler.java: ########## @@ -0,0 +1,222 @@ +/* + * 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.seatunnel.engine.server.task.error; + +import lombok.extern.slf4j.Slf4j; + +import java.io.Serializable; +import java.util.Objects; +import java.util.concurrent.atomic.AtomicLong; + +/** Error handler for row-level error counting, logging and threshold checks. */ +@Slf4j +public class ErrorHandler<T> implements Serializable, AutoCloseable { + + private final StageErrorConfig config; + private final ErrorSinkRowWriter<T> errorSinkWriter; + + private final AtomicLong totalRecords = new AtomicLong(0); + private final AtomicLong errorRecords = new AtomicLong(0); + + public ErrorHandler(StageErrorConfig config) { + this(config, null); + } + + public ErrorHandler(StageErrorConfig config, ErrorSinkRowWriter<T> errorSinkWriter) { + this.config = config; + this.errorSinkWriter = errorSinkWriter; + } + + public void incrementTotalRecords() { + if (config.getMode() == ErrorHandlerMode.DISABLE) { + return; + } + totalRecords.incrementAndGet(); + } + + public void onError(RowErrorContext ctx, T row, Throwable t) { + if (config.getMode() == ErrorHandlerMode.DISABLE) { + return; + } + + Objects.requireNonNull(ctx, "RowErrorContext must not be null"); Review Comment: `Objects.requireNonNull(ctx, "RowErrorContext must not be null");` It has been determined that ctx cannot be empty, and there are duplicate judgments in downstream logic. -- 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]
