fixed a deadlock during secondary remote search

pull/1/head
Michael Christen 13 years ago
parent c715d19c09
commit 86b3385847

@ -26,8 +26,10 @@
package net.yacy.kelondro.data.word;
import java.util.Collections;
import java.util.Iterator;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;
import net.yacy.cora.document.ASCII;
@ -39,15 +41,18 @@ import net.yacy.kelondro.util.ByteBuffer;
public class WordReferenceFactory implements ReferenceFactory<WordReference> {
@Override
public WordReference produceSlow(final Entry e) {
return new WordReferenceRow(e);
}
@Override
public WordReference produceFast(final WordReference r) {
if (r instanceof WordReferenceVars) return r;
return new WordReferenceVars(r);
}
@Override
public Row getRow() {
return WordReferenceRow.urlEntryRow;
}
@ -110,8 +115,8 @@ public class WordReferenceFactory implements ReferenceFactory<WordReference> {
* @param peerhash
* @return
*/
public static final TreeMap<String, StringBuilder> decompressIndex(ByteBuffer ci, final String peerhash) {
TreeMap<String, StringBuilder> target = new TreeMap<String, StringBuilder>();
public static final SortedMap<String, StringBuilder> decompressIndex(ByteBuffer ci, final String peerhash) {
SortedMap<String, StringBuilder> target = Collections.synchronizedSortedMap(new TreeMap<String, StringBuilder>());
// target is a mapping from url-hashes to a string of peer-hashes
if (ci.byteAt(0) != '{' || ci.byteAt(ci.length() - 1) != '}') return target;
//System.out.println("DEBUG-DECOMPRESS: input is " + ci.toString());

@ -26,6 +26,7 @@
package net.yacy.search.query;
import java.util.Collections;
import java.util.Iterator;
import java.util.Map;
import java.util.SortedMap;
@ -516,8 +517,8 @@ public final class SearchEvent
private final Semaphore trigger;
public SecondarySearchSuperviser() {
this.abstractsCache = new TreeMap<String, SortedMap<String, StringBuilder>>();
this.checkedPeers = new TreeSet<String>();
this.abstractsCache = Collections.synchronizedSortedMap(new TreeMap<String, SortedMap<String, StringBuilder>>());
this.checkedPeers = Collections.synchronizedSortedSet(new TreeSet<String>());
this.trigger = new Semaphore(0);
}
@ -527,16 +528,14 @@ public final class SearchEvent
* @param wordhash
* @param singleAbstract // a mapping from url-hashes to a string of peer-hashes
*/
public void addAbstract(final String wordhash, final TreeMap<String, StringBuilder> singleAbstract) {
public void addAbstract(final String wordhash, final SortedMap<String, StringBuilder> singleAbstract) {
final SortedMap<String, StringBuilder> oldAbstract;
synchronized ( this.abstractsCache ) {
oldAbstract = this.abstractsCache.get(wordhash);
if ( oldAbstract == null ) {
// new abstracts in the cache
this.abstractsCache.put(wordhash, singleAbstract);
return;
}
}
// extend the abstracts in the cache: join the single abstracts
new Thread() {
@Override
@ -544,14 +543,12 @@ public final class SearchEvent
for ( final Map.Entry<String, StringBuilder> oneref : singleAbstract.entrySet() ) {
final String urlhash = oneref.getKey();
final StringBuilder peerlistNew = oneref.getValue();
synchronized ( oldAbstract ) {
final StringBuilder peerlistOld = oldAbstract.put(urlhash, peerlistNew);
if ( peerlistOld != null ) {
peerlistOld.append(peerlistNew);
}
}
}
}
}.start();
// abstractsCache.put(wordhash, oldAbstract); // put not necessary since it is sufficient to just change the value content (it stays assigned)
}
@ -567,7 +564,6 @@ public final class SearchEvent
SortedMap<String, StringBuilder> urlPeerlist;
int p;
boolean hasURL;
synchronized ( this ) {
final Iterator<Map.Entry<String, SortedMap<String, StringBuilder>>> i =
this.abstractsCache.entrySet().iterator();
while ( i.hasNext() ) {
@ -588,7 +584,6 @@ public final class SearchEvent
wordlist += word;
}
}
}
return wordlist;
}

Loading…
Cancel
Save