为了避免在写入完成之前其他线程写入同一个分区而导致事务冲突,如何判断PartitionedTableAppender是否已经写入完成?
Exception caught in getHistory: Task [-2] come across exception : 127.0.0.1:8503 Server response: '<ChunkInTransaction>The openChunks operation failed because the chunk '/candle_db/202403M/6v' is currently locked and in use by transaction 35087. RefId:S00002
可以调用
waitForThreadCompletion()
进行同步,以阻塞的方式等待所有写入任务完成。请参考以下内容
scripts:
String dbPath = "dfs://test";
String tableName = "pt";
int threadCount = 10;
DBConnectionPool connPool = new ExclusiveDBConnectionPool(host, port, username, password, threadCount, false, false);
PartitionedTableAppender appender = new PartitionedTableAppender(dbPath, tableName, "symbol", connPool);
BasicTable data = (BasicTable) conn.run("select * from t limit 10000");
int rows = appender.append(data);
System.out.println(rows + " rows inserted.");
connPool.waitForThreadCompletion();