Skip to content

Commit 713efcf

Browse files
authored
[bugfix] do not remove from waiters before segment allocated (#974)
1 parent e9ced05 commit 713efcf

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

fluss-common/src/main/java/com/alibaba/fluss/memory/LazyMemorySegmentPool.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ public void returnAll(List<MemorySegment> memory) {
231231
pageUsage = newPageUsage;
232232
cachePages.addAll(memory);
233233
for (int i = 0; i < memory.size() && !waiters.isEmpty(); i++) {
234-
waiters.pollFirst().signal();
234+
waiters.peekFirst().signal();
235235
}
236236
});
237237
}

fluss-common/src/test/java/com/alibaba/fluss/memory/LazyMemorySegmentPoolTest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,30 @@ void testCannotAllocateMorePagesThanAvailable() throws Exception {
193193
.hasMessageContaining("Total pages: 2. Requested pages: 3");
194194
}
195195

196+
@Test
197+
void testComplexDelayedAllocation() throws Exception {
198+
LazyMemorySegmentPool pool = buildLazyMemorySegmentSource(8, 1024, Long.MAX_VALUE, 1024);
199+
// allocate all segments
200+
List<MemorySegment> segments1 = pool.allocatePages(4);
201+
List<MemorySegment> segments2 = pool.allocatePages(4);
202+
203+
CountDownLatch doDealloc1 = asyncReturnAll(pool, segments1);
204+
CountDownLatch doDealloc2 = asyncReturnAll(pool, segments2);
205+
206+
// should block until all memory is returned
207+
CountDownLatch allocation = asyncAllocatePages(pool, 8);
208+
assertThat(allocation.getCount()).isEqualTo(1);
209+
// return a part of memory
210+
doDealloc1.countDown();
211+
212+
// no enough memory allocate
213+
assertThat(allocation.await(1, TimeUnit.SECONDS)).isFalse();
214+
215+
doDealloc2.countDown();
216+
// have enough memory to allocate
217+
assertThat(allocation.await(1, TimeUnit.SECONDS)).isTrue();
218+
}
219+
196220
@Test
197221
void testDelayedAllocation() throws Exception {
198222
LazyMemorySegmentPool pool = buildLazyMemorySegmentSource(5, 1024, Long.MAX_VALUE, 1024);

0 commit comments

Comments
 (0)