531651225 commented on code in PR #4752: URL: https://github.com/apache/incubator-seatunnel/pull/4752#discussion_r1196003413
########## seatunnel-connectors-v2/connector-starrocks/src/main/java/org/apache/seatunnel/connectors/seatunnel/starrocks/client/sink/StarRocksSinkManagerV2.java: ########## @@ -0,0 +1,274 @@ +/* + * 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.connectors.seatunnel.starrocks.client.sink; + +import org.apache.seatunnel.api.sink.SinkWriter; +import org.apache.seatunnel.common.utils.JsonUtils; +import org.apache.seatunnel.connectors.seatunnel.starrocks.client.sink.entity.StreamLoadResponse; +import org.apache.seatunnel.connectors.seatunnel.starrocks.config.SinkConfig; +import org.apache.seatunnel.connectors.seatunnel.starrocks.sink.committer.StarRocksCommitInfo; +import org.apache.seatunnel.connectors.seatunnel.starrocks.sink.state.StarRocksSinkState; + +import com.google.common.collect.Lists; +import lombok.extern.slf4j.Slf4j; + +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Optional; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.locks.Condition; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.LockSupport; +import java.util.concurrent.locks.ReentrantLock; + +@Slf4j +public class StarRocksSinkManagerV2 implements StreamLoadManager { + + private Thread manager; + private Thread current; + private volatile Throwable flushException; + private TableRegion tableRegion; + private final long flushFrequencyMs; + private SinkConfig sinkConfig; + private TransactionStreamLoader streamLoader; + protected long checkpointId = 0L; + protected String transactionId; + + private final Lock lock = new ReentrantLock(); + + private Condition writable = lock.newCondition(); + private Condition flushable = lock.newCondition(); + + private volatile boolean savepoint; + + private final long maxCacheBytes; + private long rowCountForCurrentTransaction; + protected int subTaskIndex; + private LabelGenerator labelGenerator; + + public StarRocksSinkManagerV2( + LabelGenerator labelGenerator, SinkConfig sinkConfig, SinkWriter.Context context) { + this.sinkConfig = sinkConfig; + this.flushFrequencyMs = sinkConfig.getFlushFrequencyMs(); + this.maxCacheBytes = sinkConfig.getBatchMaxBytes(); + this.streamLoader = new TransactionStreamLoader(sinkConfig, this); + this.tableRegion = new TransactionTableRegion(this, sinkConfig, streamLoader); + this.subTaskIndex = context.getIndexOfSubtask(); + this.labelGenerator = labelGenerator; + init(); + } + + @Override + public void init() { + this.manager = Review Comment: Creating a new thread is used to trigger flush batch data to stream load within the interval specified in "flush_frequency_ms". Batch writes can be triggered multiple times within a single transaction -- 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]
