From 063063aa0ca0dfaf4d6c2299a7d0a692ba62b0ee Mon Sep 17 00:00:00 2001 From: orbiter Date: Fri, 13 Apr 2007 13:40:19 +0000 Subject: [PATCH] fix for 100% cpu bug during dht selection see also: http://www.yacy-forum.de/viewtopic.php?p=34068#34068 git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@3570 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- source/de/anomic/kelondro/kelondroRotateIterator.java | 3 +++ source/de/anomic/plasma/plasmaWordIndex.java | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/source/de/anomic/kelondro/kelondroRotateIterator.java b/source/de/anomic/kelondro/kelondroRotateIterator.java index eb31f5d46..7e55d50d3 100644 --- a/source/de/anomic/kelondro/kelondroRotateIterator.java +++ b/source/de/anomic/kelondro/kelondroRotateIterator.java @@ -47,6 +47,9 @@ public class kelondroRotateIterator implements kelondroCloneableIterator { } public Object next() { + // attention: this iterator has no termination - on purpose. + // it must be taken care that a calling method has a termination predicate different + // from the hasNext() method if (!(a.hasNext())) { a = (kelondroCloneableIterator) clone.clone(modifier); } diff --git a/source/de/anomic/plasma/plasmaWordIndex.java b/source/de/anomic/plasma/plasmaWordIndex.java index 9a088eb0e..c3d93de8d 100644 --- a/source/de/anomic/plasma/plasmaWordIndex.java +++ b/source/de/anomic/plasma/plasmaWordIndex.java @@ -496,14 +496,18 @@ public final class plasmaWordIndex implements indexRI { Iterator i = wordContainers(startHash, ram, rot); if (ram) count = Math.min(dhtOutCache.size(), count); indexContainer container; + // this loop does not terminate using the i.hasNex() predicate when rot == true + // because then the underlying iterator is a rotating iterator without termination + // in this case a termination must be ensured with a counter + // It must also be ensured that the counter is in/decreased every loop while ((count > 0) && (i.hasNext())) { container = (indexContainer) i.next(); if ((container != null) && (container.size() > 0)) { containers.add(container); - count--; } + count--; // decrease counter even if the container was null or empty to ensure termination } - return containers; + return containers; // this may return less containers as demanded } public kelondroCloneableIterator wordContainers(String startHash, boolean ram, boolean rot) {