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

[Enhancement] Return the first exception after retry #279

Merged
merged 1 commit into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
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 @@ -323,6 +323,7 @@ private boolean asyncFlush() throws Exception {
stopScheduler();
LOG.info(String.format("Async stream load: db[%s] table[%s] rows[%d] bytes[%d] label[%s].", flushData.getDatabase(), flushData.getTable(), flushData.getBatchCount(), flushData.getBatchSize(), flushData.getLabel()));
long startWithRetries = System.nanoTime();
Exception firstException = null;
for (int i = 0; i <= sinkOptions.getSinkMaxRetries(); i++) {
try {
long start = System.nanoTime();
Expand All @@ -349,8 +350,12 @@ private boolean asyncFlush() throws Exception {
totalFlushFailedTimes.inc();
}
LOG.warn("Failed to flush batch data to StarRocks, retry times = {}", i, e);
if (firstException == null) {
firstException = e;
}

if (i >= sinkOptions.getSinkMaxRetries()) {
throw e;
throw firstException;
}
if (e instanceof StarRocksStreamLoadFailedException && ((StarRocksStreamLoadFailedException)e).needReCreateLabel()) {
String oldLabel = flushData.getLabel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ enum State {
private volatile int numRetries;
private volatile long lastFailTimeMs;

// First exception if retry many times
private volatile Throwable firstException;

public TransactionTableRegion(String uniqueKey,
String database,
String table,
Expand Down Expand Up @@ -270,10 +273,17 @@ public boolean commit() {

@Override
public void fail(Throwable e) {
if (firstException == null) {
firstException = e;
}

if (numRetries >= maxRetries || !isRetryable(e)) {
manager.callback(e);
LOG.error("Failed to flush data for db: {}, table: {} after {} times retry, the last exception is",
database, table, numRetries, e);
manager.callback(firstException);
return;
}

responseFuture = null;
numRetries += 1;
lastFailTimeMs = System.currentTimeMillis();
Expand All @@ -291,6 +301,7 @@ public void complete(StreamLoadResponse response) {
response.setFlushRows(chunk.numRows());
manager.callback(response);
numRetries = 0;
firstException = null;

LOG.info("Stream load flushed, db: {}, table: {}, label : {}", database, table, label);
if (!inactiveChunks.isEmpty()) {
Expand Down
Loading