Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[Fix] Fix various symcache issues
  • Loading branch information
vstakhov committed May 1, 2022
1 parent f8851d8 commit 5c0c81f
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 13 deletions.
5 changes: 4 additions & 1 deletion src/libserver/symcache/symcache_c.cxx
Expand Up @@ -181,7 +181,10 @@ void
rspamd_symcache_inc_frequency(struct rspamd_symcache *_cache, struct rspamd_symcache_item *item)
{
auto *real_item = C_API_SYMCACHE_ITEM(item);
real_item->inc_frequency();

if (real_item) {
real_item->inc_frequency();
}
}

void
Expand Down
14 changes: 7 additions & 7 deletions src/libserver/symcache/symcache_impl.cxx
Expand Up @@ -88,10 +88,6 @@ auto symcache::init() -> bool
it->process_deps(*this);
}

for (auto &it: virtual_symbols) {
it->process_deps(*this);
}

/* Sorting stuff */
auto postfilters_cmp = [](const auto &it1, const auto &it2) -> int {
if (it1->priority > it2->priority) {
Expand Down Expand Up @@ -404,9 +400,9 @@ auto symcache::add_dependency(int id_from, std::string_view to, int virtual_id_f


if (virtual_id_from >= 0) {
g_assert (virtual_id_from < (gint) virtual_symbols.size());
g_assert (virtual_id_from < (gint) items_by_id.size());
/* We need that for settings id propagation */
const auto &vsource = virtual_symbols[virtual_id_from];
const auto &vsource = items_by_id[virtual_id_from];
g_assert (vsource.get() != nullptr);
vsource->deps.emplace_back(cache_item_ptr{nullptr},
std::string(to),
Expand Down Expand Up @@ -754,9 +750,13 @@ auto symcache::validate(bool strict) -> bool

if (item->is_virtual()) {
if (!(item->flags & SYMBOL_TYPE_GHOST)) {
item->resolve_parent(*this);
auto *parent = const_cast<cache_item *>(item->get_parent(*this));

if (parent == nullptr) {
item->resolve_parent(*this);
parent = const_cast<cache_item *>(item->get_parent(*this));
}

if (::fabs(parent->st->weight) < ::fabs(item->st->weight)) {
parent->st->weight = item->st->weight;
}
Expand Down
36 changes: 31 additions & 5 deletions src/libserver/symcache/symcache_item.cxx
Expand Up @@ -33,6 +33,17 @@ auto cache_item::get_parent(const symcache &cache) const -> const cache_item *
return nullptr;
}

auto cache_item::get_parent_mut(const symcache &cache) -> cache_item *
{
if (is_virtual()) {
auto &virtual_sp = std::get<virtual_item>(specific);

return virtual_sp.get_parent_mut(cache);
}

return nullptr;
}

auto cache_item::process_deps(const symcache &cache) -> void
{
/* Allow logging macros to work */
Expand Down Expand Up @@ -117,12 +128,18 @@ auto cache_item::process_deps(const symcache &cache) -> void
}
else {
/* Create a reverse dep */
dit->rdeps.emplace_back(getptr(), dep.sym, id, -1);
dep.item = dit->getptr();
dep.id = dit->id;
if (is_virtual()) {
auto *parent = get_parent_mut(cache);

if (parent) {
dit->rdeps.emplace_back(parent->getptr(), dep.sym, parent->id, -1);
dep.item = dit->getptr();
dep.id = dit->id;

msg_debug_cache ("add dependency from %d on %d", id,
dit->id);
msg_debug_cache ("added reverse dependency from %d on %d", id,
dit->id);
}
}
}
}
}
Expand Down Expand Up @@ -332,6 +349,15 @@ auto virtual_item::get_parent(const symcache &cache) const -> const cache_item *
return cache.get_item_by_id(parent_id, false);
}

auto virtual_item::get_parent_mut(const symcache &cache) -> cache_item *
{
if (parent) {
return parent.get();
}

return const_cast<cache_item *>(cache.get_item_by_id(parent_id, false));
}

auto virtual_item::resolve_parent(const symcache &cache) -> bool
{
if (parent) {
Expand Down
2 changes: 2 additions & 0 deletions src/libserver/symcache/symcache_item.hxx
Expand Up @@ -113,6 +113,7 @@ public:
}

auto get_parent(const symcache &cache) const -> const cache_item *;
auto get_parent_mut(const symcache &cache) -> cache_item *;

auto resolve_parent(const symcache &cache) -> bool;
};
Expand Down Expand Up @@ -255,6 +256,7 @@ public:
}

auto get_parent(const symcache &cache) const -> const cache_item *;
auto get_parent_mut(const symcache &cache) -> cache_item *;

auto resolve_parent(const symcache &cache) -> bool;

Expand Down
1 change: 1 addition & 0 deletions src/libserver/symcache/symcache_runtime.cxx
Expand Up @@ -738,6 +738,7 @@ symcache_runtime::finalize_item(struct rspamd_task *task, cache_item *item) -> v
cbd->event = rspamd_session_add_event (task->s,
rspamd_symcache_delayed_item_fin, cbd,
"symcache");
cbd->runtime = this;

/*
* If no event could be added, then we are already in the destruction
Expand Down

0 comments on commit 5c0c81f

Please sign in to comment.