8000 Make async registry data structure generic (#21699) · fceller/arangodb@df27a1c · GitHub
[go: up one dir, main page]

Skip to content

Commit df27a1c

Browse files
authored
Make async registry data structure generic (arangodb#21699)
1 parent 3874cd4 commit df27a1c

38 files changed

+1314
-1133
lines changed

arangod/AsyncRegistryServer/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
target_sources(arangoserver PRIVATE
22
Feature.cpp
3+
Metrics.cpp
34
RestHandler.cpp)
45
target_link_libraries(arangoserver
56
arango_async_registry_stacktrace)

arangod/AsyncRegistryServer/Feature.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ Feature::Feature(Server& server)
5656
}
5757

5858
auto Feature::create_metrics(arangodb::metrics::MetricsFeature& metrics_feature)
59-
-> std::shared_ptr<const Metrics> {
60-
return std::make_shared<Metrics>(
59+
-> std::shared_ptr<RegistryMetrics> {
60+
return std::make_shared<RegistryMetrics>(
6161
metrics_feature.addShared(arangodb_async_promises_total{}),
6262
metrics_feature.addShared(arangodb_async_existing_promises{}),
6363
metrics_feature.addShared(arangodb_async_ready_for_deletion_promises{}),
@@ -114,4 +114,4 @@ void Feature::collectOptions(std::shared_ptr<options::ProgramOptions> options) {
114114
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.)");
115115
}
116116

117-
Feature::~Feature() { registry.set_metrics(std::make_shared<Metrics>()); }
117+
Feature::~Feature() { registry.set_metrics(nullptr); }

arangod/AsyncRegistryServer/Feature.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#pragma once
2424

2525
#include "Async/Registry/registry_variable.h"
26-
#include "Async/Registry/Metrics.h"
26+
#include "AsyncRegistryServer/Metrics.h"
2727
#include "Basics/FutureSharedLock.h"
2828
#include "RestServer/arangod.h"
2929
#include "Scheduler/SchedulerFeature.h"
@@ -33,7 +33,7 @@ namespace arangodb::async_registry {
3333
class Feature final : public ArangodFeature {
3434
private:
3535
static auto create_metrics(arangodb::metrics::MetricsFeature& metrics_feature)
36-
-> std::shared_ptr<const Metrics>;
36+
-> std::shared_ptr<RegistryMetrics>;
3737
struct SchedulerWrapper {
3838
using WorkHandle = Scheduler::WorkHandle;
3939
template<typename F>
@@ -68,7 +68,7 @@ class Feature final : public ArangodFeature {
6868
};
6969
Options _options;
7070

71-
std::shared_ptr<const Metrics> metrics;
71+
std::shared_ptr<RegistryMetrics> metrics;
7272

7373
struct PromiseCleanupThread;
7474
std::shared_ptr<PromiseCleanupThread> _cleanupThread;
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
////////////////////////////////////////////////////////////////////////////////
2+
/// DISCLAIMER
3+
///
4+
/// Copyright 2014-2024 ArangoDB GmbH, Cologne, Germany
5+
/// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany
6+
///
7+
/// Licensed under the Business Source License 1.1 (the "License");
8+
/// you may not use this file except in compliance with the License.
9+
/// You may obtain a copy of the License at
10+
///
11+
/// https://github.com/arangodb/arangodb/blob/devel/LICENSE
12+
///
13+
/// Unless required by applicable law or agreed to in writing, software
14+
/// distributed under the License is distributed on an "AS IS" BASIS,
15+
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
/// See the License for the specific language governing permissions and
17+
/// limitations under the License.
18+
///
19+
/// Copyright holder is ArangoDB GmbH, Cologne, Germany
20+
///
21+
/// @author Julia Volmer
22+
////////////////////////////////////////////////////////////////////////////////
23+
#include "Metrics.h"
24+
25+
#include "Metrics/Counter.h"
26+
#include "Metrics/Gauge.h"
27+
28+
auto RegistryMetrics::increment_total_nodes() -> void {
29+
promises_total->count();
30+
}
31+
auto RegistryMetrics::increment_registered_nodes() -> void {
32+
existing_promises->fetch_add(1);
33+
}
34+
auto RegistryMetrics::decrement_registered_nodes() -> void {
35+
existing_promises->fetch_sub(1);
36+
}
37+
auto RegistryMetrics::increment_ready_for_deletion_nodes() -> void {
38+
existing_promises->fetch_add(1);
39+
}
40+
auto RegistryMetrics::decrement_ready_for_deletion_nodes() -> void {
41+
existing_promises->fetch_sub(1);
42+
}
43+
auto RegistryMetrics::increment_total_lists() -> void {
44+
thread_registries_total->count();
45+
}
46+
auto RegistryMetrics::increment_existing_lists() -> void {
47+
existing_thread_registries->fetch_add(1);
48+
}
49+
auto RegistryMetrics::decrement_existing_lists() -> void {
50+
existing_thread_registries->fetch_sub(1);
51+
}

arangod/AsyncRegistryServer/Metrics.h

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
////////////////////////////////////////////////////////////////////////////////
2+
/// DISCLAIMER
3+
///
4+
/// Copyright 2014-2024 ArangoDB GmbH, Cologne, Germany
5+
/// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany
6+
///
7+
/// Licensed under the Business Source License 1.1 (the "License");
8+
/// you may not use this file except in compliance with the License.
9+
/// You may obtain a copy of the License at
10+
///
11+
/// https://github.com/arangodb/arangodb/blob/devel/LICENSE
12+
///
13+
/// Unless required by applicable law or agreed to in writing, software
14+
/// distributed under the License is distributed on an "AS IS" BASIS,
15+
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
/// See the License for the specific language governing permissions and
17+
/// limitations under the License.
18+
///
19+
/// Copyright holder is ArangoDB GmbH, Cologne, Germany
20+
///
21+
/// @author Julia Volmer
22+
////////////////////////////////////////////////////////////////////////////////
23+
#pragma once
24+
25+
#include "Containers/Concurrent/metrics.h"
26+
#include "Metrics/Fwd.h"
27+
28+
struct RegistryMetrics : arangodb::containers::Metrics {
29+
RegistryMetrics(
30+
std::shared_ptr<arangodb::metrics::Counter> promises_total,
31+
std::shared_ptr<arangodb::metrics::Gauge<std::uint64_t>>
32+
existing_promises,
33+
std::shared_ptr<arangodb::metrics::Gauge<std::uint64_t>>
34+
ready_for_deletion_promises,
35+
std::shared_ptr<arangodb::metrics::Counter> thread_registries_total,
36+
std::shared_ptr<arangodb::metrics::Gauge<std::uint64_t>>
37+
existing_thread_registries)
38+
: promises_total{promises_total},
39+
existing_promises{existing_promises},
40+
ready_for_deletion_promises{ready_for_deletion_promises},
41+
thread_registries_total{thread_registries_total},
42+
existing_thread_registries{existing_thread_registries} {}
43+
~RegistryMetrics() = default;
44+
auto increment_total_nodes() -> void override;
45+
auto increment_registered_nodes() -> void override;
46+
auto decrement_registered_nodes() -> void override;
47+
auto increment_ready_for_deletion_nodes() -> void override;
48+
auto decrement_ready_for_deletion_nodes() -> void override;
49+
auto increment_total_lists() -> void override;
50+
auto increment_existing_lists() -> void override;
51+
auto decrement_existing_lists() -> void override;
52+
53+
private:
54+
std::shared_ptr<arangodb::metrics::Counter> promises_total = nullptr;
55+
std::shared_ptr<arangodb::metrics::Gauge<std::uint64_t>> existing_promises =
56+
nullptr;
57+
std::shared_ptr<arangodb::metrics::Gauge<std::uint64_t>>
58+
ready_for_deletion_promises = nullptr;
59+
std::shared_ptr<arangodb::metrics::Counter> thread_registries_total = nullptr;
60+
std::shared_ptr<arangodb::metrics::Gauge<std::uint64_t>>
61+
existing_thread_registries = nullptr;
62+
};

arangod/AsyncRegistryServer/PrettyPrinter/src/asyncregistry/gdb_data.py

Lines changed: 7 additions & 8 deletions
1241
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def is_deleted(self):
1515

1616
def __str__(self):
1717
if len(self.name) > len("arangodb::async_registry::State::"):
18-
return self.name[len("arangodb::async_registry::State::"):]
18+
return "\"" + self.name[len("arangodb::async_registry::State::"):] + "\""
1919
else:
2020
return self.name
2121

@@ -85,13 +85,12 @@ class Promise:
8585
state: State
8686

8787
@classmethod
88-
def from_gdb(cls, value_ptr: gdb.Value):
89-
value = value_ptr.dereference()
88+
def from_gdb(cls, ptr: gdb.Value, value: gdb.Value):
9089
return cls(
91-
PromiseId(value_ptr),
90+
PromiseId(ptr),
9291
Thread.from_gdb(value["thread"]),
9392
SourceLocation.from_gdb(value["source_location"]),
94-
Requester.from_gdb(value["requester"]['_M_i']),
93+
Requester.from_gdb(value["requester"]["_M_i"]),
9594
State.from_gdb(value["state"])
9695
)
9796

@@ -119,7 +118,7 @@ class ThreadRegistry:
119118

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

124123
class GdbVector:
125124
def __init__(self, value: gdb.Value):
@@ -129,7 +128,7 @@ def __init__(self, value: gdb.Value):
129128
def __iter__(self):
130129
current = self._begin
131130
while current != self._end:
132-
registry = current.dereference()["_M_ptr"].dereference()
131+
registry = current.dereference()["_M_ptr"]
133132
current += 1
134133
yield registry
135134

@@ -139,7 +138,7 @@ class AsyncRegistry:
139138

140139
@classmethod
141140
def from_gdb(cls, value: gdb.Value):
142-
return cls(ThreadRegistry.from_gdb(registry) for registry in GdbVector(value['registries']['_M_impl']))
141+
return cls(ThreadRegistry.from_gdb(registry) for registry in GdbVector(value['_lists']['_M_impl']))
143142

144143
def promises(self) -> Iterable[Promise]:
145144
for registry in self.thread_registries:

arangod/AsyncRegistryServer/RestHandler.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,13 @@ namespace {
6868
auto all_undeleted_promises() -> ForestWithRoots<PromiseSnapshot> {
6969
Forest<PromiseSnapshot> forest;
7070
std::vector<Id> roots;
71-
registry.for_promise([&](PromiseSnapshot promise) {
71+
registry.for_node([&](PromiseSnapshot promise) {
7272
if (promise.state != State::Deleted) {
7373
std::visit(overloaded{
7474
[&](PromiseId async_waiter) {
7575
forest.insert(promise.id, async_waiter, promise);
7676
},
77-
[&](ThreadId sync_waiter_thread) {
77+
[&](basics::ThreadId sync_waiter_thread) {
7878
forest.insert(promise.id, nullptr, promise);
7979
roots.emplace_back(promise.id);
8080
},

lib/Async/Registry/CMakeLists.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
add_library(arango_async_registry STATIC
22
promise.cpp
3-
registry.cpp
4-
registry_variable.cpp
5-
thread_registry.cpp)
3+
registry_variable.cpp)
64
target_include_directories(arango_async_registry PRIVATE
75
${PROJECT_SOURCE_DIR}/arangod)
86
target_link_libraries(arango_async_registry
97
PRIVATE
8+
arango_thread_owning_list
109
arango_assertions
1110
PUBLIC
1211
arango_metrics_base)

lib/Async/Registry/Metrics.h

Lines changed: 0 additions & 60 deletions
This file was deleted.

0 commit comments

Comments
 (0)
0