SiyaoIsHiding opened a new pull request, #1902:
URL: https://github.com/apache/cassandra-java-driver/pull/1902

   I implemented the retry mechanism in two ways. Apart from the current one, 
the following also works:
   ```java
     @NonNull
     protected BufferedReader fetchProxyMetadata(
         @NonNull URL metadataServiceUrl, @NonNull SSLContext sslContext) 
throws IOException {
       HttpsURLConnection connection = null;
       int attempt = 0;
       while(attempt < METADATA_RETRY_MAX_ATTEMPTS){
         try {
           connection = (HttpsURLConnection) 
metadataServiceUrl.openConnection();
           connection.setSSLSocketFactory(sslContext.getSocketFactory());
           connection.setRequestMethod("GET");
           connection.setRequestProperty("host", "localhost");
           return new BufferedReader(
                   new InputStreamReader(connection.getInputStream(), 
StandardCharsets.UTF_8));
         } catch (ConnectException e) {
           throw new IllegalStateException(
                   "Unable to connect to cloud metadata service. Please make 
sure your cluster is not parked or terminated",
                   e);
         } catch (UnknownHostException e) {
           throw new IllegalStateException(
                   "Unable to resolve host for cloud metadata service. Please 
make sure your cluster is not terminated",
                   e);
         } catch (IOException e) {
           attempt++;
           // if this is the last try, throw
           // else if status code not 200, retry; otherwise, throw
           if (attempt != METADATA_RETRY_MAX_ATTEMPTS && connection != null && 
connection.getResponseCode() != 200) {
             try {
               Thread.sleep(METADATA_RETRY_INITIAL_DELAY_MS);
             } catch (InterruptedException interruptedException) {
               Thread.currentThread().interrupt();
               throw new IOException("Interrupted while waiting to retry 
metadata fetch", interruptedException);
             }
           } else {
             throw e;
           }
         }
       }
       throw new DriverTimeoutException("Unable to fetch metadata from cloud 
metadata service"); // dead code
     }
   ```
   We could discuss those design decisions in our next meeting :)


-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to