From: Timo Sirainen Date: Thu, 3 May 2018 13:58:21 +0000 (+0300) Subject: cassandra: Cleanup - Move code to query_error_want_fallback() X-Git-Tag: 2.3.2.rc1~116 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=313b5f5c516c43d7d9e31c28813f67fd97413c09;p=thirdparty%2Fdovecot%2Fcore.git cassandra: Cleanup - Move code to query_error_want_fallback() This allows extending it more easily. --- diff --git a/src/lib-sql/driver-cassandra.c b/src/lib-sql/driver-cassandra.c index dc396745e2..b4c397b0a3 100644 --- a/src/lib-sql/driver-cassandra.c +++ b/src/lib-sql/driver-cassandra.c @@ -910,6 +910,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; @@ -938,22 +963,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);