Skip to content

Commit

Permalink
Merge pull request #1026 from Mashape/feature/cassandra-consistency
Browse files Browse the repository at this point in the history
Configurable Cassandra consistency level
  • Loading branch information
subnetmarco committed Feb 26, 2016
2 parents c35b4bf + 3127eb8 commit ee87ecb
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
5 changes: 5 additions & 0 deletions kong.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@
# dc1: 2
# dc2: 3

#####
## Consistency level to use.
## See http://docs.datastax.com/en/cassandra/2.0/cassandra/dml/dml_config_consistency_c.html
# consistency: ONE

#####
## Client-to-node TLS options.
## `enabled`: if true, will connect to your Cassandra instance using TLS.
Expand Down
4 changes: 3 additions & 1 deletion kong/dao/cassandra/factory.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

local constants = require "kong.constants"
local cassandra = require "cassandra"
local types = require "cassandra.types"
local DaoError = require "kong.dao.error"
local stringy = require "stringy"
local Object = require "classic"
Expand Down Expand Up @@ -115,7 +116,8 @@ function CassandraFactory:get_session_options()
contact_points = self.properties.contact_points,
keyspace = self.properties.keyspace,
query_options = {
prepare = true
prepare = true,
consistency = types.consistencies[self.properties.consistency:lower()]
},
socket_options = {
connect_timeout = self.properties.timeout,
Expand Down
2 changes: 2 additions & 0 deletions kong/tools/config_defaults.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ return {
["data_centers"] = {type = "table", default = {}},
["username"] = {type = "string", nullable = true},
["password"] = {type = "string", nullable = true},
["consistency"] = {type = "string", default = "ONE", enum = {"ANY", "ONE", "TWO", "THREE", "QUORUM", "ALL", "LOCAL_QUORUM",
"EACH_QUORUM", "SERIAL", "LOCAL_SERIAL", "LOCAL_ONE"}},
["ssl"] = {
type = "table",
content = {
Expand Down
6 changes: 6 additions & 0 deletions spec/unit/dao/cassandra/factory_spec.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
local Factory = require "kong.dao.cassandra.factory"
local utils = require "kong.tools.utils"
local cassandra = require "cassandra"
local types = require "cassandra.types"
local spec_helpers = require "spec.spec_helpers"
local env = spec_helpers.get_env()
local default_dao_properties = env.configuration.cassandra
Expand All @@ -23,6 +24,7 @@ describe("Cassadra factory", function()
contact_points = dao_properties.contact_points,
keyspace = dao_properties.keyspace,
query_options = {
consistency = types.consistencies.one,
prepare = true
},
socket_options = {
Expand All @@ -49,6 +51,7 @@ describe("Cassadra factory", function()
contact_points = {"127.0.0.1:9042"},
keyspace = "my_keyspace",
query_options = {
consistency = types.consistencies.one,
prepare = true
},
socket_options = {
Expand All @@ -75,6 +78,7 @@ describe("Cassadra factory", function()
contact_points = {"127.0.0.1:9042"},
keyspace = "kong_tests",
query_options = {
consistency = types.consistencies.one,
prepare = true
},
socket_options = {
Expand Down Expand Up @@ -103,6 +107,7 @@ describe("Cassadra factory", function()
contact_points = {"127.0.0.1:9042"},
keyspace = "kong_tests",
query_options = {
consistency = types.consistencies.one,
prepare = true
},
socket_options = {
Expand All @@ -127,6 +132,7 @@ describe("Cassadra factory", function()
contact_points = {"127.0.0.1:9042"},
keyspace = "kong_tests",
query_options = {
consistency = types.consistencies.one,
prepare = true
},
socket_options = {
Expand Down

0 comments on commit ee87ecb

Please sign in to comment.