diff --git a/s3stream/src/main/java/com/automq/stream/s3/cache/LogCache.java b/s3stream/src/main/java/com/automq/stream/s3/cache/LogCache.java index c0d9051c07..a65008bb84 100644 --- a/s3stream/src/main/java/com/automq/stream/s3/cache/LogCache.java +++ b/s3stream/src/main/java/com/automq/stream/s3/cache/LogCache.java @@ -380,13 +380,13 @@ public long capacity() { } public void clearStreamRecords(long streamId) { - readLock.lock(); + writeLock.lock(); try { for (LogCacheBlock block : blocks) { block.free(streamId); } } finally { - readLock.unlock(); + writeLock.unlock(); } } @@ -519,12 +519,10 @@ public void free() { } public void free(long streamId) { - suppress(() -> { - StreamCache streamCache = map.remove(streamId); - if (streamCache != null) { - streamCache.free(); - } - }, LOGGER); + StreamCache streamCache = map.remove(streamId); + if (streamCache != null) { + LOG_CACHE_ASYNC_EXECUTOR.execute(() -> suppress(streamCache::free, LOGGER)); + } } public void addFreeListener(FreeListener freeListener) {