Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make master outlive confdata out of shared memory errors #946

Merged
merged 21 commits into from
Dec 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
354017d
[tests] fix binaries searching logic for easier local testing
DrDet Dec 3, 2023
78e6c4a
introduce soft/hard OOM throttling at confdata reading
DrDet Dec 2, 2023
c47fe59
added heuristics that confdata allocator have enough memory
DrDet Dec 3, 2023
a332587
option --confdata-force-ignore-keys-prefix
tolk-vm Dec 1, 2023
2ace4f1
some stats into statshouse for confdata
tolk-vm Dec 4, 2023
d58a3a6
fix unit tests compilation after confdata refactoring
tolk-vm Dec 4, 2023
2a6fe1a
delete forgotten fprintf left due to local testing
tolk-vm Dec 4, 2023
f59fe55
fix array out of bound error on collecting confdata section stats
DrDet Dec 4, 2023
70ebde0
make Confdata OOM warnings more explicit
DrDet Dec 4, 2023
4aa8eb8
extract add_confdata_master_stats() and call it separately
tolk-vm Dec 5, 2023
afbc6ef
added confdata binlog update timeout
DrDet Dec 5, 2023
ee705a1
added confdata soft oom ratio option
DrDet Dec 6, 2023
e27d6a4
ignore keys with dots in soft oom as well
DrDet Dec 6, 2023
68c6de2
always generate coredumps on asserts from master
DrDet Dec 7, 2023
51934f4
fix expiration bug: never add throttled elements to expiration_trace
DrDet Dec 8, 2023
6d5f482
keep memory_status unchanged during thw whole 'generic_operation'
DrDet Dec 8, 2023
5336b45
added 'kphp_confdata_update_timeouts' statshouse metric
DrDet Dec 9, 2023
fc52a66
fix tests
DrDet Dec 9, 2023
45b9a11
rework confdata update fails metric
DrDet Dec 9, 2023
0e45883
review fixes
DrDet Dec 9, 2023
8e97de6
review fix 2
DrDet Dec 9, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions runtime/array_decl.inl
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,10 @@ public:
// we can create true vector
bool has_no_string_keys() const noexcept;

static size_t estimate_size(int64_t n, bool is_vector) noexcept {
return array_inner::estimate_size(n, is_vector);
}

T &operator[](int64_t int_key);
T &operator[](int32_t key) { return (*this)[int64_t{key}]; }
T &operator[](const string &s);
Expand Down
5 changes: 3 additions & 2 deletions runtime/confdata-global-manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,12 @@ ConfdataGlobalManager &ConfdataGlobalManager::get() noexcept {

void ConfdataGlobalManager::init(size_t confdata_memory_limit,
std::unordered_set<vk::string_view> &&predefined_wilrdcards,
std::unique_ptr<re2::RE2> &&blacklist_pattern) noexcept {
std::unique_ptr<re2::RE2> &&blacklist_pattern,
std::forward_list<vk::string_view> &&force_ignore_prefixes) noexcept {
resource_.init(mmap_shared(confdata_memory_limit), confdata_memory_limit);
confdata_samples_.init(resource_);
predefined_wildcards_.set_wildcards(std::move(predefined_wilrdcards));
key_blacklist_.set_blacklist(std::move(blacklist_pattern));
key_blacklist_.set_blacklist(std::move(blacklist_pattern), std::move(force_ignore_prefixes));
}

ConfdataGlobalManager::~ConfdataGlobalManager() noexcept {
Expand Down
5 changes: 3 additions & 2 deletions runtime/confdata-global-manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ class ConfdataGlobalManager : vk::not_copyable {
static ConfdataGlobalManager &get() noexcept;

void init(size_t confdata_memory_limit,
std::unordered_set<vk::string_view> &&predefined_wilrdcards,
std::unique_ptr<re2::RE2> &&blacklist_pattern) noexcept;
std::unordered_set<vk::string_view> &&predefined_wilrdcards,
std::unique_ptr<re2::RE2> &&blacklist_pattern,
std::forward_list<vk::string_view> &&force_ignore_prefixes) noexcept;

void force_release_all_resources_acquired_by_this_proc_if_init() noexcept {
if (is_initialized()) {
Expand Down
9 changes: 9 additions & 0 deletions runtime/confdata-keys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,12 @@ void ConfdataKeyMaker::forcibly_change_first_key_wildcard_dots_from_two_to_one()
second_key_ = string::make_const_string_on_memory(first_key_end, second_key_len, second_key_buffer_.data(), second_key_buffer_.size());
first_key_type_ = ConfdataFirstKeyType::one_dot_wildcard;
}

bool ConfdataKeyBlacklist::is_key_forcibly_ignored_by_prefix(vk::string_view key) const noexcept {
for (const vk::string_view &prefix : force_ignore_prefixes_) {
if (key.starts_with(prefix)) {
return true;
}
}
return false;
}
20 changes: 17 additions & 3 deletions runtime/confdata-keys.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#pragma once
#include <array>
#include <re2/re2.h>
#include <forward_list>
#include <unordered_map>
#include <unordered_set>
#include <vector>
Expand Down Expand Up @@ -112,18 +113,31 @@ class ConfdataKeyMaker : vk::not_copyable {
};

class ConfdataKeyBlacklist : vk::not_copyable {
bool is_key_forcibly_ignored_by_prefix(vk::string_view key) const noexcept;

public:
void set_blacklist(std::unique_ptr<re2::RE2> &&blacklist_pattern) noexcept {
void set_blacklist(std::unique_ptr<re2::RE2> &&blacklist_pattern, std::forward_list<vk::string_view> &&force_ignore_prefixes) noexcept {
blacklist_pattern_ = std::move(blacklist_pattern);
force_ignore_prefixes_ = std::move(force_ignore_prefixes);
}

bool is_blacklisted(vk::string_view key) const noexcept {
return blacklist_pattern_ &&
// from PHP class KphpConfiguration, e.g. for langs
if (blacklist_pattern_ &&
re2::RE2::FullMatch(
re2::StringPiece(key.data(), static_cast<uint32_t>(key.size())),
*blacklist_pattern_);
*blacklist_pattern_)) {
return true;
}
// emergency startup option to disable keys by prefix, e.g. 'highload.vid'
if (unlikely(!force_ignore_prefixes_.empty()) &&
is_key_forcibly_ignored_by_prefix(key)) {
return true;
}
return false;
}

private:
std::unique_ptr<re2::RE2> blacklist_pattern_;
std::forward_list<vk::string_view> force_ignore_prefixes_;
};
4 changes: 4 additions & 0 deletions server/confdata-binlog-events.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ struct lev_confdata_store_wrapper : impl_::confdata_event<BASE, impl_::select_st
return size <= 0 ? mixed{string{}} : mc_get_value(mem, size, get_flags());
}

size_t get_data_size() const noexcept {
return BASE::data_len;
}

vk::string_view get_value_as_string() const noexcept {
const char *mem = BASE::data + BASE::key_len;
const int size = BASE::data_len;
Expand Down
Loading