} \
}
+/// @brief a helper structure with a function call operator that returns
+/// key value in a format expected by std::hash.
struct ExchangeDataTypeHash {
public:
size_t operator()(const ExchangeDataType& key) const {
}
};
+/// @brief Defines a type for storing aux. Cassandra functions
typedef std::unordered_map<ExchangeDataType, CqlFunction, ExchangeDataTypeHash>
CqlFunctionMap;
extern CqlFunctionMap CQL_FUNCTIONS;
/// @brief hash function for CassTypeMap
///
-/// Required by c++ versions 5 and below.
+/// Required by g++ versions 5 and below.
///
/// @param key being hashed
///
/// @brief Map types used to determine exchange type
/// @{
+
+/// @brief Defines type that maps specific type to an enum
typedef std::unordered_map<std::type_index, ExchangeDataType> AnyTypeMap;
-// Declare uint8_t as key here for compatibility with c++-5. Ideally, it would
-// be CassValueType
+
+// Declare uint8_t as key here for compatibility with g++ version 5. Ideally,
+// it would be CassValueType
typedef std::unordered_map<uint8_t, ExchangeDataType> CassTypeMap;
/// @}
{typeid(std::string*), EXCHANGE_DATA_TYPE_STRING},
{typeid(CassBlob*), EXCHANGE_DATA_TYPE_BYTES},
{typeid(CassUuid*), EXCHANGE_DATA_TYPE_UUID},
- {typeid(Udt*), EXCHANGE_DATA_TYPE_UDT},
- {typeid(Collection*), EXCHANGE_DATA_TYPE_COLLECTION}};
+ {typeid(Udt*), EXCHANGE_DATA_TYPE_UDT}, // user data type
+ {typeid(AnyCollection*), EXCHANGE_DATA_TYPE_COLLECTION}};
/// @brief Maps Cassandra type to exchange type
static CassTypeMap CASS_TYPE_MAP = {
{CASS_VALUE_TYPE_UDT, EXCHANGE_DATA_TYPE_UDT},
{CASS_VALUE_TYPE_TUPLE, EXCHANGE_DATA_TYPE_UDT}};
-/// @brief Udt method implementations
+/// @brief Udt (user data type) method implementations
/// @{
Udt::Udt(const CqlConnection& connection, const std::string& name)
: AnyArray(), connection_(connection), name_(name) {
}
Udt::~Udt() {
+ /// @todo: Need to get back to this issue. This is likely a memory leak.
+ //
// Bug: it seems that if there is no call to
// cass_user_type_set_*(cass_user_type_), then
// cass_user_type_free(cass_user_type_) might SIGSEGV, so we never
CassStatement* statement) {
Udt* udt = boost::any_cast<Udt*>(value);
+ if (!udt) {
+ isc_throw(BadValue, "Invalid value specified, not an Udt object");
+ }
+
size_t i = 0u;
+
+ // Let's iterate over all elements in udt and check that we indeed
+ // can assign the set function for each specified type.
for (boost::any& element : *udt) {
try {
KEA_CASS_CHECK(
CqlBindCollection(const boost::any& value,
const size_t& index,
CassStatement* statement) {
- Collection* elements = boost::any_cast<Collection*>(value);
+ AnyCollection* elements = boost::any_cast<AnyCollection*>(value);
CassCollection* collection =
cass_collection_new(CASS_COLLECTION_TYPE_SET, elements->size());
+ // Iterate over all elements and assign appropriate append function
+ // for each.
for (boost::any& element : *elements) {
ExchangeDataType type = exchangeType(element);
KEA_CASS_CHECK(CQL_FUNCTIONS[type].cqlCollectionAppendFunction_(
static CassError
CqlGetCollection(const boost::any& data, const CassValue* value) {
- Collection* collection = boost::any_cast<Collection*>(data);
+ AnyCollection* collection = boost::any_cast<AnyCollection*>(data);
+ if (!collection) {
+ isc_throw(DbOperationError, "CqlGetCollection(): column is not a collection");
+ }
+
BOOST_ASSERT(collection->size() == 1);
- // @todo: Create a copy of the underlying object rather than referencing to
- // it.
+ /// @todo: Create a copy of the underlying object rather than referencing to
+ /// it.
boost::any underlying_object = *collection->begin();
collection->clear();
collection->push_back(underlying_object);
KEA_CASS_CHECK(CQL_FUNCTIONS[exchangeType(type)].cqlGetFunction_(
*collection->rbegin(), item_value));
- // If cqlGetFunction_() returns != CASS_OK, don't
+ // If cqlGetFunction_() returns != CASS_OK, don't call
// cass_iterator_free(items_iterator) because we're returning from this
// function and throwing from the callee.
}
CqlExchange::convertFromDatabaseTime(const cass_int64_t& expire,
const cass_int64_t& valid_lifetime,
time_t& cltt) {
+ /// @todo: Although 2037 is still far away, there are people who use infinite
+ /// lifetimes. Cassandra doesn't have to support it right now, but at least
+ /// we should be able to detect a problem.
+
// Convert to local time
cltt = static_cast<time_t>(expire - valid_lifetime);
}
AnyArray
-CqlExchange::executeSelect(const CqlConnection& connection,
- const AnyArray& data,
- StatementTag statement_tag,
- const bool& single /* = false */) {
+CqlExchange::executeSelect(const CqlConnection& connection, const AnyArray& data,
+ StatementTag statement_tag, const bool& single /* = false */) {
CassError rc;
CassStatement* statement = NULL;
CassFuture* future = NULL;
AnyArray local_data = data;
- StatementMap::const_iterator it =
- connection.statements_.find(statement_tag);
+ // Find the query statement first.
+ StatementMap::const_iterator it = connection.statements_.find(statement_tag);
if (it == connection.statements_.end()) {
isc_throw(DbOperationError,
"CqlExchange::executeSelect(): Statement "
<< statement_tag << "has not been prepared.");
}
+
+ // Bind the data before the query is executed.
CqlTaggedStatement tagged_statement = it->second;
- if (tagged_statement.is_raw_statement_) {
+ if (tagged_statement.is_raw_) {
// The entire query is the first element in data.
std::string* query = boost::any_cast<std::string*>(local_data.back());
local_data.pop_back();
}
}
+ // Set specific level of consistency if we're told to do so.
if (connection.force_consistency_) {
rc = cass_statement_set_consistency(statement, connection.consistency_);
if (rc != CASS_OK) {
CqlCommon::bindData(local_data, statement);
+ // Everything's ready. Call the actual statement.
future = cass_session_execute(connection.session_, statement);
if (!future) {
cass_statement_free(statement);
"CqlExchange::executeSelect(): no CassFuture for statement "
<< tagged_statement.name_);
}
+
+ // Wait for the statement execution to complete.
cass_future_wait(future);
const std::string error = connection.checkFutureError(
"CqlExchange::executeSelect(): cass_session_execute() != CASS_OK",
}
void
-CqlExchange::executeMutation(
- const CqlConnection& connection,
- const AnyArray& data,
- StatementTag statement_tag) {
+CqlExchange::executeMutation(const CqlConnection& connection, const AnyArray& data,
+ StatementTag statement_tag) {
CassError rc;
CassStatement* statement = NULL;
CassFuture* future = NULL;
+ // Find the statement on a list of prepared statements.
StatementMap::const_iterator it =
connection.statements_.find(statement_tag);
if (it == connection.statements_.end()) {
- isc_throw(DbOperationError,
- "CqlExchange::executeSelect(): Statement "
- << statement_tag << "has not been prepared.");
+ isc_throw(DbOperationError, "CqlExchange::executeSelect(): Statement "
+ << statement_tag << "has not been prepared.");
}
+ // Bind the statement.
CqlTaggedStatement tagged_statement = it->second;
statement = cass_prepared_bind(tagged_statement.prepared_statement_);
if (!statement) {
<< tagged_statement.name_);
}
+ // Set specific level of consistency, if told to do so.
if (connection.force_consistency_) {
rc = cass_statement_set_consistency(statement, connection.consistency_);
if (rc != CASS_OK) {
cass_statement_free(statement);
- isc_throw(DbOperationError,
- "CqlExchange::executeMutation(): unable to set statement "
- "consistency for statement "
- << tagged_statement.name_
- << ", Cassandra error code: " << cass_error_desc(rc));
+ isc_throw(DbOperationError, "CqlExchange::executeMutation(): unable to set"
+ " statement consistency for statement " << tagged_statement.name_
+ << ", Cassandra error code: " << cass_error_desc(rc));
}
}
<< tagged_statement.name_);
}
cass_future_wait(future);
- const std::string error = connection.checkFutureError(
- "CqlExchange::executeMutation(): cass_session_execute() != CASS_OK",
- future, statement_tag);
+ const std::string error = connection.checkFutureError("CqlExchange::executeMutation():"
+ "cass_session_execute() != CASS_OK", future, statement_tag);
rc = cass_future_error_code(future);
if (rc != CASS_OK) {
cass_future_free(future);
}
// Check if statement has been applied.
- bool applied = hasStatementBeenApplied(future);
+ bool applied = statementApplied(future);
// Free resources.
cass_future_free(future);
}
bool
-CqlExchange::hasStatementBeenApplied(CassFuture* future,
+CqlExchange::statementApplied(CassFuture* future,
size_t* row_count,
size_t* column_count) {
const CassResult* result_collection = cass_future_get_result(future);
+ if (!result_collection) {
+ isc_throw(DbOperationError, "CqlExchange::statementApplied(): unable to get"
+ " results collection");
+ }
if (row_count) {
*row_count = cass_result_row_count(result_collection);
}
constexpr StatementTag CqlVersionExchange::GET_VERSION;
StatementMap CqlVersionExchange::tagged_statements_ = {
- {GET_VERSION, //
- {GET_VERSION, //
- "SELECT "
- "version, minor "
- "FROM schema_version "}} //
+ {GET_VERSION, {GET_VERSION, "SELECT version, minor FROM schema_version "}}
};
CqlVersionExchange::CqlVersionExchange() {
}
void
-CqlVersionExchange::createBindForSelect(
- AnyArray& data, StatementTag /* statement_tag = NULL */) {
- // Start with a fresh array.
- data.clear();
- // id: blob
- data.add(&version_);
- // host_identifier: blob
- data.add(&minor_);
+CqlVersionExchange::createBindForSelect(AnyArray& data, StatementTag) {
+ data.clear(); // Start with a fresh array.
+ data.add(&version_); // first column is a major version
+ data.add(&minor_); // second column is a minor version
}
boost::any
/// @brief Common CQL and Lease Data Methods
///
-/// The CqlLease4Exchange and CqlLease6Exchange classes provide the
+/// The @ref CqlLease4Exchange and @ref CqlLease6Exchange classes provide the
/// functionality to set up binding information between variables in the
/// program and data extracted from the database. This class is the common
/// base to both of them, containing some common methods.
class CqlLeaseExchange : public CqlExchange {
public:
+ /// @brief Constructor
+ ///
+ /// @param connection already open Cassandra connection.
CqlLeaseExchange(const CqlConnection &connection)
: connection_(connection), valid_lifetime_(0), expire_(0),
subnet_id_(0), fqdn_fwd_(cass_false), fqdn_rev_(cass_false),
/// @brief Lease expiry time
cass_int64_t expire_;
- /// @brief Subnet identification
+ /// @brief Subnet identifier
cass_int32_t subnet_id_;
- /// @brief Has forward DNS update been performed
+ /// @brief Has forward DNS update been performed?
cass_bool_t fqdn_fwd_;
- /// @brief Has reverse DNS update been performed
+ /// @brief Has reverse DNS update been performed?
cass_bool_t fqdn_rev_;
/// @brief Client hostname
cass_int32_t state_;
};
-/// @brief Exchange CQL and Lease4 Data
+/// @brief Exchange Lease4 information between Kea and CQL
///
/// On any CQL operation, arrays of CQL BIND structures must be built to
/// describe the parameters in the prepared statements. Where information is
///
/// The initialization of the variables here is only to satisfy cppcheck -
/// all variables are initialized/set in the methods before they are used.
+ ///
+ /// @param connection connection used for this query
explicit CqlLease4Exchange(const CqlConnection &connection);
/// @brief Create CQL_BIND objects for Lease4 Pointer
///
/// Fills in the CQL_BIND array for sending data in the Lease4 object to
/// the database. Used for INSERT statements.
+ ///
+ /// @param lease The lease information to be inserted
+ /// @param data Lease info will be stored here in CQL format
void createBindForInsert(const Lease4Ptr &lease, AnyArray &data);
/// @brief Create CQL_BIND objects for Lease4 Pointer
///
/// Fills in the CQL_BIND array for sending data in the Lease4 object to
/// the database. Used for UPDATE statements.
+ ///
+ /// @param lease Updated lease information.
+ /// @param data lease info in CQL format will be stored here
+ /// @param statement_tag tag identifying the query (optional)
void createBindForUpdate(const Lease4Ptr &lease,
AnyArray &data,
StatementTag statement_tag = NULL);
///
/// Fills in the CQL_BIND array for sending data in the Lease4 object to
/// the database. Used for DELETE statements.
+ ///
+ /// @param address address of the lease to be deleted
+ /// @param data lease info in CQL format will be stored here
+ /// @param statement_tag tag identifying the query (optional)
void createBindForDelete(const IOAddress &address,
AnyArray &data,
StatementTag statement_tag = NULL);
/// @brief Create BIND array to receive data
///
/// Creates a CQL_BIND array to receive Lease4 data from the database.
+ ///
+ /// @param data info returned by CQL will be stored here
+ /// @param statement_tag tag identifying the query (optional)
virtual void
- createBindForSelect(AnyArray &data,
- StatementTag statement_tag = NULL) override;
+ createBindForSelect(AnyArray &data, StatementTag statement_tag = NULL) override;
+ /// @brief Retrieves the Lease4 object in Kea format
+ ///
+ /// @return C++ representation of the object being returned
virtual boost::any retrieve() override;
- void getLeaseCollection(StatementTag &statement_tag,
- AnyArray &data,
+ /// @brief Retrieves zero or more IPv4 leases
+ ///
+ /// @param statement_tag query to be executed
+ /// @param data parameters for the query
+ /// @param result this lease collection will be updated
+ void getLeaseCollection(StatementTag &statement_tag, AnyArray &data,
Lease4Collection &result);
+ /// @brief Retrieves one IPv4 lease
+ ///
+ /// @param statement_tag query to be executed
+ /// @param data parameters for the query
+ /// @param result pointer to the lease being returned (or null)
void
getLease(StatementTag &statement_tag, AnyArray &data, Lease4Ptr &result);
- void getExpiredLeases(const size_t &max_leases,
- Lease4Collection &expired_leases);
+ /// @brief Returns expired leases.
+ ///
+ /// This method returns up to specified number (see max_leases) of
+ /// expired leases.
+ ///
+ /// @param max_leases at most this number of leases will be returned
+ /// @param expired_leases expired leases will be stored here
+ void getExpiredLeases(const size_t &max_leases, Lease4Collection &expired_leases);
/// @brief Cassandra statements
static StatementMap tagged_statements_;
StatementMap CqlLease4Exchange::tagged_statements_{
- {INSERT_LEASE4, //
- {INSERT_LEASE4, //
+ // Inserts new IPv4 lease
+ {INSERT_LEASE4,
+ {INSERT_LEASE4,
"INSERT INTO lease4( "
"address, hwaddr, client_id, valid_lifetime, expire, subnet_id, "
"fqdn_fwd, fqdn_rev, hostname, state "
") "
"IF NOT EXISTS "}},
- {UPDATE_LEASE4, //
- {UPDATE_LEASE4, //
+ // Updates existing IPv4 lease
+ {UPDATE_LEASE4,
+ {UPDATE_LEASE4,
"UPDATE lease4 SET "
"hwaddr = ?, "
"client_id = ?, "
"WHERE address = ? "
"IF EXISTS "}},
- {DELETE_LEASE4, //
- {DELETE_LEASE4, //
+ // Deletes existing IPv4 lease
+ {DELETE_LEASE4,
+ {DELETE_LEASE4,
"DELETE FROM lease4 "
"WHERE address = ? "
"IF EXISTS "}},
- {GET_LEASE4_EXPIRE, //
- {GET_LEASE4_EXPIRE, //
+ // Gets up to a certain number of expired IPv4 leases
+ {GET_LEASE4_EXPIRE,
+ {GET_LEASE4_EXPIRE,
"SELECT "
"address, hwaddr, client_id, valid_lifetime, expire, subnet_id, "
"fqdn_fwd, fqdn_rev, hostname, state "
"LIMIT ? "
"ALLOW FILTERING "}},
- {GET_LEASE4_ADDR, //
- {GET_LEASE4_ADDR, //
+ // Gets an IPv4 lease with specified IPv4 address
+ {GET_LEASE4_ADDR,
+ {GET_LEASE4_ADDR,
"SELECT "
"address, hwaddr, client_id, valid_lifetime, expire, subnet_id, "
"fqdn_fwd, fqdn_rev, hostname, state "
"FROM lease4 "
"WHERE address = ? "}},
- {GET_LEASE4_CLIENTID, //
- {GET_LEASE4_CLIENTID, //
+ // Gets an IPv4 lease(s) with specified client-id
+ {GET_LEASE4_CLIENTID,
+ {GET_LEASE4_CLIENTID,
"SELECT "
"address, hwaddr, client_id, valid_lifetime, expire, subnet_id, "
"fqdn_fwd, fqdn_rev, hostname, state "
"WHERE client_id = ? "
"ALLOW FILTERING "}},
- {GET_LEASE4_CLIENTID_SUBID, //
- {GET_LEASE4_CLIENTID_SUBID, //
+ // Gets an IPv4 lease with specified client-id and subnet-id
+ {GET_LEASE4_CLIENTID_SUBID,
+ {GET_LEASE4_CLIENTID_SUBID,
"SELECT "
"address, hwaddr, client_id, valid_lifetime, expire, subnet_id, "
"fqdn_fwd, fqdn_rev, hostname, state "
"AND subnet_id = ? "
"ALLOW FILTERING "}},
- {GET_LEASE4_HWADDR, //
- {GET_LEASE4_HWADDR, //
+ // Gets all IPv4 leases with specified hardware address
+ {GET_LEASE4_HWADDR,
+ {GET_LEASE4_HWADDR,
"SELECT "
"address, hwaddr, client_id, valid_lifetime, expire, subnet_id, "
"fqdn_fwd, fqdn_rev, hostname, state "
"WHERE hwaddr = ? "
"ALLOW FILTERING "}},
- {GET_LEASE4_HWADDR_SUBID, //
- {GET_LEASE4_HWADDR_SUBID, //
+ // Gets an IPv4 lease with specified hardware addr and subnet-id
+ {GET_LEASE4_HWADDR_SUBID,
+ {GET_LEASE4_HWADDR_SUBID,
"SELECT "
"address, hwaddr, client_id, valid_lifetime, expire, subnet_id, "
"fqdn_fwd, fqdn_rev, hostname, state "
}
void
-CqlLease4Exchange::createBindForUpdate(
- const Lease4Ptr &lease,
- AnyArray &data,
- StatementTag statement_tag /* = NULL */) {
- (void)statement_tag; // [maybe_unused]
-
+CqlLease4Exchange::createBindForUpdate(const Lease4Ptr &lease, AnyArray &data,
+ StatementTag /* unused */) {
if (!lease) {
isc_throw(BadValue, "CqlLease4Exchange::createBindForUpdate(): "
"Lease4 object is NULL");
}
void
-CqlLease4Exchange::createBindForDelete(
- const IOAddress &address,
- AnyArray &data,
- StatementTag statement_tag /* = NULL */) {
- (void)statement_tag; // [maybe_unused]
-
+CqlLease4Exchange::createBindForDelete(const IOAddress &address, AnyArray &data,
+ StatementTag /* unused */) {
// Set up the structures for the various components of the lease4
// structure.
}
}
-/// @brief Create BIND array to receive data
-///
-/// Creates a CQL_BIND array to receive Lease4 data from the database.
void
-CqlLease4Exchange::createBindForSelect(
- AnyArray &data, StatementTag /* statement_tag = NULL */) {
+CqlLease4Exchange::createBindForSelect(AnyArray &data, StatementTag /* unused */) {
// Start with a fresh array.
data.clear();
result->state_ = state_;
- return result;
+ return (result);
} catch (const Exception &ex) {
isc_throw(DbOperationError,
"CqlLease4Exchange::retrieveLease(): "
}
void
-CqlLease4Exchange::getLeaseCollection(StatementTag &statement_tag,
- AnyArray &data,
+CqlLease4Exchange::getLeaseCollection(StatementTag &statement_tag, AnyArray &data,
Lease4Collection &result) {
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_CQL_GET_ADDR4)
.arg(statement_tag);
}
void
-CqlLease4Exchange::getLease(StatementTag &statement_tag,
- AnyArray &data,
+CqlLease4Exchange::getLease(StatementTag &statement_tag, AnyArray &data,
Lease4Ptr &result) {
// This particular method is called when only one or zero matches is
// expected.
// Return single record if present, else clear the lease.
const size_t collection_size = collection.size();
if (collection_size >= 2u) {
- isc_throw(
- MultipleRecords,
- "CqlLease4Exchange::getLease(): multiple records were found in "
- "the database where only one was expected for statement "
- << statement_tag);
+ isc_throw(MultipleRecords,
+ "CqlLease4Exchange::getLease(): multiple records were found in "
+ "the database where only one was expected for statement "
+ << statement_tag);
} else if (collection_size == 0u) {
result.reset();
} else {
}
}
-/// @brief Exchange CQL and Lease6 Data
+/// @brief Exchange Lease6 information between Kea and CQL
///
/// On any CQL operation, arrays of CQL BIND structures must be built to
/// describe the parameters in the prepared statements. Where information is
/// @brief Constructor
///
/// The initialization of the variables here is nonly to satisfy
- /// cppcheck -
- /// all variables are initialized/set in the methods before they are
- /// used.
+ /// cppcheck - all variables are initialized/set in the methods before
+ /// they are used.
+ ///
+ /// @param connection connection used for this query
explicit CqlLease6Exchange(const CqlConnection &connection);
- /// @brief Create CQL_BIND objects for Lease4 Pointer
+ /// @brief Create CQL_BIND objects for Lease6 Pointer
///
/// Fills in the CQL_BIND array for sending data in the Lease4 object to
/// the database. Used for INSERT statements.
+ ///
+ /// @param lease The lease information to be inserted
+ /// @param data Lease info will be stored here in CQL format
void createBindForInsert(const Lease6Ptr &lease, AnyArray &data);
- /// @brief Create CQL_BIND objects for Lease4 Pointer
+ /// @brief Create CQL_BIND objects for Lease6 Pointer
///
/// Fills in the CQL_BIND array for sending data in the Lease4 object to
/// the database. Used for UPDATE statements.
- void createBindForUpdate(const Lease6Ptr &lease,
- AnyArray &data,
+ ///
+ /// @param lease Updated lease information.
+ /// @param data lease info in CQL format will be stored here
+ /// @param statement_tag tag identifying the query (optional)
+ void createBindForUpdate(const Lease6Ptr &lease, AnyArray &data,
StatementTag statement_tag = NULL);
/// @brief Create CQL_BIND objects for Lease4 Pointer
///
/// Fills in the CQL_BIND array for sending data in the Lease4 object to
/// the database. Used for DELETE statements.
- void createBindForDelete(const IOAddress &lease,
- AnyArray &data,
+ ///
+ /// @param address address of the lease to be deleted
+ /// @param data lease info in CQL format will be stored here
+ /// @param statement_tag tag identifying the query (optional)
+ void createBindForDelete(const IOAddress &address, AnyArray &data,
StatementTag statement_tag = NULL);
/// @brief Create BIND array to receive data
///
/// Creates a CQL_BIND array to receive Lease6 data from the database.
+ ///
+ /// @param data info returned by CQL will be stored here
+ /// @param statement_tag tag identifying the query (optional)
void createBindForSelect(AnyArray &data,
StatementTag statement_tag = NULL) override;
+ /// @brief Retrieves the Lease6 object in Kea format
+ ///
+ /// @return C++ representation of the object being returned
boost::any retrieve() override;
- void getLeaseCollection(StatementTag &statement_tag,
- AnyArray &data,
+ /// @brief Retrieves zero or more IPv6 leases
+ ///
+ /// @param statement_tag query to be executed
+ /// @param data parameters for the query
+ /// @param result this lease collection will be updated
+ void getLeaseCollection(StatementTag &statement_tag, AnyArray &data,
Lease6Collection &result);
+ /// @brief Retrieves one IPv6 lease
+ ///
+ /// @param statement_tag query to be executed
+ /// @param data parameters for the query
+ /// @param result pointer to the lease being returned (or null)
void
getLease(StatementTag &statement_tag, AnyArray &data, Lease6Ptr &result);
- void getExpiredLeases(const size_t &max_leases,
- Lease6Collection &expired_leases);
+ /// @brief Returns expired leases.
+ ///
+ /// This method returns up to specified number (see max_leases) of
+ /// expired leases.
+ ///
+ /// @param max_leases at most this number of leases will be returned
+ /// @param expired_leases expired leases will be stored here
+ void getExpiredLeases(const size_t &max_leases, Lease6Collection &expired_leases);
/// @brief Cassandra statements
static StatementMap tagged_statements_;
static constexpr StatementTag GET_LEASE6_EXPIRE = "GET_LEASE6_EXPIRE";
static constexpr StatementTag GET_LEASE6_ADDR = "GET_LEASE6_ADDR";
static constexpr StatementTag GET_LEASE6_DUID_IAID = "GET_LEASE6_DUID_IAID";
- static constexpr StatementTag GET_LEASE6_DUID_IAID_SUBID =
- "GET_LEASE6_DUID_IAID_SUBID";
+ static constexpr StatementTag GET_LEASE6_DUID_IAID_SUBID = "GET_LEASE6_DUID_IAID_SUBID";
// @}
private:
/// @brief Identity association identifier
cass_int32_t iaid_;
- /// @brief Lease type
+ /// @brief Lease type (NA, TA or PD)
cass_int32_t lease_type_;
/// @brief Prefix length
StatementMap CqlLease6Exchange::tagged_statements_ = {
- {INSERT_LEASE6, //
- {INSERT_LEASE6, //
+ // Inserts new IPv6 lease
+ {INSERT_LEASE6,
+ {INSERT_LEASE6,
"INSERT INTO lease6("
"address, valid_lifetime, expire, subnet_id, pref_lifetime, duid, iaid, "
"lease_type, prefix_len, fqdn_fwd, fqdn_rev, hostname, hwaddr, hwtype, "
") "
"IF NOT EXISTS "}},
- {UPDATE_LEASE6, //
- {UPDATE_LEASE6, //
+ // Updates existing IPv6 lease
+ {UPDATE_LEASE6,
+ {UPDATE_LEASE6,
"UPDATE lease6 SET "
"valid_lifetime = ?, "
"expire = ?, "
"WHERE address = ? "
"IF EXISTS "}},
- {DELETE_LEASE6, //
- {DELETE_LEASE6, //
+ // Deletes existing IPv6 lease
+ {DELETE_LEASE6,
+ {DELETE_LEASE6,
"DELETE FROM lease6 "
"WHERE address = ? "
"IF EXISTS "}},
- {GET_LEASE6_EXPIRE, //
- {GET_LEASE6_EXPIRE, //
+ // Gets up to a certain number of expired IPv6 leases
+ {GET_LEASE6_EXPIRE,
+ {GET_LEASE6_EXPIRE,
"SELECT "
"address, valid_lifetime, expire, subnet_id, pref_lifetime, duid, iaid, "
"lease_type, prefix_len, fqdn_fwd, fqdn_rev, hostname, hwaddr, hwtype, "
"LIMIT ? "
"ALLOW FILTERING "}},
- {GET_LEASE6_ADDR, //
- {GET_LEASE6_ADDR, //
+ // Gets an IPv6 lease with specified IPv4 address
+ {GET_LEASE6_ADDR,
+ {GET_LEASE6_ADDR,
"SELECT "
"address, valid_lifetime, expire, subnet_id, pref_lifetime, duid, iaid, "
"lease_type, prefix_len, fqdn_fwd, fqdn_rev, hostname, hwaddr, hwtype, "
"AND lease_type = ? "
"ALLOW FILTERING "}},
- {GET_LEASE6_DUID_IAID, //
- {GET_LEASE6_DUID_IAID, //
+ // Gets an IPv6 lease(s) with specified duid and iaid
+ {GET_LEASE6_DUID_IAID,
+ {GET_LEASE6_DUID_IAID,
"SELECT "
"address, valid_lifetime, expire, subnet_id, pref_lifetime, duid, iaid, "
"lease_type, prefix_len, fqdn_fwd, fqdn_rev, hostname, hwaddr, hwtype, "
"AND lease_type = ? "
"ALLOW FILTERING "}},
- {GET_LEASE6_DUID_IAID_SUBID, //
- {GET_LEASE6_DUID_IAID_SUBID, //
+ // Gets an IPv6 lease with specified duid, iaid and subnet-id
+ {GET_LEASE6_DUID_IAID_SUBID,
+ {GET_LEASE6_DUID_IAID_SUBID,
"SELECT "
"address, valid_lifetime, expire, subnet_id, pref_lifetime, duid, iaid, "
"lease_type, prefix_len, fqdn_fwd, fqdn_rev, hostname, hwaddr, hwtype, "
};
-/// @brief Constructor
-///
-/// The initialization of the variables here is not only to satisfy
-/// cppcheck -
-/// all variables are initialized/set in the methods before they are
-/// used.
CqlLease6Exchange::CqlLease6Exchange(const CqlConnection &connection)
: CqlLeaseExchange(connection), pref_lifetime_(0), iaid_(0), lease_type_(0),
prefix_len_(0), hwtype_(0), hwaddr_source_(0) {
}
-/// @brief Create CQL_BIND objects for Lease6 Pointer
-///
-/// Fills in the CQL_BIND array for sending data in the Lease6 object to
-/// the database.
+
void
CqlLease6Exchange::createBindForInsert(const Lease6Ptr &lease, AnyArray &data) {
if (!lease) {
// address: varchar
address_ = lease_->addr_.toText();
if (address_.size() > ADDRESS6_TEXT_MAX_LEN) {
- isc_throw(BadValue,
- "address " << address_ << " of length " << address_.size()
- << " exceeds maximum allowed length of "
- << ADDRESS6_TEXT_MAX_LEN);
+ isc_throw(BadValue, "address " << address_ << " of length " << address_.size()
+ << " exceeds maximum allowed length of " << ADDRESS6_TEXT_MAX_LEN);
}
// valid lifetime: bigint
// For convenience for external tools, this is converted to lease
// expiry time (expire). The relationship is given by:
// expire = cltt_ + valid_lft_
- CqlExchange::convertToDatabaseTime(lease_->cltt_, lease_->valid_lft_,
- expire_);
+ CqlExchange::convertToDatabaseTime(lease_->cltt_, lease_->valid_lft_, expire_);
// subnet_id: int
subnet_id_ = static_cast<cass_int32_t>(lease_->subnet_id_);
// duid: blob
if (!lease_->duid_) {
- isc_throw(DbOperationError,
- "lease6 with address " << address_
- << " is missing mandatory duid");
+ isc_throw(DbOperationError, "lease6 with address " << address_
+ << " is missing mandatory duid");
}
duid_ = lease_->duid_->getDuid();
// hostname: varchar
if (lease_->hostname_.size() > HOSTNAME_MAX_LEN) {
- isc_throw(BadValue,
- "hostname" << lease_->hostname_ << " of length "
- << lease_->hostname_.size()
- << " exceeds maximum allowed length of "
- << HOSTNAME_MAX_LEN);
+ isc_throw(BadValue, "hostname" << lease_->hostname_ << " of length "
+ << lease_->hostname_.size() << " exceeds maximum allowed length of "
+ << HOSTNAME_MAX_LEN);
}
hostname_ = lease_->hostname_;
// hwaddr: blob
if (lease_->hwaddr_ && lease->hwaddr_->hwaddr_.size() > 0) {
if (lease_->hwaddr_->hwaddr_.size() > HWAddr::MAX_HWADDR_LEN) {
- isc_throw(DbOperationError,
- "hardware address "
- << lease_->hwaddr_->toText() << " of length "
- << lease_->hwaddr_->hwaddr_.size()
- << " exceeds maximum allowed length of "
- << HWAddr::MAX_HWADDR_LEN);
+ isc_throw(DbOperationError, "hardware address " << lease_->hwaddr_->toText()
+ << " of length " << lease_->hwaddr_->hwaddr_.size()
+ << " exceeds maximum allowed length of " << HWAddr::MAX_HWADDR_LEN);
}
hwaddr_ = lease_->hwaddr_->hwaddr_;
} else {
data.add(&state_);
} catch (const Exception &ex) {
- isc_throw(DbOperationError,
- "CqlLease6Exchange::createBindForInsert(): "
- "could not create bind array from Lease6: "
- << lease_->addr_.toText() << ", reason: " << ex.what());
+ isc_throw(DbOperationError, "CqlLease6Exchange::createBindForInsert(): "
+ "could not create bind array from Lease6: " << lease_->addr_.toText()
+ << ", reason: " << ex.what());
}
}
-/// @brief Create CQL_BIND objects for Lease6 Pointer
-///
-/// Fills in the CQL_BIND array for sending data in the Lease6 object to
-/// the database.
-void
-CqlLease6Exchange::createBindForUpdate(
- const Lease6Ptr &lease,
- AnyArray &data,
- StatementTag statement_tag /* = NULL */) {
- (void)statement_tag; // [maybe_unused]
+void
+CqlLease6Exchange::createBindForUpdate(const Lease6Ptr &lease, AnyArray &data,
+ StatementTag /* unused */) {
if (!lease) {
isc_throw(BadValue, "Lease6 object is NULL");
}
}
}
-/// @brief Create CQL_BIND objects for Lease6 Pointer
-///
-/// Fills in the CQL_BIND array for sending data in the Lease6 object to
-/// the database.
void
-CqlLease6Exchange::createBindForDelete(
- const IOAddress &address,
- AnyArray &data,
- StatementTag statement_tag /* = NULL */) {
- (void)statement_tag; // [maybe_unused]
+CqlLease6Exchange::createBindForDelete(const IOAddress &address, AnyArray &data,
+ StatementTag /* unused */) {
// Set up the structures for the various components of the lease4
// structure.
}
}
-/// @brief Create BIND array to receive data
-///
-/// Creates a CQL_BIND array to receive Lease6 data from the database.
void
-CqlLease6Exchange::createBindForSelect(
- AnyArray &data, StatementTag /* statement_tag = NULL */) {
+CqlLease6Exchange::createBindForSelect(AnyArray &data, StatementTag /* unused */) {
// Start with a fresh array.
data.clear();
}
void
-CqlLease6Exchange::getLeaseCollection(StatementTag &statement_tag,
- AnyArray &data,
+CqlLease6Exchange::getLeaseCollection(StatementTag &statement_tag, AnyArray &data,
Lease6Collection &result) {
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_CQL_GET_ADDR4)
.arg(statement_tag);
}
void
-CqlLease6Exchange::getLease(StatementTag &statement_tag,
- AnyArray &data,
+CqlLease6Exchange::getLease(StatementTag &statement_tag, AnyArray &data,
Lease6Ptr &result) {
// This particular method is called when only one or zero matches is
// expected.
std::stringstream tmp;
tmp << "CQL backend " << CQL_SCHEMA_VERSION_MAJOR;
tmp << "." << CQL_SCHEMA_VERSION_MINOR;
- tmp << ", library cassandra_static";
+ tmp << ", library cassandra";
return tmp.str();
}
new CqlLease4Exchange(dbconn_));
exchange4->createBindForInsert(lease, data);
try {
- exchange4->executeMutation(dbconn_, data,
- CqlLease4Exchange::INSERT_LEASE4);
+ exchange4->executeMutation(dbconn_, data, CqlLease4Exchange::INSERT_LEASE4);
} catch (const Exception &exception) {
- LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
- DHCPSRV_CQL_LEASE_EXCEPTION_THROWN)
+ LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_CQL_LEASE_EXCEPTION_THROWN)
.arg(exception.what());
return false;
}
AnyArray data;
- std::unique_ptr<CqlLease6Exchange> exchange6(
- new CqlLease6Exchange(dbconn_));
+ std::unique_ptr<CqlLease6Exchange> exchange6(new CqlLease6Exchange(dbconn_));
exchange6->createBindForInsert(lease, data);
try {
- exchange6->executeMutation(dbconn_, data,
- CqlLease6Exchange::INSERT_LEASE6);
+ exchange6->executeMutation(dbconn_, data, CqlLease6Exchange::INSERT_LEASE6);
} catch (const Exception &exception) {
- LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
- DHCPSRV_CQL_LEASE_EXCEPTION_THROWN)
+ LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_CQL_LEASE_EXCEPTION_THROWN)
.arg(exception.what());
return false;
}
// Get the data.
Lease4Ptr result;
- std::unique_ptr<CqlLease4Exchange> exchange4(
- new CqlLease4Exchange(dbconn_));
+ std::unique_ptr<CqlLease4Exchange> exchange4(new CqlLease4Exchange(dbconn_));
exchange4->getLease(CqlLease4Exchange::GET_LEASE4_ADDR, data, result);
- return result;
+ return (result);
}
Lease4Collection
// Get the data.
Lease4Collection result;
- std::unique_ptr<CqlLease4Exchange> exchange4(
- new CqlLease4Exchange(dbconn_));
- exchange4->getLeaseCollection(CqlLease4Exchange::GET_LEASE4_HWADDR, data,
- result);
+ std::unique_ptr<CqlLease4Exchange> exchange4(new CqlLease4Exchange(dbconn_));
+ exchange4->getLeaseCollection(CqlLease4Exchange::GET_LEASE4_HWADDR, data, result);
- return result;
+ return (result);
}
Lease4Ptr
// Get the data.
Lease4Ptr result;
- std::unique_ptr<CqlLease4Exchange> exchange4(
- new CqlLease4Exchange(dbconn_));
- exchange4->getLease(CqlLease4Exchange::GET_LEASE4_HWADDR_SUBID, data,
- result);
+ std::unique_ptr<CqlLease4Exchange> exchange4(new CqlLease4Exchange(dbconn_));
+ exchange4->getLease(CqlLease4Exchange::GET_LEASE4_HWADDR_SUBID, data, result);
- return result;
+ return (result);
}
Lease4Collection
CqlLeaseMgr::getLease4(const ClientId &clientid) const {
- LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
- DHCPSRV_CQL_GET_CLIENTID)
+ LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_CQL_GET_CLIENTID)
.arg(clientid.toText());
// Set up the WHERE clause value
// Get the data.
Lease4Collection result;
- std::unique_ptr<CqlLease4Exchange> exchange4(
- new CqlLease4Exchange(dbconn_));
- exchange4->getLeaseCollection(CqlLease4Exchange::GET_LEASE4_CLIENTID, data,
- result);
+ std::unique_ptr<CqlLease4Exchange> exchange4(new CqlLease4Exchange(dbconn_));
+ exchange4->getLeaseCollection(CqlLease4Exchange::GET_LEASE4_CLIENTID, data, result);
return result;
}
Lease4Ptr
-CqlLeaseMgr::getLease4(const ClientId &clientid,
- const HWAddr &hwaddr,
+CqlLeaseMgr::getLease4(const ClientId &clientid, const HWAddr &hwaddr,
SubnetID subnet_id) const {
+ /// @todo: Remove this method in this and all other implementations.
/// This method is currently not implemented because allocation engine
/// searches for the lease using HW address or client identifier.
/// It never uses both parameters in the same time. We need to
/// consider if this method is needed at all.
- LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
- DHCPSRV_CQL_GET_CLIENTID_HWADDR_SUBID)
+ LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_CQL_GET_CLIENTID_HWADDR_SUBID)
.arg(clientid.toText())
.arg(hwaddr.toText())
.arg(subnet_id);
- isc_throw(NotImplemented, "CqlLeaseMgr::getLease4() not implemented yet");
+ isc_throw(NotImplemented, "CqlLeaseMgr::getLease4() is obsolete");
}
Lease4Ptr
CqlLeaseMgr::getLease4(const ClientId &clientid, SubnetID subnet_id) const {
- LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
- DHCPSRV_CQL_GET_SUBID_CLIENTID)
+ LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_CQL_GET_SUBID_CLIENTID)
.arg(subnet_id)
.arg(clientid.toText());
// Get the data.
Lease4Ptr result;
- std::unique_ptr<CqlLease4Exchange> exchange4(
- new CqlLease4Exchange(dbconn_));
- exchange4->getLease(CqlLease4Exchange::GET_LEASE4_CLIENTID_SUBID, data,
- result);
+ std::unique_ptr<CqlLease4Exchange> exchange4(new CqlLease4Exchange(dbconn_));
+ exchange4->getLease(CqlLease4Exchange::GET_LEASE4_CLIENTID_SUBID, data, result);
- return result;
+ return (result);
}
Lease6Ptr
data.add(&lease_type_data);
Lease6Ptr result;
- std::unique_ptr<CqlLease6Exchange> exchange6(
- new CqlLease6Exchange(dbconn_));
+ std::unique_ptr<CqlLease6Exchange> exchange6(new CqlLease6Exchange(dbconn_));
exchange6->getLease(CqlLease6Exchange::GET_LEASE6_ADDR, data, result);
- return result;
+ return (result);
}
Lease6Collection
-CqlLeaseMgr::getLeases6(Lease::Type lease_type,
- const DUID &duid,
- uint32_t iaid) const {
- LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
- DHCPSRV_CQL_GET_IAID_DUID)
+CqlLeaseMgr::getLeases6(Lease::Type lease_type, const DUID &duid, uint32_t iaid) const {
+ LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_CQL_GET_IAID_DUID)
.arg(iaid)
.arg(duid.toText())
.arg(lease_type);
// Get the data.
Lease6Collection result;
- std::unique_ptr<CqlLease6Exchange> exchange6(
- new CqlLease6Exchange(dbconn_));
- exchange6->getLeaseCollection(CqlLease6Exchange::GET_LEASE6_DUID_IAID, data,
- result);
+ std::unique_ptr<CqlLease6Exchange> exchange6(new CqlLease6Exchange(dbconn_));
+ exchange6->getLeaseCollection(CqlLease6Exchange::GET_LEASE6_DUID_IAID, data, result);
return result;
}
Lease6Collection
-CqlLeaseMgr::getLeases6(Lease::Type lease_type,
- const DUID &duid,
- uint32_t iaid,
+CqlLeaseMgr::getLeases6(Lease::Type lease_type, const DUID &duid, uint32_t iaid,
SubnetID subnet_id) const {
- LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
- DHCPSRV_CQL_GET_IAID_SUBID_DUID)
+ LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_CQL_GET_IAID_SUBID_DUID)
.arg(iaid)
.arg(subnet_id)
.arg(duid.toText())
// Get the data.
Lease6Collection result;
- std::unique_ptr<CqlLease6Exchange> exchange6(
- new CqlLease6Exchange(dbconn_));
- exchange6->getLeaseCollection(CqlLease6Exchange::GET_LEASE6_DUID_IAID_SUBID,
- data, result);
-
- return result;
+ std::unique_ptr<CqlLease6Exchange> exchange6(new CqlLease6Exchange(dbconn_));
+ exchange6->getLeaseCollection(CqlLease6Exchange::GET_LEASE6_DUID_IAID_SUBID, data, result);
+ return (result);
}
void
CqlLeaseMgr::getExpiredLeases4(Lease4Collection &expired_leases,
const size_t max_leases) const {
- LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
- DHCPSRV_CQL_GET_EXPIRED4)
+ LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_CQL_GET_EXPIRED4)
.arg(max_leases);
- std::unique_ptr<CqlLease4Exchange> exchange4(
- new CqlLease4Exchange(dbconn_));
+ std::unique_ptr<CqlLease4Exchange> exchange4(new CqlLease4Exchange(dbconn_));
exchange4->getExpiredLeases(max_leases, expired_leases);
}
void
CqlLeaseMgr::getExpiredLeases6(Lease6Collection &expired_leases,
const size_t max_leases) const {
- LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
- DHCPSRV_CQL_GET_EXPIRED6)
+ LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_CQL_GET_EXPIRED6)
.arg(max_leases);
std::unique_ptr<CqlLease6Exchange> exchange6(
void
CqlLeaseMgr::updateLease4(const Lease4Ptr &lease) {
- LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
- DHCPSRV_CQL_UPDATE_ADDR4)
+ LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_CQL_UPDATE_ADDR4)
.arg(lease->addr_.toText());
- std::unique_ptr<CqlLease4Exchange> exchange4(
- new CqlLease4Exchange(dbconn_));
+ std::unique_ptr<CqlLease4Exchange> exchange4(new CqlLease4Exchange(dbconn_));
try {
AnyArray data;
- exchange4->createBindForUpdate(lease, data,
- CqlLease4Exchange::UPDATE_LEASE4);
- exchange4->executeMutation(dbconn_, data,
- CqlLease4Exchange::UPDATE_LEASE4);
+ exchange4->createBindForUpdate(lease, data, CqlLease4Exchange::UPDATE_LEASE4);
+ exchange4->executeMutation(dbconn_, data, CqlLease4Exchange::UPDATE_LEASE4);
} catch (const StatementNotApplied &exception) {
isc_throw(NoSuchLease, exception.what());
}
void
CqlLeaseMgr::updateLease6(const Lease6Ptr &lease) {
- LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
- DHCPSRV_CQL_UPDATE_ADDR6)
+ LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_CQL_UPDATE_ADDR6)
.arg(lease->addr_.toText());
- std::unique_ptr<CqlLease6Exchange> exchange6(
- new CqlLease6Exchange(dbconn_));
+ std::unique_ptr<CqlLease6Exchange> exchange6(new CqlLease6Exchange(dbconn_));
try {
AnyArray data;
- exchange6->createBindForUpdate(lease, data,
- CqlLease6Exchange::UPDATE_LEASE6);
- exchange6->executeMutation(dbconn_, data,
- CqlLease6Exchange::UPDATE_LEASE6);
+ exchange6->createBindForUpdate(lease, data, CqlLease6Exchange::UPDATE_LEASE6);
+ exchange6->executeMutation(dbconn_, data, CqlLease6Exchange::UPDATE_LEASE6);
} catch (const StatementNotApplied &exception) {
isc_throw(NoSuchLease, exception.what());
}
try {
if (addr.isV4()) {
- std::unique_ptr<CqlLease4Exchange> exchange4(
- new CqlLease4Exchange(dbconn_));
- exchange4->createBindForDelete(addr, data,
- CqlLease4Exchange::DELETE_LEASE4);
- exchange4->executeMutation(dbconn_, data,
- CqlLease4Exchange::DELETE_LEASE4);
+ std::unique_ptr<CqlLease4Exchange> exchange4(new CqlLease4Exchange(dbconn_));
+ exchange4->createBindForDelete(addr, data, CqlLease4Exchange::DELETE_LEASE4);
+ exchange4->executeMutation(dbconn_, data, CqlLease4Exchange::DELETE_LEASE4);
} else if (addr.isV6()) {
- std::unique_ptr<CqlLease6Exchange> exchange6(
- new CqlLease6Exchange(dbconn_));
- exchange6->createBindForDelete(addr, data,
- CqlLease6Exchange::DELETE_LEASE6);
- exchange6->executeMutation(dbconn_, data,
- CqlLease6Exchange::DELETE_LEASE6);
+ std::unique_ptr<CqlLease6Exchange> exchange6(new CqlLease6Exchange(dbconn_));
+ exchange6->createBindForDelete(addr, data, CqlLease6Exchange::DELETE_LEASE6);
+ exchange6->executeMutation(dbconn_, data, CqlLease6Exchange::DELETE_LEASE6);
} else {
return false;
}
} catch (const Exception &exception) {
- LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
- DHCPSRV_CQL_LEASE_EXCEPTION_THROWN)
+ LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_CQL_LEASE_EXCEPTION_THROWN)
.arg(exception.what());
return false;
}
DHCPSRV_CQL_DELETE_EXPIRED_RECLAIMED4)
.arg(secs);
AnyArray data;
- uint64_t n_of_deleted_leases = 0u;
+ uint64_t deleted = 0u;
cass_int32_t limit = 1024;
// State is reclaimed.
- cass_int32_t state =
- static_cast<cass_int32_t>(Lease::STATE_EXPIRED_RECLAIMED);
+ cass_int32_t state = static_cast<cass_int32_t>(Lease::STATE_EXPIRED_RECLAIMED);
data.add(&state);
// Expiration timestamp.
- cass_int64_t expiration =
- static_cast<cass_int64_t>(time(NULL) - static_cast<time_t>(secs));
+ cass_int64_t expiration = static_cast<cass_int64_t>(time(NULL) - static_cast<time_t>(secs));
data.add(&expiration);
data.add(&limit);
// Get the data.
Lease4Collection leases;
- std::unique_ptr<CqlLease4Exchange> exchange4(
- new CqlLease4Exchange(dbconn_));
- exchange4->getLeaseCollection(CqlLease4Exchange::GET_LEASE4_EXPIRE, data,
- leases);
+ std::unique_ptr<CqlLease4Exchange> exchange4(new CqlLease4Exchange(dbconn_));
+ exchange4->getLeaseCollection(CqlLease4Exchange::GET_LEASE4_EXPIRE, data, leases);
for (Lease4Ptr &lease : leases) {
if (deleteLease(lease->addr_)) {
- ++n_of_deleted_leases;
+ ++deleted;
}
}
- return n_of_deleted_leases;
+ return (deleted);
}
uint64_t
cass_int32_t limit = 1024;
// State is reclaimed.
- cass_int32_t state =
- static_cast<cass_int32_t>(Lease::STATE_EXPIRED_RECLAIMED);
+ cass_int32_t state = static_cast<cass_int32_t>(Lease::STATE_EXPIRED_RECLAIMED);
data.add(&state);
// Expiration timestamp.
- cass_int64_t expiration =
- static_cast<cass_int64_t>(time(NULL) - static_cast<time_t>(secs));
+ cass_int64_t expiration = static_cast<cass_int64_t>(time(NULL) - static_cast<time_t>(secs));
data.add(&expiration);
data.add(&limit);
// Get the data.
Lease6Collection leases;
- std::unique_ptr<CqlLease6Exchange> exchange6(
- new CqlLease6Exchange(dbconn_));
- exchange6->getLeaseCollection(CqlLease6Exchange::GET_LEASE6_EXPIRE, data,
- leases);
+ std::unique_ptr<CqlLease6Exchange> exchange6(new CqlLease6Exchange(dbconn_));
+ exchange6->getLeaseCollection(CqlLease6Exchange::GET_LEASE6_EXPIRE, data, leases);
for (Lease6Ptr &lease : leases) {
if (deleteLease(lease->addr_)) {
++n_of_deleted_leases;
size_t
CqlLeaseMgr::wipeLeases4(const SubnetID & /*subnet_id*/) {
- isc_throw(NotImplemented,
- "wipeLeases4 is not implemented for Cassandra backend");
+ /// @todo: Need to implement this, so wipe leases would work.
+ isc_throw(NotImplemented, "wipeLeases4 is not implemented for Cassandra backend");
}
size_t
CqlLeaseMgr::wipeLeases6(const SubnetID & /*subnet_id*/) {
- isc_throw(NotImplemented,
- "wipeLeases6 is not implemented for Cassandra backend");
+ /// @todo: Need to implement this, so wipe leases would work.
+ isc_throw(NotImplemented, "wipeLeases6 is not implemented for Cassandra backend");
}
std::string
VersionPair
CqlLeaseMgr::getVersion() const {
- LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
- DHCPSRV_CQL_GET_VERSION);
+ LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_CQL_GET_VERSION);
- std::unique_ptr<CqlVersionExchange> version_exchange(
- new CqlVersionExchange());
+ std::unique_ptr<CqlVersionExchange> version_exchange(new CqlVersionExchange());
return version_exchange->retrieveVersion(dbconn_);
}