diff --git a/db/view/view.cc b/db/view/view.cc index 748c76bcf1..7693d3872c 100644 --- a/db/view/view.cc +++ b/db/view/view.cc @@ -1685,6 +1685,13 @@ static bool should_update_synchronously(const schema& s) { return *tag_opt == "true"; } +size_t memory_usage_of(const frozen_mutation_and_schema& mut) { + // Overhead of sending a view mutation, in terms of data structures used by the storage_proxy, as well as possible background tasks + // allocated for a remote view update. + constexpr size_t base_overhead_bytes = 2288; + return base_overhead_bytes + mut.fm.representation().size(); +} + // Take the view mutations generated by generate_view_updates(), which pertain // to a modification of a single base partition, and apply them to the // appropriate paired replicas. This is done asynchronously - we do not wait @@ -1716,7 +1723,7 @@ future<> view_update_generator::mutate_MV( bool use_legacy_self_pairing = !ks.uses_tablets(); auto target_endpoint = get_view_natural_endpoint(base_ermp, view_ermp, network_topology, base_token, view_token, use_legacy_self_pairing); auto remote_endpoints = view_ermp->get_pending_endpoints(view_token); - auto sem_units = pending_view_updates.split(mut.fm.representation().size()); + auto sem_units = pending_view_updates.split(memory_usage_of(mut)); const bool update_synchronously = should_update_synchronously(*mut.s); if (update_synchronously) { diff --git a/db/view/view.hh b/db/view/view.hh index 2465aa96c5..d852dac088 100644 --- a/db/view/view.hh +++ b/db/view/view.hh @@ -315,6 +315,8 @@ future calculate_affected_clustering_ranges( bool needs_static_row(const mutation_partition& mp, const std::vector& views); +size_t memory_usage_of(const frozen_mutation_and_schema& mut); + /** * create_virtual_column() adds a "virtual column" to a schema builder. * The definition of a "virtual column" is based on the given definition diff --git a/replica/table.cc b/replica/table.cc index 591eb5d4f2..f59b891ec3 100644 --- a/replica/table.cc +++ b/replica/table.cc @@ -2598,12 +2598,9 @@ std::vector table::affected_views(shared_ptr& ms) { - // Overhead of sending a view mutation, in terms of data structures used by the storage_proxy, as well as possible background tasks - // allocated for a remote view update. - constexpr size_t base_overhead_bytes = 2288; return boost::accumulate(ms | boost::adaptors::transformed([] (const frozen_mutation_and_schema& m) { - return m.fm.representation().size(); - }), size_t{base_overhead_bytes * ms.size()}); + return db::view::memory_usage_of(m); + }), 0); } /**