Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix(s3stream): guard BlockCache OOM handle with lock #775

Merged
merged 1 commit into from
Dec 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ void put0(long streamId, long raAsyncOffset, long raEndOffset, List<StreamRecord
}

// ensure the cache size.
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("[S3BlockCache] block cache size: {}/{}, ensure size: {} ", this.size.get(), maxSize, size);
}
ensureCapacity(size);

// split to 1MB cache blocks which one block contains sequential records.
Expand Down Expand Up @@ -332,10 +335,6 @@ private void ensureCapacity(int size) {
}

private int ensureCapacity0(int size, boolean forceEvict) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("[S3BlockCache] block cache size: {}/{}, ensure size: {} ", this.size.get(), maxSize, size);
}

if (!forceEvict && (maxSize - this.size.get() >= size)) {
return 0;
}
Expand All @@ -355,8 +354,8 @@ private int ensureCapacity0(int size, boolean forceEvict) {
if (cacheBlock == null) {
LOGGER.error("[BUG] Cannot find stream cache block: {} {}", entry.getKey().streamId, entry.getKey().startOffset);
} else {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("[S3BlockCache] evict block, stream={}, {}-{}, total bytes: {} ", entry.getKey().streamId, cacheBlock.firstOffset, cacheBlock.lastOffset, cacheBlock.size);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("[S3BlockCache] evict block, stream={}, {}-{}, total bytes: {} ", entry.getKey().streamId, cacheBlock.firstOffset, cacheBlock.lastOffset, cacheBlock.size);
}
cacheBlock.free();
evictBytes += cacheBlock.size;
Expand Down Expand Up @@ -403,11 +402,14 @@ private void put(long streamId, StreamCache streamCache, CacheBlock cacheBlock)

@Override
public int handle(int memoryRequired) {
writeLock.lock();
try {
return ensureCapacity0(memoryRequired, true);
} catch (Throwable e) {
LOGGER.error("[UNEXPECTED] handle OOM failed", e);
return 0;
} finally {
writeLock.unlock();
}
}

Expand Down
Loading