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 nf...@apache.org on 2024/07/22 08:41:53 UTC
(jackrabbit-oak) branch trunk updated: OAK-10965 - Make ConsoleIndexingReporter thread safe. (#1592)
This is an automated email from the ASF dual-hosted git repository.
nfsantos 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 56f151a06b OAK-10965 - Make ConsoleIndexingReporter thread safe. (#1592)
56f151a06b is described below
commit 56f151a06ba6041b34545e8e7d22e369fc1379ca
Author: Nuno Santos <ns...@adobe.com>
AuthorDate: Mon Jul 22 10:41:49 2024 +0200
OAK-10965 - Make ConsoleIndexingReporter thread safe. (#1592)
---
.../oak/plugins/index/ConsoleIndexingReporter.java | 25 +++++++++++-----------
1 file changed, 13 insertions(+), 12 deletions(-)
diff --git a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/ConsoleIndexingReporter.java b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/ConsoleIndexingReporter.java
index aa20405210..18168bfb3f 100644
--- a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/ConsoleIndexingReporter.java
+++ b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/ConsoleIndexingReporter.java
@@ -26,20 +26,19 @@ import org.jetbrains.annotations.NotNull;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
-import java.util.TreeMap;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class ConsoleIndexingReporter implements IndexingReporter {
- // Print configuration in alphabetical order
- private final Map<String, String> config = new TreeMap<>();
// Print timings in the order they were added
private final Map<String, String> timings = new LinkedHashMap<>();
- // Print configuration in alphabetical order
- private final Map<String, String> metrics = new TreeMap<>();
+ // Print metrics and configuration in alphabetical order. They are sorted when printed.
+ private final Map<String, String> metrics = new HashMap<>();
+ private final Map<String, String> config = new HashMap<>();
private final List<String> envVariablesToLog;
private List<String> indexes = List.of();
private final List<String> informationStrings = new ArrayList<>();
@@ -55,24 +54,24 @@ public class ConsoleIndexingReporter implements IndexingReporter {
this.envVariablesToLog = List.copyOf(envVariablesToLog);
}
- public void setIndexNames(@NotNull List<String> indexes) {
+ public synchronized void setIndexNames(@NotNull List<String> indexes) {
this.indexes = List.copyOf(indexes);
}
- public void addConfig(String key, Object value) {
+ public synchronized void addConfig(String key, Object value) {
config.put(key, value.toString());
}
- public void addTiming(String stage, String time) {
+ public synchronized void addTiming(String stage, String time) {
timings.put(stage, time);
}
- public void addMetric(String name, long value) {
+ public synchronized void addMetric(String name, long value) {
metrics.put(name, String.valueOf(value));
}
@Override
- public void addInformation(String value) {
+ public synchronized void addInformation(String value) {
informationStrings.add(value);
}
@@ -81,10 +80,12 @@ public class ConsoleIndexingReporter implements IndexingReporter {
if (value >= FileUtils.ONE_KB) {
v += " (" + IOUtils.humanReadableByteCountBin(value) + ")";
}
- metrics.put(name, v);
+ synchronized (this) {
+ metrics.put(name, v);
+ }
}
- public String generateReport() {
+ public synchronized String generateReport() {
return "Indexes: " + String.join(", ", indexes) + "\n" +
"Date: " + DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(ZonedDateTime.now()) + "\n" +
"OAK Version: " + OakVersion.getVersion() + "\n" +