From 93c535d1118c4265f7405c2288e6f7e160a3ef13 Mon Sep 17 00:00:00 2001 From: orbiter Date: Wed, 3 Nov 2010 20:58:50 +0000 Subject: [PATCH] fixed http://forum.yacy-websuche.de/viewtopic.php?p=21113#p21113 fixed a concurrent modification exception during search and a time-out problem git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@7298 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- source/de/anomic/crawler/Balancer.java | 2 +- source/de/anomic/search/SearchEvent.java | 3 ++ source/de/anomic/yacy/dht/PeerSelection.java | 3 +- source/net/yacy/kelondro/util/SetTools.java | 29 +++++++++++++------- 4 files changed, 25 insertions(+), 12 deletions(-) diff --git a/source/de/anomic/crawler/Balancer.java b/source/de/anomic/crawler/Balancer.java index 5cdaf56d7..6ff684db6 100644 --- a/source/de/anomic/crawler/Balancer.java +++ b/source/de/anomic/crawler/Balancer.java @@ -361,7 +361,7 @@ public class Balancer { //final int s = urlFileIndex.size(); Row.Entry rowEntry = (nexthash == null) ? null : urlFileIndex.remove(nexthash); if (rowEntry == null) { - System.out.println("*** rowEntry=null, nexthash=" + new String(nexthash)); + //System.out.println("*** rowEntry=null, nexthash=" + new String(nexthash)); rowEntry = urlFileIndex.removeOne(); if (rowEntry == null) { nexthash = null; diff --git a/source/de/anomic/search/SearchEvent.java b/source/de/anomic/search/SearchEvent.java index d87ab65e6..7f629ff86 100644 --- a/source/de/anomic/search/SearchEvent.java +++ b/source/de/anomic/search/SearchEvent.java @@ -467,9 +467,12 @@ public final class SearchEvent { public void run() { try { + int t = 0; while (this.trigger.tryAcquire(10000, TimeUnit.MILLISECONDS)) { // a trigger was released prepareSecondarySearch(); + t++; + if (t > 10) break; } } catch (InterruptedException e) { // the thread was interrupted diff --git a/source/de/anomic/yacy/dht/PeerSelection.java b/source/de/anomic/yacy/dht/PeerSelection.java index e2a3d4381..a901da4ec 100755 --- a/source/de/anomic/yacy/dht/PeerSelection.java +++ b/source/de/anomic/yacy/dht/PeerSelection.java @@ -350,7 +350,8 @@ public class PeerSelection { while ((s.hasNext()) && (searchcount-- > 0)) { ys = s.next(); if ((ys != null) && (ys.get(yacySeed.LASTSEEN, "").length() > 10)) try { - absage = Math.abs(System.currentTimeMillis() + DateFormatter.dayMillis - ys.getLastSeenUTC()); + absage = Math.abs(System.currentTimeMillis() + DateFormatter.dayMillis - ys.getLastSeenUTC()) / 1000 / 60; + if (absage > Integer.MAX_VALUE) absage = Integer.MAX_VALUE; seedScore.inc(ys.hash, (int) absage); // the higher absage, the older is the peer } catch (final Exception e) {} } diff --git a/source/net/yacy/kelondro/util/SetTools.java b/source/net/yacy/kelondro/util/SetTools.java index 30ef3987b..7c5806e83 100644 --- a/source/net/yacy/kelondro/util/SetTools.java +++ b/source/net/yacy/kelondro/util/SetTools.java @@ -33,6 +33,7 @@ import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Collection; import java.util.Comparator; +import java.util.ConcurrentModificationException; import java.util.Iterator; import java.util.Map; import java.util.Set; @@ -40,6 +41,7 @@ import java.util.TreeMap; import java.util.TreeSet; import net.yacy.kelondro.index.HandleSet; +import net.yacy.kelondro.logging.Log; public class SetTools { @@ -133,16 +135,23 @@ public class SetTools { private final static TreeMap joinConstructiveByTest(final TreeMap small, final TreeMap large, final boolean concatStrings) { final Iterator> mi = small.entrySet().iterator(); final TreeMap result = new TreeMap(large.comparator()); - Map.Entry mentry1; - B mobj2; - while (mi.hasNext()) { - mentry1 = mi.next(); - mobj2 = large.get(mentry1.getKey()); - if (mobj2 != null) { - if (mentry1.getValue() instanceof String) { - result.put(mentry1.getKey(), (B) ((concatStrings) ? (mentry1.getValue() + (String) mobj2) : mentry1.getValue())); - } else { - result.put(mentry1.getKey(), mentry1.getValue()); + synchronized (mi) { + Map.Entry mentry1; + B mobj2; + loop: while (mi.hasNext()) { + try { + mentry1 = mi.next(); + mobj2 = large.get(mentry1.getKey()); + if (mobj2 != null) { + if (mentry1.getValue() instanceof String) { + result.put(mentry1.getKey(), (B) ((concatStrings) ? (mentry1.getValue() + (String) mobj2) : mentry1.getValue())); + } else { + result.put(mentry1.getKey(), mentry1.getValue()); + } + } + } catch (ConcurrentModificationException e) { + Log.logWarning("SetTools", e.getMessage(), e); + break loop; } } }