]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
Merge branch 'cassandra-update' into cassandra-host-data-source
authorAndrei Pavel <andrei.pavel@qualitance.com>
Fri, 18 Aug 2017 14:00:29 +0000 (17:00 +0300)
committerAndrei Pavel <andrei.pavel@qualitance.com>
Fri, 18 Aug 2017 14:00:29 +0000 (17:00 +0300)
1  2 
src/lib/dhcpsrv/cql_connection.h
src/lib/dhcpsrv/dhcpsrv_messages.mes
src/lib/dhcpsrv/tests/Makefile.am
src/lib/dhcpsrv/tests/cql_lease_mgr_unittest.cc
src/share/database/scripts/cql/dhcpdb_create.cql

index aa6e5a411d730b5ebaa54f11e0ad26f8e6da1015,a3b88d8c1525bd09fc51b5d566a7a63b7bf2aa49..70db2f2be0dca2f40f1e8fb4dfa166411535fbcc
  namespace isc {
  namespace dhcp {
  
- /// @brief Defines a single statement
+ /// @brief Pair containing major and minor versions
+ typedef std::pair<uint32_t, uint32_t> 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<std::string>.
+ struct StatementTagHash {
+     size_t operator()(StatementTag const& key) const {
+         return std::hash<std::string>{}(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<StatementTag,
+                            CqlTaggedStatement,
+                            StatementTagHash,
+                            StatementTagEqual>
+     StatementMap;
+ typedef std::pair<StatementTag, CqlTaggedStatement> StatementMapEntry;
  /// @brief Common CQL connector pool
  ///
  /// Provides common operations for the Cassandra database connection used by
index 7c15c151a5bf5f8a2612a7680b70ce750162c71d,bb24bf495fefaed73fcb9102707dfde1b10efb5b..04df354a091d8caf7fc4fb212e016fbf3f8c22ca
@@@ -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.
  
index 0c2f8cceeba9ea1ffccf73eb099ef1b74b0be367,520708319494910a4939d371ec24de5b82b3bfe2..9beafc8813c307e43599aeaee38076613ca78ab5
@@@ -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
index 1a1d35bed1c671e1f8b60899ac898c3fb0f0b0bb,49f242ab0d2896e24bab5dd9de269bb7f420ed72..2d6ab7d86f7de2dbf8310ad9ae028b8c04537d7b
@@@ -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
++