8000 Make async registry data structure generic by jvolmer · Pull Request #21699 · arangodb/arangodb · GitHub
[go: up one dir, main page]

Skip to content

Make async registry data structure generic #21699

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

Merged
merged 12 commits into from
Apr 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions arangod/AsyncRegistryServer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
target_sources(arangoserver PRIVATE
Feature.cpp
Metrics.cpp
RestHandler.cpp)
target_link_libraries(arangoserver
arango_async_registry_stacktrace)
Expand Down
6 changes: 3 additions & 3 deletions arangod/AsyncRegistryServer/Feature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ Feature::Feature(Server& server)
}

auto Feature::create_metrics(arangodb::metrics::MetricsFeature& metrics_feature)
-> std::shared_ptr<const Metrics> {
return std::make_shared<Metrics>(
-> std::shared_ptr<RegistryMetrics> {
return std::make_shared<RegistryMetrics>(
metrics_feature.addShared(arangodb_async_promises_total{}),
metrics_feature.addShared(arangodb_async_existing_promises{}),
metrics_feature.addShared(arangodb_async_ready_for_deletion_promises{}),
Expand Down Expand Up @@ -114,4 +114,4 @@ void Feature::collectOptions(std::shared_ptr<options::ProgramOptions> options) {
R"(Each thread that is involved in the async-registry needs to garbage collect its finished async function calls regularly. This option controls how often this is done in seconds. This can possibly be performance relevant because each involved thread aquires a lock.)");
}

Feature::~Feature() { registry.set_metrics(std::make_shared<Metrics>()); }
Feature::~Feature() { registry.set_metrics(nullptr); }
6 changes: 3 additions & 3 deletions arangod/AsyncRegistryServer/Feature.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#pragma once

#include "Async/Registry/registry_variable.h"
#include "Async/Registry/Metrics.h"
#include "AsyncRegistryServer/Metrics.h"
#include "Basics/FutureSharedLock.h"
#include "RestServer/arangod.h"
#include "Scheduler/SchedulerFeature.h"
Expand All @@ -33,7 +33,7 @@ namespace arangodb::async_registry {
class Feature final : public ArangodFeature {
private:
static auto create_metrics(arangodb::metrics::MetricsFeature& metrics_feature)
-> std::shared_ptr<const Metrics>;
-> std::shared_ptr<RegistryMetrics>;
struct SchedulerWrapper {
using WorkHandle = Scheduler::WorkHandle;
template<typename F>
Expand Down Expand Up @@ -68,7 +68,7 @@ class Feature final : public ArangodFeature {
};
Options _options;

std::shared_ptr<const Metrics> metrics;
std::shared_ptr<RegistryMetrics> metrics;

struct PromiseCleanupThread;
std::shared_ptr<PromiseCleanupThread> _cleanupThread;
Expand Down
51 changes: 51 additions & 0 deletions arangod/AsyncRegistryServer/Metrics.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
////////////////////////////////////////////////////////////////////////////////
/// DISCLAIMER
///
/// Copyright 2014-2024 ArangoDB GmbH, Cologne, Germany
/// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany
///
/// Licensed under the Business Source License 1.1 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
/// https://github.com/arangodb/arangodb/blob/devel/LICENSE
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
///
/// Copyright holder is ArangoDB GmbH, Cologne, Germany
///
/// @author Julia Volmer
////////////////////////////////////////////////////////////////////////////////
#include "Metrics.h"

#include "Metrics/Counter.h"
#include "Metrics/Gauge.h"

auto RegistryMetrics::increment_total_nodes() -> void {
promises_total->count();
}
auto RegistryMetrics::increment_registered_nodes() -> void {
existing_promises->fetch_add(1);
}
1E0A auto RegistryMetrics::decrement_registered_nodes() -> void {
existing_promises->fetch_sub(1);
}
auto RegistryMetrics::increment_ready_for_deletion_nodes() -> void {
existing_promises->fetch_add(1);
}
auto RegistryMetrics::decrement_ready_for_deletion_nodes() -> void {
existing_promises->fetch_sub(1);
}
auto RegistryMetrics::increment_total_lists() -> void {
thread_registries_total->count();
}
auto RegistryMetrics::increment_existing_lists() -> void {
existing_thread_registries->fetch_add(1);
}
auto RegistryMetrics::decrement_existing_lists() -> void {
existing_thread_registries->fetch_sub(1);
}
62 changes: 62 additions & 0 deletions arangod/AsyncRegistryServer/Metrics.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
////////////////////////////////////////////////////////////////////////////////
/// DISCLAIMER
///
/// Copyright 2014-2024 ArangoDB GmbH, Cologne, Germany
/// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany
///
/// Licensed under the Business Source License 1.1 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
/// https://github.com/arangodb/arangodb/blob/devel/LICENSE
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
///
/// Copyright holder is ArangoDB GmbH, Cologne, Germany
///
/// @author Julia Volmer
////////////////////////////////////////////////////////////////////////////////
#pragma once

#include "Containers/Concurrent/metrics.h"
#include "Metrics/Fwd.h"

struct RegistryMetrics : arangodb::containers::Metrics {
RegistryMetrics(
std::shared_ptr<arangodb::metrics::Counter> promises_total,
std::shared_ptr<arangodb::metrics::Gauge<std::uint64_t>>
existing_promises,
std::shared_ptr<arangodb::metrics::Gauge<std::uint64_t>>
ready_for_deletion_promises,
std::shared_ptr<arangodb::metrics::Counter> thread_registries_total,
std::shared_ptr<arangodb::metrics::Gauge<std::uint64_t>>
existing_thread_registries)
: promises_total{promises_total},
existing_promises{existing_promises},
ready_for_deletion_promises{ready_for_deletion_promises},
thread_registries_total{thread_registries_total},
existing_thread_registries{existing_thread_registries} {}
~RegistryMetrics() = default;
auto increment_total_nodes() -> void override;
auto increment_registered_nodes() -> void override;
auto decrement_registered_nodes() -> void override;
auto increment_ready_for_deletion_nodes() -> void override;
auto decrement_ready_for_deletion_nodes() -> void override;
auto increment_total_lists() -> void override;
auto increment_existing_lists() -> void override;
auto decrement_existing_lists() -> void override;

private:
std::shared_ptr<arangodb::metrics::Counter> promises_total = nullptr;
std::shared_ptr<arangodb::metrics::Gauge<std::uint64_t>> existing_promises =
nullptr;
std::shared_ptr<arangodb::metrics::Gauge<std::uint64_t>>
ready_for_deletion_promises = nullptr;
std::shared_ptr<arangodb::metrics::Counter> thread_registries_total = nullptr;
std::shared_ptr<arangodb::metrics::Gauge<std::uint64_t>>
existing_thread_registries = nullptr;
};
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def is_deleted(self):

def __str__(self):
if len(self.name) > len("arangodb::async_registry::State::"):
return self.name[len("arangodb::async_registry::State::"):]
return "\"" + self.name[len("arangodb::async_registry::State::"):] + "\""
else:
return self.name

Expand Down Expand Up @@ -85,13 +85,12 @@ class Promise:
state: State

@classmethod
def from_gdb(cls, value_ptr: gdb.Value):
value = value_ptr.dereference()
def from_gdb(cls, ptr: gdb.Value, value: gdb.Value):
return cls(
PromiseId(value_ptr),
PromiseId(ptr),
Thread.from_gdb(value["thread"]),
SourceLocation.from_gdb(value["source_location"]),
Requester.from_gdb(value["requester"]['_M_i']),
Requester.from_gdb(value["requester"]["_M_i"]),
State.from_gdb(value["state"])
)

Expand Down Expand Up @@ -119,7 +118,7 @@ class ThreadRegistry:

@classmethod
def from_gdb(cls, value: gdb.Value):
return cls(Promise.from_gdb(promise) for promise in GdbAtomicList(value["promise_head"]["_M_b"]["_M_p"]))
return cls(Promise.from_gdb(node_ptr, node_ptr.dereference()["data"]) for node_ptr in GdbAtomicList(value["_head"]["_M_b"]["_M_p"]))

class GdbVector:
def __init__(self, value: gdb.Value):
Expand All @@ -129,7 +128,7 @@ def __init__(self, value: gdb.Value):
def __iter__(self):
current = self._begin
while current != self._end:
registry = current.dereference()["_M_ptr"].dereference()
registry = current.dereference()["_M_ptr"]
current += 1
yield registry

Expand All @@ -139,7 +138,7 @@ class AsyncRegistry:

@classmethod
def from_gdb(cls, value: gdb.Value):
return cls(ThreadRegistry.from_gdb(registry) for registry in GdbVector(value['registries']['_M_impl']))
return cls(ThreadRegistry.from_gdb(registry) for registry in GdbVector(value['_lists']['_M_impl']))

def promises(self) -> Iterable[Promise]:
for registry in self.thread_registries:
Expand Down
4 changes: 2 additions & 2 deletions arangod/AsyncRegistryServer/RestHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ namespace {
auto all_undeleted_promises() -> ForestWithRoots<PromiseSnapshot> {
Forest<PromiseSnapshot> forest;
std::vector<Id> roots;
registry.for_promise([&](PromiseSnapshot promise) {
registry.for_node([&](PromiseSnapshot promise) {
if (promise.state != State::Deleted) {
std::visit(overloaded{
[&](PromiseId async_waiter) {
forest.insert(promise.id, async_waiter, promise);
},
[&](ThreadId sync_waiter_thread) {
[&](basics::ThreadId sync_waiter_thread) {
forest.insert(promise.id, nullptr, promise);
roots.emplace_back(promise.id);
},
Expand Down
5 changes: 2 additions & 3 deletions lib/Async/Registry/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
add_library(arango_async_registry STATIC
promise.cpp
registry.cpp
registry_variable.cpp
thread_registry.cpp)
registry_variable.cpp)
target_include_directories(arango_async_registry PRIVATE
${PROJECT_SOURCE_DIR}/arangod)
target_link_libraries(arango_async_registry
PRIVATE
arango_thread_owning_list
arango_assertions
PUBLIC
arango_metrics_base)
60 changes: 0 additions & 60 deletions lib/Async/Registry/Metrics.h

This file was deleted.

Loading
0