This is an automated email from the ASF dual-hosted git repository.
NSAmelchev pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git
The following commit(s) were added to refs/heads/master by this push:
new b0c397908d0 IGNITE-29277 Add a histogram of currently held explicit
locks (#13816)
b0c397908d0 is described below
commit b0c397908d0b336459620bb1865f790597aae800
Author: Nikita Amelchev <[email protected]>
AuthorDate: Wed Nov 11 18:56:13 2026 +0300
IGNITE-29277 Add a histogram of currently held explicit locks (#13816)
---
docs/_docs/distributed-locks.adoc | 7 +-
docs/_docs/monitoring-metrics/new-metrics.adoc | 3 +-
.../cache/GridCacheExplicitLockSpan.java | 18 +++++
.../transactions/TransactionMetricsAdapter.java | 35 ++++++--
.../processors/metric/impl/HistogramGauge.java | 92 ++++++++++++++++++++++
.../ignite/internal/TransactionMetricsTest.java | 33 +++++++-
6 files changed, 178 insertions(+), 10 deletions(-)
diff --git a/docs/_docs/distributed-locks.adoc
b/docs/_docs/distributed-locks.adoc
index 04b17fde4d8..3c2aa51ee46 100644
--- a/docs/_docs/distributed-locks.adoc
+++ b/docs/_docs/distributed-locks.adoc
@@ -73,6 +73,11 @@ control for transactions which will acquire explicit locks
for relevant cluster
== Monitoring
The node that acquired a lock reports how long explicit locks are held: the
`MaxExplicitLockHoldTime` metric shows the
-maximum hold time of the locks currently held, and the
`ExplicitLockHoldTimeHistogram` metric shows the distribution of
+maximum hold time of the locks currently held, the
`CurrentExplicitLockHoldTime` metric shows the distribution of their
+hold times, and the `ReleasedExplicitLockHoldTime` metric shows the
distribution of
hold times of released locks, see
link:monitoring-metrics/new-metrics#transactions[Transactions] metrics. The
locks held at
the moment are listed in the
link:monitoring-metrics/system-views#cache_explicit_locks[CACHE_EXPLICIT_LOCKS]
system view.
+
+`CurrentExplicitLockHoldTime` has a single bound of 60 seconds by default, so
its last bucket is the number of locks held
+for longer than that. The bound is set in milliseconds and can be changed with
+`control.sh --metric --configure-histogram` (see
link:tools/control-script#metric-configure-command[Metric configure command]).
diff --git a/docs/_docs/monitoring-metrics/new-metrics.adoc
b/docs/_docs/monitoring-metrics/new-metrics.adoc
index 249bbc8f120..545c0fa8af7 100644
--- a/docs/_docs/monitoring-metrics/new-metrics.adoc
+++ b/docs/_docs/monitoring-metrics/new-metrics.adoc
@@ -226,12 +226,13 @@ Register name: `tx`
|===
|Name | Type | Description
|AllOwnerTransactions | Map<String, String> | Map of local node owning
transactions.
-|ExplicitLockHoldTimeHistogram | histogram | Explicit locks hold times on node
represented as histogram, in milliseconds.
+|CurrentExplicitLockHoldTime | histogram | Hold times of explicit locks
currently held on the node represented as histogram, in milliseconds.
|LockedKeysNumber | long | The number of keys locked on the node.
|LongRunningCacheFuturesCount | long | The count of cache futures currently in
progress on the node whose duration exceeds the long operations dump timeout.
|MaxCacheFutureDuration | long | Maximum duration of cache futures currently
in progress on the node, in milliseconds.
|MaxExplicitLockHoldTime | long | Maximum hold time of explicit locks
currently held on the node, in milliseconds.
|OwnerTransactionsNumber | long | The number of active transactions for which
this node is the initiator.
+|ReleasedExplicitLockHoldTime | histogram | Released explicit locks hold times
on node represented as histogram, in milliseconds.
|TransactionsHoldingLockNumber | long | The number of active transactions
holding at least one key lock.
|commitTime | long | Last commit time.
|nodeSystemTimeHistogram | histogram | Transactions system times on node
represented as histogram, in milliseconds.
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheExplicitLockSpan.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheExplicitLockSpan.java
index 8c09abcd5c9..feaff015837 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheExplicitLockSpan.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheExplicitLockSpan.java
@@ -25,6 +25,7 @@ import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map;
import java.util.concurrent.locks.ReentrantLock;
+import java.util.function.LongConsumer;
import org.apache.ignite.internal.IgniteInternalFuture;
import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
import org.apache.ignite.internal.processors.cache.transactions.IgniteTxKey;
@@ -325,6 +326,23 @@ public class GridCacheExplicitLockSpan extends
ReentrantLock {
}
}
+ /** @param c Consumer of the time each acquired key of the span has been
locked for, in milliseconds. */
+ public void holdTimes(LongConsumer c) {
+ lock();
+
+ try {
+ long now = U.currentTimeMillis();
+
+ for (KeyCandidates keyCands : cands.values()) {
+ if (keyCands.acquireTime != 0)
+ c.accept(keyCands.holdTime(now));
+ }
+ }
+ finally {
+ unlock();
+ }
+ }
+
/**
* Gets explicit lock candidate for given key.
*
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/TransactionMetricsAdapter.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/TransactionMetricsAdapter.java
index db55059528c..66ff0e7cc1f 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/TransactionMetricsAdapter.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/TransactionMetricsAdapter.java
@@ -26,6 +26,7 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
+import java.util.function.LongConsumer;
import org.apache.ignite.cluster.ClusterNode;
import org.apache.ignite.internal.GridKernalContext;
import org.apache.ignite.internal.processors.cache.GridCacheExplicitLockSpan;
@@ -34,6 +35,7 @@ import
org.apache.ignite.internal.processors.cache.GridCacheMvccManager;
import
org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal;
import org.apache.ignite.internal.processors.metric.MetricRegistryImpl;
import org.apache.ignite.internal.processors.metric.impl.AtomicLongMetric;
+import org.apache.ignite.internal.processors.metric.impl.HistogramGauge;
import org.apache.ignite.internal.processors.metric.impl.HistogramMetricImpl;
import org.apache.ignite.internal.processors.metric.impl.IntMetricImpl;
import org.apache.ignite.internal.processors.metric.impl.LongAdderMetric;
@@ -43,11 +45,12 @@ import org.apache.ignite.internal.util.typedef.internal.S;
import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.lang.IgniteClosure;
import org.apache.ignite.lang.IgnitePredicate;
-import org.apache.ignite.metric.MetricRegistry;
import org.apache.ignite.transactions.TransactionMetrics;
import org.apache.ignite.transactions.TransactionState;
+import static
org.apache.ignite.internal.IgniteKernal.DFLT_LONG_OPERATIONS_DUMP_TIMEOUT;
import static
org.apache.ignite.internal.processors.metric.GridMetricManager.TX_METRICS;
+import static
org.apache.ignite.internal.processors.metric.impl.MetricUtils.metricName;
/**
* Tx metrics adapter.
@@ -74,8 +77,11 @@ public class TransactionMetricsAdapter implements
TransactionMetrics {
/** Metric name for count of long running cache futures currently in
progress on node. */
public static final String METRIC_LONG_RUNNING_CACHE_FUTURES_COUNT =
"LongRunningCacheFuturesCount";
- /** Metric name for explicit lock hold time histogram on node. */
- public static final String METRIC_EXPLICIT_LOCK_HOLD_TIME_HISTOGRAM =
"ExplicitLockHoldTimeHistogram";
+ /** Metric name for released explicit lock hold time histogram on node. */
+ public static final String METRIC_RELEASED_EXPLICIT_LOCK_HOLD_TIME =
"ReleasedExplicitLockHoldTime";
+
+ /** Metric name for histogram of hold times of explicit locks currently
held on node. */
+ public static final String METRIC_CURRENT_EXPLICIT_LOCK_HOLD_TIME =
"CurrentExplicitLockHoldTime";
/** Histogram buckets for metrics of system and user time. */
public static final long[] METRIC_TIME_BUCKETS =
@@ -143,15 +149,15 @@ public class TransactionMetricsAdapter implements
TransactionMetrics {
);
explicitLockHoldTimeHistogram = mreg.histogram(
- METRIC_EXPLICIT_LOCK_HOLD_TIME_HISTOGRAM,
+ METRIC_RELEASED_EXPLICIT_LOCK_HOLD_TIME,
METRIC_TIME_BUCKETS,
- "Explicit locks hold times on node represented as histogram, in
milliseconds."
+ "Released explicit locks hold times on node represented as
histogram, in milliseconds."
);
}
/** Callback invoked when {@link IgniteTxManager} started. */
public void onTxManagerStarted() {
- MetricRegistry mreg = gridKernalCtx.metric().registry(TX_METRICS);
+ MetricRegistryImpl mreg = gridKernalCtx.metric().registry(TX_METRICS);
mreg.register("AllOwnerTransactions",
this::getAllOwnerTransactions,
@@ -170,6 +176,12 @@ public class TransactionMetricsAdapter implements
TransactionMetrics {
this::maxExplicitLockHoldTime,
"Maximum hold time of explicit locks currently held on the node,
in milliseconds.");
+ mreg.register(new HistogramGauge(
+ metricName(TX_METRICS, METRIC_CURRENT_EXPLICIT_LOCK_HOLD_TIME),
+ "Hold times of explicit locks currently held on the node
represented as histogram, in milliseconds.",
+ new long[] {DFLT_LONG_OPERATIONS_DUMP_TIMEOUT},
+ this::explicitLockHoldTimes));
+
mreg.register(METRIC_MAX_CACHE_FUTURE_DURATION,
this::maxCacheFutureDuration,
"Maximum duration of cache futures currently in progress on the
node, in milliseconds.");
@@ -464,6 +476,17 @@ public class TransactionMetricsAdapter implements
TransactionMetrics {
return max;
}
+ /** @param c Consumer of hold times of explicit locks currently held on
the node, in milliseconds. */
+ private void explicitLockHoldTimes(LongConsumer c) {
+ GridCacheMvccManager mvccMgr = gridKernalCtx.cache().context().mvcc();
+
+ if (mvccMgr == null)
+ return;
+
+ for (GridCacheExplicitLockSpan span : mvccMgr.activeExplicitLocks())
+ span.holdTimes(c);
+ }
+
/** @return Maximum duration of cache futures currently in progress on the
node, in milliseconds. */
private long maxCacheFutureDuration() {
GridCacheMvccManager mvccMgr = gridKernalCtx.cache().context().mvcc();
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/processors/metric/impl/HistogramGauge.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/metric/impl/HistogramGauge.java
new file mode 100644
index 00000000000..414b5979c53
--- /dev/null
+++
b/modules/core/src/main/java/org/apache/ignite/internal/processors/metric/impl/HistogramGauge.java
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ */
+
+package org.apache.ignite.internal.processors.metric.impl;
+
+import java.util.function.Consumer;
+import java.util.function.LongConsumer;
+import org.apache.ignite.internal.processors.metric.AbstractMetric;
+import
org.apache.ignite.internal.processors.metric.ConfigurableHistogramMetric;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.internal.A;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Histogram of the values supplied at the time of reading: unlike {@link
HistogramMetricImpl}, it does not accumulate
+ * measurements.
+ */
+public class HistogramGauge extends AbstractMetric implements
ConfigurableHistogramMetric {
+ /** Source of the values to distribute over the bounds intervals: passes
them to the given consumer. */
+ private final Consumer<LongConsumer> src;
+
+ /** */
+ private volatile long[] bounds;
+
+ /**
+ * @param name Name.
+ * @param desc Description.
+ * @param bounds Bounds.
+ * @param src Source of the values to distribute over the bounds
intervals: passes them to the given consumer.
+ */
+ public HistogramGauge(String name, @Nullable String desc, long[] bounds,
Consumer<LongConsumer> src) {
+ super(name, desc);
+
+ this.bounds = bounds;
+ this.src = src;
+ }
+
+ /** {@inheritDoc} */
+ @Override public long[] value() {
+ long[] bounds = this.bounds;
+
+ long[] res = new long[bounds.length + 1];
+
+ src.accept(val -> {
+ int idx = 0;
+
+ while (idx < bounds.length && val > bounds[idx])
+ idx++;
+
+ res[idx]++;
+ });
+
+ return res;
+ }
+
+ /** {@inheritDoc} */
+ @Override public long[] bounds() {
+ return bounds;
+ }
+
+ /** {@inheritDoc} */
+ @Override public void bounds(long[] bounds) {
+ checkBounds(bounds);
+
+ this.bounds = bounds;
+ }
+
+ /** {@inheritDoc} */
+ @Override public void checkBounds(long[] bounds) {
+ A.notEmpty(bounds, "bounds");
+ A.ensure(F.isSorted(bounds), "bounds should be sorted");
+ }
+
+ /** {@inheritDoc} */
+ @Override public Class<long[]> type() {
+ return long[].class;
+ }
+}
diff --git
a/modules/core/src/test/java/org/apache/ignite/internal/TransactionMetricsTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/TransactionMetricsTest.java
index 4558270f12f..821a5e981c8 100644
---
a/modules/core/src/test/java/org/apache/ignite/internal/TransactionMetricsTest.java
+++
b/modules/core/src/test/java/org/apache/ignite/internal/TransactionMetricsTest.java
@@ -42,12 +42,16 @@ import org.junit.Test;
import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC;
-import static
org.apache.ignite.internal.processors.cache.transactions.TransactionMetricsAdapter.METRIC_EXPLICIT_LOCK_HOLD_TIME_HISTOGRAM;
+import static
org.apache.ignite.internal.metric.MetricsConfigurationTest.metricsBean;
+import static
org.apache.ignite.internal.processors.cache.transactions.TransactionMetricsAdapter.METRIC_CURRENT_EXPLICIT_LOCK_HOLD_TIME;
import static
org.apache.ignite.internal.processors.cache.transactions.TransactionMetricsAdapter.METRIC_MAX_EXPLICIT_LOCK_HOLD_TIME;
+import static
org.apache.ignite.internal.processors.cache.transactions.TransactionMetricsAdapter.METRIC_RELEASED_EXPLICIT_LOCK_HOLD_TIME;
import static
org.apache.ignite.internal.processors.metric.GridMetricManager.TX_METRICS;
+import static
org.apache.ignite.internal.processors.metric.impl.MetricUtils.metricName;
import static org.apache.ignite.testframework.GridTestUtils.waitForCondition;
import static
org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC;
import static
org.apache.ignite.transactions.TransactionIsolation.REPEATABLE_READ;
+import static org.junit.Assert.assertArrayEquals;
/**
*
@@ -248,6 +252,31 @@ public class TransactionMetricsTest extends
GridCommonAbstractTest {
checkExplicitLockMetrics(client, srv,
client.createNearCache(DEFAULT_CACHE_NAME, new NearCacheConfiguration<>()));
}
+ /** */
+ @Test
+ public void testCurrentExplicitLockHoldTime() throws Exception {
+ IgniteEx ignite = startGrid(0);
+
+ HistogramMetric hist =
ignite.context().metric().registry(TX_METRICS).findMetric(METRIC_CURRENT_EXPLICIT_LOCK_HOLD_TIME);
+
+ Lock lock = ignite.cache(DEFAULT_CACHE_NAME).lock(1);
+
+ lock.lock();
+
+ try {
+ assertArrayEquals(new long[] {1, 0}, hist.value());
+
+
metricsBean(ignite).configureHistogramMetric(metricName(TX_METRICS,
METRIC_CURRENT_EXPLICIT_LOCK_HOLD_TIME), new long[] {100});
+
+ assertTrue(waitForCondition(() -> Arrays.equals(new long[] {0, 1},
hist.value()), getTestTimeout()));
+ }
+ finally {
+ lock.unlock();
+ }
+
+ assertArrayEquals(new long[] {0, 0}, hist.value());
+ }
+
/**
* @param owner Node acquiring the locks.
* @param other Node that does not acquire them.
@@ -258,7 +287,7 @@ public class TransactionMetricsTest extends
GridCommonAbstractTest {
MetricRegistry mreg = owner.context().metric().registry(TX_METRICS);
LongMetric maxHoldTime =
mreg.findMetric(METRIC_MAX_EXPLICIT_LOCK_HOLD_TIME);
- HistogramMetric holdTimeHistogram =
mreg.findMetric(METRIC_EXPLICIT_LOCK_HOLD_TIME_HISTOGRAM);
+ HistogramMetric holdTimeHistogram =
mreg.findMetric(METRIC_RELEASED_EXPLICIT_LOCK_HOLD_TIME);
Lock lock = cache.lock(1);