|
38 | 38 | import java.util.UUID; |
39 | 39 | import java.util.concurrent.BlockingQueue; |
40 | 40 | import java.util.concurrent.ConcurrentHashMap; |
| 41 | +import java.util.concurrent.CountDownLatch; |
41 | 42 | import java.util.concurrent.ExecutorService; |
42 | 43 | import java.util.concurrent.LinkedBlockingDeque; |
43 | 44 | import java.util.concurrent.LinkedBlockingQueue; |
@@ -80,6 +81,7 @@ public class DorisBatchStreamLoad implements Serializable { |
80 | 81 | private BlockingQueue<BatchRecordBuffer> flushQueue; |
81 | 82 | private final AtomicBoolean started; |
82 | 83 | private volatile boolean loadThreadAlive = false; |
| 84 | + private final CountDownLatch loadThreadStarted = new CountDownLatch(1); |
83 | 85 | private AtomicReference<Throwable> exception = new AtomicReference<>(null); |
84 | 86 | private long maxBlockedBytes; |
85 | 87 | private final AtomicLong currentCacheBytes = new AtomicLong(0L); |
@@ -110,6 +112,16 @@ public DorisBatchStreamLoad(long jobId, String targetDb) { |
110 | 112 | this.loadExecutorService.execute(loadAsyncExecutor); |
111 | 113 | this.targetDb = targetDb; |
112 | 114 | this.jobId = jobId; |
| 115 | + // Wait for the load thread to start |
| 116 | + try { |
| 117 | + if (!loadThreadStarted.await(10, TimeUnit.SECONDS)) { |
| 118 | + throw new RuntimeException("LoadAsyncExecutor thread startup timed out"); |
| 119 | + } |
| 120 | + } catch (InterruptedException e) { |
| 121 | + Thread.currentThread().interrupt(); |
| 122 | + throw new RuntimeException( |
| 123 | + "Thread interrupted while waiting for load thread to start", e); |
| 124 | + } |
113 | 125 | } |
114 | 126 |
|
115 | 127 | /** |
@@ -310,6 +322,7 @@ public LoadAsyncExecutor(int flushQueueSize, long jobId) { |
310 | 322 | public void run() { |
311 | 323 | LOG.info("LoadAsyncExecutor start for jobId {}", jobId); |
312 | 324 | loadThreadAlive = true; |
| 325 | + loadThreadStarted.countDown(); |
313 | 326 | List<BatchRecordBuffer> recordList = new ArrayList<>(flushQueueSize); |
314 | 327 | while (started.get()) { |
315 | 328 | recordList.clear(); |
|
0 commit comments