Skip to content

Commit 451566e

Browse files
authored
fix(logcache): guard cache free with writeLock (#3022)
Signed-off-by: Robin Han <[email protected]>
1 parent 42c42c2 commit 451566e

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

s3stream/src/main/java/com/automq/stream/s3/cache/LogCache.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -380,13 +380,13 @@ public long capacity() {
380380
}
381381

382382
public void clearStreamRecords(long streamId) {
383-
readLock.lock();
383+
writeLock.lock();
384384
try {
385385
for (LogCacheBlock block : blocks) {
386386
block.free(streamId);
387387
}
388388
} finally {
389-
readLock.unlock();
389+
writeLock.unlock();
390390
}
391391
}
392392

@@ -519,12 +519,10 @@ public void free() {
519519
}
520520

521521
public void free(long streamId) {
522-
suppress(() -> {
523-
StreamCache streamCache = map.remove(streamId);
524-
if (streamCache != null) {
525-
streamCache.free();
526-
}
527-
}, LOGGER);
522+
StreamCache streamCache = map.remove(streamId);
523+
if (streamCache != null) {
524+
LOG_CACHE_ASYNC_EXECUTOR.execute(() -> suppress(streamCache::free, LOGGER));
525+
}
528526
}
529527

530528
public void addFreeListener(FreeListener freeListener) {

0 commit comments

Comments
 (0)