From 1a43849cd2ffbf0dfa4dd1cc6d38d7d3bb7c50cd Mon Sep 17 00:00:00 2001 From: Piotr Jastrzebski Date: Tue, 5 May 2020 08:36:10 +0200 Subject: [PATCH] table: Add cache_enabled member function This function determines cache usage based both on table _config and dynamic schema information. Signed-off-by: Piotr Jastrzebski --- database.hh | 3 +++ table.cc | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/database.hh b/database.hh index c8615ce775..ebdd4537b8 100644 --- a/database.hh +++ b/database.hh @@ -574,6 +574,9 @@ public: _is_bootstrap_or_replace = false; } private: + bool cache_enabled() const { + return _config.enable_cache && _schema->caching_options().enabled(); + } void update_stats_for_new_sstable(uint64_t disk_space_used_by_sstable, const std::vector& shards_for_the_sstable) noexcept; // Adds new sstable to the set of sstables // Doesn't update the cache. The cache must be synchronized in order for reads to see diff --git a/table.cc b/table.cc index be92b847a7..a37429010a 100644 --- a/table.cc +++ b/table.cc @@ -469,7 +469,7 @@ table::make_reader(schema_ptr s, readers.emplace_back(mt->make_flat_reader(s, range, slice, pc, trace_state, fwd, fwd_mr)); } - if (_config.enable_cache && !slice.options.contains(query::partition_slice::option::bypass_cache)) { + if (cache_enabled() && !slice.options.contains(query::partition_slice::option::bypass_cache)) { readers.emplace_back(_cache.make_reader(s, range, slice, pc, std::move(trace_state), fwd, fwd_mr)); } else { readers.emplace_back(make_sstable_reader(s, _sstables, range, slice, pc, std::move(trace_state), fwd, fwd_mr)); @@ -720,7 +720,7 @@ table::update_cache(lw_shared_ptr m, sstables::shared_sstable sst) { m->mark_flushed(std::move(newtab_ms)); try_trigger_compaction(); }; - if (_config.enable_cache) { + if (cache_enabled()) { return _cache.update(adder, *m); } else { adder(); @@ -841,7 +841,7 @@ table::seal_active_streaming_memtable_immediate(flush_permit&& permit) { try_trigger_compaction(); tlogger.debug("Flushing to {} done", newtab->get_filename()); }; - if (_config.enable_cache) { + if (cache_enabled()) { return _cache.update_invalidating(adder, *old); } else { adder();