From: Andrei Pavel Date: Fri, 18 Aug 2017 14:00:29 +0000 (+0300) Subject: Merge branch 'cassandra-update' into cassandra-host-data-source X-Git-Tag: trac5425a_base~11^2~1^2~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4cd773d5423afc34b9d0d3cce30eda65acd116c6;p=thirdparty%2Fkea.git Merge branch 'cassandra-update' into cassandra-host-data-source --- 4cd773d5423afc34b9d0d3cce30eda65acd116c6 diff --cc src/lib/dhcpsrv/cql_connection.h index aa6e5a411d,a3b88d8c15..70db2f2be0 --- a/src/lib/dhcpsrv/cql_connection.h +++ b/src/lib/dhcpsrv/cql_connection.h @@@ -33,25 -33,78 +33,82 @@@ namespace isc { namespace dhcp { - /// @brief Defines a single statement + /// @brief Pair containing major and minor versions + typedef std::pair VersionPair; + + /// @brief Statement index representing the statement name + typedef char const* const StatementTag; + + /// @brief Define CQL backend version: 2.3 + /// @{ + constexpr uint32_t CQL_DRIVER_VERSION_MAJOR = CASS_VERSION_MAJOR; + constexpr uint32_t CQL_DRIVER_VERSION_MINOR = CASS_VERSION_MINOR; + /// @} + + /// Define CQL schema version: 2.0 + /// @{ + constexpr uint32_t CQL_SCHEMA_VERSION_MAJOR = 2u; + constexpr uint32_t CQL_SCHEMA_VERSION_MINOR = 0u; + /// @} + + /// @brief Defines a single statement or query /// - /// @param params_ parameter names /// @param name_ short description of the query /// @param text_ text representation of the actual query + /// @param prepared_statement_ internal Cassandra object representing the + /// prepared statement + /// @param is_raw_statement_ shows if statement should be executed rawly or with + /// binds struct CqlTaggedStatement { - const char** params_; - const char* name_; - const char* text_; + StatementTag name_; + char const* const text_; + const CassPrepared* prepared_statement_; + bool is_raw_statement_; + + /// @brief Constructor + CqlTaggedStatement(StatementTag name, char const* const text) + : name_(name), text_(text), prepared_statement_(NULL), + is_raw_statement_(false) { + } + + /// @brief Constructor + CqlTaggedStatement(StatementTag name, + char const* const text, + bool const& is_raw_statement) + : name_(name), text_(text), prepared_statement_(NULL), + is_raw_statement_(is_raw_statement) { + } }; - // Define CQL backend version: 2.3 - const uint32_t CQL_DRIVER_VERSION_MAJOR = CASS_VERSION_MAJOR; - const uint32_t CQL_DRIVER_VERSION_MINOR = CASS_VERSION_MINOR; + /// @brief Hash function for StatementMap keys + /// + /// Delegates to std::hash. + struct StatementTagHash { + size_t operator()(StatementTag const& key) const { + return std::hash{}(std::string(key)); + } + }; +/// Define CQL schema version: 2.0 +const uint32_t CQL_SCHEMA_VERSION_MAJOR = 2; +const uint32_t CQL_SCHEMA_VERSION_MINOR = 0; + + /// @brief Equality function for StatementMap keys + struct StatementTagEqual { + bool operator()(StatementTag const& lhs, StatementTag const& rhs) const { + return std::strcmp(lhs, rhs) == 0; + } + }; + + /// @brief Contains all statements. + typedef std::unordered_map + StatementMap; + + typedef std::pair StatementMapEntry; + /// @brief Common CQL connector pool /// /// Provides common operations for the Cassandra database connection used by diff --cc src/lib/dhcpsrv/dhcpsrv_messages.mes index 7c15c151a5,bb24bf495f..04df354a09 --- a/src/lib/dhcpsrv/dhcpsrv_messages.mes +++ b/src/lib/dhcpsrv/dhcpsrv_messages.mes @@@ -185,18 -185,12 +185,24 @@@ with the specified address to the Cassa A debug message issued when the server is about to add an IPv6 lease with the specified address to the Cassandra backend database. +% DHCPSRV_CQL_BEGIN_TRANSACTION committing to Cassandra database. +The server has issued a begin transaction call. + +% DHCPSRV_CQL_COMMIT committing to Cassandra database +A commit call been issued on the server. For Cassandra, this is a no-op. + +% DHCPSRV_CQL_DB opening Cassandra lease database: %1 +This informational message is logged when a DHCP server (either V4 or +V6) is about to open a Cassandra lease database. The parameters of +the connection including database name and username needed to access it +(but not the password if any) are logged. + + % DHCPSRV_CQL_COMMIT committing to Cassandra database. + A commit call been issued on the server. For Cassandra, this is a no-op. + + % DHCPSRV_CQL_CONNECTION_COMMIT committing to Cassandra database on current connection. + A commit call been issued on the server. For Cassandra, this is a no-op. + % DHCPSRV_CQL_DEALLOC_ERROR An error occurred while closing the CQL connection: %1 This is an error message issued when a DHCP server (either V4 or V6) experienced and error freeing CQL database resources as part of closing its connection to @@@ -313,6 -449,26 +461,8 @@@ host from a CQL database by IPv4 criter An informational message logged when a DHCP server is about to retrieve one host from a CQL database by IPv6 criteria. -% DHCPSRV_CQL_HOST_LOOKUP_BY_ID_4S Looking up primary key "id" filtering by host identifier. - -% DHCPSRV_CQL_HOST_LOOKUP_BY_4S Looking up primary key "id" filtering by host IPv4 address. - -% DHCPSRV_CQL_HOST_LOOKUP_BY_6S Looking up primary key "id" filtering by host IPv4 subnet ID. - -% DHCPSRV_CQL_HOST_LOOKUP_BY_ID_6S Looking up primary key "id" filtering by host identifier type. - -% DHCPSRV_CQL_HOST_LOOKUP_BY_4A Looking up primary key "id" filtering by host IPv4 address. - -% DHCPSRV_CQL_HOST_LOOKUP_BY_4S_4A Looking up primary key "id" filtering by host IPv6 subnet ID. - -% DHCPSRV_CQL_HOST_LOOKUP_BY_6S_6A Looking up primary key "id" filtering by reserved prefix address. - -% DHCPSRV_CQL_HOST_LOOKUP_BY_6A_6L Looking up primary key "id" filtering by reserved prefix length. - -% DHCPSRV_CQL_HOST_SYNC_RESERVATIONS Syncing reservations in database with kea.conf. - + % DHCPSRV_CQL_LEASE_EXCEPTION_THROWN Exception thrown during Cassandra operation: %1 + % DHCPSRV_DHCP4O6_RECEIVED_BAD_PACKET received bad DHCPv4o6 packet: %1 A bad DHCPv4o6 packet was received. diff --cc src/lib/dhcpsrv/tests/Makefile.am index 0c2f8cceeb,5207083194..9beafc8813 --- a/src/lib/dhcpsrv/tests/Makefile.am +++ b/src/lib/dhcpsrv/tests/Makefile.am @@@ -118,8 -118,8 +118,9 @@@ libdhcpsrv_unittests_SOURCES += pgsql_h libdhcpsrv_unittests_SOURCES += pgsql_lease_mgr_unittest.cc endif if HAVE_CQL + libdhcpsrv_unittests_SOURCES += cql_connection_unittest.cc libdhcpsrv_unittests_SOURCES += cql_lease_mgr_unittest.cc +libdhcpsrv_unittests_SOURCES += cql_host_data_source_unittest.cc endif libdhcpsrv_unittests_SOURCES += pool_unittest.cc libdhcpsrv_unittests_SOURCES += srv_config_unittest.cc diff --cc src/share/database/scripts/cql/dhcpdb_create.cql index 1a1d35bed1,49f242ab0d..2d6ab7d86f --- a/src/share/database/scripts/cql/dhcpdb_create.cql +++ b/src/share/database/scripts/cql/dhcpdb_create.cql @@@ -227,3 -230,3 +230,4 @@@ TRUNCATE SCHEMA_VERSION INSERT INTO schema_version (version, minor) VALUES(2, 0); -- This line concludes database upgrade to version 2.0 ++