Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

fix(s3stream): try fix append memory leak #385

Merged
merged 1 commit into from
Oct 19, 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
9 changes: 7 additions & 2 deletions s3stream/src/main/java/com/automq/stream/s3/S3Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ public void shutdown() {

@Override
public CompletableFuture<Void> append(StreamRecordBatch streamRecord) {

CompletableFuture<Void> cf = new CompletableFuture<>();
append0(streamRecord, cf);
return cf;
Expand Down Expand Up @@ -240,6 +239,7 @@ public void append0(StreamRecordBatch streamRecord, CompletableFuture<Void> cf)
handleAppendRequest(writeRequest);
appendResult.future().thenAccept(nil -> handleAppendCallback(writeRequest));
cf.whenComplete((nil, ex) -> {
streamRecord.release();
OperationMetricsStats.getOrCreateOperationMetrics(S3Operation.APPEND_STORAGE).operationCount.inc();
OperationMetricsStats.getOrCreateOperationMetrics(S3Operation.APPEND_STORAGE).operationTime.update(timerUtil.elapsed());
});
Expand Down Expand Up @@ -305,7 +305,11 @@ private CompletableFuture<ReadDataBlock> read0(long streamId, long startOffset,
}
continuousCheck(rst);
return new ReadDataBlock(rst);
}, mainReadExecutor);
}, mainReadExecutor).whenComplete((rst, ex) -> {
if (ex != null) {
logCacheRecords.forEach(StreamRecordBatch::release);
}
});
}

private void continuousCheck(List<StreamRecordBatch> records) {
Expand Down Expand Up @@ -350,6 +354,7 @@ private void handleAppendCallback(WalWriteRequest request) {
private void handleAppendCallback0(WalWriteRequest request) {
List<WalWriteRequest> waitingAckRequests = callbackSequencer.after(request);
long walConfirmOffset = callbackSequencer.getWALConfirmOffset();
waitingAckRequests.forEach(r -> r.record.retain());
mainReadExecutor.execute(() -> {
for (WalWriteRequest waitingAckRequest : waitingAckRequests) {
if (logCache.put(waitingAckRequest.record)) {
Expand Down