diff options
-rw-r--r-- | src/bin/dhcp4/dhcp4_lexer.ll | 11 | ||||
-rw-r--r-- | src/bin/dhcp4/dhcp4_parser.yy | 10 | ||||
-rw-r--r-- | src/bin/dhcp6/dhcp6_lexer.ll | 11 | ||||
-rw-r--r-- | src/bin/dhcp6/dhcp6_parser.yy | 10 | ||||
-rw-r--r-- | src/lib/cql/cql_connection.cc | 36 | ||||
-rw-r--r-- | src/lib/cql/cql_connection.h | 3 | ||||
-rw-r--r-- | src/lib/database/database_connection.cc | 15 | ||||
-rw-r--r-- | src/lib/database/database_connection.h | 6 | ||||
-rw-r--r-- | src/lib/database/db_log.cc | 2 | ||||
-rw-r--r-- | src/lib/database/db_log.h | 1 | ||||
-rw-r--r-- | src/lib/database/dbaccess_parser.cc | 29 | ||||
-rw-r--r-- | src/lib/database/dbaccess_parser.h | 6 |
12 files changed, 118 insertions, 22 deletions
diff --git a/src/bin/dhcp4/dhcp4_lexer.ll b/src/bin/dhcp4/dhcp4_lexer.ll index f5d2293c79..de2e0caca6 100644 --- a/src/bin/dhcp4/dhcp4_lexer.ll +++ b/src/bin/dhcp4/dhcp4_lexer.ll @@ -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: diff --git a/src/bin/dhcp4/dhcp4_parser.yy b/src/bin/dhcp4/dhcp4_parser.yy index a91c949fb1..e7f41c47fe 100644 --- a/src/bin/dhcp4/dhcp4_parser.yy +++ b/src/bin/dhcp4/dhcp4_parser.yy @@ -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); diff --git a/src/bin/dhcp6/dhcp6_lexer.ll b/src/bin/dhcp6/dhcp6_lexer.ll index 6565d4ae5e..2c7137757a 100644 --- a/src/bin/dhcp6/dhcp6_lexer.ll +++ b/src/bin/dhcp6/dhcp6_lexer.ll @@ -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: diff --git a/src/bin/dhcp6/dhcp6_parser.yy b/src/bin/dhcp6/dhcp6_parser.yy index 164598c3e8..6d84c9f339 100644 --- a/src/bin/dhcp6/dhcp6_parser.yy +++ b/src/bin/dhcp6/dhcp6_parser.yy @@ -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); diff --git a/src/lib/cql/cql_connection.cc b/src/lib/cql/cql_connection.cc index e60da1d8b2..fa4cd8dbe9 100644 --- a/src/lib/cql/cql_connection.cc +++ b/src/lib/cql/cql_connection.cc @@ -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 { diff --git a/src/lib/cql/cql_connection.h b/src/lib/cql/cql_connection.h index fa70ff90cf..f0fe4ec1e9 100644 --- a/src/lib/cql/cql_connection.h +++ b/src/lib/cql/cql_connection.h @@ -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 diff --git a/src/lib/database/database_connection.cc b/src/lib/database/database_connection.cc index 131266c5da..ba7ff43019 100644 --- a/src/lib/database/database_connection.cc +++ b/src/lib/database/database_connection.cc @@ -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 { diff --git a/src/lib/database/database_connection.h b/src/lib/database/database_connection.h index 854d8a4f1d..c673111f50 100644 --- a/src/lib/database/database_connection.h +++ b/src/lib/database/database_connection.h @@ -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 diff --git a/src/lib/database/db_log.cc b/src/lib/database/db_log.cc index 2b60a9b65b..b86ac9339a 100644 --- a/src/lib/database/db_log.cc +++ b/src/lib/database/db_log.cc @@ -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 = { diff --git a/src/lib/database/db_log.h b/src/lib/database/db_log.h index 0351ba8c32..159a0ff202 100644 --- a/src/lib/database/db_log.h +++ b/src/lib/database/db_log.h @@ -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 /// diff --git a/src/lib/database/dbaccess_parser.cc b/src/lib/database/dbaccess_parser.cc index 9afb625cd9..23080fa069 100644 --- a/src/lib/database/dbaccess_parser.cc +++ b/src/lib/database/dbaccess_parser.cc @@ -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() << ")"); diff --git a/src/lib/database/dbaccess_parser.h b/src/lib/database/dbaccess_parser.h index e1ca821e0f..a6f9d4fcb2 100644 --- a/src/lib/database/dbaccess_parser.h +++ b/src/lib/database/dbaccess_parser.h @@ -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 |