You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by mi...@apache.org on 2026/05/26 12:44:26 UTC
(jackrabbit-oak) branch issue/OAK-12181_v2 created (now 814d2467dd)
This is an automated email from the ASF dual-hosted git repository.
smiroslav pushed a change to branch issue/OAK-12181_v2
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git
at 814d2467dd OAK-12181 - add metric when repository lock could not be renewed
This branch includes the following new commits:
new 814d2467dd OAK-12181 - add metric when repository lock could not be renewed
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(jackrabbit-oak) 01/01: OAK-12181 - add metric when repository lock could not be renewed
Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
smiroslav pushed a commit to branch issue/OAK-12181_v2
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git
commit 814d2467dd8e1ef713f15731e74d3abb845ede0c
Author: smiroslav <mi...@apache.com>
AuthorDate: Tue May 26 14:27:09 2026 +0200
OAK-12181 - add metric when repository lock could not be renewed
---
.../oak/segment/azure/AzurePersistence.java | 18 ++++-
.../oak/segment/azure/v8/AzurePersistenceV8.java | 20 +++--
.../segment/azure/AzurePersistenceMetricsTest.java | 81 +++++++++++++++++++
.../oak/segment/azure/AzureRepositoryLockTest.java | 41 ++++++++++
.../azure/v8/AzurePersistenceV8MetricsTest.java | 90 ++++++++++++++++++++++
.../azure/v8/AzureRepositoryLockV8Test.java | 36 +++++++++
.../segment/file/MetricsRemoteStoreMonitor.java | 8 ++
.../segment/spi/monitor/RemoteStoreMonitor.java | 2 +
.../spi/monitor/RemoteStoreMonitorAdapter.java | 5 ++
.../file/MetricsRemoteStoreMonitorTest.java | 18 ++++-
10 files changed, 308 insertions(+), 11 deletions(-)
diff --git a/oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/AzurePersistence.java b/oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/AzurePersistence.java
index 295ca41b1e..7f437540e7 100644
--- a/oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/AzurePersistence.java
+++ b/oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/AzurePersistence.java
@@ -37,6 +37,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
+import java.util.concurrent.atomic.AtomicReference;
public class AzurePersistence implements SegmentNodeStorePersistence {
private static final Logger log = LoggerFactory.getLogger(AzurePersistence.class);
@@ -51,6 +52,8 @@ public class AzurePersistence implements SegmentNodeStorePersistence {
protected AzureHttpRequestLoggingPolicy azureHttpRequestLoggingPolicy;
+ private final AtomicReference<RemoteStoreMonitor> remoteStoreMonitor = new AtomicReference<>();
+
protected WriteAccessController writeAccessController = new WriteAccessController();
private final Integer journalLineLimit;
@@ -110,10 +113,16 @@ public class AzurePersistence implements SegmentNodeStorePersistence {
BlockBlobClient blockBlobClient = getBlockBlob("repo.lock");
BlockBlobClient noRetryBlockBlobClient = getNoRetryBlockBlob("repo.lock");
BlobLeaseClient blobLeaseClient = new BlobLeaseClientBuilder().blobClient(noRetryBlockBlobClient).buildClient();
- return new AzureRepositoryLock(blockBlobClient, blobLeaseClient, () -> {
- log.warn("Lost connection to the Azure. The client will be closed.");
- // TODO close the connection
- }, writeAccessController).lock();
+ return new AzureRepositoryLock(blockBlobClient, blobLeaseClient,
+ this::onRepositoryLockLost, writeAccessController).lock();
+ }
+
+ void onRepositoryLockLost() {
+ log.error("Lost connection to Azure. The repository lock lease could not be renewed.");
+ RemoteStoreMonitor monitor = remoteStoreMonitor.get();
+ if (monitor != null) {
+ monitor.repositoryLockLost();
+ }
}
private BlockBlobClient getBlockBlob(String path) throws IOException {
@@ -141,6 +150,7 @@ public class AzurePersistence implements SegmentNodeStorePersistence {
}
private void attachRemoteStoreMonitor(RemoteStoreMonitor remoteStoreMonitor) {
+ this.remoteStoreMonitor.set(remoteStoreMonitor);
if (azureHttpRequestLoggingPolicy != null) {azureHttpRequestLoggingPolicy.setRemoteStoreMonitor(remoteStoreMonitor);}
}
diff --git a/oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/v8/AzurePersistenceV8.java b/oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/v8/AzurePersistenceV8.java
index 0b056f768f..910363e108 100644
--- a/oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/v8/AzurePersistenceV8.java
+++ b/oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/v8/AzurePersistenceV8.java
@@ -21,6 +21,7 @@ import java.net.URISyntaxException;
import java.util.Date;
import java.util.EnumSet;
import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
import com.microsoft.azure.storage.OperationContext;
import com.microsoft.azure.storage.RequestCompletedEvent;
@@ -50,6 +51,8 @@ public class AzurePersistenceV8 implements SegmentNodeStorePersistence {
protected final CloudBlobDirectory segmentstoreDirectory;
+ private final AtomicReference<RemoteStoreMonitor> remoteStoreMonitor = new AtomicReference<>();
+
protected WriteAccessController writeAccessController = new WriteAccessController();
public AzurePersistenceV8(CloudBlobDirectory segmentStoreDirectory) {
@@ -100,10 +103,16 @@ public class AzurePersistenceV8 implements SegmentNodeStorePersistence {
@Override
public RepositoryLock lockRepository() throws IOException {
- return new AzureRepositoryLockV8(getBlockBlob("repo.lock"), () -> {
- log.warn("Lost connection to the Azure. The client will be closed.");
- // TODO close the connection
- }, writeAccessController).lock();
+ return new AzureRepositoryLockV8(getBlockBlob("repo.lock"),
+ this::onRepositoryLockLost, writeAccessController).lock();
+ }
+
+ void onRepositoryLockLost() {
+ log.error("Lost connection to Azure. The repository lock lease could not be renewed.");
+ RemoteStoreMonitor monitor = remoteStoreMonitor.get();
+ if (monitor != null) {
+ monitor.repositoryLockLost();
+ }
}
private CloudBlockBlob getBlockBlob(String path) throws IOException {
@@ -122,7 +131,8 @@ public class AzurePersistenceV8 implements SegmentNodeStorePersistence {
}
}
- private static void attachRemoteStoreMonitor(RemoteStoreMonitor remoteStoreMonitor) {
+ private void attachRemoteStoreMonitor(RemoteStoreMonitor remoteStoreMonitor) {
+ this.remoteStoreMonitor.set(remoteStoreMonitor);
OperationContext.getGlobalRequestCompletedEventHandler().addListener(new StorageEvent<RequestCompletedEvent>() {
@Override
diff --git a/oak-segment-azure/src/test/java/org/apache/jackrabbit/oak/segment/azure/AzurePersistenceMetricsTest.java b/oak-segment-azure/src/test/java/org/apache/jackrabbit/oak/segment/azure/AzurePersistenceMetricsTest.java
new file mode 100644
index 0000000000..5307997953
--- /dev/null
+++ b/oak-segment-azure/src/test/java/org/apache/jackrabbit/oak/segment/azure/AzurePersistenceMetricsTest.java
@@ -0,0 +1,81 @@
+/*
+ * 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.jackrabbit.oak.segment.azure;
+
+import com.azure.storage.blob.BlobContainerClient;
+import org.apache.jackrabbit.oak.commons.concurrent.ExecutorCloser;
+import org.apache.jackrabbit.oak.segment.file.MetricsRemoteStoreMonitor;
+import org.apache.jackrabbit.oak.segment.spi.monitor.FileStoreMonitor;
+import org.apache.jackrabbit.oak.segment.spi.monitor.IOMonitor;
+import org.apache.jackrabbit.oak.stats.CounterStats;
+import org.apache.jackrabbit.oak.stats.DefaultStatisticsProvider;
+import org.apache.jackrabbit.oak.stats.StatsOptions;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+
+import static org.junit.Assert.assertEquals;
+
+public class AzurePersistenceMetricsTest {
+
+ private ScheduledExecutorService executor;
+ private DefaultStatisticsProvider statisticsProvider;
+ private CounterStats lockLostCounter;
+
+ @Before
+ public void setup() {
+ executor = Executors.newSingleThreadScheduledExecutor();
+ statisticsProvider = new DefaultStatisticsProvider(executor);
+ lockLostCounter = statisticsProvider.getCounterStats(
+ MetricsRemoteStoreMonitor.REPOSITORY_LOCK_LOST, StatsOptions.DEFAULT);
+ }
+
+ @After
+ public void tearDown() {
+ new ExecutorCloser(executor).close();
+ }
+
+ @Test
+ public void onRepositoryLockLostIncrementsMetricWhenMonitorAttached() {
+ MetricsRemoteStoreMonitor monitor = new MetricsRemoteStoreMonitor(statisticsProvider);
+ BlobContainerClient containerClient = Mockito.mock(BlobContainerClient.class);
+ AzurePersistence persistence = new AzurePersistence(containerClient, "oak");
+
+ persistence.createArchiveManager(false, false,
+ Mockito.mock(IOMonitor.class), Mockito.mock(FileStoreMonitor.class), monitor);
+
+ assertEquals(0, lockLostCounter.getCount());
+
+ persistence.onRepositoryLockLost();
+
+ assertEquals(1, lockLostCounter.getCount());
+ }
+
+ @Test
+ public void onRepositoryLockLostIsNoOpWhenMonitorNotAttached() {
+ BlobContainerClient containerClient = Mockito.mock(BlobContainerClient.class);
+ AzurePersistence persistence = new AzurePersistence(containerClient, "oak");
+
+ persistence.onRepositoryLockLost();
+
+ assertEquals(0, lockLostCounter.getCount());
+ }
+}
diff --git a/oak-segment-azure/src/test/java/org/apache/jackrabbit/oak/segment/azure/AzureRepositoryLockTest.java b/oak-segment-azure/src/test/java/org/apache/jackrabbit/oak/segment/azure/AzureRepositoryLockTest.java
index 10e8370d13..58478d6d59 100644
--- a/oak-segment-azure/src/test/java/org/apache/jackrabbit/oak/segment/azure/AzureRepositoryLockTest.java
+++ b/oak-segment-azure/src/test/java/org/apache/jackrabbit/oak/segment/azure/AzureRepositoryLockTest.java
@@ -31,8 +31,13 @@ import com.azure.storage.blob.models.BlobStorageException;
import com.azure.storage.blob.specialized.BlobLeaseClient;
import com.azure.storage.blob.specialized.BlobLeaseClientBuilder;
import com.azure.storage.blob.specialized.BlockBlobClient;
+import org.apache.jackrabbit.oak.commons.concurrent.ExecutorCloser;
+import org.apache.jackrabbit.oak.segment.file.MetricsRemoteStoreMonitor;
import org.apache.jackrabbit.oak.segment.remote.WriteAccessController;
import org.apache.jackrabbit.oak.segment.spi.persistence.RepositoryLock;
+import org.apache.jackrabbit.oak.stats.CounterStats;
+import org.apache.jackrabbit.oak.stats.DefaultStatisticsProvider;
+import org.apache.jackrabbit.oak.stats.StatsOptions;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Rule;
@@ -48,12 +53,15 @@ import java.net.URISyntaxException;
import java.nio.channels.UnresolvedAddressException;
import java.security.InvalidKeyException;
import java.time.Duration;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Predicate;
+import static org.awaitility.Awaitility.await;
import static org.junit.Assert.*;
import static org.mockito.ArgumentMatchers.*;
@@ -372,6 +380,39 @@ public class AzureRepositoryLockTest {
}
}
+ @Test
+ public void testRepositoryLockLostMetricOnNonTransientError() throws Exception {
+ ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
+ DefaultStatisticsProvider statisticsProvider = new DefaultStatisticsProvider(executor);
+ try (ExecutorCloser ignored = new ExecutorCloser(executor)) {
+ MetricsRemoteStoreMonitor monitor = new MetricsRemoteStoreMonitor(statisticsProvider);
+ CounterStats lockLostCounter = statisticsProvider.getCounterStats(
+ MetricsRemoteStoreMonitor.REPOSITORY_LOCK_LOST, StatsOptions.DEFAULT);
+
+ BlockBlobClient blockBlobClient = readBlobContainerClient.getBlobClient("oak/repo.lock").getBlockBlobClient();
+ BlockBlobClient noRetryBlockBlobClient = noRetryBlobContainerClient.getBlobClient("oak/repo.lock").getBlockBlobClient();
+ BlobLeaseClient blobLeaseClient = new BlobLeaseClientBuilder().blobClient(noRetryBlockBlobClient).buildClient();
+
+ BlobLeaseClient blobLeaseMocked = Mockito.spy(blobLeaseClient);
+
+ // Throw a non-transient, non-BlobStorageException error on renewal to trigger the shutdown hook
+ Mockito.doThrow(new SecurityException("simulated non-transient error"))
+ .when(blobLeaseMocked).renewLeaseWithResponse((RequestConditions) any(), any(), any());
+
+ assertEquals("Counter should be zero before test", 0, lockLostCounter.getCount());
+
+ AzureRepositoryLock lock = new AzureRepositoryLock(blockBlobClient, blobLeaseMocked,
+ monitor::repositoryLockLost, new WriteAccessController());
+
+ lock.lock();
+
+ await().atMost(Duration.ofSeconds(10))
+ .untilAsserted(() -> assertEquals(
+ "REPOSITORY_LOCK_LOST counter should be incremented after non-transient error",
+ 1, lockLostCounter.getCount()));
+ }
+ }
+
/**
* HTTP pipeline policy that injects delays into specific requests.
* Used to cause real client-side timeouts in tests.
diff --git a/oak-segment-azure/src/test/java/org/apache/jackrabbit/oak/segment/azure/v8/AzurePersistenceV8MetricsTest.java b/oak-segment-azure/src/test/java/org/apache/jackrabbit/oak/segment/azure/v8/AzurePersistenceV8MetricsTest.java
new file mode 100644
index 0000000000..abe99a85ce
--- /dev/null
+++ b/oak-segment-azure/src/test/java/org/apache/jackrabbit/oak/segment/azure/v8/AzurePersistenceV8MetricsTest.java
@@ -0,0 +1,90 @@
+/*
+ * 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.jackrabbit.oak.segment.azure.v8;
+
+import com.microsoft.azure.storage.blob.BlobRequestOptions;
+import com.microsoft.azure.storage.blob.CloudBlobClient;
+import com.microsoft.azure.storage.blob.CloudBlobDirectory;
+import org.apache.jackrabbit.oak.commons.concurrent.ExecutorCloser;
+import org.apache.jackrabbit.oak.segment.file.MetricsRemoteStoreMonitor;
+import org.apache.jackrabbit.oak.segment.spi.monitor.FileStoreMonitor;
+import org.apache.jackrabbit.oak.segment.spi.monitor.IOMonitor;
+import org.apache.jackrabbit.oak.stats.CounterStats;
+import org.apache.jackrabbit.oak.stats.DefaultStatisticsProvider;
+import org.apache.jackrabbit.oak.stats.StatsOptions;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.when;
+
+public class AzurePersistenceV8MetricsTest {
+
+ private ScheduledExecutorService executor;
+ private DefaultStatisticsProvider statisticsProvider;
+ private CounterStats lockLostCounter;
+
+ @Before
+ public void setup() {
+ executor = Executors.newSingleThreadScheduledExecutor();
+ statisticsProvider = new DefaultStatisticsProvider(executor);
+ lockLostCounter = statisticsProvider.getCounterStats(
+ MetricsRemoteStoreMonitor.REPOSITORY_LOCK_LOST, StatsOptions.DEFAULT);
+ }
+
+ @After
+ public void tearDown() {
+ new ExecutorCloser(executor).close();
+ }
+
+ @Test
+ public void onRepositoryLockLostIncrementsMetricWhenMonitorAttached() {
+ MetricsRemoteStoreMonitor monitor = new MetricsRemoteStoreMonitor(statisticsProvider);
+ AzurePersistenceV8 persistence = new AzurePersistenceV8(newCloudBlobDirectoryMock());
+
+ persistence.createArchiveManager(false, false,
+ Mockito.mock(IOMonitor.class), Mockito.mock(FileStoreMonitor.class), monitor);
+
+ assertEquals(0, lockLostCounter.getCount());
+
+ persistence.onRepositoryLockLost();
+
+ assertEquals(1, lockLostCounter.getCount());
+ }
+
+ @Test
+ public void onRepositoryLockLostIsNoOpWhenMonitorNotAttached() {
+ AzurePersistenceV8 persistence = new AzurePersistenceV8(newCloudBlobDirectoryMock());
+
+ persistence.onRepositoryLockLost();
+
+ assertEquals(0, lockLostCounter.getCount());
+ }
+
+ private static CloudBlobDirectory newCloudBlobDirectoryMock() {
+ CloudBlobDirectory directory = Mockito.mock(CloudBlobDirectory.class);
+ CloudBlobClient blobClient = Mockito.mock(CloudBlobClient.class);
+ when(directory.getServiceClient()).thenReturn(blobClient);
+ when(blobClient.getDefaultRequestOptions()).thenReturn(new BlobRequestOptions());
+ return directory;
+ }
+}
diff --git a/oak-segment-azure/src/test/java/org/apache/jackrabbit/oak/segment/azure/v8/AzureRepositoryLockV8Test.java b/oak-segment-azure/src/test/java/org/apache/jackrabbit/oak/segment/azure/v8/AzureRepositoryLockV8Test.java
index 2695921745..72e4b82322 100644
--- a/oak-segment-azure/src/test/java/org/apache/jackrabbit/oak/segment/azure/v8/AzureRepositoryLockV8Test.java
+++ b/oak-segment-azure/src/test/java/org/apache/jackrabbit/oak/segment/azure/v8/AzureRepositoryLockV8Test.java
@@ -28,8 +28,13 @@ import com.microsoft.azure.storage.blob.CloudBlobClient;
import com.microsoft.azure.storage.blob.CloudBlobContainer;
import com.microsoft.azure.storage.blob.CloudBlockBlob;
import org.apache.jackrabbit.oak.blob.cloud.azure.blobstorage.AzuriteDockerRule;
+import org.apache.jackrabbit.oak.commons.concurrent.ExecutorCloser;
+import org.apache.jackrabbit.oak.segment.file.MetricsRemoteStoreMonitor;
import org.apache.jackrabbit.oak.segment.remote.WriteAccessController;
import org.apache.jackrabbit.oak.segment.spi.persistence.RepositoryLock;
+import org.apache.jackrabbit.oak.stats.CounterStats;
+import org.apache.jackrabbit.oak.stats.DefaultStatisticsProvider;
+import org.apache.jackrabbit.oak.stats.StatsOptions;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Rule;
@@ -42,6 +47,9 @@ import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.net.URISyntaxException;
import java.security.InvalidKeyException;
+import java.time.Duration;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
@@ -266,4 +274,32 @@ public class AzureRepositoryLockV8Test {
wireMockServer.stop();
}
}
+
+ @Test
+ public void testRepositoryLockLostMetricOnNonTransientError() throws Exception {
+ ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
+ DefaultStatisticsProvider statisticsProvider = new DefaultStatisticsProvider(executor);
+ try (ExecutorCloser ignored = new ExecutorCloser(executor)) {
+ MetricsRemoteStoreMonitor monitor = new MetricsRemoteStoreMonitor(statisticsProvider);
+ CounterStats lockLostCounter = statisticsProvider.getCounterStats(
+ MetricsRemoteStoreMonitor.REPOSITORY_LOCK_LOST, StatsOptions.DEFAULT);
+
+ CloudBlockBlob blob = container.getBlockBlobReference("oak/repo.lock");
+ CloudBlockBlob blobMocked = Mockito.spy(blob);
+
+ // Throw a non-transient, non-StorageException error on renewal to trigger the shutdown hook
+ Mockito.doThrow(new SecurityException("simulated non-transient error"))
+ .when(blobMocked).renewLease(Mockito.any(), Mockito.any(), Mockito.any());
+
+ assertEquals("Counter should be zero before test", 0, lockLostCounter.getCount());
+
+ AzureRepositoryLockV8 lock = new AzureRepositoryLockV8(blobMocked, monitor::repositoryLockLost, new WriteAccessController());
+ lock.lock();
+
+ await().atMost(Duration.ofSeconds(10))
+ .untilAsserted(() -> assertEquals(
+ "REPOSITORY_LOCK_LOST counter should be incremented after non-transient error",
+ 1, lockLostCounter.getCount()));
+ }
+ }
}
diff --git a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/MetricsRemoteStoreMonitor.java b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/MetricsRemoteStoreMonitor.java
index b84a280f89..7bfa9ba42c 100644
--- a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/MetricsRemoteStoreMonitor.java
+++ b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/MetricsRemoteStoreMonitor.java
@@ -31,15 +31,18 @@ public class MetricsRemoteStoreMonitor extends RemoteStoreMonitorAdapter {
public static final String REQUEST_COUNT = "REQUEST_COUNT";
public static final String REQUEST_ERROR = "REQUEST_ERROR";
public static final String REQUEST_DURATION = "REQUEST_DURATION";
+ public static final String REPOSITORY_LOCK_LOST = "REPOSITORY_LOCK_LOST";
private final CounterStats requestCountStats;
private final CounterStats requestErrorStats;
private final TimerStats requestDurationStats;
+ private final CounterStats repositoryLockLostStats;
public MetricsRemoteStoreMonitor(@NotNull StatisticsProvider statisticsProvider) {
requestCountStats = statisticsProvider.getCounterStats(REQUEST_COUNT, StatsOptions.DEFAULT);
requestErrorStats = statisticsProvider.getCounterStats(REQUEST_ERROR, StatsOptions.DEFAULT);
requestDurationStats = statisticsProvider.getTimer(REQUEST_DURATION, StatsOptions.METRICS_ONLY);
+ repositoryLockLostStats = statisticsProvider.getCounterStats(REPOSITORY_LOCK_LOST, StatsOptions.DEFAULT);
}
@Override
@@ -55,4 +58,9 @@ public class MetricsRemoteStoreMonitor extends RemoteStoreMonitorAdapter {
public void requestDuration(long duration, TimeUnit timeUnit) {
requestDurationStats.update(duration, timeUnit);
}
+
+ @Override
+ public void repositoryLockLost() {
+ repositoryLockLostStats.inc();
+ }
}
diff --git a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/monitor/RemoteStoreMonitor.java b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/monitor/RemoteStoreMonitor.java
index f777430dd5..4d6eca4cc8 100644
--- a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/monitor/RemoteStoreMonitor.java
+++ b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/monitor/RemoteStoreMonitor.java
@@ -28,4 +28,6 @@ public interface RemoteStoreMonitor {
public void requestDuration(long duration, TimeUnit timeUnit);
+ default void repositoryLockLost() {}
+
}
diff --git a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/monitor/RemoteStoreMonitorAdapter.java b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/monitor/RemoteStoreMonitorAdapter.java
index 49443b6e3e..b70c56aea6 100644
--- a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/monitor/RemoteStoreMonitorAdapter.java
+++ b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/monitor/RemoteStoreMonitorAdapter.java
@@ -37,4 +37,9 @@ public class RemoteStoreMonitorAdapter implements RemoteStoreMonitor {
public void requestDuration(long duration, TimeUnit timeUnit) {
// Intentionally left blank
}
+
+ @Override
+ public void repositoryLockLost() {
+ // Intentionally left blank
+ }
}
diff --git a/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/MetricsRemoteStoreMonitorTest.java b/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/MetricsRemoteStoreMonitorTest.java
index 00ba4c4c29..952d158a62 100644
--- a/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/MetricsRemoteStoreMonitorTest.java
+++ b/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/MetricsRemoteStoreMonitorTest.java
@@ -36,6 +36,8 @@ import java.util.concurrent.TimeUnit;
public class MetricsRemoteStoreMonitorTest {
private ScheduledExecutorService executor;
+ private DefaultStatisticsProvider statisticsProvider;
+ private MetricsRemoteStoreMonitor remoteStoreMonitor;
private CounterStats requestCount;
private CounterStats requestErrorCount;
@@ -47,8 +49,8 @@ public class MetricsRemoteStoreMonitorTest {
@Before
public void setup(){
executor = Executors.newSingleThreadScheduledExecutor();
- DefaultStatisticsProvider statisticsProvider = new DefaultStatisticsProvider(executor);
- MetricsRemoteStoreMonitor remoteStoreMonitor = new MetricsRemoteStoreMonitor(statisticsProvider);
+ statisticsProvider = new DefaultStatisticsProvider(executor);
+ remoteStoreMonitor = new MetricsRemoteStoreMonitor(statisticsProvider);
requestCount = statisticsProvider.getCounterStats(REQUEST_COUNT, StatsOptions.DEFAULT);
requestErrorCount = statisticsProvider.getCounterStats(REQUEST_ERROR, StatsOptions.DEFAULT);
requestDuration = statisticsProvider.getTimer(REQUEST_DURATION, StatsOptions.METRICS_ONLY);
@@ -74,4 +76,16 @@ public class MetricsRemoteStoreMonitorTest {
assertEquals(requestErrorCountExpected, requestErrorCount.getCount());
assertEquals(1, requestDuration.getCount());
}
+
+ @Test
+ public void testRepositoryLockLost() {
+ CounterStats lockLostCount = statisticsProvider.getCounterStats(REPOSITORY_LOCK_LOST, StatsOptions.DEFAULT);
+ assertEquals(0, lockLostCount.getCount());
+
+ remoteStoreMonitor.repositoryLockLost();
+ assertEquals(1, lockLostCount.getCount());
+
+ remoteStoreMonitor.repositoryLockLost();
+ assertEquals(2, lockLostCount.getCount());
+ }
}