Skip to content
This repository has been archived by the owner on Mar 3, 2020. It is now read-only.

Commit

Permalink
KEP-1093 Implement Volatile TTL Eviction Policy - corrected two addit…
Browse files Browse the repository at this point in the history
…ional unused variable warnings
  • Loading branch information
rnistuk committed Sep 25, 2019
1 parent 466401b commit ccaa452
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
6 changes: 2 additions & 4 deletions crud/crud.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,9 @@ namespace bzn
class crud final : public bzn::crud_base, public bzn::status_provider_base, public std::enable_shared_from_this<crud>
{
public:
crud(
std::shared_ptr<bzn::asio::io_context_base> io_context, std::shared_ptr<bzn::storage_base> storage
crud(std::shared_ptr<bzn::asio::io_context_base> io_context, std::shared_ptr<bzn::storage_base> storage
, std::shared_ptr<bzn::subscription_manager_base> subscription_manager
, std::shared_ptr<bzn::node_base> node
, bzn::key_t owner_public_key = "");
, std::shared_ptr<bzn::node_base> node, bzn::key_t owner_public_key = "");

void handle_request(const bzn::caller_id_t& caller_id, const database_msg& request, std::shared_ptr<bzn::session_base> session) override;

Expand Down
13 changes: 6 additions & 7 deletions policy/volatile_ttl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ namespace bzn::policy

// 4: from the top of the list of keys pull out enough key value pairs
// to make room for the new pair or update,
const auto [keys, current_db_size]{this->storage->get_size(request.header().db_uuid())};
const auto current_db_size{this->storage->get_size(request.header().db_uuid()).second};
const auto current_free = (max_db_size - current_db_size) - (request.has_update() ? request.update().value().size() : 0);
const auto key_value_size {
request.has_update()
Expand All @@ -69,14 +69,13 @@ namespace bzn::policy

// how much room do we need to free?
// enough for the new key value pair: key_value_size
// How much room do we have?
// current_free
// How much do we need to free
// How much room do we have? -> current_free
// How much do we need to free? -> required_size
auto required_size = key_value_size - current_free;
for (auto [key, size, ttl] : ttl_items)
for (const auto ttl /*[key, size, ttl]*/ : ttl_items)
{
keys_to_evict.emplace(key);
required_size -= size < required_size ? size : required_size;
keys_to_evict.emplace(ttl.key);
required_size -= (ttl.value_size < required_size ? ttl.value_size : required_size);
if (!required_size)
{
break;
Expand Down

0 comments on commit ccaa452

Please sign in to comment.