Commit df949c9e authored by Tomek Mrugalski's avatar Tomek Mrugalski 🛰
Browse files

Merge branch 'cassandra-update' of https://github.com/andreipavelQ/kea into github35

parents e2d29b95 382a9b9f
......@@ -155,7 +155,8 @@ Kea uses log4cplus (http://sourceforge.net/projects/log4cplus/) for logging,
Boost (http://www.boost.org/) library for almost everything, and can use Botan
(http://botan.randombit.net/) or OpenSSL (https://www.openssl.org/) for
cryptographic operations. It can also optionally use PostgreSQL
(http://www.postgresql.org/) and/or MySQL (http://www.mysql.com/) as a database.
(http://www.postgresql.org/) and/or MySQL (http://www.mysql.com/) and/or
Cassandra (http://cassandra.apache.org/) as a database.
Kea can use googletest for unit-tests (https://github.com/google/googletest).
......
......@@ -448,17 +448,29 @@ be followed by a comma and another object definition.</para>
<xref linkend="cql-database-create"/>).
<screen>
"Dhcp4": { "lease-database": { <userinput>"name": "<replaceable>database-name</replaceable>" </userinput>, ... }, ... }
</screen>
For Cassandra:
<screen>
"Dhcp4": { "lease-database": { <userinput>"keyspace": "<replaceable>database-name</replaceable>" </userinput>, ... }, ... }
</screen>
If the database is located on a different system to the DHCPv4 server, the
database host name must also be specified. (It should be noted that this
configuration may have a severe impact on server performance.):
<screen>
"Dhcp4": { "lease-database": { <userinput>"host": <replaceable>remote-host-name</replaceable></userinput>, ... }, ... }
"Dhcp4": { "lease-database": { <userinput>"host": "<replaceable>remote-host-name</replaceable>"</userinput>, ... }, ... }
</screen>
For Cassandra, multiple contact points can be provided:
<screen>
"Dhcp4": { "lease-database": { <userinput>"contact-points": "<replaceable>remote-host-name[, ...] </replaceable>"</userinput>, ... }, ... }
</screen>
The usual state of affairs will be to have the database on the same machine as
the DHCPv4 server. In this case, set the value to the empty string:
<screen>
"Dhcp4": { "lease-database": { <userinput>"host" : ""</userinput>, ... }, ... }
</screen>
For Cassandra:
<screen>
"Dhcp4": { "lease-database": { <userinput>"contact-points": ""</userinput>, ... }, ... }
</screen>
Should the database use a port different than default, it may be
specified as well:
......@@ -3396,7 +3408,6 @@ It is merely echoed by the server
Cassandra (CQL).</para>
</section>
<section id="reservations4-tuning">
<title>Fine Tuning DHCPv4 Host Reservation</title>
......@@ -3505,9 +3516,6 @@ If not specified, the default value is:
src/lib/dhcpsrv/cfg_host_operations.cc -->
</para>
</section>
</section>
......
......@@ -443,17 +443,29 @@ be followed by a comma and another object definition.</para>
or <xref linkend="cql-database-create"/>).
<screen>
"Dhcp6": { "lease-database": { <userinput>"name": "<replaceable>database-name</replaceable>" </userinput>, ... }, ... }
</screen>
For Cassandra:
<screen>
"Dhcp6": { "lease-database": { <userinput>"keyspace": "<replaceable>database-name</replaceable>" </userinput>, ... }, ... }
</screen>
If the database is located on a different system to the DHCPv6 server, the
database host name must also be specified. (It should be noted that this
configuration may have a severe impact on server performance.):
<screen>
"Dhcp6": { "lease-database": { <userinput>"host": <replaceable>remote-host-name</replaceable></userinput>, ... }, ... }
"Dhcp6": { "lease-database": { <userinput>"host": "<replaceable>remote-host-name</replaceable>"</userinput>, ... }, ... }
</screen>
For Cassandra, multiple contact points can be provided:
<screen>
"Dhcp6": { "lease-database": { <userinput>"contact-points": "<replaceable>remote-host-name[, ...]</replaceable>" </userinput>, ... }, ... }
</screen>
The usual state of affairs will be to have the database on the same machine as
the DHCPv6 server. In this case, set the value to the empty string:
<screen>
"Dhcp6": { "lease-database": { <userinput>"host" : ""</userinput>, ... }, ... }
</screen>
For Cassandra:
<screen>
"Dhcp6": { "lease-database": { <userinput>"contact-points": ""</userinput>, ... }, ... }
</screen>
Should the database use a port different than default, it may be
specified as well:
......@@ -587,7 +599,6 @@ for MySQL and PostgreSQL databases.</para></note>
</section>
<section id="dhcp6-interface-selection">
<title>Interface Selection</title>
<para>The DHCPv6 server has to be configured to listen on specific network
......@@ -1217,7 +1228,6 @@ temporarily override a list of interface names and listen on all interfaces.
no means to validate the format at the moment.
</para>
<para>
<table frame="all" id="dhcp6-std-options-list">
<title>List of Standard DHCPv6 Options</title>
......@@ -2114,7 +2124,6 @@ should include options from the isc option space:
</itemizedlist>
</para>
<section id="dhcpv6-d2-io-config">
<title>DHCP-DDNS Server Connectivity</title>
<para>
......
......@@ -18,7 +18,7 @@
mysql_execute() {
QUERY=$1
shift
if [ $# -gt 1 ]; then
if [ $# -ge 1 ]; then
mysql -N -B $* -e "${QUERY}"
retcode=$?
else
......@@ -47,7 +47,7 @@ mysql_version() {
pgsql_execute() {
QUERY=$1
shift
if [ $# -gt 0 ]; then
if [ $# -ge 1 ]; then
echo $QUERY | psql --set ON_ERROR_STOP=1 -A -t -h localhost -q $*
retcode=$?
else
......@@ -71,7 +71,7 @@ pgsql_execute() {
pgsql_execute_script() {
file=$1
shift
if [ $# -gt 0 ]; then
if [ $# -ge 1 ]; then
psql --set ON_ERROR_STOP=1 -A -t -h localhost -q -f $file $*
retcode=$?
else
......@@ -90,8 +90,8 @@ pgsql_version() {
cql_execute() {
query=$1
shift
if [ $# -gt 1 ]; then
cqlsh $* -e "$query"
if [ $# -ge 1 ]; then
cqlsh "$@" -e "$query"
retcode=$?
else
cqlsh -u $db_user -p $db_password -k $db_name -e "$query"
......@@ -109,8 +109,8 @@ cql_execute() {
cql_execute_script() {
file=$1
shift
if [ $# -gt 1 ]; then
cqlsh $* -e "$file"
if [ $# -ge 1 ]; then
cqlsh "$@" -f "$file"
retcode=$?
else
cqlsh -u $db_user -p $db_password -k $db_name -f "$file"
......@@ -126,8 +126,9 @@ cql_execute_script() {
}
cql_version() {
version=`cql_execute "SELECT version, minor FROM schema_version" "$@"`
version=`echo "$version" | grep -A 1 "+" | grep -v "+" | tr -d ' ' | cut -d "|" -f 1-2 --output-delimiter="."`
echo $version
return $?
version=$(cql_execute "SELECT version, minor FROM schema_version" "$@")
error=$?
version=$(echo "$version" | grep -A 1 "+" | grep -v "+" | tr -d ' ' | cut -d "|" -f 1-2 --output-delimiter=".")
echo "$version"
return $error
}
......@@ -205,8 +205,8 @@ pgsql_init() {
cql_init() {
printf "Checking if there is a database initialized already... Please ignore errors.\n"
result=`cql_execute "USE $db_name; DESCRIBE tables;"`
if [ "$result"="<empty>" ]; then
result=$(cql_execute "DESCRIBE tables;")
if [ $(echo "$result" | grep "<empty>" | wc -w) -gt 0 ]; then
printf "Creating and initializing tables using script %s...\n" $scripts_dir/cql/dhcpdb_create.cql
cql_execute_script $scripts_dir/cql/dhcpdb_create.cql
else
......@@ -214,8 +214,8 @@ cql_init() {
exit 2
fi
version=`cql_version`
printf "Lease DB version reported after initialization: $version\n"
version=$(cql_version)
printf "Lease DB version reported after initialization: %s\n" "$version"
exit 0
}
......
......@@ -13,6 +13,7 @@ endif
if HAVE_CQL
SHTESTS += cql_tests.sh
endif
noinst_SCRIPTS = $(SHTESTS)
EXTRA_DIST = dhcpdb_create_1.0.mysql
......
......@@ -44,8 +44,7 @@ cql_lease_init_test() {
assert_eq 0 $? "lease4 table check failed, expected exit code: %d, actual: %d"
# Check lease6 table
cql_execute "SELECT address, duid, valid_lifetime, expire, subnet_id, pref_lifetime, lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname,\
state FROM lease6;"
cql_execute "SELECT address, duid, valid_lifetime, expire, subnet_id, pref_lifetime, lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname, state FROM lease6;"
assert_eq 0 $? "lease6 table check failed, expected exit code: %d, actual: %d"
# Check lease6_types table
......@@ -151,20 +150,20 @@ cql_lease4_dump_test() {
# 1430694930 corresponds to 2015-04-04 01:15:30
# 1433464245 corresponds to 2015-05-05 02:30:45
# 1436173267 corresponds to 2015-06-06 11:01:07
insert_sql="\
insert into lease4(address, hwaddr, client_id, valid_lifetime, expire, subnet_id,\
insert_cql="\
INSERT INTO lease4(address, hwaddr, client_id, valid_lifetime, expire, subnet_id,\
fqdn_fwd, fqdn_rev, hostname, state)\
values(-1073741302,textAsBlob('20'),textAsBlob('30'),40,1430694930,50,true,true,\
VALUES(-1073741302,textAsBlob('20'),textAsBlob('30'),40,1430694930,50,true,true,\
'one.example.com', 0);\
insert into lease4(address, hwaddr, client_id, valid_lifetime, expire, subnet_id,\
INSERT INTO lease4(address, hwaddr, client_id, valid_lifetime, expire, subnet_id,\
fqdn_fwd, fqdn_rev, hostname, state)\
values(-1073741301,NULL,textAsBlob('123'),40,1433464245,50,true,true,'', 1);\
insert into lease4(address, hwaddr, client_id, valid_lifetime, expire, subnet_id,\
VALUES(-1073741301,NULL,textAsBlob('123'),40,1433464245,50,true,true,'', 1);\
INSERT INTO lease4(address, hwaddr, client_id, valid_lifetime, expire, subnet_id,\
fqdn_fwd, fqdn_rev, hostname, state)\
values(-1073741300,textAsBlob('22'),NULL,40,1436173267,50,true,true,\
VALUES(-1073741300,textAsBlob('22'),NULL,40,1436173267,50,true,true,\
'three.example.com', 2);"
cql_execute "$insert_sql"
cql_execute "$insert_cql"
assert_eq 0 $? "insert into lease4 failed, expected exit code %d, actual %d"
# Dump lease4 to output_file.
......@@ -220,24 +219,24 @@ cql_lease6_dump_test() {
# 1430694930 corresponds to 2015-04-04 01:15:30
# 1433464245 corresponds to 2015-05-05 02:30:45
# 1436173267 corresponds to 2015-06-06 11:01:07
insert_sql="\
insert into lease6(address, duid, valid_lifetime, expire, subnet_id,\
insert_cql="\
INSERT INTO lease6(address, duid, valid_lifetime, expire, subnet_id,\
pref_lifetime, lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname,\
hwaddr, hwtype, hwaddr_source, state)\
values('2001:db8::10',textAsBlob('20'),30,1430694930,40,50,1,60,70,true,true,\
VALUES('2001:db8::10',textAsBlob('20'),30,1430694930,40,50,1,60,70,true,true,\
'one.example.com',textAsBlob('80'),90,16,0);\
insert into lease6(address, duid, valid_lifetime, expire, subnet_id,\
INSERT INTO lease6(address, duid, valid_lifetime, expire, subnet_id,\
pref_lifetime, lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname,\
hwaddr, hwtype, hwaddr_source, state)\
values('2001:db8::11',NULL,30,1433464245,40,50,1,60,70,true,true,\
VALUES('2001:db8::11',NULL,30,1433464245,40,50,1,60,70,true,true,\
'',textAsBlob('80'),90,1,1);\
insert into lease6(address, duid, valid_lifetime, expire, subnet_id,\
INSERT INTO lease6(address, duid, valid_lifetime, expire, subnet_id,\
pref_lifetime, lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname,\
hwaddr, hwtype, hwaddr_source, state)\
values('2001:db8::12',textAsBlob('21'),30,1436173267,40,50,1,60,70,true,true,\
VALUES('2001:db8::12',textAsBlob('21'),30,1436173267,40,50,1,60,70,true,true,\
'three.example.com',textAsBlob('80'),90,4,2);"
cql_execute "$insert_sql"
cql_execute "$insert_cql"
assert_eq 0 $? "insert into lease6 failed, expected exit code %d, actual %d"
# Dump lease4 to output_file.
......
-- Copyright (C) 2015 - 2016 Deutsche Telekom AG.
-- Copyright (C) 2015-2017 Deutsche Telekom AG.
-- Author: Razvan Becheriu <razvan.becheriu@qualitance.com>
......@@ -43,7 +43,10 @@
-- This line starts database initialization to 1.0.
-- Holds the IPv4 leases.
CREATE TABLE lease4 (
-- -----------------------------------------------------
-- Table `lease4`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS lease4 (
address int,
hwaddr blob,
client_id blob,
......@@ -54,27 +57,31 @@ CREATE TABLE lease4 (
fqdn_rev boolean,
hostname varchar,
state int,
PRIMARY KEY (address)
PRIMARY KEY ((address))
);
-- Create search indexes for lease4 table
CREATE INDEX lease4index1 ON lease4 (client_id);
CREATE INDEX lease4index2 ON lease4 (subnet_id);
CREATE INDEX lease4index3 ON lease4 (hwaddr);
CREATE INDEX lease4index4 ON lease4 (state);
CREATE INDEX IF NOT EXISTS lease4index1 ON lease4 (client_id);
CREATE INDEX IF NOT EXISTS lease4index2 ON lease4 (subnet_id);
CREATE INDEX IF NOT EXISTS lease4index3 ON lease4 (hwaddr);
CREATE INDEX IF NOT EXISTS lease4index4 ON lease4 (expire);
CREATE INDEX IF NOT EXISTS lease4index5 ON lease4 (state);
-- Holds the IPv6 leases.
-- N.B. The use of a VARCHAR for the address is temporary for development:
-- it will eventually be replaced by BINARY(16).
CREATE TABLE lease6 (
-- -----------------------------------------------------
-- Table `lease6`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS lease6 (
address varchar,
duid blob,
valid_lifetime bigint,
expire bigint,
subnet_id int,
pref_lifetime bigint,
lease_type int,
duid blob,
iaid int,
lease_type int,
prefix_len int,
fqdn_fwd boolean,
fqdn_rev boolean,
......@@ -83,41 +90,47 @@ CREATE TABLE lease6 (
hwtype int,
hwaddr_source int,
state int,
PRIMARY KEY (address)
PRIMARY KEY ((address))
);
-- Create search indexes for lease6 table
CREATE INDEX lease6index1 ON lease6 (lease_type);
CREATE INDEX lease6index2 ON lease6 (duid);
CREATE INDEX lease6index3 ON lease6 (iaid);
CREATE INDEX lease6index4 ON lease6 (subnet_id);
CREATE INDEX lease6index5 ON lease6 (state);
CREATE INDEX IF NOT EXISTS lease6index1 ON lease6 (duid);
CREATE INDEX IF NOT EXISTS lease6index2 ON lease6 (iaid);
CREATE INDEX IF NOT EXISTS lease6index3 ON lease6 (lease_type);
CREATE INDEX IF NOT EXISTS lease6index4 ON lease6 (subnet_id);
CREATE INDEX IF NOT EXISTS lease6index5 ON lease6 (expire);
CREATE INDEX IF NOT EXISTS lease6index6 ON lease6 (state);
-- ... and a definition of lease6 types. This table is a convenience for
-- users of the database - if they want to view the lease table and use the
-- type names, they can join this table with the lease6 table.
-- Make sure those values match Lease6::LeaseType enum (see src/bin/dhcpsrv/
-- lease_mgr.h)
CREATE TABLE lease6_types (
-- -----------------------------------------------------
-- Table `lease6_types`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS lease6_types (
lease_type int, -- Lease type code.
name varchar, -- Name of the lease type
PRIMARY KEY (lease_type)
PRIMARY KEY ((lease_type))
);
INSERT INTO lease6_types (lease_type, name) VALUES (0, 'IA_NA'); -- Non-temporary v6 addresses
INSERT INTO lease6_types (lease_type, name) VALUES (1, 'IA_TA'); -- Temporary v6 addresses
INSERT INTO lease6_types (lease_type, name) VALUES (2, 'IA_PD'); -- Prefix delegations
-- Kea keeps track of the hardware/MAC address source, i.e. how the address
-- was obtained. Depending on the technique and your network topology, it may
-- be more or less trustworthy. This table is a convenience for
-- users of the database - if they want to view the lease table and use the
-- type names, they can join this table with the lease6 table. For details,
-- see constants defined in src/lib/dhcp/dhcp/pkt.h for detailed explanation.
CREATE TABLE lease_hwaddr_source (
-- -----------------------------------------------------
-- Table `lease_hwaddr_source`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS lease_hwaddr_source (
hwaddr_source int,
name varchar,
PRIMARY KEY (hwaddr_source)
PRIMARY KEY ((hwaddr_source))
);
-- Hardware address obtained from raw sockets
......@@ -141,51 +154,16 @@ INSERT INTO lease_hwaddr_source (hwaddr_source, name) VALUES (32, 'HWADDR_SOURCE
-- Hardware address extracted from docsis options
INSERT INTO lease_hwaddr_source (hwaddr_source, name) VALUES (64, 'HWADDR_SOURCE_DOCSIS_CMTS');
-- -----------------------------------------------------
-- Table `dhcp4_options`
-- -----------------------------------------------------
CREATE TABLE dhcp4_options (
option_id int,
code int,
value blob,
formatted_value varchar,
space varchar,
persistent int,
dhcp_client_class varchar,
dhcp4_subnet_id int,
host_id int,
PRIMARY KEY (option_id)
);
-- Create search indexes for dhcp4_options table
CREATE INDEX dhcp4_optionsindex1 ON dhcp4_options (host_id);
-- -----------------------------------------------------
-- Table `dhcp6_options`
-- -----------------------------------------------------
CREATE TABLE dhcp6_options (
option_id int,
code int,
value blob,
formatted_value varchar,
space varchar,
persistent int,
dhcp_client_class varchar,
dhcp6_subnet_id int,
host_id int,
PRIMARY KEY (option_id)
);
-- Create search indexes for dhcp6_options table
CREATE INDEX dhcp6_optionsindex1 ON dhcp6_options (host_id);
-- Create table holding mapping of the lease states to their names.
-- This is not used in queries from the DHCP server but rather in
-- direct queries from the lease database management tools.
CREATE TABLE lease_state (
-- -----------------------------------------------------
-- Table `lease_state`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS lease_state (
state int,
name varchar,
PRIMARY KEY (state)
PRIMARY KEY ((state))
);
-- Insert currently defined state names.
......@@ -199,9 +177,16 @@ INSERT INTO lease_state (state, name) VALUES (2, 'expired-reclaimed');
-- first column is called "version" and not "major".
-- Note: This MUST be kept in step with src/share/database/scripts/cassandra/dhcpdb_create.cql,
-- which defines the schema for the unit tests.
CREATE TABLE schema_version (
-- -----------------------------------------------------
-- Table `schema_version`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS schema_version (
version int,
minor int,
PRIMARY KEY (version)
PRIMARY KEY ((version))
);
INSERT INTO schema_version (version, minor) VALUES (1, 0);
-- This line concludes database initialization to version 1.0.
......@@ -3224,7 +3224,7 @@ const char* UNPARSED_CONFIGS[] = {
" {\n"
" \"always-send\": false,\n"
" \"code\": 7,\n"
" \"csv-format\": false,\n"
" \"csv-format\": true,\n"
" \"data\": \"01\",\n"
" \"name\": \"preference\",\n"
" \"space\": \"dhcp6\"\n"
......
......@@ -131,6 +131,7 @@ libkea_dhcpsrv_la_SOURCES += logging.cc logging.h
libkea_dhcpsrv_la_SOURCES += logging_info.cc logging_info.h
libkea_dhcpsrv_la_SOURCES += memfile_lease_mgr.cc memfile_lease_mgr.h
libkea_dhcpsrv_la_SOURCES += memfile_lease_storage.h
libkea_dhcpsrv_la_SOURCES += sql_common.h
if HAVE_MYSQL
libkea_dhcpsrv_la_SOURCES += mysql_lease_mgr.cc mysql_lease_mgr.h
......@@ -148,10 +149,13 @@ libkea_dhcpsrv_la_SOURCES += pgsql_exchange.cc pgsql_exchange.h
libkea_dhcpsrv_la_SOURCES += pgsql_host_data_source.cc pgsql_host_data_source.h
libkea_dhcpsrv_la_SOURCES += pgsql_lease_mgr.cc pgsql_lease_mgr.h
endif
if HAVE_CQL
libkea_dhcpsrv_la_SOURCES += cql_lease_mgr.cc cql_lease_mgr.h
libkea_dhcpsrv_la_SOURCES += cql_connection.cc cql_connection.h
libkea_dhcpsrv_la_SOURCES += cql_exchange.cc cql_exchange.h
libkea_dhcpsrv_la_SOURCES += cql_lease_mgr.cc cql_lease_mgr.h
endif
libkea_dhcpsrv_la_SOURCES += pool.cc pool.h
libkea_dhcpsrv_la_SOURCES += shared_network.cc shared_network.h
libkea_dhcpsrv_la_SOURCES += srv_config.cc srv_config.h
......@@ -337,5 +341,3 @@ libkea_dhcpsrv_parsers_include_HEADERS = \
install-data-local:
$(mkinstalldirs) $(DESTDIR)$(dhcp_data_dir)
......@@ -108,7 +108,7 @@ CfgDbAccess::toElementDbAccessString(const std::string& dbaccess) {
(keyword == "password") ||
(keyword == "host") ||
(keyword == "name") ||
(keyword == "contact_points") ||
(keyword == "contact-points") ||
(keyword == "keyspace")) {
result->set(keyword, Element::create(value));
} else {
......
......@@ -169,9 +169,9 @@ CfgOption::mergeInternal(const OptionSpaceContainer<OptionContainer,
// If there is no such option in the destination container,
// add one.
if (std::distance(range.first, range.second) == 0) {
dest_container.addItem(OptionDescriptor(src_opt->option_,
src_opt->persistent_),
*it);
dest_container.addItem(OptionDescriptor(
src_opt->option_, src_opt->persistent_,
src_opt->formatted_value_), *it);
}
}
}
......
// Copyright (C) 2015 - 2016 Deutsche Telekom AG.
// Copyright (C) 2015-2017 Deutsche Telekom AG.
//
// Author: Razvan Becheriu <razvan.becheriu@qualitance.com>
// Authors: Razvan Becheriu <razvan.becheriu@qualitance.com>
// Andrei Pavel <andrei.pavel@qualitance.com>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
......@@ -14,36 +15,45 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include <config.h>
#include <dhcpsrv/cql_connection.h>
#include <string>
#include <dhcpsrv/cql_exchange.h>
#include <dhcpsrv/db_exceptions.h>
#include <dhcpsrv/dhcpsrv_log.h>
using namespace std;
#include <memory> // for std::unique_ptr
namespace isc {
namespace dhcp {
CqlConnection::CqlConnection(const ParameterMap& parameters) :
DatabaseConnection(parameters), cluster_(NULL), session_(NULL),
tagged_statements_(NULL) {
CqlConnection::CqlConnection(const ParameterMap& parameters)
: DatabaseConnection(parameters), statements_(), cluster_(NULL),
session_(NULL), consistency_(CASS_CONSISTENCY_QUORUM), schema_meta_(NULL),
keyspace_meta_(NULL), force_consistency_(true) {
}
CqlConnection::~CqlConnection() {
// Free up the prepared statements, ignoring errors.
// Session and connection resources are deallocated.
// Free up the prepared statements, ignoring errors. Session and connection
// resources are deallocated.
CassError rc = CASS_OK;
std::string error;
for (int i = 0; i < statements_.size(); i++) {
if (statements_[i]) {
cass_prepared_free(statements_[i]);
for (StatementMapEntry s : statements_) {
// typeid(s.second.first) is CassPrepared*
CqlTaggedStatement statement = s.second;
if (statement.prepared_statement_) {
cass_prepared_free(statement.prepared_statement_);
}
statements_[i] = NULL;
}
if (session_) {
cass_schema_meta_free(schema_meta_);
CassFuture* close_future = cass_session_close(session_);
cass_future_wait(close_future);
checkStatementError(error, close_future, "could not close connection to DB");
error = checkFutureError(
"CqlConnection::~CqlConnection(): cass_sesssion_close() != CASS_OK",
close_future);
rc = cass_future_error_code(close_future);
cass_future_free(close_future);
cass_session_free(session_);
......@@ -55,10 +65,9 @@ CqlConnection::~CqlConnection() {
cluster_ = NULL;
}
// We're closing the connection anyway. Let's not throw at this
// stage
if (rc != CASS_OK) {
isc_throw(DbOpenError, error);
// We're closing the connection anyway. Let's not throw at this stage.
LOG_ERROR(dhcpsrv_logger, DHCPSRV_CQL_DEALLOC_ERROR).arg(error);
}
}
......@@ -67,25 +76,25 @@ CqlConnection::openDatabase() {
CassError rc;
// Set up the values of the parameters
const char* contact_points = "127.0.0.1";
string scontact_points;
std::string scontact_points;
try {
scontact_points = getParameter("contact-points");
contact_points = scontact_points.c_str();
} catch (...) {
// No host. Fine, we'll use "localhost".
// No host. Fine, we'll use "127.0.0.1".
}
const char* port = NULL;
string sport;
std::string sport;
try {