[freenet-cvs] r18906 - trunk/freenet/src/freenet/client/async

toad at freenetproject.org toad at freenetproject.org
Wed Apr 2 01:34:21 UTC 2008


Author: toad
Date: 2008-04-02 01:34:21 +0000 (Wed, 02 Apr 2008)
New Revision: 18906

Modified:
   trunk/freenet/src/freenet/client/async/SplitFileFetcherSegment.java
Log:
Get the new subsegment earlier on, and use it to queue the cooldown immediately for the right client.

Modified: trunk/freenet/src/freenet/client/async/SplitFileFetcherSegment.java
===================================================================
--- trunk/freenet/src/freenet/client/async/SplitFileFetcherSegment.java	2008-04-02 01:29:15 UTC (rev 18905)
+++ trunk/freenet/src/freenet/client/async/SplitFileFetcherSegment.java	2008-04-02 01:34:21 UTC (rev 18906)
@@ -383,40 +383,44 @@
 		boolean failed = false;
 		boolean cooldown = false;
 		ClientCHK key;
+		SplitFileFetcherSubSegment sub = null;
 		synchronized(this) {
 			if(isFinished()) return;
 			if(blockNo < dataKeys.length) {
 				key = dataKeys[blockNo];
 				tries = ++dataRetries[blockNo];
 				if(tries > maxTries && maxTries >= 0) failed = true;
-				else if(tries % ClientRequestScheduler.COOLDOWN_RETRIES == 0) {
+				else {
+					sub = getSubSegment(tries);
+					if(tries % ClientRequestScheduler.COOLDOWN_RETRIES == 0) {
 					long now = System.currentTimeMillis();
 					if(dataCooldownTimes[blockNo] > now)
 						Logger.error(this, "Already on the cooldown queue! for "+this+" data block no "+blockNo, new Exception("error"));
 					else
-					// FIXME ideally we'd only register once, with the new segment, but the cost is 
-					// trivial, and it simplifies locking. Reconsider sometime...
-					dataCooldownTimes[blockNo] = sched.queueCooldown(key, seg);
+					dataCooldownTimes[blockNo] = sched.queueCooldown(key, sub);
 					cooldown = true;
+					}
 				}
 			} else {
 				int checkNo = blockNo - dataKeys.length;
 				key = checkKeys[checkNo];
 				tries = ++checkRetries[checkNo];
 				if(tries > maxTries && maxTries >= 0) failed = true;
-				else if(tries % ClientRequestScheduler.COOLDOWN_RETRIES == 0) {
+				else {
+					sub = getSubSegment(tries);
+					if(tries % ClientRequestScheduler.COOLDOWN_RETRIES == 0) {
 					long now = System.currentTimeMillis();
 					if(checkCooldownTimes[checkNo] > now)
 						Logger.error(this, "Already on the cooldown queue! for "+this+" check block no "+blockNo, new Exception("error"));
 					else
-					checkCooldownTimes[checkNo] = sched.queueCooldown(key, seg);
+					checkCooldownTimes[checkNo] = sched.queueCooldown(key, sub);
 					cooldown = true;
+					}
 				}
 			}
 		}
 		if(cooldown) {
 			// Register key to next sub-segment and remove from previous one to save memory (avoid duplication).
-			SplitFileFetcherSubSegment sub = getSubSegment(tries);
 			sub.getScheduler().addPendingKey(key, sub);
 			seg.unregisterKey(key.getNodeKey());
 			return;
@@ -430,7 +434,6 @@
 		// If we are here we are going to retry
 		// Unregister from the old sub-segment before registering on the new.
 		seg.unregisterKey(key.getNodeKey());
-		SplitFileFetcherSubSegment sub = getSubSegment(tries);
 		if(logMINOR)
 			Logger.minor(this, "Retrying block "+blockNo+" on "+this+" : tries="+tries+"/"+maxTries+" : "+sub);
 		sub.add(blockNo, false);




More information about the cvs mailing list