changeset 22960:f10330f73af6

cassandra: Cleanup - Move code to query_error_want_fallback() This allows extending it more easily.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Thu, 03 May 2018 16:58:21 +0300
parents 99445a6b0bfd
children 34315e5fd52e
files src/lib-sql/driver-cassandra.c
diffstat 1 files changed, 26 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-sql/driver-cassandra.c	Fri Oct 06 15:54:47 2017 +0300
+++ b/src/lib-sql/driver-cassandra.c	Thu May 03 16:58:21 2018 +0300
@@ -908,6 +908,31 @@
 	}
 }
 
+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 @@
 			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);