Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

- possibly better termination for SplitTable - better abstraction in DidYouMean

orbiterf8371707e5b4
diff --git a/source/de/anomic/data/DidYouMean.java b/source/de/anomic/data/DidYouMean.java
index ab4159d27..21ef2a4f2 100644
--- a/source/de/anomic/data/DidYouMean.java
+++ b/source/de/anomic/data/DidYouMean.java
@@ -97,7 +97,7 @@ public class DidYouMean {
* @return
*/
public SortedSet<String> getSuggestions(final String word, long timeout, int preSortSelection) {
- if (word.indexOf(' ') > 0) return getSuggestions(word.split(" "), timeout, preSortSelection);
+ if (word.indexOf(' ') > 0) return getSuggestions(word.split(" "), timeout, preSortSelection, this.index);
long startTime = System.currentTimeMillis();
SortedSet<String> preSorted = getSuggestions(word, timeout);
long timelimit = 2 * System.currentTimeMillis() - startTime + timeout;
@@ -123,11 +123,10 @@ public class DidYouMean {
* @return
*/
@SuppressWarnings("unchecked")
- public SortedSet<String> getSuggestions(final String[] words, long timeout, int preSortSelection) {
+ public static SortedSet<String> getSuggestions(final String[] words, long timeout, int preSortSelection, final IndexCell<WordReference> index) {
SortedSet<String>[] s = new SortedSet[words.length];
for (int i = 0; i < words.length; i++) {
- s[i] = getSuggestions(words[i], timeout / words.length, preSortSelection);
- this.reset();
+ s[i] = new DidYouMean(index).getSuggestions(words[i], timeout / words.length, preSortSelection);
}
// make all permutations
SortedSet<String> result = new TreeSet<String>();
diff --git a/source/de/anomic/kelondro/table/SplitTable.java b/source/de/anomic/kelondro/table/SplitTable.java
index f34054cae..ac5509591 100644
--- a/source/de/anomic/kelondro/table/SplitTable.java
+++ b/source/de/anomic/kelondro/table/SplitTable.java
@@ -83,7 +83,7 @@ public class SplitTable implements ObjectIndex {
private boolean useTailCache;
private boolean exceed134217727;
private BlockingQueue<DiscoverOrder> orderQueue;
- private int discoverThreads;
+ private Discovery[] discoveryThreads;
public SplitTable(
final File path,
@@ -111,9 +111,10 @@ public class SplitTable implements ObjectIndex {
this.exceed134217727 = exceed134217727;
this.entryOrder = new Row.EntryComparator(rowdef.objectOrder);
this.orderQueue = new LinkedBlockingQueue<DiscoverOrder>();
- this.discoverThreads = Runtime.getRuntime().availableProcessors() + 1;
- for (int i = 0; i < this.discoverThreads; i++) {
- new Discovery(this.orderQueue).start();
+ this.discoveryThreads = new Discovery[Runtime.getRuntime().availableProcessors() + 1];
+ for (int i = 0; i < this.discoveryThreads.length; i++) {
+ this.discoveryThreads[i] = new Discovery(this.orderQueue);
+ this.discoveryThreads[i].start();
}
init();
}
@@ -417,10 +418,26 @@ public class SplitTable implements ObjectIndex {
// check if in the given objectIndex is the key as given in the order
order.executeOrder();
}
+ Log.logInfo("SplitTable.Discovery", "terminated discovery thread " + this.getName());
}
}
+
+ private boolean discoveriesAlive() {
+ for (int i = 0; i < this.discoveryThreads.length; i++) {
+ if (!this.discoveryThreads[i].isAlive()) return false;
+ }
+ return true;
+ }
private ObjectIndex keeperOf(final byte[] key) {
+ if (!discoveriesAlive()) {
+ synchronized (tables) {
+ for (ObjectIndex oi: tables.values()) {
+ if (oi.has(key)) return oi;
+ }
+ return null;
+ }
+ }
Challenge challenge = null;
synchronized (tables) {
int tableCount = this.tables.size();
@@ -587,7 +604,7 @@ public class SplitTable implements ObjectIndex {
public synchronized void close() {
// stop discover threads
- if (this.orderQueue != null) for (int i = 0; i < this.discoverThreads; i++) {
+ if (this.orderQueue != null) for (int i = 0; i < this.discoveryThreads.length; i++) {
try {
this.orderQueue.put(poisonDiscoverOrder);
} catch (InterruptedException e) {