# HG changeset patch # User Timo Sirainen # Date 1525355901 -10800 # Node ID f10330f73af60c2cb3f379c0b0f1f4f5c0a530e5 # Parent 99445a6b0bfd8039ade27c850c7950357766ef62 cassandra: Cleanup - Move code to query_error_want_fallback() This allows extending it more easily. diff -r 99445a6b0bfd -r f10330f73af6 src/lib-sql/driver-cassandra.c --- 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);