From 2c228ce37ab6684fae89adc3bd3c557e80876497 Mon Sep 17 00:00:00 2001 From: qaate47 Date: Wed, 4 Dec 2024 18:12:52 +0100 Subject: [PATCH] add time when reindexing lucenes --- .../qendpoint/core/util/StopWatch.java | 4 ++ .../qendpoint/compiler/CompiledSail.java | 50 +++++++++---------- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/qendpoint-core/src/main/java/com/the_qa_company/qendpoint/core/util/StopWatch.java b/qendpoint-core/src/main/java/com/the_qa_company/qendpoint/core/util/StopWatch.java index 46fc58a77..41d0843e1 100644 --- a/qendpoint-core/src/main/java/com/the_qa_company/qendpoint/core/util/StopWatch.java +++ b/qendpoint-core/src/main/java/com/the_qa_company/qendpoint/core/util/StopWatch.java @@ -35,6 +35,10 @@ public long getMeasure() { return end - ini; } + public long getMeasureMillis() { + return (end - ini) / 1_000_000; + } + public long stopAndGet() { stop(); return getMeasure(); diff --git a/qendpoint-store/src/main/java/com/the_qa_company/qendpoint/compiler/CompiledSail.java b/qendpoint-store/src/main/java/com/the_qa_company/qendpoint/compiler/CompiledSail.java index 215ea43e7..96d889e90 100644 --- a/qendpoint-store/src/main/java/com/the_qa_company/qendpoint/compiler/CompiledSail.java +++ b/qendpoint-store/src/main/java/com/the_qa_company/qendpoint/compiler/CompiledSail.java @@ -6,6 +6,7 @@ import com.the_qa_company.qendpoint.core.hdt.HDTManager; import com.the_qa_company.qendpoint.core.options.HDTOptions; import com.the_qa_company.qendpoint.core.triples.TripleString; +import com.the_qa_company.qendpoint.core.util.StopWatch; import com.the_qa_company.qendpoint.store.EndpointFiles; import com.the_qa_company.qendpoint.store.EndpointStore; import com.the_qa_company.qendpoint.store.exception.EndpointStoreException; @@ -216,6 +217,26 @@ public NotifyingSail getSource() { return source; } + private void reindexSail(LuceneSail sail) { + // bypass filtering system to use the source + NotifyingSail oldSail = sail.getBaseSail(); + try { + sail.setBaseSail(source); + String indexId = sail.getParameter(LuceneSail.INDEX_ID); + if (indexId == null || indexId.isEmpty()) { + indexId = ""; + } + StopWatch sw = new StopWatch(); + sw.reset(); + logger.info("Reindexing sail {}", indexId); + sail.reindex(); + sw.stop(); + logger.info("Sail {} reindexed in {} ({}ms)", indexId, sw, sw.getMeasureMillis()); + } finally { + sail.setBaseSail(oldSail); + } + } + /** * reindex all the compiled lucene sails * @@ -225,19 +246,7 @@ public NotifyingSail getSource() { public void reindexLuceneSails() throws SailException { for (LuceneSail sail : luceneSails) { // bypass filtering system to use the source - NotifyingSail oldSail = sail.getBaseSail(); - try { - sail.setBaseSail(source); - String indexId = sail.getParameter(LuceneSail.INDEX_ID); - if (indexId == null || indexId.isEmpty()) { - indexId = "no id"; - } - logger.info("Reindexing sail: {}", indexId); - sail.reindex(); - } finally { - sail.setBaseSail(oldSail); - } - + reindexSail(sail); } } @@ -254,20 +263,7 @@ public void reindexLuceneSail(String index) throws SailException { if (!index.equals(sail.getParameter(LuceneSail.INDEX_ID))) { continue; // ignore } - // bypass filtering system to use the source - NotifyingSail oldSail = sail.getBaseSail(); - try { - sail.setBaseSail(source); - String indexId = sail.getParameter(LuceneSail.INDEX_ID); - if (indexId == null || indexId.isEmpty()) { - indexId = "no id"; - } - logger.info("Reindexing sail: {}", indexId); - sail.reindex(); - } finally { - sail.setBaseSail(oldSail); - } - + reindexSail(sail); } }