Fixes and avoid of catching bad exceptions (some):

- Rewrote usage of HashMap/Map to concurrent versions (to avoid a
CME=ConcurrentModificationException)
- Rewrote ConnectionInfo (as an example) to use a synchronized iterator
instead of synchronizing an
  already synced HashSet (see Collections call)
- This avoids catching CMEs again
- Commented out noisy ConcurrentLog.logException() call

Conflicts:
	source/net/yacy/repository/LoaderDispatcher.java
pull/1/head
Roland Haeder 11 years ago committed by orbiter
parent 841a28ae76
commit aaedc0405d

@ -29,6 +29,7 @@ import java.util.Set;
import net.yacy.cora.protocol.ConnectionInfo;
import net.yacy.cora.protocol.RequestHeader;
import net.yacy.cora.util.ConcurrentLog;
import net.yacy.search.Switchboard;
import net.yacy.server.serverObjects;
import net.yacy.server.serverSwitch;
@ -126,7 +127,10 @@ public class AccessPicture_p {
time[h] = time2;
}
}
} catch (final ConcurrentModificationException e) {} // we don't want to synchronize this
} catch (final ConcurrentModificationException e) {
// we don't want to synchronize this
ConcurrentLog.logException(e);
}
}
// draw left column: access from outside

@ -37,6 +37,7 @@ import net.yacy.cora.date.GenericFormatter;
import net.yacy.cora.protocol.Domains;
import net.yacy.cora.protocol.HeaderFramework;
import net.yacy.cora.protocol.RequestHeader;
import net.yacy.cora.util.ConcurrentLog;
import net.yacy.peers.Seed;
import net.yacy.search.Switchboard;
import net.yacy.search.query.AccessTracker;
@ -84,7 +85,10 @@ public class AccessTracker_p {
prop.putNum("page_list_" + entCount + "_countHour", sb.latestAccessCount(host, 1000 * 60 * 60));
entCount++;
}
} catch (final ConcurrentModificationException e) {} // we don't want to synchronize this
} catch (final ConcurrentModificationException e) {
// we don't want to synchronize this
ConcurrentLog.logException(e);
}
prop.put("page_list", entCount);
prop.put("page_num", entCount);
@ -95,7 +99,10 @@ public class AccessTracker_p {
prop.putNum("page_bflist_" + entCount + "_countSecond", bfe.getValue());
entCount++;
}
} catch (final ConcurrentModificationException e) {} // we dont want to synchronize this
} catch (final ConcurrentModificationException e) {
// we don't want to synchronize this
ConcurrentLog.logException(e);
}
prop.put("page_bflist", entCount);
} else if (page == 1) {
String host = (post == null) ? "" : post.get("host", "");
@ -114,7 +121,10 @@ public class AccessTracker_p {
prop.putHTML("page_list_" + entCount + "_path", entry.getPath());
entCount++;
}
} catch (final ConcurrentModificationException e) {} // we don't want to synchronize this
} catch (final ConcurrentModificationException e) {
// we don't want to synchronize this
ConcurrentLog.logException(e);
}
}
} else {
try {
@ -131,7 +141,10 @@ public class AccessTracker_p {
entCount++;
}
}
} catch (final ConcurrentModificationException e) {} // we dont want to synchronize this
} catch (final ConcurrentModificationException e) {
// we don't want to synchronize this
ConcurrentLog.logException(e);
}
}
prop.put("page_list", entCount);
prop.put("page_num", entCount);
@ -154,6 +167,8 @@ public class AccessTracker_p {
try {
query = ai.next();
} catch (final ConcurrentModificationException e) {
// we don't want to synchronize this
ConcurrentLog.logException(e);
break;
}
// put values in template
@ -272,7 +287,10 @@ public class AccessTracker_p {
// next
m++;
}
} catch (final ConcurrentModificationException e) {} // we dont want to synchronize this
} catch (final ConcurrentModificationException e) {
// we don't want to synchronize this
ConcurrentLog.logException(e);
}
// return empty values to not break the table view if no results can be listed
if (m==0) {
prop.put("page_list", 1);

@ -269,7 +269,9 @@ public class CrawlStartScanner_p
ConcurrentLog.logException(e);
}
}
} catch (final ConcurrentModificationException e ) {
} catch (final ConcurrentModificationException e) {
// we don't want to synchronize this
ConcurrentLog.logException(e);
}
}

