fix for possible deadlock, see

http://forum.yacy-websuche.de/viewtopic.php?p=17017#p17017

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@6252 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 16 years ago
parent 6354b5e447
commit cf739edc2e

@ -116,17 +116,18 @@ public class Balancer {
return new Request(entry); return new Request(entry);
} }
public synchronized int removeAllByProfileHandle(final String profileHandle, final long timeout) throws IOException { public int removeAllByProfileHandle(final String profileHandle, final long timeout) throws IOException {
// removes all entries with a specific profile hash. // removes all entries with a specific profile hash.
// this may last some time // this may last some time
// returns number of deletions // returns number of deletions
// first find a list of url hashes that shall be deleted // first find a list of url hashes that shall be deleted
final Iterator<Row.Entry> i = urlFileIndex.rows();
final HashSet<String> urlHashes = new HashSet<String>(); final HashSet<String> urlHashes = new HashSet<String>();
final long terminate = (timeout > 0) ? System.currentTimeMillis() + timeout : Long.MAX_VALUE;
synchronized (this) {
final Iterator<Row.Entry> i = urlFileIndex.rows();
Row.Entry rowEntry; Row.Entry rowEntry;
Request crawlEntry; Request crawlEntry;
final long terminate = (timeout > 0) ? System.currentTimeMillis() + timeout : Long.MAX_VALUE;
while (i.hasNext() && (System.currentTimeMillis() < terminate)) { while (i.hasNext() && (System.currentTimeMillis() < terminate)) {
rowEntry = i.next(); rowEntry = i.next();
crawlEntry = new Request(rowEntry); crawlEntry = new Request(rowEntry);
@ -134,6 +135,7 @@ public class Balancer {
urlHashes.add(crawlEntry.url().hash()); urlHashes.add(crawlEntry.url().hash());
} }
} }
}
// then delete all these urls from the queues and the file index // then delete all these urls from the queues and the file index
return this.remove(urlHashes); return this.remove(urlHashes);
@ -242,10 +244,8 @@ public class Balancer {
if (domainList == null) { if (domainList == null) {
// create new list // create new list
domainList = new LinkedList<String>(); domainList = new LinkedList<String>();
synchronized (domainStacks) {
domainList.add(hash); domainList.add(hash);
domainStacks.put(dom, domainList); domainStacks.put(dom, domainList);
}
} else { } else {
// extend existent domain list // extend existent domain list
if (domainList.size() < maxstacksize) domainList.addLast(hash); if (domainList.size() < maxstacksize) domainList.addLast(hash);
@ -268,13 +268,11 @@ public class Balancer {
private String nextFromDelayed() { private String nextFromDelayed() {
if (this.delayed.size() == 0) return null; if (this.delayed.size() == 0) return null;
synchronized (this.delayed) {
if (this.delayed.size() == 0) return null; if (this.delayed.size() == 0) return null;
Long first = this.delayed.firstKey(); Long first = this.delayed.firstKey();
if (first.longValue() < System.currentTimeMillis()) { if (first.longValue() < System.currentTimeMillis()) {
return this.delayed.remove(first); return this.delayed.remove(first);
} }
}
return null; return null;
} }

Loading…
Cancel
Save