From 8e1248ffe30a21dfb967c970209cfec8390a6ac4 Mon Sep 17 00:00:00 2001 From: Michael Peter Christen Date: Fri, 26 Oct 2012 15:35:42 +0200 Subject: [PATCH] force a commit in advance of a search for the administrator to get most recent results even if commit time is high and an indexing is ongoing. --- htroot/index.java | 4 ++++ htroot/yacysearch.java | 3 ++- .../cora/federate/solr/connector/MirrorSolrConnector.java | 1 - source/net/yacy/search/index/Fulltext.java | 7 +++++++ 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/htroot/index.java b/htroot/index.java index e75e16711..79ad68e05 100644 --- a/htroot/index.java +++ b/htroot/index.java @@ -62,6 +62,10 @@ public class index { } } + if (authorizedAccess) { + sb.index.fulltext().commit(); // call this only as superuser to prevent that this can be misused for DoS + } + boolean global = (post == null) ? true : post.get("resource", "global").equals("global"); final boolean focus = (post == null) ? true : post.get("focus", "1").equals("1"); diff --git a/htroot/yacysearch.java b/htroot/yacysearch.java index 1900cb866..13ee14b9d 100644 --- a/htroot/yacysearch.java +++ b/htroot/yacysearch.java @@ -111,7 +111,8 @@ public class yacysearch { "network.unit.description", "") : env.getConfig(SwitchboardConstants.GREETING, ""); final String client = header.get(HeaderFramework.CONNECTION_PROP_CLIENTIP); // the search client who initiated the search - + if (authenticated) sb.index.fulltext().commit(); + // get query final String originalquerystring = (post == null) ? "" : post.get("query", post.get("search", "")).trim(); diff --git a/source/net/yacy/cora/federate/solr/connector/MirrorSolrConnector.java b/source/net/yacy/cora/federate/solr/connector/MirrorSolrConnector.java index e11c665bd..cece1360e 100644 --- a/source/net/yacy/cora/federate/solr/connector/MirrorSolrConnector.java +++ b/source/net/yacy/cora/federate/solr/connector/MirrorSolrConnector.java @@ -33,7 +33,6 @@ import net.yacy.cora.storage.ARC; import net.yacy.cora.storage.ConcurrentARC; import net.yacy.kelondro.util.MemoryControl; -import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.client.solrj.response.QueryResponse; import org.apache.solr.client.solrj.util.ClientUtils; import org.apache.solr.common.SolrDocument; diff --git a/source/net/yacy/search/index/Fulltext.java b/source/net/yacy/search/index/Fulltext.java index d76693789..87f8d8c1e 100644 --- a/source/net/yacy/search/index/Fulltext.java +++ b/source/net/yacy/search/index/Fulltext.java @@ -69,6 +69,8 @@ import org.apache.solr.common.SolrInputDocument; public final class Fulltext implements Iterable { + private static final long forcedCommitTimeout = 3000; // wait this time until a next forced commit is executed + // class objects private final File location; private Index urlIndexFile; @@ -77,6 +79,7 @@ public final class Fulltext implements Iterable { private ArrayList statsDump; private final MirrorSolrConnector solr; private final SolrConfiguration solrScheme; + private long forcedCommitTime; protected Fulltext(final File path, final SolrConfiguration solrScheme) { this.location = path; @@ -86,6 +89,7 @@ public final class Fulltext implements Iterable { this.statsDump = null; this.solr = new MirrorSolrConnector(1000, 1000, 100); this.solrScheme = solrScheme; + this.forcedCommitTime = 0; } protected void connectUrlDb(final String tablename, final boolean useTailCache, final boolean exceed134217727) { @@ -191,7 +195,10 @@ public final class Fulltext implements Iterable { } public void commit() { + if (this.forcedCommitTime + forcedCommitTimeout < System.currentTimeMillis()) return; + this.forcedCommitTime = Long.MAX_VALUE - forcedCommitTimeout; // set the time high to prevent that other processes get to this point meanwhile this.solr.commit(); + this.forcedCommitTime = System.currentTimeMillis(); // set the exact time } /**