Skip to content

Commit

Permalink
WIP historical cache
Browse files Browse the repository at this point in the history
  • Loading branch information
maxtropets committed Jun 26, 2024
1 parent dcb1329 commit d87bc03
Show file tree
Hide file tree
Showing 7 changed files with 287 additions and 15 deletions.
2 changes: 1 addition & 1 deletion doc/build_apps/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ Historical Queries

.. doxygenclass:: ccf::historical::AbstractStateCache
:project: CCF
:members: set_default_expiry_duration, get_state_at, get_store_at, get_store_range, drop_cached_states
:members: set_default_expiry_duration, set_soft_cache_limit, get_state_at, get_store_at, get_store_range, drop_cached_states

.. doxygenstruct:: ccf::historical::State
:project: CCF
Expand Down
9 changes: 9 additions & 0 deletions include/ccf/historical_queries_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ namespace ccf::historical

using ExpiryDuration = std::chrono::seconds;

using CacheSize = size_t;

/** Stores the progress of historical query requests.
*
* A request will generally need to be made multiple times (with the same
Expand Down Expand Up @@ -79,6 +81,13 @@ namespace ccf::historical
virtual void set_default_expiry_duration(
ExpiryDuration seconds_until_expiry) = 0;

/** Set the cache limit (in bytes) to evict least recently used requests
* from the cache after it's size growth beyond this limit. The limit is not
* strict. It is estimated based on serialized states' sizes approximation
* and checked once per tick, so it can overflow for a short time.
*/
virtual void set_soft_cache_limit(CacheSize cache_limit) = 0;

/** EXPERIMENTAL: Set the tracking of deletes on missing keys for historical
* queries.
*
Expand Down
5 changes: 5 additions & 0 deletions samples/apps/logging/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,11 @@ namespace loggingapp
PUBLIC_RECORDS, context, 10000, 20);
context.get_indexing_strategies().install_strategy(index_per_public_key);

// According to manual obvervation it's enough to start evicting old
// requests on historical perf test.
constexpr size_t cache_limit = 1024 * 1024 * 5; // MB
context.get_historical_state().set_soft_cache_limit(cache_limit);

const ccf::AuthnPolicies auth_policies = {
ccf::jwt_auth_policy,
ccf::user_cert_auth_policy,
Expand Down
Loading

0 comments on commit d87bc03

Please sign in to comment.