phoenix-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [phoenix] vincentpoon commented on a change in pull request #453: [PHOENIX-5172] Harden the PQS canary synth test tool with retry mechanism and more logging
Date Wed, 06 Mar 2019 19:04:39 GMT
vincentpoon commented on a change in pull request #453: [PHOENIX-5172] Harden the PQS canary
synth test tool with retry mechanism and more logging
URL: https://github.com/apache/phoenix/pull/453#discussion_r263088123
 
 

 ##########
 File path: phoenix-core/src/main/java/org/apache/phoenix/tool/PhoenixCanaryTool.java
 ##########
 @@ -464,11 +364,60 @@ public Void call() {
         return 0;
     }
 
+    private static Connection getConnectionWithRetry(String connectionURL, Properties connProps){
+        Connection connection = null;
+        boolean isSuccess;
+        int currentAttempt = 1;
+        do {
+            try {
+                connection = DriverManager.getConnection(connectionURL, connProps);
+                LOG.info("Successfully established connection within "
+                        +currentAttempt+ "/" + MAX_ATTEMPTS + " attempts");
+                LOG.info("connectionURL :" +connectionURL);
+                LOG.info("connProps :" + connProps);
+                isSuccess = true;
+            } catch (Exception e) {
+                LOG.error("Failed to get connection." +
+                        " Exhausted attempts : "+ currentAttempt+ "/" + MAX_ATTEMPTS);
+                LOG.error("connectionURL :" + connectionURL);
+                LOG.error("connProps :" + connProps);
+                LOG.error("Something went wrong while getting Connection", e);
+                isSuccess = false;
+                sleepBeforeRetry(currentAttempt);
+                currentAttempt++;
+            }
+        } while (isSuccess != true && currentAttempt <= MAX_ATTEMPTS);
+        return connection;
+    }
+
+    private static void sleepBeforeRetry(int attempt) {
+        final int sleepTimesInSeconds= getSleepTime(attempt);
+        try {
+            LOG.info("Sleeping for " + sleepTimesInSeconds +" seconds");
+            TimeUnit.SECONDS.sleep(sleepTimesInSeconds);
+        } catch (InterruptedException e) {
+            LOG.error("Thread interrupted", e);
+        }
+    }
+
+    //fibonacci sequence of sleep interval
+    private static int getSleepTime(int attempt) {
+        if(attempt<=0){
+            LOG.error("INVALID ATTEMPT!");
+            return 0;
+        }
+        if(attempt ==1 || attempt ==2) {
+            return 1;
+        }
+        else {
+            return getSleepTime(attempt-1)+getSleepTime(attempt-2);
+        }
+    }
+
     public static void main(final String[] args) {
-        int result = 0;
         try {
             LOG.info("Starting Phoenix Canary Test tool...");
-            result = ToolRunner.run(new PhoenixCanaryTool(), args);
+            ToolRunner.run(new PhoenixCanaryTool(), args);
 
 Review comment:
   use System.exit() to exit the program with an error code if there was an exception

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message