Skip to content
This repository

RetryRunner Dies If ThriftCluster Was Not Created Via HFactory. #429

Merged
merged 1 commit into from about 2 years ago

2 participants

cherron Patricio Echague
cherron

Fixes issues #423 and #424.

Patricio Echague
Collaborator

did you have the chance to test it ?

Yes, it has been tested and has been running in production for about a week.

Collaborator

Thanks.

Patricio Echague patricioe merged commit db74f37 into from
Patricio Echague patricioe closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Feb 29, 2012
RetryRunner Dies If ThriftCluster Was Not Created Via HFactory. Fixes…
… issues #423 and #424.
903ab5e
This page is out of date. Refresh to see the latest.
55  core/src/main/java/me/prettyprint/cassandra/connection/CassandraHostRetryService.java
@@ -109,11 +109,19 @@ public void flushQueue() {
109 109
 
110 110
     @Override
111 111
     public void run() {
112  
-      if( downedHostQueue.isEmpty()) {
113  
-          log.debug("Retry service fired... nothing to do.");
114  
-          return;
  112
+      if(!downedHostQueue.isEmpty()) {
  113
+        log.debug("Retry service fired, checking {} downed hosts.", downedHostQueue.size());
  114
+        try {
  115
+          retryDownedHosts();
  116
+        } catch (Throwable t) {
  117
+          log.error("An error occurred while retrying one or more downed hosts", t);
  118
+        }
  119
+      } else {
  120
+        log.debug("Retry service fired... nothing to do.");
115 121
       }
116  
-
  122
+    }
  123
+    
  124
+    private void retryDownedHosts() {
117 125
       // we only check the ring if we have nodes in the cluster to query
118 126
       boolean checkRing = connectionManager.getHosts().size() > 0 ? true : false;
119 127
       Set<CassandraHost> ringInfo = null;
@@ -135,8 +143,9 @@ public void run() {
135 143
         }
136 144
 
137 145
         // The host may have been removed from the ring. It makes no sense to keep trying
138  
-        // to connect to it.
139  
-        if ( checkRing && !ringInfo.contains(cassandraHost)) {
  146
+        // to connect to it. If the ThriftCluster is unknown to HFactory, ringInfo may not be available,
  147
+        // in which case we have no choice but to continue checking.
  148
+        if ( checkRing && ringInfo != null && !ringInfo.contains(cassandraHost)) {
140 149
           log.info("Removing host " + cassandraHost.getName() + " - It does no longer exist in the ring.");
141 150
           iter.remove();
142 151
           continue;
@@ -152,31 +161,35 @@ public void run() {
152 161
             iter.remove();
153 162
           }
154 163
         }
155  
-      }
  164
+      }      
156 165
     }
157 166
 
158 167
 
159 168
     private Set<CassandraHost> buildRingInfo() {
160  
-      Set<CassandraHost> ringInfo = new HashSet<CassandraHost>();
161 169
 
162 170
       ThriftCluster cluster = (ThriftCluster) HFactory.getCluster(connectionManager.getClusterName());
163 171
 
164  
-      for(KeyspaceDefinition keyspaceDefinition: cluster.describeKeyspaces()) {
165  
-        if (!keyspaceDefinition.getName().equals(Keyspace.KEYSPACE_SYSTEM)) {
166  
-          List<TokenRange> tokenRanges = cluster.describeRing(keyspaceDefinition.getName());
167  
-          for (TokenRange tokenRange : tokenRanges) {
168  
-            for (String host : tokenRange.getEndpoints()) {
169  
-              CassandraHost aHost = new CassandraHost(host, cassandraHostConfigurator.getPort());
170  
-              if (!ringInfo.contains(aHost) ) {
171  
-                ringInfo.add(aHost);
  172
+      // ThriftCluster is not exclusively created & cached by HFactory. E.g. Some users instantiate directly via Spring.
  173
+      if(cluster != null) {
  174
+        Set<CassandraHost> ringInfo = new HashSet<CassandraHost>();
  175
+        for(KeyspaceDefinition keyspaceDefinition: cluster.describeKeyspaces()) {
  176
+          if (!keyspaceDefinition.getName().equals(Keyspace.KEYSPACE_SYSTEM)) {
  177
+            List<TokenRange> tokenRanges = cluster.describeRing(keyspaceDefinition.getName());
  178
+            for (TokenRange tokenRange : tokenRanges) {
  179
+              for (String host : tokenRange.getEndpoints()) {
  180
+                CassandraHost aHost = new CassandraHost(host, cassandraHostConfigurator.getPort());
  181
+                if (!ringInfo.contains(aHost) ) {
  182
+                  ringInfo.add(aHost);
  183
+                }
172 184
               }
173 185
             }
  186
+            break;
174 187
           }
175  
-          break;
176 188
         }
  189
+        return ringInfo;
  190
+      } else {
  191
+        return null;
177 192
       }
178  
-
179  
-      return ringInfo;
180 193
     }
181 194
   }
182 195
 
@@ -193,8 +206,8 @@ private boolean verifyConnection(CassandraHost cassandraHost) {
193 206
       client.close();
194 207
     } catch (HectorTransportException he) {
195 208
       log.warn("Downed {} host still appears to be down: {}", cassandraHost, he.getMessage());
196  
-    } catch (Exception ex) {
197  
-      log.error("Downed Host retry failed attempt to verify CassandraHost", ex);
  209
+    } catch (Throwable t) {
  210
+      log.error("Downed Host retry failed attempt to verify CassandraHost", t);
198 211
     }
199 212
     return found;
200 213
   }
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.