Commit b825815f authored by Razvan Becheriu's avatar Razvan Becheriu
Browse files

configure serial consistency as well

parent 7d8d91be
......@@ -495,6 +495,17 @@ ControlCharacterFill [^"\\]|\\{JSONEscapeSequence}
}
}
\"serial-consistency\" {
switch(driver.ctx_) {
case isc::dhcp::Parser4Context::LEASE_DATABASE:
case isc::dhcp::Parser4Context::HOSTS_DATABASE:
case isc::dhcp::Parser4Context::CONFIG_DATABASE:
return isc::dhcp::Dhcp4Parser::make_SERIAL_CONSISTENCY(driver.loc_);
default:
return isc::dhcp::Dhcp4Parser::make_STRING("serial-consistency", driver.loc_);
}
}
\"reconnect-wait-time\" {
switch(driver.ctx_) {
case isc::dhcp::Parser4Context::LEASE_DATABASE:
......
......@@ -91,6 +91,7 @@ using namespace std;
CONTACT_POINTS "contact-points"
KEYSPACE "keyspace"
CONSISTENCY "consistency"
SERIAL_CONSISTENCY "serial-consistency"
MAX_RECONNECT_TRIES "max-reconnect-tries"
RECONNECT_WAIT_TIME "reconnect-wait-time"
REQUEST_TIMEOUT "request-timeout"
......@@ -714,6 +715,7 @@ database_map_param: database_type
| tcp_nodelay
| keyspace
| consistency
| serial_consistency
| unknown_map_entry
;
......@@ -826,6 +828,14 @@ consistency: CONSISTENCY {
ctx.leave();
};
serial_consistency: SERIAL_CONSISTENCY {
ctx.enter(ctx.NO_KEYWORD);
} COLON STRING {
ElementPtr c(new StringElement($4, ctx.loc2pos(@4)));
ctx.stack_.back()->set("serial-consistency", c);
ctx.leave();
};
max_reconnect_tries: MAX_RECONNECT_TRIES COLON INTEGER {
ElementPtr n(new IntElement($3, ctx.loc2pos(@3)));
ctx.stack_.back()->set("max-reconnect-tries", n);
......
......@@ -690,6 +690,17 @@ ControlCharacterFill [^"\\]|\\{JSONEscapeSequence}
}
}
\"serial-consistency\" {
switch(driver.ctx_) {
case isc::dhcp::Parser6Context::LEASE_DATABASE:
case isc::dhcp::Parser6Context::HOSTS_DATABASE:
case isc::dhcp::Parser6Context::CONFIG_DATABASE:
return isc::dhcp::Dhcp6Parser::make_SERIAL_CONSISTENCY(driver.loc_);
default:
return isc::dhcp::Dhcp6Parser::make_STRING("serial-consistency", driver.loc_);
}
}
\"reconnect-wait-time\" {
switch(driver.ctx_) {
case isc::dhcp::Parser6Context::LEASE_DATABASE:
......
......@@ -78,6 +78,7 @@ using namespace std;
RECONNECT_WAIT_TIME "reconnect-wait-time"
KEYSPACE "keyspace"
CONSISTENCY "consistency"
SERIAL_CONSISTENCY "serial-consistency"
REQUEST_TIMEOUT "request-timeout"
TCP_KEEPALIVE "tcp-keepalive"
TCP_NODELAY "tcp-nodelay"
......@@ -634,6 +635,7 @@ database_map_param: database_type
| tcp_nodelay
| keyspace
| consistency
| serial_consistency
| unknown_map_entry
;
......@@ -756,6 +758,14 @@ consistency: CONSISTENCY {
ctx.leave();
};
serial_consistency: SERIAL_CONSISTENCY {
ctx.enter(ctx.NO_KEYWORD);
} COLON STRING {
ElementPtr c(new StringElement($4, ctx.loc2pos(@4)));
ctx.stack_.back()->set("serial-consistency", c);
ctx.leave();
};
sanity_checks: SANITY_CHECKS {
ElementPtr m(new MapElement(ctx.loc2pos(@1)));
ctx.stack_.back()->set("sanity-checks", m);
......
......@@ -30,7 +30,8 @@ namespace db {
CqlConnection::CqlConnection(const ParameterMap& parameters)
: DatabaseConnection(parameters), statements_(), cluster_(NULL),
session_(NULL), consistency_(CASS_CONSISTENCY_QUORUM), schema_meta_(NULL),
session_(NULL), consistency_(CASS_CONSISTENCY_QUORUM),
serial_consistency_(CASS_CONSISTENCY_UNKNOWN), schema_meta_(NULL),
keyspace_meta_(NULL), force_consistency_(true) {
}
......@@ -152,6 +153,15 @@ CqlConnection::openDatabase() {
// No user. Fine, we'll use NULL.
}
const char* serial_consistency = NULL;
std::string sserial_consistency;
try {
sserial_consistency = getParameter("serial-consistency");
serial_consistency = sserial_consistency.c_str();
} catch (...) {
// No user. Fine, we'll use NULL.
}
const char* reconnect_wait_time = NULL;
std::string sreconnect_wait_time;
try {
......@@ -225,8 +235,12 @@ CqlConnection::openDatabase() {
if (consistency) {
CassConsistency desired_consistency = CqlConnection::parseConsistency(sconsistency);
CassConsistency desired_serial_consistency = CASS_CONSISTENCY_UNKNOWN;
if (serial_consistency) {
desired_serial_consistency = CqlConnection::parseConsistency(sserial_consistency);
}
if (desired_consistency != CASS_CONSISTENCY_UNKNOWN) {
setConsistency(true, desired_consistency);
setConsistency(true, desired_consistency, desired_serial_consistency);
}
}
......@@ -379,9 +393,12 @@ CqlConnection::prepareStatements(StatementMap& statements) {
}
void
CqlConnection::setConsistency(bool force, CassConsistency consistency) {
CqlConnection::setConsistency(bool force,
CassConsistency consistency,
CassConsistency serial_consistency) {
force_consistency_ = force;
consistency_ = consistency;
serial_consistency_ = serial_consistency;
}
void
......
......@@ -160,7 +160,9 @@ public:
void openDatabase();
/// @brief Set consistency
void setConsistency(bool force, CassConsistency consistency);
void setConsistency(bool force,
CassConsistency consistency,
CassConsistency serial_consistency);
/// @brief Start transaction
void startTransaction();
......@@ -202,6 +204,9 @@ public:
/// @brief CQL consistency
CassConsistency consistency_;
/// @brief CQL serial consistency
CassConsistency serial_consistency_;
// @brief Schema meta information, used for UDTs
const CassSchemaMeta* schema_meta_;
......
......@@ -811,6 +811,17 @@ CqlExchange::executeSelect(const CqlConnection& connection, const AnyArray& data
<< tagged_statement.name_
<< ", Cassandra error code: " << cass_error_desc(rc));
}
if (connection.serial_consistency_ != CASS_CONSISTENCY_UNKNOWN) {
rc = cass_statement_set_serial_consistency(statement, connection.serial_consistency_);
if (rc != CASS_OK) {
cass_statement_free(statement);
isc_throw(DbOperationError,
"CqlExchange::executeSelect(): unable to set statement "
"serial consistency for statement "
<< tagged_statement.name_
<< ", Cassandra error code: " << cass_error_desc(rc));
}
}
}
CqlCommon::bindData(local_data, statement);
......
......@@ -195,6 +195,7 @@ DatabaseConnection::toElement(const ParameterMap& params) {
(keyword == "name") ||
(keyword == "contact-points") ||
(keyword == "consistency") ||
(keyword == "serial-consistency") ||
(keyword == "keyspace")) {
result->set(keyword, isc::data::Element::create(value));
} else {
......
......@@ -110,6 +110,7 @@ DbAccessParser::parse(std::string& access_string,
// contact-points
// keyspace
// consistency
// serial-consistency
values_copy[param.first] = param.second->stringValue();
}
} catch (const isc::data::TypeError& ex) {
......
......@@ -261,6 +261,7 @@ TEST(DatabaseConnection, toElementDbAccessStringValid) {
"\"connect-timeout\" : 200, \n"
"\"contact-points\": \"contact_str\", \n"
"\"consistency\": \"quorum\", \n"
"\"serial-consistency\": \"serial\", \n"
"\"host\": \"host_str\", \n"
"\"keyspace\": \"keyspace_str\", \n"
"\"lfc-interval\" : 100, \n"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment