Skip to content

Commit

Permalink
Retry logging logic. (#252)
Browse files Browse the repository at this point in the history
  • Loading branch information
anjagruenheid authored Mar 7, 2024
1 parent 65297e8 commit b3c1dc6
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/main/java/com/microsoft/lst_bench/client/JDBCConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,24 @@ private QueryResult execute(String sqlText, boolean ignoreResults) throws Client
}
// Log verbosely, if enabled.
if (this.showWarnings && LOGGER.isWarnEnabled()) {
LOGGER.warn(createWarningString(s));
LOGGER.warn(
createWarningString(
s,
/* prefix= */ errorCount > 0
? ("Retried query, error count: " + errorCount)
: ""));
}
// Return here if successful.
return queryResult;
} catch (Exception e) {
queryResult = null;
String lastErrorMsg =
"Query execution ("
+ this.maxNumRetries
+ " retries) unsuccessful; "
+ "Warnings: "
+ createWarningString(s)
"Query execution attempt "
+ (errorCount + 1)
+ " unsuccessful, will retry "
+ (this.maxNumRetries - errorCount)
+ " more times; "
+ createWarningString(s, /* prefix= */ "")
+ "stack trace: "
+ ExceptionUtils.getStackTrace(e);

Expand All @@ -98,7 +104,6 @@ private QueryResult execute(String sqlText, boolean ignoreResults) throws Client
LOGGER.warn(lastErrorMsg);
}
errorCount++;

} finally {
if (s != null) {
try {
Expand Down Expand Up @@ -130,7 +135,7 @@ public void close() throws ClientException {
}
}

private String createWarningString(Statement s) throws ClientException {
private String createWarningString(Statement s, String prefix) throws ClientException {
List<String> warningList = new ArrayList<>();

if (s != null) {
Expand All @@ -146,6 +151,6 @@ private String createWarningString(Statement s) throws ClientException {
}
}

return String.join("; ", warningList);
return prefix + ";" + String.join("; ", warningList);
}
}

0 comments on commit b3c1dc6

Please sign in to comment.