Author: nextgens
Date: 2009-01-29 17:12:57 +0000 (Thu, 29 Jan 2009)
New Revision: 25364
Modified:
trunk/freenet/src/freenet/node/FNPPacketMangler.java
trunk/freenet/src/freenet/node/PacketSender.java
trunk/freenet/src/freenet/node/PeerNode.java
trunk/freenet/src/freenet/node/RequestSender.java
trunk/freenet/src/freenet/support/Logger.java
trunk/freenet/src/freenet/support/LoggerHook.java
Log:
some untested code trying to address the lock-contention problem in the logger
Modified: trunk/freenet/src/freenet/node/FNPPacketMangler.java
===================================================================
--- trunk/freenet/src/freenet/node/FNPPacketMangler.java 2009-01-29
16:36:30 UTC (rev 25363)
+++ trunk/freenet/src/freenet/node/FNPPacketMangler.java 2009-01-29
17:12:57 UTC (rev 25364)
@@ -47,6 +47,7 @@
import freenet.support.HTMLNode;
import freenet.support.HexUtil;
import freenet.support.Logger;
+import freenet.support.LogThresholdCallback;
import freenet.support.SimpleFieldSet;
import freenet.support.TimeUtil;
import freenet.support.WouldBlockException;
@@ -62,8 +63,18 @@
* changes in IncomingPacketFilter).
*/
public class FNPPacketMangler implements OutgoingPacketMangler,
IncomingPacketFilter {
- private static boolean logMINOR;
- private static boolean logDEBUG;
+ private static volatile boolean logMINOR;
+ private static volatile boolean logDEBUG;
+
+ static {
+ Logger.registerLogThresholdCallback(new LogThresholdCallback(){
+ public void shouldUpdate(){
+ logMINOR = Logger.shouldLog(Logger.MINOR, this);
+ logDEBUG = Logger.shouldLog(Logger.DEBUG, this);
+ }
+ });
+ }
+
private final Node node;
private final NodeCrypto crypto;
private final MessageCore usm;
@@ -168,8 +179,6 @@
fullHeadersLengthMinimum = HEADERS_LENGTH_MINIMUM +
sock.getHeadersLength();
fullHeadersLengthOneMessage = HEADERS_LENGTH_ONE_MESSAGE +
sock.getHeadersLength();
- logMINOR = Logger.shouldLog(Logger.MINOR, this);
- logDEBUG = Logger.shouldLog(Logger.DEBUG, this);
}
/**
@@ -208,8 +217,6 @@
*/
public void process(byte[] buf, int offset, int length, Peer peer, long
now) {
node.random.acceptTimerEntropy(fnpTimingSource, 0.25);
- logMINOR = Logger.shouldLog(Logger.MINOR, this);
- logDEBUG = Logger.shouldLog(Logger.DEBUG, this);
if(logMINOR) Logger.minor(this, "Packet length "+length+" from
"+peer);
/**
@@ -1806,7 +1813,7 @@
private boolean tryProcess(byte[] buf, int offset, int length,
SessionKey tracker, long now) {
// Need to be able to call with tracker == null to simplify
code above
if(tracker == null) {
- if(Logger.shouldLog(Logger.DEBUG, this))
Logger.debug(this, "Tracker == null");
+ if(logDEBUG) Logger.debug(this, "Tracker == null");
return false;
}
if(logMINOR) Logger.minor(this,"Entering tryProcess:
"+Fields.hashCode(buf)+ ',' +offset+ ',' +length+ ',' +tracker);
Modified: trunk/freenet/src/freenet/node/PacketSender.java
===================================================================
--- trunk/freenet/src/freenet/node/PacketSender.java 2009-01-29 16:36:30 UTC
(rev 25363)
+++ trunk/freenet/src/freenet/node/PacketSender.java 2009-01-29 17:12:57 UTC
(rev 25364)
@@ -19,6 +19,7 @@
import freenet.support.FileLoggerHook;
import freenet.support.HTMLNode;
import freenet.support.Logger;
+import freenet.support.LogThresholdCallback;
import freenet.support.OOMHandler;
import freenet.support.TimeUtil;
import freenet.support.io.NativeThread;
@@ -34,8 +35,18 @@
// a generic task scheduler. Either rename this class, or create another
tricker for non-Packet tasks
public class PacketSender implements Runnable, Ticker {
- private static boolean logMINOR;
- private static boolean logDEBUG;
+ private static volatile boolean logMINOR;
+ private static volatile boolean logDEBUG;
+
+ static {
+ Logger.registerLogThresholdCallback(new LogThresholdCallback(){
+ public void shouldUpdate(){
+ logMINOR = Logger.shouldLog(Logger.MINOR, this);
+ logDEBUG = Logger.shouldLog(Logger.DEBUG, this);
+ }
+ });
+ }
+
/** Maximum time we will queue a message for in milliseconds */
static final int MAX_COALESCING_DELAY = 100;
/** If opennet is enabled, and there are fewer than this many
connections,
@@ -76,8 +87,6 @@
this.node = node;
myThread = new NativeThread(this, "PacketSender thread for " +
node.getDarknetPortNumber(), NativeThread.MAX_PRIORITY, false);
myThread.setDaemon(true);
- logMINOR = Logger.shouldLog(Logger.MINOR, this);
- logDEBUG = Logger.shouldLog(Logger.DEBUG, this);
rpiTemp = new Vector<ResendPacketItem>();
rpiIntTemp = new int[64];
}
@@ -176,7 +185,6 @@
while(true) {
lastReceivedPacketFromAnyNode = lastReportedNoPackets;
try {
- logMINOR = Logger.shouldLog(Logger.MINOR, this);
brokeAt = realRun(brokeAt);
} catch(OutOfMemoryError e) {
OOMHandler.handleOOM(e);
@@ -423,8 +431,6 @@
if(sleepTime > 0) {
// Update logging only when have time to do so
- logMINOR = Logger.shouldLog(Logger.MINOR, this);
- logDEBUG = Logger.shouldLog(Logger.DEBUG, this);
try {
synchronized(this) {
if(logMINOR)
Modified: trunk/freenet/src/freenet/node/PeerNode.java
===================================================================
--- trunk/freenet/src/freenet/node/PeerNode.java 2009-01-29 16:36:30 UTC
(rev 25363)
+++ trunk/freenet/src/freenet/node/PeerNode.java 2009-01-29 17:12:57 UTC
(rev 25364)
@@ -63,6 +63,7 @@
import freenet.support.HexUtil;
import freenet.support.IllegalBase64Exception;
import freenet.support.Logger;
+import freenet.support.LogThresholdCallback;
import freenet.support.SimpleFieldSet;
import freenet.support.TimeUtil;
import freenet.support.WouldBlockException;
@@ -348,7 +349,15 @@
* responder in message2 match what was chosen in message 1
*/
protected final HashMap<Peer,byte[]> jfkNoncesSent = new
HashMap<Peer,byte[]>();
- private static boolean logMINOR;
+ private static volatile boolean logMINOR;
+
+ static {
+ Logger.registerLogThresholdCallback(new LogThresholdCallback(){
+ public void shouldUpdate(){
+ logMINOR = Logger.shouldLog(Logger.MINOR, this);
+ }
+ });
+ }
/**
* If this returns true, we will generate the identity from the pubkey.
@@ -378,7 +387,6 @@
public PeerNode(SimpleFieldSet fs, Node node2, NodeCrypto crypto,
PeerManager peers, boolean fromLocal, boolean fromAnonymousInitiator,
OutgoingPacketMangler mangler, boolean isOpennet) throws FSParseException,
PeerParseException, ReferenceSignatureVerificationException {
boolean noSig = false;
if(fromLocal || fromAnonymousInitiator) noSig = true;
- logMINOR = Logger.shouldLog(Logger.MINOR, PeerNode.class);
myRef = new WeakReference<PeerNode>(this);
this.outgoingMangler = mangler;
this.node = node2;
@@ -1596,8 +1604,6 @@
}
public void updateLocation(double newLoc, double[] newLocs) {
- logMINOR = Logger.shouldLog(Logger.MINOR, PeerNode.class);
-
if(newLoc < 0.0 || newLoc > 1.0) {
Logger.error(this, "Invalid location update for " +
this+ " ("+newLoc+')', new Exception("error"));
// Ignore it
@@ -1831,7 +1837,6 @@
* it's a new tracker. -1 to indicate failure.
*/
public long completedHandshake(long thisBootID, byte[] data, int
offset, int length, BlockCipher encCipher, byte[] encKey, Peer replyTo, boolean
unverified, int negType, long trackerID, boolean isJFK4, boolean jfk4SameAsOld)
{
- logMINOR = Logger.shouldLog(Logger.MINOR, PeerNode.class);
long now = System.currentTimeMillis();
if(logMINOR) Logger.minor(this, "Tracker ID "+trackerID+"
isJFK4="+isJFK4+" jfk4SameAsOld="+jfk4SameAsOld);
Modified: trunk/freenet/src/freenet/node/RequestSender.java
===================================================================
--- trunk/freenet/src/freenet/node/RequestSender.java 2009-01-29 16:36:30 UTC
(rev 25363)
+++ trunk/freenet/src/freenet/node/RequestSender.java 2009-01-29 17:12:57 UTC
(rev 25364)
@@ -31,6 +31,7 @@
import freenet.node.FailureTable.OfferList;
import freenet.store.KeyCollisionException;
import freenet.support.Logger;
+import freenet.support.LogThresholdCallback;
import freenet.support.ShortBuffer;
import freenet.support.SimpleFieldSet;
import freenet.support.TimeUtil;
@@ -141,7 +142,14 @@
return getStatusString(getStatus());
}
- private static boolean logMINOR;
+ private static volatile boolean logMINOR;
+ static {
+ Logger.registerLogThresholdCallback(new LogThresholdCallback(){
+ public void shouldUpdate(){
+ logMINOR = Logger.shouldLog(Logger.MINOR, this);
+ }
+ });
+ }
@Override
public String toString() {
@@ -165,7 +173,6 @@
this.tryOffersOnly = offersOnly;
target = key.toNormalizedDouble();
node.addRequestSender(key, htl, this);
- logMINOR = Logger.shouldLog(Logger.MINOR, this);
}
public void start() {
Modified: trunk/freenet/src/freenet/support/Logger.java
===================================================================
--- trunk/freenet/src/freenet/support/Logger.java 2009-01-29 16:36:30 UTC
(rev 25363)
+++ trunk/freenet/src/freenet/support/Logger.java 2009-01-29 17:12:57 UTC
(rev 25364)
@@ -15,7 +15,6 @@
*/
public abstract class Logger {
-
public final static class OSThread {
private static boolean getPIDEnabled = false;
@@ -385,6 +384,15 @@
public abstract void setDetailedThresholds(String details) throws
InvalidThresholdException;
/**
+ * Register a LogThresholdCallback; this callback will be called after
registration
+ */
+ public static void registerLogThresholdCallback(LogThresholdCallback
ltc) {
+ logger.instanceRegisterLogThresholdCallback(ltc);
+ }
+
+ public abstract void
instanceRegisterLogThresholdCallback(LogThresholdCallback ltc);
+
+ /**
* Report a fatal error and exit.
* @param cause the object or class involved
* @param retcode the return code
Modified: trunk/freenet/src/freenet/support/LoggerHook.java
===================================================================
--- trunk/freenet/src/freenet/support/LoggerHook.java 2009-01-29 16:36:30 UTC
(rev 25363)
+++ trunk/freenet/src/freenet/support/LoggerHook.java 2009-01-29 17:12:57 UTC
(rev 25364)
@@ -27,6 +27,7 @@
}
public DetailedThreshold[] detailedThresholds = new
DetailedThreshold[0];
+ private LogThresholdCallback[] thresholdsCallbacks = new
LogThresholdCallback[0];
/**
* Log a message
@@ -109,6 +110,7 @@
@Override
public void setThreshold(int thresh) {
this.threshold = thresh;
+ notifyLogThresholdCallbacks();
}
@Override
@@ -145,6 +147,7 @@
stuff.toArray(newThresholds);
synchronized(this) {
detailedThresholds = newThresholds;
+ notifyLogThresholdCallbacks();
}
}
@@ -231,7 +234,21 @@
return instanceShouldLog(prio, o == null ? null : o.getClass());
}
+ public synchronized final void
instanceRegisterLogThresholdCallback(LogThresholdCallback ltc) {
+ LogThresholdCallback[] newLTC = new
LogThresholdCallback[thresholdsCallbacks.length+1];
+ newLTC[0] = ltc;
+ System.arraycopy(thresholdsCallbacks, 0, newLTC, 1,
thresholdsCallbacks.length);
+ thresholdsCallbacks = newLTC;
+ // Call the new callback to avoid code duplication
+ ltc.shouldUpdate();
+ }
+
+ private synchronized final void notifyLogThresholdCallbacks() {
+ for(LogThresholdCallback ltc : thresholdsCallbacks)
+ ltc.shouldUpdate();
+ }
+
public abstract long minFlags(); // ignore unless all these bits set
public abstract long notFlags(); // reject if any of these bits set
_______________________________________________
cvs mailing list
[email protected]
http://emu.freenetproject.org/cgi-bin/mailman/listinfo/cvs