From b3c1dc65a7fe30a2bc37899d6d317cad188fb6a3 Mon Sep 17 00:00:00 2001 From: anjagruenheid <87397397+anjagruenheid@users.noreply.github.com> Date: Thu, 7 Mar 2024 20:02:06 +0100 Subject: [PATCH] Retry logging logic. (#252) --- .../lst_bench/client/JDBCConnection.java | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/microsoft/lst_bench/client/JDBCConnection.java b/src/main/java/com/microsoft/lst_bench/client/JDBCConnection.java index 4c8a7a43..a15e5f86 100644 --- a/src/main/java/com/microsoft/lst_bench/client/JDBCConnection.java +++ b/src/main/java/com/microsoft/lst_bench/client/JDBCConnection.java @@ -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); @@ -98,7 +104,6 @@ private QueryResult execute(String sqlText, boolean ignoreResults) throws Client LOGGER.warn(lastErrorMsg); } errorCount++; - } finally { if (s != null) { try { @@ -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 warningList = new ArrayList<>(); if (s != null) { @@ -146,6 +151,6 @@ private String createWarningString(Statement s) throws ClientException { } } - return String.join("; ", warningList); + return prefix + ";" + String.join("; ", warningList); } }