@ -32,6 +32,7 @@ import java.util.Map;
import net.yacy.cora.protocol.Domains;
import net.yacy.cora.protocol.RequestHeader;
import net.yacy.cora.util.ConcurrentLog;
import net.yacy.kelondro.index.Cache;
import net.yacy.kelondro.index.RAMIndex;
import net.yacy.kelondro.table.Table;
@ -138,6 +139,8 @@ public class PerformanceMemory_p {
try {
oie = oi.next();
} catch (final ConcurrentModificationException e) {
// we don't want to synchronize this
ConcurrentLog.logException(e);
break;
}
filename = oie.getKey();

@ -86,6 +86,7 @@ public class ServerScannerList {
prop.put("servertable_edit_num", i);
break table;
} catch (final ConcurrentModificationException e) {
ConcurrentLog.logException(e);
continue table;
}
}

@ -28,6 +28,7 @@ import java.util.SortedSet;
import net.yacy.cora.protocol.HeaderFramework;
import net.yacy.cora.protocol.RequestHeader;
import net.yacy.cora.protocol.ResponseHeader;
import net.yacy.cora.util.ConcurrentLog;
import net.yacy.data.DidYouMean;
import net.yacy.search.Switchboard;
import net.yacy.server.serverObjects;
@ -85,7 +86,9 @@ public class suggest {
}
prop.put("suggestions_" + c + "_eol", 0);
c++;
} catch (final ConcurrentModificationException e) {}
} catch (final ConcurrentModificationException e) {
ConcurrentLog.logException(e);
}
}
}
}

@ -29,14 +29,12 @@
import java.io.IOException;
import java.net.InetAddress;
import java.util.ConcurrentModificationException;
import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.ConcurrentMap;
import net.yacy.cora.protocol.Domains;
import net.yacy.cora.protocol.HeaderFramework;
import net.yacy.cora.protocol.RequestHeader;
import net.yacy.cora.util.ConcurrentLog;
import net.yacy.peers.Network;
import net.yacy.peers.DHTSelection;
import net.yacy.peers.Protocol;
@ -216,7 +214,7 @@ public final class hello {
if (count > 100) { count = 100; }
// latest seeds
final Map<String, Seed> ySeeds = DHTSelection.seedsByAge(sb.peers, true, count); // peerhash/yacySeed relation
final ConcurrentMap<String, Seed> ySeeds = DHTSelection.seedsByAge(sb.peers, true, count); // peerhash/yacySeed relation
// attach also my own seed
seeds.append("seed0=").append(sb.peers.mySeed().genSeedStr(key)).append(serverCore.CRLF_STRING);
@ -230,14 +228,12 @@ public final class hello {
String seedString;
while (si.hasNext()) {
s = si.next();
if ((s != null) && (s.isProper(false) == null)) try {
if ((s != null) && (s.isProper(false) == null)) {
seedString = s.genSeedStr(key);
if (seedString != null) {
seeds.append("seed").append(count).append('=').append(seedString).append(serverCore.CRLF_STRING);
count++;
}
} catch (final ConcurrentModificationException e) {
ConcurrentLog.logException(e);
}
}
}

@ -783,9 +783,14 @@ public class yacysearch {
suggestion).toString());
prop.put("didYouMean_suggestions_" + meanCount + "_sep", "|");
meanCount++;
} catch (final ConcurrentModificationException e) {break meanCollect;}
} catch (final ConcurrentModificationException e) {
ConcurrentLog.logException(e);
break meanCollect;
}
}
} catch (final ConcurrentModificationException e) {}
} catch (final ConcurrentModificationException e) {
ConcurrentLog.logException(e);
}
prop.put("didYouMean_suggestions_" + (meanCount - 1) + "_sep", "");
prop.put("didYouMean", meanCount > 0 ? 1 : 0);
prop.put("didYouMean_suggestions", meanCount);

@ -29,6 +29,8 @@ import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import net.yacy.cora.util.ConcurrentLog;
public class RSSFeed implements Iterable<RSSMessage> {
public static final int DEFAULT_MAXSIZE = 10000;
@ -146,6 +148,7 @@ public class RSSFeed implements Iterable<RSSMessage> {
try {
this.lastGUID = this.GUIDiterator.next();
} catch (final ConcurrentModificationException e) {
ConcurrentLog.logException(e);
return null;
}
if (this.lastGUID == null) return null;

@ -275,7 +275,9 @@ public class WordCache {
break;
}
}
} catch (final ConcurrentModificationException e) {}
} catch (final ConcurrentModificationException e) {
ConcurrentLog.logException(e);
}
return ret;
}

