This is an automated email from the ASF dual-hosted git repository.
reschke pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git
The following commit(s) were added to refs/heads/trunk by this push:
new 2e996d78f0 OAK-10656: MongoDocumentStore: keep metrics about document
size related exceptions (#1313)
2e996d78f0 is described below
commit 2e996d78f0a565b17287af5691f2c1be7d2e925d
Author: Julian Reschke <[email protected]>
AuthorDate: Wed Feb 21 13:25:13 2024 +0100
OAK-10656: MongoDocumentStore: keep metrics about document size related
exceptions (#1313)
* OAK-10656: MongoDocumentStore: keep metrics about document size related
exceptions
* OAK-10656: MongoDocumentStore: keep metrics about document size related
exceptions - fix typo
---
.../oak/plugins/document/mongo/MongoDocumentStore.java | 12 ++++++++++++
.../document/mongo/MongoDocumentStoreMetrics.java | 18 ++++++++++++------
.../document/mongo/MongoDocumentStoreMetricsTest.java | 1 +
3 files changed, 25 insertions(+), 6 deletions(-)
diff --git
a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java
b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java
index 3303f0fb75..5025fe7fe3 100644
---
a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java
+++
b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java
@@ -34,6 +34,7 @@ import java.util.Objects;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.locks.Lock;
import org.apache.jackrabbit.guava.common.base.Optional;
@@ -215,6 +216,8 @@ public class MongoDocumentStore implements DocumentStore {
private final long maxReplicationLagMillis;
+ private final AtomicLong mongoWriteExceptions = new AtomicLong();
+
/**
* Duration in seconds under which queries would use index on _modified
field
* If set to -1 then modifiedTime index would not be used.
@@ -2317,10 +2320,19 @@ public class MongoDocumentStore implements
DocumentStore {
invalidateCache(collection, id);
}
}
+
+ if (ex instanceof MongoWriteException) {
+ mongoWriteExceptions.incrementAndGet();
+ }
+
return asDocumentStoreException(ex.getMessage(), ex,
getDocumentStoreExceptionTypeFor(ex), ids);
}
+ public long getAmountOfMongoWriteExceptions() {
+ return mongoWriteExceptions.get();
+ }
+
private <T extends Document> DocumentStoreException
handleException(Throwable ex,
Collection<T> collection,
String
id) {
diff --git
a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStoreMetrics.java
b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStoreMetrics.java
index 8ebc4287ef..72f46012ee 100644
---
a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStoreMetrics.java
+++
b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStoreMetrics.java
@@ -22,7 +22,6 @@ import java.util.TreeSet;
import org.apache.jackrabbit.guava.common.collect.ImmutableList;
import com.mongodb.BasicDBObject;
import com.mongodb.MongoException;
-import com.mongodb.client.MongoDatabase;
import org.apache.jackrabbit.oak.plugins.document.Collection;
import org.apache.jackrabbit.oak.plugins.document.Document;
@@ -44,13 +43,13 @@ public final class MongoDocumentStoreMetrics implements
Runnable {
Collection.NODES, Collection.JOURNAL, Collection.CLUSTER_NODES,
Collection.SETTINGS, Collection.BLOBS
);
- private final MongoDatabase db;
+ private final MongoDocumentStore store;
private final StatisticsProvider statsProvider;
public MongoDocumentStoreMetrics(MongoDocumentStore store,
StatisticsProvider statsProvider) {
- this.db = store.getDatabase();
+ this.store = store;
this.statsProvider = statsProvider;
}
@@ -67,7 +66,7 @@ public final class MongoDocumentStoreMetrics implements
Runnable {
LOG.debug("Updating counters");
try {
Set<String> collectionNames = new TreeSet<>();
- db.listCollectionNames().into(collectionNames);
+ store.getDatabase().listCollectionNames().into(collectionNames);
for (Collection<? extends Document> c : COLLECTIONS) {
if (!collectionNames.contains(c.toString())) {
LOG.debug("Collection {} does not exist", c);
@@ -82,6 +81,8 @@ public final class MongoDocumentStoreMetrics implements
Runnable {
DatabaseStats dbStats = getDBStats();
updateCounter(getDBCounter("fsUsedSize"), dbStats.fsUsedSize);
updateCounter(getDBCounter("fsTotalSize"), dbStats.fsTotalSize);
+
+ updateCounter(getDocumentStoreCounter("mongoWriteExceptions"),
store.getAmountOfMongoWriteExceptions());
} catch (MongoException e) {
LOG.warn("Updating counters failed: {}", e.toString());
}
@@ -94,7 +95,7 @@ public final class MongoDocumentStoreMetrics implements
Runnable {
private CollectionStats getStats(Collection<? extends Document> c)
throws MongoException {
CollectionStats stats = new CollectionStats();
- BasicDBObject result = new BasicDBObject(db.runCommand(new
org.bson.Document("collStats", c.toString())));
+ BasicDBObject result = new
BasicDBObject(store.getDatabase().runCommand(new org.bson.Document("collStats",
c.toString())));
stats.count = result.getLong("count", 0);
stats.size = result.getLong("size", 0);
stats.storageSize = result.getLong("storageSize", 0);
@@ -104,7 +105,7 @@ public final class MongoDocumentStoreMetrics implements
Runnable {
private DatabaseStats getDBStats() throws MongoException {
DatabaseStats stats = new DatabaseStats();
- BasicDBObject result = new BasicDBObject(db.runCommand(new
org.bson.Document("dbStats", 1)));
+ BasicDBObject result = new
BasicDBObject(store.getDatabase().runCommand(new org.bson.Document("dbStats",
1)));
stats.fsUsedSize = result.getLong("fsUsedSize", 0);
stats.fsTotalSize = result.getLong("fsTotalSize", 0);
return stats;
@@ -121,6 +122,11 @@ public final class MongoDocumentStoreMetrics implements
Runnable {
return statsProvider.getCounterStats(counterName, METRICS_ONLY);
}
+ private CounterStats getDocumentStoreCounter(String name) {
+ String counterName = "MongoDB.DocumentStore." + name;
+ return statsProvider.getCounterStats(counterName, METRICS_ONLY);
+ }
+
private static final class CollectionStats {
long count;
long size;
diff --git
a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStoreMetricsTest.java
b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStoreMetricsTest.java
index 078aa98746..20d0dc9990 100644
---
a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStoreMetricsTest.java
+++
b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStoreMetricsTest.java
@@ -62,6 +62,7 @@ public class MongoDocumentStoreMetricsTest extends
AbstractMongoConnectionTest {
MongoDocumentStoreMetrics metrics = new
MongoDocumentStoreMetrics(store, statsProvider);
assertEquals(0, getCount("MongoDB.fsUsedSize"));
assertEquals(0, getCount("MongoDB.fsTotalSize"));
+ assertEquals(0,
getCount("MongoDB.DocumentStore.mongoWriteExceptions"));
metrics.run();
assertThat(getCount("MongoDB.fsUsedSize"), greaterThan(0L));