]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
cassandra: Cleanup - Move code to query_error_want_fallback()
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Thu, 3 May 2018 13:58:21 +0000 (16:58 +0300)
committerVille Savolainen <ville.savolainen@dovecot.fi>
Fri, 18 May 2018 07:46:11 +0000 (10:46 +0300)
This allows extending it more easily.

src/lib-sql/driver-cassandra.c

index 27603567d77cbccb93f433252bffdf41051e0482..b6a3f2a301e79f84fa83ca336b9eb5127e1c1f24 100644 (file)
@@ -908,6 +908,31 @@ static void counters_inc_error(struct cassandra_db *db, CassError error)
        }
 }
 
+static bool query_error_want_fallback(CassError error)
+{
+       switch (error) {
+       case CASS_ERROR_LIB_NO_HOSTS_AVAILABLE:
+               /* The client library couldn't connect to enough Cassandra
+                  nodes. The error message text is the same as for
+                  CASS_ERROR_SERVER_UNAVAILABLE. */
+               return TRUE;
+       case CASS_ERROR_SERVER_UNAVAILABLE:
+               /* Cassandra server knows that there aren't enough nodes
+                  available. "All hosts in current policy attempted and were
+                  either unavailable or failed". */
+               return TRUE;
+       case CASS_ERROR_SERVER_WRITE_TIMEOUT:
+               /* Cassandra server couldn't reach all the needed nodes.
+                  This may be because it hasn't yet detected that the servers
+                  are down, or because the servers are just too busy. We'll
+                  try the fallback consistency to avoid unnecessary temporary
+                  errors. */
+               return TRUE;
+       default:
+               return FALSE;
+       }
+}
+
 static void query_callback(CassFuture *future, void *context)
 {
        struct cassandra_result *result = context;
@@ -936,22 +961,7 @@ static void query_callback(CassFuture *future, void *context)
                        result->query, (int)errsize, errmsg, msecs/1000, msecs%1000,
                        result->page_num == 0 ? "" : t_strdup_printf(", page %u", result->page_num));
 
-               /* unavailable = cassandra server knows that there aren't
-                  enough nodes available. "All hosts in current policy
-                  attempted and were either unavailable or failed"
-
-                  no hosts available = The client library couldn't connect to
-                  enough cassanra nodes. Error message is the same as for
-                  "unavailable".
-
-                  write timeout = cassandra server couldn't reach all the
-                  needed nodes. this may be because it hasn't yet detected
-                  that the servers are down, or because the servers are just
-                  too busy. we'll try the fallback consistency to avoid
-                  unnecessary temporary errors. */
-               if ((error == CASS_ERROR_SERVER_UNAVAILABLE ||
-                    error == CASS_ERROR_LIB_NO_HOSTS_AVAILABLE ||
-                    error == CASS_ERROR_SERVER_WRITE_TIMEOUT) &&
+               if (query_error_want_fallback(error) &&
                    result->fallback_consistency != result->consistency) {
                        /* retry with fallback consistency */
                        query_resend_with_fallback(result);