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

feat(s3stream): add storage status check #1717

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
10 changes: 9 additions & 1 deletion s3stream/src/main/java/com/automq/stream/s3/S3Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ public class S3Storage implements Storage {
ThreadUtils.createThreadFactory("storage-timeout-detect", true), 1, TimeUnit.SECONDS, 100);
private long lastLogTimestamp = 0L;
private volatile double maxDataWriteRate = 0.0;
private volatile boolean shutdown;

private final AtomicLong pendingUploadBytes = new AtomicLong(0L);

Expand Down Expand Up @@ -377,6 +378,7 @@ void recover0(WriteAheadLog deltaWAL, StreamManager streamManager, ObjectManager

@Override
public void shutdown() {
shutdown = true;
drainBackoffTask.cancel(false);
for (WalWriteRequest request : backoffRecords) {
request.cf.completeExceptionally(new IOException("S3Storage is shutdown"));
Expand Down Expand Up @@ -417,7 +419,7 @@ public CompletableFuture<Void> append(AppendContext context, StreamRecordBatch s
* @return backoff status.
*/
public boolean append0(AppendContext context, WalWriteRequest request, boolean fromBackoff) {
// TODO: storage status check, fast fail the request when storage closed.
checkStatus(request);
if (!fromBackoff && !backoffRecords.isEmpty()) {
backoffRecords.offer(request);
return true;
Expand Down Expand Up @@ -574,6 +576,12 @@ private void handleTimeout(Timeout timeout, long streamId, long startOffset, lon
}
}

public void checkStatus(WalWriteRequest request) {
if (shutdown) {
request.cf.completeExceptionally(new IOException("S3Storage is shutdown"));
}
}

private void continuousCheck(List<StreamRecordBatch> records) {
long expectStartOffset = -1L;
for (StreamRecordBatch record : records) {
Expand Down
Loading