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
pull/1/head
orbiter 18 years ago
parent f15fa7c5b1
commit 063063aa0c

@ -47,6 +47,9 @@ public class kelondroRotateIterator implements kelondroCloneableIterator {
} }
public Object next() { 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())) { if (!(a.hasNext())) {
a = (kelondroCloneableIterator) clone.clone(modifier); a = (kelondroCloneableIterator) clone.clone(modifier);
} }

@ -496,14 +496,18 @@ public final class plasmaWordIndex implements indexRI {
Iterator i = wordContainers(startHash, ram, rot); Iterator i = wordContainers(startHash, ram, rot);
if (ram) count = Math.min(dhtOutCache.size(), count); if (ram) count = Math.min(dhtOutCache.size(), count);
indexContainer container; 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())) { while ((count > 0) && (i.hasNext())) {
container = (indexContainer) i.next(); container = (indexContainer) i.next();
if ((container != null) && (container.size() > 0)) { if ((container != null) && (container.size() > 0)) {
containers.add(container); 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) { public kelondroCloneableIterator wordContainers(String startHash, boolean ram, boolean rot) {

Loading…
Cancel
Save