mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-08-31 14:05:33 +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\" {
|
||||
switch(driver.ctx_) {
|
||||
case isc::dhcp::Parser4Context::LEASE_DATABASE:
|
||||
|
@@ -90,6 +90,7 @@ using namespace std;
|
||||
CONNECT_TIMEOUT "connect-timeout"
|
||||
CONTACT_POINTS "contact-points"
|
||||
KEYSPACE "keyspace"
|
||||
CQL_CONSISTENCY "cql-consistency"
|
||||
MAX_RECONNECT_TRIES "max-reconnect-tries"
|
||||
RECONNECT_WAIT_TIME "reconnect-wait-time"
|
||||
REQUEST_TIMEOUT "request-timeout"
|
||||
@@ -712,6 +713,7 @@ database_map_param: database_type
|
||||
| tcp_keepalive
|
||||
| tcp_nodelay
|
||||
| keyspace
|
||||
| cql_consistency
|
||||
| unknown_map_entry
|
||||
;
|
||||
|
||||
@@ -816,6 +818,14 @@ keyspace: KEYSPACE {
|
||||
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 {
|
||||
ElementPtr n(new IntElement($3, ctx.loc2pos(@3)));
|
||||
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\" {
|
||||
switch(driver.ctx_) {
|
||||
case isc::dhcp::Parser6Context::LEASE_DATABASE:
|
||||
|
@@ -77,6 +77,7 @@ using namespace std;
|
||||
MAX_RECONNECT_TRIES "max-reconnect-tries"
|
||||
RECONNECT_WAIT_TIME "reconnect-wait-time"
|
||||
KEYSPACE "keyspace"
|
||||
CQL_CONSISTENCY "cql-consistency"
|
||||
REQUEST_TIMEOUT "request-timeout"
|
||||
TCP_KEEPALIVE "tcp-keepalive"
|
||||
TCP_NODELAY "tcp-nodelay"
|
||||
@@ -632,6 +633,7 @@ database_map_param: database_type
|
||||
| tcp_keepalive
|
||||
| tcp_nodelay
|
||||
| keyspace
|
||||
| cql_consistency
|
||||
| unknown_map_entry
|
||||
;
|
||||
|
||||
@@ -746,6 +748,14 @@ keyspace: KEYSPACE {
|
||||
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 {
|
||||
ElementPtr m(new MapElement(ctx.loc2pos(@1)));
|
||||
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
|
||||
CqlConnection::openDatabase() {
|
||||
CassError rc;
|
||||
@@ -123,6 +143,15 @@ CqlConnection::openDatabase() {
|
||||
// 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;
|
||||
std::string sreconnect_wait_time;
|
||||
try {
|
||||
@@ -194,6 +223,13 @@ CqlConnection::openDatabase() {
|
||||
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) {
|
||||
int32_t reconnect_wait_time_number;
|
||||
try {
|
||||
|
@@ -171,6 +171,9 @@ public:
|
||||
/// @brief Rollback Transactions
|
||||
virtual void rollback();
|
||||
|
||||
/// @brief parse Consistency value
|
||||
static CassConsistency parseConsistency(std::string value);
|
||||
|
||||
/// @brief Check for errors
|
||||
///
|
||||
/// Check for errors on the current database operation and returns text
|
||||
|
@@ -163,12 +163,11 @@ DatabaseConnection::toElement(const ParameterMap& params) {
|
||||
|
||||
if ((keyword == "lfc-interval") ||
|
||||
(keyword == "connect-timeout") ||
|
||||
(keyword == "request-timeout") ||
|
||||
(keyword == "port") ||
|
||||
(keyword == "max-reconnect-tries") ||
|
||||
(keyword == "reconnect-wait-time") ||
|
||||
(keyword == "tcp-keepalive")) {
|
||||
|
||||
(keyword == "max-reconnect-tries") ||
|
||||
(keyword == "request-timeout") ||
|
||||
(keyword == "tcp-keepalive") ||
|
||||
(keyword == "port")) {
|
||||
// integer parameters
|
||||
int64_t int_value;
|
||||
try {
|
||||
@@ -179,9 +178,8 @@ DatabaseConnection::toElement(const ParameterMap& params) {
|
||||
.arg("integer").arg(keyword).arg(value);
|
||||
}
|
||||
} else if ((keyword == "persist") ||
|
||||
(keyword == "readonly") ||
|
||||
(keyword == "tcp-nodelay")) {
|
||||
|
||||
(keyword == "tcp-nodelay") ||
|
||||
(keyword == "readonly")) {
|
||||
if (value == "true") {
|
||||
result->set(keyword, isc::data::Element::create(true));
|
||||
} else if (value == "false") {
|
||||
@@ -196,6 +194,7 @@ DatabaseConnection::toElement(const ParameterMap& params) {
|
||||
(keyword == "host") ||
|
||||
(keyword == "name") ||
|
||||
(keyword == "contact-points") ||
|
||||
(keyword == "cql-consistency") ||
|
||||
(keyword == "keyspace")) {
|
||||
result->set(keyword, isc::data::Element::create(value));
|
||||
} else {
|
||||
|
@@ -97,7 +97,7 @@ public:
|
||||
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() {
|
||||
return (max_retries_);
|
||||
}
|
||||
@@ -243,7 +243,7 @@ private:
|
||||
|
||||
};
|
||||
|
||||
}; // end of isc::db namespace
|
||||
}; // end of isc namespace
|
||||
} // namespace db
|
||||
} // namespace isc
|
||||
|
||||
#endif // DATABASE_CONNECTION_H
|
||||
|
@@ -18,7 +18,7 @@ namespace isc {
|
||||
namespace db {
|
||||
|
||||
/// @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.
|
||||
const DbLogger::MessageMap db_message_map = {
|
||||
|
@@ -44,7 +44,6 @@ extern const int DB_DBG_TRACE_DETAIL;
|
||||
/// @brief Common database library logger.
|
||||
extern isc::log::Logger database_logger;
|
||||
|
||||
|
||||
///@{
|
||||
/// @brief Database messages
|
||||
///
|
||||
|
@@ -59,8 +59,9 @@ DbAccessParser::parse(std::string& access_string,
|
||||
// 2. Update the copy with the passed keywords.
|
||||
for (std::pair<std::string, ConstElementPtr> param : database_config->mapValue()) {
|
||||
try {
|
||||
if ((param.first == "persist") || (param.first == "readonly") ||
|
||||
(param.first == "tcp-nodelay")) {
|
||||
if ((param.first == "persist") ||
|
||||
(param.first == "tcp-nodelay") ||
|
||||
(param.first == "readonly")) {
|
||||
values_copy[param.first] = (param.second->boolValue() ?
|
||||
"true" : "false");
|
||||
|
||||
@@ -100,6 +101,15 @@ DbAccessParser::parse(std::string& access_string,
|
||||
boost::lexical_cast<std::string>(port);
|
||||
|
||||
} else {
|
||||
// all remaining string parameters
|
||||
// type
|
||||
// user
|
||||
// password
|
||||
// host
|
||||
// name
|
||||
// contact-points
|
||||
// keyspace
|
||||
// cql-consistency
|
||||
values_copy[param.first] = param.second->stringValue();
|
||||
}
|
||||
} catch (const isc::data::TypeError& ex) {
|
||||
@@ -165,14 +175,14 @@ DbAccessParser::parse(std::string& access_string,
|
||||
<< " (" << value->getPosition() << ")");
|
||||
}
|
||||
|
||||
// Check that the max-reconnect-retries reasonable.
|
||||
// Check that the max-reconnect-tries is reasonable.
|
||||
if (max_reconnect_tries < 0) {
|
||||
ConstElementPtr value = database_config->get("max-reconnect-tries");
|
||||
isc_throw(DbConfigError, "max-reconnect-tries cannot be less than zero: "
|
||||
<< " (" << value->getPosition() << ")");
|
||||
}
|
||||
|
||||
// Check that the reconnect-wait-time reasonable.
|
||||
// Check that the reconnect-wait-time is reasonable.
|
||||
if ((reconnect_wait_time < 0) ||
|
||||
(reconnect_wait_time > std::numeric_limits<uint32_t>::max())) {
|
||||
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.
|
||||
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) ||
|
||||
(reconnect_wait_time > std::numeric_limits<uint32_t>::max())) {
|
||||
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) "
|
||||
<< " (" << value->getPosition() << ")");
|
||||
}
|
||||
|
||||
// Check that tcp_keepalive value makes sense.
|
||||
if ((tcp_keepalive < 0) ||
|
||||
(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
|
||||
<< " must be in range 0...MAX_UINT32 (4294967295) "
|
||||
<< " (" << value->getPosition() << ")");
|
||||
|
@@ -22,7 +22,6 @@ namespace db {
|
||||
/// This class is the parser for the database configuration. This is a
|
||||
/// map under the top-level "lease-database", "host-database" and
|
||||
/// "config-database" elements, and comprises a map of strings.
|
||||
///
|
||||
class DbAccessParser: public isc::data::SimpleParser {
|
||||
public:
|
||||
/// @brief Constructor
|
||||
@@ -79,8 +78,7 @@ private:
|
||||
DatabaseConnection::ParameterMap values_; ///< Stored parameter values
|
||||
};
|
||||
|
||||
}; // namespace db
|
||||
}; // namespace isc
|
||||
|
||||
} // namespace db
|
||||
} // namespace isc
|
||||
|
||||
#endif // DBACCESS_PARSER_H
|
||||
|
Reference in New Issue
Block a user