Skip to content

Commit 3506202

Browse files
morningmanclaude
andcommitted
[test](fe) Wait for the peer reclaim queue before checking coalesced requests
### What problem does this PR solve? Issue Number: None Related PR: #66717, #67726 Problem Summary: `peerReclaimCoalescesQueuedRequestsToTheLargestAdmission` checked the reclaim targets as soon as the second reclaim callback counted down its latch. At that point the second drain is still running: its callback has not returned, and it has not yet decided whether a request is left for another drain. A regression that leaves a request behind after the coalesced drain could therefore pass if the next drain ran after the assertion. The test now waits on two barriers before it checks the targets. Each barrier is a drain of a separate budget manager on the same process-wide reclaim thread. The first barrier runs after the second drain has finished and queued anything it left behind; the second runs after that queued drain. ### Release note None ### Check List (For Author) - Test: Unit Test - `MetaCacheBudgetManagerTest` (13) passes locally. With a mutation that keeps the request pending after a drain and pauses 50 ms at the start of each drain, the previous version of the test passes, and this version fails with targets `[10, 20, 20, 20]`. - Behavior changed: No - Does this need documentation: No Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 742c58b commit 3506202

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

‎fe/fe-connector/fe-connector-cache/src/test/java/org/apache/doris/connector/cache/MetaCacheBudgetManagerTest.java‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,10 @@ void peerReclaimCoalescesQueuedRequestsToTheLargestAdmission() throws Exception
279279
releaseFirstReclaim.countDown();
280280

281281
Assertions.assertTrue(secondReclaimFinished.await(10L, TimeUnit.SECONDS));
282+
// The second drain may still be running here. The first barrier runs after it has finished and
283+
// has queued any further drain for a request it left behind; the second barrier runs after that.
284+
awaitPeerReclaimBarrier();
285+
awaitPeerReclaimBarrier();
282286
Assertions.assertEquals(Arrays.asList(10L, 20L), new ArrayList<>(targets),
283287
"misses queued behind a running reclamation collapse into one request for the largest");
284288
} finally {
@@ -453,6 +457,30 @@ private static void awaitCount(List<?> observed, int expected) throws Interrupte
453457
Assertions.assertTrue(observed.size() >= expected, "reclaimer was not asked in time");
454458
}
455459

460+
/**
461+
* Returns once the process-wide peer-reclaim thread has run every drain queued before this call. The
462+
* barrier is a drain of a separate manager, so it never touches the budgets under test.
463+
*/
464+
private static void awaitPeerReclaimBarrier() throws InterruptedException {
465+
MetaCacheBudgetManager barrierManager = new MetaCacheBudgetManager(OptionalLong.of(1L));
466+
EntryBudget holder = barrierManager.createEntryBudget(1L, "barrier", "holder", "holder", NONE, NONE);
467+
EntryBudget requester = barrierManager.createEntryBudget(1L, "barrier", "requester", "requester", NONE, NONE);
468+
AdmissionReservation held = holder.tryReserve(1L).get();
469+
CountDownLatch reached = new CountDownLatch(1);
470+
holder.setReclaimer(target -> {
471+
reached.countDown();
472+
return 0L;
473+
});
474+
try {
475+
requester.requestPeerReclaim(1L);
476+
Assertions.assertTrue(reached.await(10L, TimeUnit.SECONDS), "peer-reclaim barrier did not run in time");
477+
} finally {
478+
held.release();
479+
holder.close();
480+
requester.close();
481+
}
482+
}
483+
456484
private static void await(CountDownLatch latch) {
457485
try {
458486
Assertions.assertTrue(latch.await(10L, TimeUnit.SECONDS));

0 commit comments

Comments
 (0)