Skip to content

Commit 55f8b52

Browse files
authored
Fix: avoid duplicate link metrics (arangodb#20420)
* Labels are part of the metric key, so they should be included in the duplicate metric error msg * Include indexId in the link metric to ensure uniqueness. We cannot update a link, but have to drop and recreate it. Until now, this new index had the same set of labels as the old one. However, on followers (and with replication2 also on the leader), the DropIndex and EnsureIndex actions could run concurrently. I.e., we could try to create the new index before the old one was fully removed. In this case we could get a duplicate metric exception, preventing the index from being created. Such errors are not really handled ATM, they are simply logged and otherwise ignored. That means the index will simply not be available on the affected server, since we will also do not retry to create it at a later time. * Add changelog entry * Also adjust getLabels * Also add indexId for inverted index metrics * Change order of labels Shard label must be last, because some parsing code relies on it (the shard label is removed when accumulating collection metrics from different shards) * Fix unit tests * Adjust aggregation on coordinator
1 parent 5ce531f commit 55f8b52

File tree

7 files changed

+136
-117
lines changed

7 files changed

+136
-117
lines changed

CHANGELOG

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
devel
22
-----
33

4+
* Fix: we cannot update a link, but have to drop and recreate it. Until now,
5+
this new index had the same set of labels as the old one. However, on followers
6+
(and with replication2 also on the leader), the DropIndex and EnsureIndex
7+
actions could run concurrently. I.e., we could try to create the new index
8+
before the old one was fully removed. In this case we could get a duplicate
9+
metric exception, preventing the index from being created. Such errors are not
10+
really handled ATM - they are simply logged and otherwise ignored. That means
11+
the index will simply not be available on the affected server, since we will
12+
also not retry to create it at a later time.
13+
To avoid this, we add a new `indexId` label to the metric to make it unique.
14+
415
* Expose REST API endpoints for server options discovery:
516
- GET `/_admin/options-description`: returns a JSON description of all
617
available server options.

arangod/IResearch/IResearchInvertedClusterIndex.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ IResearchDataStore::Stats IResearchInvertedClusterIndex::stats() const {
105105
auto labels = absl::StrCat( // clang-format off
106106
"db=\"", getDbName(), "\","
107107
"index=\"", name(), "\","
108-
"collection=\"", getCollectionName(), "\""); // clang-format on
108+
"collection=\"", getCollectionName(), "\",",
109+
"indexId=\"", id().id(), "\""); // clang-format on
109110
return {
110111
metrics.get<std::uint64_t>("arangodb_search_num_docs", labels),
111112
metrics.get<std::uint64_t>("arangodb_search_num_live_docs", labels),

arangod/IResearch/IResearchLink.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ T getMetric(IResearchLink const& link) {
9595
metric.addLabel("db", link.getDbName());
9696
metric.addLabel("view", link.getViewId());
9797
metric.addLabel("collection", link.getCollectionName());
98+
metric.addLabel("indexId", std::to_string(link.index().id().id()));
9899
metric.addLabel("shard", link.getShardName());
99100
return metric;
100101
}
@@ -103,6 +104,7 @@ std::string getLabels(IResearchLink const& link) {
103104
return absl::StrCat("db=\"", link.getDbName(), //
104105
"\",view=\"", link.getViewId(), //
105106
"\",collection=\"", link.getCollectionName(), //
107+
"\",indexId=\"", link.index().id().id(), //
106108
"\",shard=\"", link.getShardName(), "\"");
107109
}
108110

arangod/IResearch/IResearchLinkCoordinator.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ IResearchDataStore::Stats IResearchLinkCoordinator::stats() const {
8585
auto labels = absl::StrCat( // clang-format off
8686
"db=\"", getDbName(), "\","
8787
"view=\"", getViewId(), "\","
88-
"collection=\"", getCollectionName(), "\""); // clang-format on
88+
"collection=\"", getCollectionName(), "\","
89+
"indexId=\"", id().id(), "\""); // clang-format on
8990
return {
9091
metrics.get<std::uint64_t>("arangodb_search_num_docs", labels),
9192
metrics.get<std::uint64_t>("arangodb_search_num_live_docs", labels),

arangod/IResearch/IResearchRocksDBInvertedIndex.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ T getMetric(IResearchRocksDBInvertedIndex const& index) {
221221
metric.addLabel("db", index.getDbName());
222222
metric.addLabel("index", index.name());
223223
metric.addLabel("collection", index.getCollectionName());
224+
metric.addLabel("indexId", std::to_string(index.id().id()));
224225
metric.addLabel("shard", index.getShardName());
225226
return metric;
226227
}
@@ -230,6 +231,7 @@ std::string getLabels(IResearchRocksDBInvertedIndex const& index) {
230231
"db=\"", index.getDbName(), "\","
231232
"index=\"", index.name(), "\","
232233
"collection=\"", index.getCollectionName(), "\","
234+
"indexId=\"", index.id().id(), "\","
233235
"shard=\"", index.getShardName(), "\""); // clang-format on
234236
}
235237

arangod/Metrics/MetricsFeature.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ std::shared_ptr<Metric> MetricsFeature::doAdd(Builder& builder) {
9494
if (!_registry.try_emplace(key, metric).second) {
9595
THROW_ARANGO_EXCEPTION_MESSAGE(
9696
TRI_ERROR_INTERNAL,
97-
absl::StrCat(builder.type(), " ", builder.name(), " already exists"));
97+
absl::StrCat(builder.type(), " ", metric->name(), ":", metric->labels(),
98+
" already exists"));
9899
}
99100
return metric;
100101
}

0 commit comments

Comments
 (0)