fixed bug caused strange search result behaviour

(results from remote peers had not been saved propery after search)

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@1213 6c8d7289-2bf4-0310-a012-ef5d649a1542
This commit is contained in:
orbiter 2005-12-15 13:21:42 +00:00
parent 4500506735
commit b5d02d649a

View File

@ -44,6 +44,7 @@ package de.anomic.plasma;
import java.util.Iterator; import java.util.Iterator;
import java.util.Set; import java.util.Set;
import java.util.HashSet;
import java.io.IOException; import java.io.IOException;
import de.anomic.kelondro.kelondroException; import de.anomic.kelondro.kelondroException;
@ -51,9 +52,11 @@ import de.anomic.server.logging.serverLog;
import de.anomic.server.serverInstantThread; import de.anomic.server.serverInstantThread;
import de.anomic.yacy.yacySearch; import de.anomic.yacy.yacySearch;
public final class plasmaSearchEvent { public final class plasmaSearchEvent extends Thread implements Runnable {
public static plasmaSearchEvent lastEvent = null; public static plasmaSearchEvent lastEvent = null;
private static HashSet flushThreads = new HashSet();
private serverLog log; private serverLog log;
private plasmaSearchQuery query; private plasmaSearchQuery query;
@ -118,7 +121,8 @@ public final class plasmaSearchEvent {
result.localContributions = rcLocal.size(); result.localContributions = rcLocal.size();
// flush results in a separate thread // flush results in a separate thread
serverInstantThread.oneTimeJob(this, "flushResults", log, 0); this.start(); // start to flush results
//serverInstantThread.oneTimeJob(this, "flushResults", log, 0);
// clean up // clean up
if ((rcLocal != null) && (!(rcLocal.isTMPEntity()))) rcLocal.close(); if ((rcLocal != null) && (!(rcLocal.isTMPEntity()))) rcLocal.close();
@ -261,10 +265,16 @@ public final class plasmaSearchEvent {
return acc; return acc;
} }
public void run() {
flushThreads.add(this); // this will care that the search event object is referenced from somewhere while it is still alive
flushResults();
flushThreads.remove(this);
}
public void flushResults() { public void flushResults() {
// put all new results into wordIndex // put all new results into wordIndex
// this must be called after search results had been computed // this must be called after search results had been computed
// it is wise to call this within a separate thread because this method waits untill all // it is wise to call this within a separate thread because this method waits untill all
if (searchThreads == null) return; if (searchThreads == null) return;
// wait until all threads are finished // wait until all threads are finished
@ -274,16 +284,19 @@ public final class plasmaSearchEvent {
long starttime = System.currentTimeMillis(); long starttime = System.currentTimeMillis();
while ((remaining = yacySearch.remainingWaiting(searchThreads)) > 0) { while ((remaining = yacySearch.remainingWaiting(searchThreads)) > 0) {
// flush the rcGlobal as much as is there so far // flush the rcGlobal as much as is there so far
synchronized (rcGlobal) { if (rcGlobal.size() > 0) synchronized (rcGlobal) {
Iterator hashi = query.queryHashes.iterator(); Iterator hashi = query.queryHashes.iterator();
while (hashi.hasNext()) { while (hashi.hasNext()) {
wordHash = (String) hashi.next(); wordHash = (String) hashi.next();
Iterator i = rcGlobal.elements(true); Iterator i = rcGlobal.elements(true);
plasmaWordIndexEntry entry; plasmaWordIndexEntry entry;
plasmaWordIndexEntryContainer container = new plasmaWordIndexEntryContainer(wordHash, rcGlobal.size());
while (i.hasNext()) { while (i.hasNext()) {
entry = (plasmaWordIndexEntry) i.next(); entry = (plasmaWordIndexEntry) i.next();
wordIndex.addEntries(plasmaWordIndexEntryContainer.instantContainer(wordHash, System.currentTimeMillis(), entry), false); container.add(entry, System.currentTimeMillis());
} }
wordIndex.addEntries(container, true);
log.logFine("FLUSHED " + wordHash + ": " + container.size() + " url entries");
} }
// the rcGlobal was flushed, empty it // the rcGlobal was flushed, empty it
count += rcGlobal.size(); count += rcGlobal.size();
@ -293,9 +306,10 @@ public final class plasmaSearchEvent {
try {Thread.sleep(3000);} catch (InterruptedException e) {} try {Thread.sleep(3000);} catch (InterruptedException e) {}
if (System.currentTimeMillis() - starttime > 90000) { if (System.currentTimeMillis() - starttime > 90000) {
yacySearch.interruptAlive(searchThreads); yacySearch.interruptAlive(searchThreads);
serverLog.logFine("PLASMA", "SEARCH FLUSH: " + remaining + " PEERS STILL BUSY; ABANDONED; SEARCH WAS " + query.queryWords); log.logFine("SEARCH FLUSH: " + remaining + " PEERS STILL BUSY; ABANDONED; SEARCH WAS " + query.queryWords);
break; break;
} }
log.logFine("FINISHED FLUSH RESULTS PROCESS for query " + query.hashes(","));
} }
serverLog.logFine("PLASMA", "FINISHED FLUSHING " + count + " GLOBAL SEARCH RESULTS FOR SEARCH " + query.queryWords); serverLog.logFine("PLASMA", "FINISHED FLUSHING " + count + " GLOBAL SEARCH RESULTS FOR SEARCH " + query.queryWords);