mirror of
https://github.com/scylladb/scylladb.git
synced 2026-05-22 15:52:13 +00:00
The free function calculate_view_update_throttling_delay() took the view_flow_control_delay_limit_in_ms as a parameter, which forced its two callers (storage_proxy and view_update_generator) to fish the option out of db::config via database::get_config(). Now that the option lives on node_update_backlog, make the throttling calculation a member of node_update_backlog and have the callers invoke it on their node_update_backlog reference. This removes two database::get_config() call sites. Signed-off-by: Pavel Emelyanov <xemul@scylladb.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
76 lines
2.5 KiB
C++
76 lines
2.5 KiB
C++
/*
|
|
* Copyright (C) 2018-present ScyllaDB
|
|
*/
|
|
|
|
/*
|
|
* SPDX-License-Identifier: LicenseRef-ScyllaDB-Source-Available-1.1
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "db/view/view_update_backlog.hh"
|
|
#include "utils/error_injection.hh"
|
|
#include "utils/updateable_value.hh"
|
|
|
|
#include <seastar/core/cacheline.hh>
|
|
#include <seastar/core/future.hh>
|
|
#include <seastar/core/lowres_clock.hh>
|
|
#include <seastar/util/bool_class.hh>
|
|
|
|
#include <atomic>
|
|
#include <chrono>
|
|
|
|
namespace db::view {
|
|
|
|
/**
|
|
* An atomic view update backlog representation, safe to update from multiple shards.
|
|
* It is legal for a stale current max value to be returned.
|
|
*/
|
|
class node_update_backlog {
|
|
using clock = seastar::lowres_clock;
|
|
using need_publishing = seastar::bool_class<class need_publishing_tag>;
|
|
struct per_shard_backlog {
|
|
// Multiply by 2 to defeat the prefetcher
|
|
alignas(seastar::cache_line_size * 2) std::atomic<update_backlog> backlog = update_backlog::no_backlog();
|
|
need_publishing need_publishing = need_publishing::no;
|
|
|
|
update_backlog load() const {
|
|
return backlog.load(std::memory_order_relaxed);
|
|
}
|
|
};
|
|
std::vector<per_shard_backlog> _backlogs;
|
|
std::chrono::milliseconds _interval;
|
|
std::atomic<clock::time_point> _last_update;
|
|
std::atomic<update_backlog> _max;
|
|
utils::updateable_value<uint32_t> _view_flow_control_delay_limit_in_ms;
|
|
|
|
public:
|
|
explicit node_update_backlog(size_t shards, std::chrono::milliseconds interval,
|
|
utils::updateable_value<uint32_t> view_flow_control_delay_limit_in_ms = utils::updateable_value<uint32_t>(1000))
|
|
: _backlogs(shards)
|
|
, _interval(interval)
|
|
, _last_update(clock::now() - _interval)
|
|
, _max(update_backlog::no_backlog())
|
|
, _view_flow_control_delay_limit_in_ms(std::move(view_flow_control_delay_limit_in_ms)) {
|
|
if (utils::get_local_injector().enter("update_backlog_immediately")) {
|
|
_interval = std::chrono::milliseconds(0);
|
|
_last_update = clock::now();
|
|
}
|
|
}
|
|
|
|
update_backlog fetch();
|
|
void add(update_backlog backlog);
|
|
update_backlog fetch_shard(unsigned shard);
|
|
seastar::future<std::optional<update_backlog>> fetch_if_changed();
|
|
|
|
std::chrono::microseconds calculate_throttling_delay(update_backlog backlog,
|
|
db::timeout_clock::time_point timeout) const;
|
|
|
|
// Exposed for testing only.
|
|
update_backlog load() const {
|
|
return _max.load(std::memory_order_relaxed);
|
|
}
|
|
};
|
|
|
|
}
|