@ -27,6 +27,7 @@ package net.yacy.cora.protocol;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
@ -132,7 +133,7 @@ public class ConnectionInfo implements Comparable<ConnectionInfo> {
* @return count of active connections
*/
public static int getCount() {
return allConnections.size();
return getAllConnections().size();
}
/**
@ -141,22 +142,20 @@ public class ConnectionInfo implements Comparable<ConnectionInfo> {
* @return load in percent
*/
public static int getLoadPercent() {
return getCount() * 100 / maxcount;
return getCount() * 100 / getMaxcount();
}
/**
* @return how many bytes queued up
*/
public static long getActiveUpbytes() {
long up = 0L;
try {
synchronized (allConnections) {
for(final ConnectionInfo con: allConnections) {
up += con.getUpbytes();
}
long up = 0L;
Iterator<ConnectionInfo> iter = getAllConnections().iterator();
synchronized (iter) {
while (iter.hasNext()) {
ConnectionInfo con = iter.next();
up += con.getUpbytes();
}
} catch (final java.util.ConcurrentModificationException e) {
// there will be another try :-)
}
return up;
}
@ -175,6 +174,7 @@ public class ConnectionInfo implements Comparable<ConnectionInfo> {
* to be used in statistics
*
* @param max connections
* @TODO Is it correct to only set if max > 0? What if maxcount is > 0 and max = 0 ?
*/
public static void setMaxcount(final int max) {
if (max > 0) maxcount = max;
@ -186,7 +186,7 @@ public class ConnectionInfo implements Comparable<ConnectionInfo> {
* @param conInfo
*/
public static void addConnection(final ConnectionInfo conInfo) {
allConnections.add(conInfo);
getAllConnections().add(conInfo);
}
/**
@ -195,7 +195,7 @@ public class ConnectionInfo implements Comparable<ConnectionInfo> {
* @param conInfo
*/
protected static void removeConnection(final ConnectionInfo conInfo) {
allConnections.remove(conInfo);
getAllConnections().remove(conInfo);
}
/**
@ -211,16 +211,14 @@ public class ConnectionInfo implements Comparable<ConnectionInfo> {
* removes stale connections
*/
public static void cleanUp() {
try {
synchronized (allConnections) {
for(final ConnectionInfo con: allConnections) {
if(con.getLifetime() > staleAfterMillis) {
allConnections.remove(con);
}
Iterator<ConnectionInfo> iter = getAllConnections().iterator();
synchronized (iter) {
while (iter.hasNext()) {
ConnectionInfo con = iter.next();
if(con.getLifetime() > staleAfterMillis) {
getAllConnections().remove(con);
}
}
} catch (final java.util.ConcurrentModificationException e) {
// there will be another try :-)
}
}

@ -33,6 +33,8 @@ import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.SortedMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import net.yacy.cora.document.ASCII;
import net.yacy.cora.federate.yacy.Distribution;
@ -461,13 +463,13 @@ public class DHTSelection {
* @param count number of wanted peers
* @return a hash map of peer hashes to seed object
*/
public static Map<String, Seed> seedsByAge(final SeedDB seedDB, final boolean up, int count) {
public static ConcurrentMap<String, Seed> seedsByAge(final SeedDB seedDB, final boolean up, int count) {
if (count > seedDB.sizeConnected()) count = seedDB.sizeConnected();
Seed ys;
//long age;
final Iterator<Seed> s = seedDB.seedsSortedConnected(!up, Seed.LASTSEEN);
try {
final Map<String, Seed> result = new HashMap<String, Seed>();
final ConcurrentMap<String, Seed> result = new ConcurrentHashMap<String, Seed>();
while (s.hasNext() && count-- > 0) {
ys = s.next();
if (ys != null && ys.hash != null) {

@ -167,8 +167,8 @@ public final class LoaderDispatcher {
} catch (final IOException e) {
// release the semaphore anyway
check = this.loaderSteering.remove(request.url());
if (check != null) check.release(1000);
//Log.logException(e);
if (check != null) check.release(1000);
// Very noisy: ConcurrentLog.logException(e);
throw new IOException(e);
}
}

Loading…
Cancel
Save