]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
cassandra: sql_transaction_commit_s() - Set query_type correctly
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Thu, 24 Aug 2017 08:13:32 +0000 (11:13 +0300)
committerAki Tuomi <aki.tuomi@dovecot.fi>
Fri, 8 Sep 2017 10:18:32 +0000 (13:18 +0300)
The queries were all sent with READ type instead of WRITE/DELETE. This
meant they were using potentially wrong consistency values. Although
synchronous commits aren't actually used anywhere, so this practically
this doesn't fix anything right now.

src/lib-sql/driver-cassandra.c

index d80fb2d39fdffb4c20c4162e351ccc4d286850b8..6a918493a881ba8f313f0675b2f162976e5e393f 100644 (file)
@@ -1123,7 +1123,8 @@ static void driver_cassandra_sync_deinit(struct cassandra_db *db)
 }
 
 static struct sql_result *
-driver_cassandra_sync_query(struct cassandra_db *db, const char *query)
+driver_cassandra_sync_query(struct cassandra_db *db, const char *query,
+                           enum cassandra_query_type query_type)
 {
        struct sql_result *result;
 
@@ -1140,7 +1141,8 @@ driver_cassandra_sync_query(struct cassandra_db *db, const char *query)
                break;
        }
 
-       driver_cassandra_query(&db->api, query, cassandra_query_s_callback, db);
+       driver_cassandra_query_full(&db->api, query, query_type,
+                                   cassandra_query_s_callback, db);
        if (db->sync_result == NULL) {
                db->io_pipe = io_loop_move_io(&db->io_pipe);
                io_loop_run(db->ioloop);
@@ -1165,7 +1167,8 @@ driver_cassandra_query_s(struct sql_db *_db, const char *query)
        struct sql_result *result;
 
        driver_cassandra_sync_init(db);
-       result = driver_cassandra_sync_query(db, query);
+       result = driver_cassandra_sync_query(db, query,
+                                            CASSANDRA_QUERY_TYPE_READ);
        driver_cassandra_sync_deinit(db);
        return result;
 }
@@ -1495,13 +1498,21 @@ static void
 driver_cassandra_try_commit_s(struct cassandra_transaction_context *ctx)
 {
        struct sql_transaction_context *_ctx = &ctx->ctx;
+       struct cassandra_db *db = (struct cassandra_db *)_ctx->db;
        struct sql_transaction_query *single_query = NULL;
        struct sql_result *result = NULL;
+       enum cassandra_query_type query_type;
 
        if (_ctx->head->next == NULL) {
                /* just a single query, send it */
                single_query = _ctx->head;
-               result = sql_query_s(_ctx->db, single_query->query);
+               if (strncasecmp(_ctx->head->query, "DELETE ", 7) == 0)
+                       query_type = CASSANDRA_QUERY_TYPE_DELETE;
+               else
+                       query_type = CASSANDRA_QUERY_TYPE_WRITE;
+               driver_cassandra_sync_init(db);
+               result = driver_cassandra_sync_query(db, single_query->query, query_type);
+               driver_cassandra_sync_deinit(db);
        } else {
                /* multiple queries - we don't actually have a transaction though */
                transaction_set_failed(ctx, "Multiple changes in transaction not supported");