mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-09-02 06:55:16 +00:00
added cql-consistency parameter
This commit is contained in:
@@ -484,6 +484,17 @@ ControlCharacterFill [^"\\]|\\{JSONEscapeSequence}
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
\"cql-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_CQL_CONSISTENCY(driver.loc_);
|
||||||
|
default:
|
||||||
|
return isc::dhcp::Dhcp4Parser::make_STRING("cql-consistency", driver.loc_);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
\"reconnect-wait-time\" {
|
\"reconnect-wait-time\" {
|
||||||
switch(driver.ctx_) {
|
switch(driver.ctx_) {
|
||||||
case isc::dhcp::Parser4Context::LEASE_DATABASE:
|
case isc::dhcp::Parser4Context::LEASE_DATABASE:
|
||||||
|
@@ -90,6 +90,7 @@ using namespace std;
|
|||||||
CONNECT_TIMEOUT "connect-timeout"
|
CONNECT_TIMEOUT "connect-timeout"
|
||||||
CONTACT_POINTS "contact-points"
|
CONTACT_POINTS "contact-points"
|
||||||
KEYSPACE "keyspace"
|
KEYSPACE "keyspace"
|
||||||
|
CQL_CONSISTENCY "cql-consistency"
|
||||||
MAX_RECONNECT_TRIES "max-reconnect-tries"
|
MAX_RECONNECT_TRIES "max-reconnect-tries"
|
||||||
RECONNECT_WAIT_TIME "reconnect-wait-time"
|
RECONNECT_WAIT_TIME "reconnect-wait-time"
|
||||||
REQUEST_TIMEOUT "request-timeout"
|
REQUEST_TIMEOUT "request-timeout"
|
||||||
@@ -712,6 +713,7 @@ database_map_param: database_type
|
|||||||
| tcp_keepalive
|
| tcp_keepalive
|
||||||
| tcp_nodelay
|
| tcp_nodelay
|
||||||
| keyspace
|
| keyspace
|
||||||
|
| cql_consistency
|
||||||
| unknown_map_entry
|
| unknown_map_entry
|
||||||
;
|
;
|
||||||
|
|
||||||
@@ -816,6 +818,14 @@ keyspace: KEYSPACE {
|
|||||||
ctx.leave();
|
ctx.leave();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
cql_consistency: CQL_CONSISTENCY {
|
||||||
|
ctx.enter(ctx.NO_KEYWORD);
|
||||||
|
} COLON STRING {
|
||||||
|
ElementPtr c(new StringElement($4, ctx.loc2pos(@4)));
|
||||||
|
ctx.stack_.back()->set("cql-consistency", c);
|
||||||
|
ctx.leave();
|
||||||
|
};
|
||||||
|
|
||||||
max_reconnect_tries: MAX_RECONNECT_TRIES COLON INTEGER {
|
max_reconnect_tries: MAX_RECONNECT_TRIES COLON INTEGER {
|
||||||
ElementPtr n(new IntElement($3, ctx.loc2pos(@3)));
|
ElementPtr n(new IntElement($3, ctx.loc2pos(@3)));
|
||||||
ctx.stack_.back()->set("max-reconnect-tries", n);
|
ctx.stack_.back()->set("max-reconnect-tries", n);
|
||||||
|
@@ -679,6 +679,17 @@ ControlCharacterFill [^"\\]|\\{JSONEscapeSequence}
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
\"cql-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_CQL_CONSISTENCY(driver.loc_);
|
||||||
|
default:
|
||||||
|
return isc::dhcp::Dhcp6Parser::make_STRING("cql-consistency", driver.loc_);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
\"reconnect-wait-time\" {
|
\"reconnect-wait-time\" {
|
||||||
switch(driver.ctx_) {
|
switch(driver.ctx_) {
|
||||||
case isc::dhcp::Parser6Context::LEASE_DATABASE:
|
case isc::dhcp::Parser6Context::LEASE_DATABASE:
|
||||||
|
@@ -77,6 +77,7 @@ using namespace std;
|
|||||||
MAX_RECONNECT_TRIES "max-reconnect-tries"
|
MAX_RECONNECT_TRIES "max-reconnect-tries"
|
||||||
RECONNECT_WAIT_TIME "reconnect-wait-time"
|
RECONNECT_WAIT_TIME "reconnect-wait-time"
|
||||||
KEYSPACE "keyspace"
|
KEYSPACE "keyspace"
|
||||||
|
CQL_CONSISTENCY "cql-consistency"
|
||||||
REQUEST_TIMEOUT "request-timeout"
|
REQUEST_TIMEOUT "request-timeout"
|
||||||
TCP_KEEPALIVE "tcp-keepalive"
|
TCP_KEEPALIVE "tcp-keepalive"
|
||||||
TCP_NODELAY "tcp-nodelay"
|
TCP_NODELAY "tcp-nodelay"
|
||||||
@@ -632,6 +633,7 @@ database_map_param: database_type
|
|||||||
| tcp_keepalive
|
| tcp_keepalive
|
||||||
| tcp_nodelay
|
| tcp_nodelay
|
||||||
| keyspace
|
| keyspace
|
||||||
|
| cql_consistency
|
||||||
| unknown_map_entry
|
| unknown_map_entry
|
||||||
;
|
;
|
||||||
|
|
||||||
@@ -746,6 +748,14 @@ keyspace: KEYSPACE {
|
|||||||
ctx.leave();
|
ctx.leave();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
cql_consistency: CQL_CONSISTENCY {
|
||||||
|
ctx.enter(ctx.NO_KEYWORD);
|
||||||
|
} COLON STRING {
|
||||||
|
ElementPtr c(new StringElement($4, ctx.loc2pos(@4)));
|
||||||
|
ctx.stack_.back()->set("cql-consistency", c);
|
||||||
|
ctx.leave();
|
||||||
|
};
|
||||||
|
|
||||||
sanity_checks: SANITY_CHECKS {
|
sanity_checks: SANITY_CHECKS {
|
||||||
ElementPtr m(new MapElement(ctx.loc2pos(@1)));
|
ElementPtr m(new MapElement(ctx.loc2pos(@1)));
|
||||||
ctx.stack_.back()->set("sanity-checks", m);
|
ctx.stack_.back()->set("sanity-checks", m);
|
||||||
|
@@ -74,6 +74,26 @@ CqlConnection::~CqlConnection() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CassConsistency CqlConnection::parseConsistency(std::string value) {
|
||||||
|
static std::map<std::string, CassConsistency> consistency_map {
|
||||||
|
{"consistency-any", CASS_CONSISTENCY_ANY},
|
||||||
|
{"consistency-one", CASS_CONSISTENCY_ONE},
|
||||||
|
{"consistency-two", CASS_CONSISTENCY_TWO},
|
||||||
|
{"consistency-three", CASS_CONSISTENCY_THREE},
|
||||||
|
{"consistency-quorum", CASS_CONSISTENCY_QUORUM},
|
||||||
|
{"consistency-all", CASS_CONSISTENCY_ALL},
|
||||||
|
{"consistency-local-quorum", CASS_CONSISTENCY_LOCAL_QUORUM},
|
||||||
|
{"consistency-each-quorum", CASS_CONSISTENCY_EACH_QUORUM},
|
||||||
|
{"consistency-serial", CASS_CONSISTENCY_SERIAL},
|
||||||
|
{"consistency-local-serial", CASS_CONSISTENCY_LOCAL_SERIAL},
|
||||||
|
{"consistency-local-one", CASS_CONSISTENCY_LOCAL_ONE}
|
||||||
|
};
|
||||||
|
if (consistency_map.find(value) == consistency_map.end()) {
|
||||||
|
return CASS_CONSISTENCY_UNKNOWN;
|
||||||
|
}
|
||||||
|
return consistency_map[value];
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
CqlConnection::openDatabase() {
|
CqlConnection::openDatabase() {
|
||||||
CassError rc;
|
CassError rc;
|
||||||
@@ -123,6 +143,15 @@ CqlConnection::openDatabase() {
|
|||||||
// No keyspace name. Fine, we'll use "keatest".
|
// No keyspace name. Fine, we'll use "keatest".
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char* consistency = NULL;
|
||||||
|
std::string sconsistency;
|
||||||
|
try {
|
||||||
|
sconsistency = getParameter("cql-consistency");
|
||||||
|
consistency = sconsistency.c_str();
|
||||||
|
} catch (...) {
|
||||||
|
// No user. Fine, we'll use NULL.
|
||||||
|
}
|
||||||
|
|
||||||
const char* reconnect_wait_time = NULL;
|
const char* reconnect_wait_time = NULL;
|
||||||
std::string sreconnect_wait_time;
|
std::string sreconnect_wait_time;
|
||||||
try {
|
try {
|
||||||
@@ -194,6 +223,13 @@ CqlConnection::openDatabase() {
|
|||||||
cass_cluster_set_port(cluster_, port_number);
|
cass_cluster_set_port(cluster_, port_number);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (consistency) {
|
||||||
|
CassConsistency desired_consistency = CqlConnection::parseConsistency(sconsistency);
|
||||||
|
if (desired_consistency != CASS_CONSISTENCY_UNKNOWN) {
|
||||||
|
setConsistency(true, desired_consistency);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (reconnect_wait_time) {
|
if (reconnect_wait_time) {
|
||||||
int32_t reconnect_wait_time_number;
|
int32_t reconnect_wait_time_number;
|
||||||
try {
|
try {
|
||||||
|
@@ -171,6 +171,9 @@ public:
|
|||||||
/// @brief Rollback Transactions
|
/// @brief Rollback Transactions
|
||||||
virtual void rollback();
|
virtual void rollback();
|
||||||
|
|
||||||
|
/// @brief parse Consistency value
|
||||||
|
static CassConsistency parseConsistency(std::string value);
|
||||||
|
|
||||||
/// @brief Check for errors
|
/// @brief Check for errors
|
||||||
///
|
///
|
||||||
/// Check for errors on the current database operation and returns text
|
/// Check for errors on the current database operation and returns text
|
||||||
|
@@ -163,12 +163,11 @@ DatabaseConnection::toElement(const ParameterMap& params) {
|
|||||||
|
|
||||||
if ((keyword == "lfc-interval") ||
|
if ((keyword == "lfc-interval") ||
|
||||||
(keyword == "connect-timeout") ||
|
(keyword == "connect-timeout") ||
|
||||||
(keyword == "request-timeout") ||
|
|
||||||
(keyword == "port") ||
|
|
||||||
(keyword == "max-reconnect-tries") ||
|
|
||||||
(keyword == "reconnect-wait-time") ||
|
(keyword == "reconnect-wait-time") ||
|
||||||
(keyword == "tcp-keepalive")) {
|
(keyword == "max-reconnect-tries") ||
|
||||||
|
(keyword == "request-timeout") ||
|
||||||
|
(keyword == "tcp-keepalive") ||
|
||||||
|
(keyword == "port")) {
|
||||||
// integer parameters
|
// integer parameters
|
||||||
int64_t int_value;
|
int64_t int_value;
|
||||||
try {
|
try {
|
||||||
@@ -179,9 +178,8 @@ DatabaseConnection::toElement(const ParameterMap& params) {
|
|||||||
.arg("integer").arg(keyword).arg(value);
|
.arg("integer").arg(keyword).arg(value);
|
||||||
}
|
}
|
||||||
} else if ((keyword == "persist") ||
|
} else if ((keyword == "persist") ||
|
||||||
(keyword == "readonly") ||
|
(keyword == "tcp-nodelay") ||
|
||||||
(keyword == "tcp-nodelay")) {
|
(keyword == "readonly")) {
|
||||||
|
|
||||||
if (value == "true") {
|
if (value == "true") {
|
||||||
result->set(keyword, isc::data::Element::create(true));
|
result->set(keyword, isc::data::Element::create(true));
|
||||||
} else if (value == "false") {
|
} else if (value == "false") {
|
||||||
@@ -196,6 +194,7 @@ DatabaseConnection::toElement(const ParameterMap& params) {
|
|||||||
(keyword == "host") ||
|
(keyword == "host") ||
|
||||||
(keyword == "name") ||
|
(keyword == "name") ||
|
||||||
(keyword == "contact-points") ||
|
(keyword == "contact-points") ||
|
||||||
|
(keyword == "cql-consistency") ||
|
||||||
(keyword == "keyspace")) {
|
(keyword == "keyspace")) {
|
||||||
result->set(keyword, isc::data::Element::create(value));
|
result->set(keyword, isc::data::Element::create(value));
|
||||||
} else {
|
} else {
|
||||||
|
@@ -97,7 +97,7 @@ public:
|
|||||||
return (retries_left_ ? --retries_left_ : false);
|
return (retries_left_ ? --retries_left_ : false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Returns the maximum number for retries allowed
|
/// @brief Returns the maximum number of retries allowed.
|
||||||
unsigned int maxRetries() {
|
unsigned int maxRetries() {
|
||||||
return (max_retries_);
|
return (max_retries_);
|
||||||
}
|
}
|
||||||
@@ -243,7 +243,7 @@ private:
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}; // end of isc::db namespace
|
} // namespace db
|
||||||
}; // end of isc namespace
|
} // namespace isc
|
||||||
|
|
||||||
#endif // DATABASE_CONNECTION_H
|
#endif // DATABASE_CONNECTION_H
|
||||||
|
@@ -18,7 +18,7 @@ namespace isc {
|
|||||||
namespace db {
|
namespace db {
|
||||||
|
|
||||||
/// @brief Database logging levels.
|
/// @brief Database logging levels.
|
||||||
extern const int DB_DBG_TRACE_DETAIL = isc::log::DBGLVL_TRACE_DETAIL;
|
const int DB_DBG_TRACE_DETAIL = isc::log::DBGLVL_TRACE_DETAIL;
|
||||||
|
|
||||||
/// @brief Map of translated messages.
|
/// @brief Map of translated messages.
|
||||||
const DbLogger::MessageMap db_message_map = {
|
const DbLogger::MessageMap db_message_map = {
|
||||||
|
@@ -44,7 +44,6 @@ extern const int DB_DBG_TRACE_DETAIL;
|
|||||||
/// @brief Common database library logger.
|
/// @brief Common database library logger.
|
||||||
extern isc::log::Logger database_logger;
|
extern isc::log::Logger database_logger;
|
||||||
|
|
||||||
|
|
||||||
///@{
|
///@{
|
||||||
/// @brief Database messages
|
/// @brief Database messages
|
||||||
///
|
///
|
||||||
|
@@ -59,8 +59,9 @@ DbAccessParser::parse(std::string& access_string,
|
|||||||
// 2. Update the copy with the passed keywords.
|
// 2. Update the copy with the passed keywords.
|
||||||
for (std::pair<std::string, ConstElementPtr> param : database_config->mapValue()) {
|
for (std::pair<std::string, ConstElementPtr> param : database_config->mapValue()) {
|
||||||
try {
|
try {
|
||||||
if ((param.first == "persist") || (param.first == "readonly") ||
|
if ((param.first == "persist") ||
|
||||||
(param.first == "tcp-nodelay")) {
|
(param.first == "tcp-nodelay") ||
|
||||||
|
(param.first == "readonly")) {
|
||||||
values_copy[param.first] = (param.second->boolValue() ?
|
values_copy[param.first] = (param.second->boolValue() ?
|
||||||
"true" : "false");
|
"true" : "false");
|
||||||
|
|
||||||
@@ -100,6 +101,15 @@ DbAccessParser::parse(std::string& access_string,
|
|||||||
boost::lexical_cast<std::string>(port);
|
boost::lexical_cast<std::string>(port);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
// all remaining string parameters
|
||||||
|
// type
|
||||||
|
// user
|
||||||
|
// password
|
||||||
|
// host
|
||||||
|
// name
|
||||||
|
// contact-points
|
||||||
|
// keyspace
|
||||||
|
// cql-consistency
|
||||||
values_copy[param.first] = param.second->stringValue();
|
values_copy[param.first] = param.second->stringValue();
|
||||||
}
|
}
|
||||||
} catch (const isc::data::TypeError& ex) {
|
} catch (const isc::data::TypeError& ex) {
|
||||||
@@ -165,14 +175,14 @@ DbAccessParser::parse(std::string& access_string,
|
|||||||
<< " (" << value->getPosition() << ")");
|
<< " (" << value->getPosition() << ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that the max-reconnect-retries reasonable.
|
// Check that the max-reconnect-tries is reasonable.
|
||||||
if (max_reconnect_tries < 0) {
|
if (max_reconnect_tries < 0) {
|
||||||
ConstElementPtr value = database_config->get("max-reconnect-tries");
|
ConstElementPtr value = database_config->get("max-reconnect-tries");
|
||||||
isc_throw(DbConfigError, "max-reconnect-tries cannot be less than zero: "
|
isc_throw(DbConfigError, "max-reconnect-tries cannot be less than zero: "
|
||||||
<< " (" << value->getPosition() << ")");
|
<< " (" << value->getPosition() << ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that the reconnect-wait-time reasonable.
|
// Check that the reconnect-wait-time is reasonable.
|
||||||
if ((reconnect_wait_time < 0) ||
|
if ((reconnect_wait_time < 0) ||
|
||||||
(reconnect_wait_time > std::numeric_limits<uint32_t>::max())) {
|
(reconnect_wait_time > std::numeric_limits<uint32_t>::max())) {
|
||||||
ConstElementPtr value = database_config->get("reconnect-wait-time");
|
ConstElementPtr value = database_config->get("reconnect-wait-time");
|
||||||
@@ -182,6 +192,14 @@ DbAccessParser::parse(std::string& access_string,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check that request_timeout value makes sense.
|
// Check that request_timeout value makes sense.
|
||||||
|
if ((request_timeout < 0) ||
|
||||||
|
(request_timeout > std::numeric_limits<uint32_t>::max())) {
|
||||||
|
ConstElementPtr value = database_config->get("request-timeout");
|
||||||
|
isc_throw(DbConfigError, "request-timeout " << request_timeout
|
||||||
|
<< " must be in range 0...MAX_UINT32 (4294967295) "
|
||||||
|
<< " (" << value->getPosition() << ")");
|
||||||
|
}
|
||||||
|
|
||||||
if ((reconnect_wait_time < 0) ||
|
if ((reconnect_wait_time < 0) ||
|
||||||
(reconnect_wait_time > std::numeric_limits<uint32_t>::max())) {
|
(reconnect_wait_time > std::numeric_limits<uint32_t>::max())) {
|
||||||
ConstElementPtr value = database_config->get("reconnect-wait-time");
|
ConstElementPtr value = database_config->get("reconnect-wait-time");
|
||||||
@@ -189,10 +207,11 @@ DbAccessParser::parse(std::string& access_string,
|
|||||||
<< " must be in range 0...MAX_UINT32 (4294967295) "
|
<< " must be in range 0...MAX_UINT32 (4294967295) "
|
||||||
<< " (" << value->getPosition() << ")");
|
<< " (" << value->getPosition() << ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that tcp_keepalive value makes sense.
|
// Check that tcp_keepalive value makes sense.
|
||||||
if ((tcp_keepalive < 0) ||
|
if ((tcp_keepalive < 0) ||
|
||||||
(tcp_keepalive > std::numeric_limits<uint32_t>::max())) {
|
(tcp_keepalive > std::numeric_limits<uint32_t>::max())) {
|
||||||
ConstElementPtr value = database_config->get("reconnect-wait-time");
|
ConstElementPtr value = database_config->get("tcp-keepalive");
|
||||||
isc_throw(DbConfigError, "tcp-keepalive " << tcp_keepalive
|
isc_throw(DbConfigError, "tcp-keepalive " << tcp_keepalive
|
||||||
<< " must be in range 0...MAX_UINT32 (4294967295) "
|
<< " must be in range 0...MAX_UINT32 (4294967295) "
|
||||||
<< " (" << value->getPosition() << ")");
|
<< " (" << value->getPosition() << ")");
|
||||||
|
@@ -22,7 +22,6 @@ namespace db {
|
|||||||
/// This class is the parser for the database configuration. This is a
|
/// This class is the parser for the database configuration. This is a
|
||||||
/// map under the top-level "lease-database", "host-database" and
|
/// map under the top-level "lease-database", "host-database" and
|
||||||
/// "config-database" elements, and comprises a map of strings.
|
/// "config-database" elements, and comprises a map of strings.
|
||||||
///
|
|
||||||
class DbAccessParser: public isc::data::SimpleParser {
|
class DbAccessParser: public isc::data::SimpleParser {
|
||||||
public:
|
public:
|
||||||
/// @brief Constructor
|
/// @brief Constructor
|
||||||
@@ -79,8 +78,7 @@ private:
|
|||||||
DatabaseConnection::ParameterMap values_; ///< Stored parameter values
|
DatabaseConnection::ParameterMap values_; ///< Stored parameter values
|
||||||
};
|
};
|
||||||
|
|
||||||
}; // namespace db
|
} // namespace db
|
||||||
}; // namespace isc
|
} // namespace isc
|
||||||
|
|
||||||
|
|
||||||
#endif // DBACCESS_PARSER_H
|
#endif // DBACCESS_PARSER_H
|
||||||
|
Reference in New Issue
Block a user