Jacob Fahlenkamp
09/05/2025, 1:10 PMimport com.starrocks.connector.flink.StarRocksSink;
import com.starrocks.connector.flink.table.sink.StarRocksSinkOptions;
import lombok.Data;
import lombok.val;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.configuration.RestOptions;
import org.apache.flink.runtime.testutils.MiniClusterResourceConfiguration;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.table.api.DataTypes;
import org.apache.flink.table.api.TableSchema;
import org.apache.flink.test.junit5.MiniClusterExtension;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.testcontainers.containers.DockerComposeContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import java.io.File;
import java.sql.DriverManager;
@Data
@Testcontainers
public class DebugIT {
@RegisterExtension
public static final MiniClusterExtension FLINK_CLUSTER = new MiniClusterExtension(
new MiniClusterResourceConfiguration.Builder()
.setNumberSlotsPerTaskManager(1)
.setNumberTaskManagers(1)
.setConfiguration(new Configuration().set(RestOptions.PORT, 8081))
.build());
@Container
static DockerComposeContainer? environment =
new DockerComposeContainer<>(new File("db/docker-compose.yml"))
.withExposedService("starrocks", 9030)
.withExposedService("starrocks", 8040)
.withExposedService("starrocks", 8030)
.withExposedService("starrocks", 9060);
@BeforeAll
static void beforeAll() {
Runtime.getRuntime().addShutdownHook(new Thread(environment::stop));
}
@Data
public static class Pojo {
long id;
}
@Test
void integrationTest() throws Exception {
environment.start();
val jdbcUrl = "jdbc:mysql://localhost:9030";
val user = "root";
val password = "";
try (val con = DriverManager.getConnection(jdbcUrl, user, password);
val stmt = con.createStatement()) {
stmt.executeUpdate("CREATE DATABASE IF NOT EXISTS DB;");
stmt.executeUpdate("""
CREATE TABLE IF NOT EXISTS DB.TEST
(
ID BIGINT NOT NULL
);""");
}
val env = StreamExecutionEnvironment.getExecutionEnvironment();
val stream = env.fromData(new Pojo());
val schema = TableSchema.builder().field("ID", DataTypes.BIGINT()).build();
val options = StarRocksSinkOptions
.builder()
.withProperty("jdbc-url", jdbcUrl)
.withProperty("load-url", "localhost:8030")
.withProperty("table-name", "TEST")
.withProperty("database-name", "DB")
.withProperty("username", "root")
.withProperty("password", "")
.withProperty("sink.label-prefix", "my-prefix")
.withProperty("sink.semantic", "exactly-once").build();
val sink = StarRocksSink.Pojosink(schema, options, (objects, o) -> objects[0] = o.id);
stream.addSink(sink);
env.execute();
try (val con = DriverManager.getConnection(jdbcUrl, user, password);
val stmt = con.createStatement()) {
val result = stmt.executeQuery("select * from DB.TEST");
Assertions.assertTrue(result.next()); // this assert fails
}
}
}
Here is what I see in the output from starrocks:
2025-09-05 15:00:45 INFO StreamLoadManagerV2:351 - Stream load manager flush
2025-09-05 15:00:45 INFO TransactionTableRegion:269 - Flush db: DB, table: TEST, label: null, cacheBytes: 1, cacheRows: 1, reason: FORCE
2025-09-05 15:00:45 INFO TransactionTableRegion:409 - Stream load chunk, db: DB, table: TEST, numRows: 1, rowBytes: 1, chunkBytes: 2
2025-09-05 15:00:45 INFO TransactionStreamLoader:117 - Transaction start, label : my-prefix-TEST-0-1
2025-09-05 15:00:45 INFO TransactionStreamLoader:133 - Transaction start, db: DB, table: TEST, label: my-prefix-TEST-0-1, request : POST http://localhost:8030/api/transaction/begin HTTP/1.1
2025-09-05 15:00:45 INFO TransactionStreamLoader:140 - Transaction started, db: DB, table: TEST, label: my-prefix-TEST-0-1, body : {
"Status": "OK",
"Message": "",
"Label": "my-prefix-TEST-0-1",
"TxnId": 15016,
"BeginTxnTimeMs": 13
}
2025-09-05 15:00:45 INFO DefaultStreamLoader:306 - Stream loading, label : my-prefix-TEST-0-1, region : DB-TEST, request : PUT http://localhost:8030/api/transaction/load HTTP/1.1
2025-09-05 15:00:45 INFO ChunkHttpEntity:104 - Write entity for table DB-TEST, size:2, time:1446us
2025-09-05 15:00:45 INFO DefaultStreamLoader:314 - Stream load completed, label : my-prefix-TEST-0-1, database : DB, table : TEST, body : {
"Status": "OK",
"Message": "",
"Label": "my-prefix-TEST-0-1",
"TxnId": 15016,
"LoadBytes": 2,
"StreamLoadPlanTimeMs": 50,
"ReceivedDataTimeMs": 0
}
2025-09-05 15:00:45 INFO StreamLoadManagerV2:300 - Receive load response, cacheByteBeforeFlush: 1, currentCacheBytes: 0, totalFlushRows : 1
2025-09-05 15:00:45 INFO TransactionTableRegion:396 - Stream load completed, db: DB, table: TEST, label: my-prefix-TEST-0-1, cacheBytes: 0, cacheRows: 0
2025-09-05 15:00:45 INFO StarRocksDynamicSinkFunctionV2:248 - Close sink function
2025-09-05 15:00:45 INFO StreamLoadManagerV2:351 - Stream load manager flush
2025-09-05 15:00:45 INFO TransactionStreamLoader:318 - Transaction rollback, label : my-prefix-TEST-0-1
2025-09-05 15:00:45 INFO TransactionStreamLoader:332 - Transaction rollback, label: my-prefix-TEST-0-1, body : {
"Status": "OK",
"Message": "",
"Label": "my-prefix-TEST-0-1"
}
2025-09-05 15:00:45 INFO StreamLoadManagerV2:412 - StreamLoadManagerV2 close, loadMetrics: LoadMetrics{startTimeNano=889074820011000, totalRunningTimeNano=272783800, numberOfSuccessLoad=1, totalSuccessLoadBytes=1, totalSuccessLoadRows=1, totalSuccessLoadTimeNano=65970100, numberOfFailedLoad=0, numberWriteTriggerFlush=0, numberWriteBlock=0, totalWriteBlockTimeNano=0}, flushAndCommit: FlushAndCommitStrategy{expectDelayTime=300000, scanFrequency=50, ageThreshold=6000, maxCacheBytes=94371840, enableAutoCommit=false, numAgeTriggerFlush=0, numCacheTriggerFlush=0, numTableTriggerFlush=0}
2025-09-05 15:00:45 INFO DefaultStreamLoader:140 - Default Stream loader closed
Why is there a transaction rollback? Does the sink not work in batch mode because there is no checkpoint in batch mode?Евгений Шишкин
09/05/2025, 1:20 PMJacob Fahlenkamp
09/05/2025, 1:25 PM.withProperty("sink.label-prefix", "my-prefix")
.withProperty("sink.semantic", "exactly-once")Jacob Fahlenkamp
09/05/2025, 7:05 PMЕвгений Шишкин
09/05/2025, 7:22 PMЕвгений Шишкин
09/05/2025, 7:25 PMЕвгений Шишкин
09/05/2025, 7:26 PMJacob Fahlenkamp
09/05/2025, 7:37 PMJacob Fahlenkamp
09/05/2025, 8:22 PMBATCH mode make sure it uses the Unified Sink API as proposed in FLIP-143."
So to have a sink which supports exactly once in both streaming and batch mode, it needs to be implemented with the new Sink interface. Looking at the starrocks sink, it implements the deprecated SinkFunction interface. So I think this is not a bug, just a consequence of the starrocks sink being implemented with the older API.Евгений Шишкин
09/05/2025, 8:29 PM