Author: toad
Date: 2008-06-28 14:04:45 +0000 (Sat, 28 Jun 2008)
New Revision: 20840
Modified:
branches/db4o/freenet/src/freenet/client/async/ClientRequestScheduler.java
branches/db4o/freenet/src/freenet/client/async/ClientRequestSchedulerCore.java
branches/db4o/freenet/src/freenet/node/RequestScheduler.java
branches/db4o/freenet/src/freenet/node/RequestStarter.java
Log:
Fix bug: if a key was first selected with a low priority, but was also wanted
by higher priorities, it would never get to run, because RequestStarter would
always find a higher priority transient request to run, and the higher priority
requests using that key would never be chosen because it's already on
keysFetching!
Implementation: keysFetching: Add to keysFetching in RequestStarter.start().
NOT when selecting the request/resuming PersistentChosenRequest's.
Modified:
branches/db4o/freenet/src/freenet/client/async/ClientRequestScheduler.java
===================================================================
--- branches/db4o/freenet/src/freenet/client/async/ClientRequestScheduler.java
2008-06-28 13:28:44 UTC (rev 20839)
+++ branches/db4o/freenet/src/freenet/client/async/ClientRequestScheduler.java
2008-06-28 14:04:45 UTC (rev 20840)
@@ -432,6 +432,10 @@
private static final int MAX_STARTER_QUEUE_SIZE = 100;
+ /**
+ * Normally this will only contain PersistentChosenRequest's, however
in the
+ * case of coalescing keys, we will put ChosenRequest's back onto it as
well.
+ */
private transient LinkedList starterQueue = new LinkedList();
public LinkedList getRequestStarterQueue() {
@@ -442,7 +446,7 @@
jobRunner.queue(requestStarterQueueFiller,
NativeThread.MAX_PRIORITY, true);
}
- void addToStarterQueue(PersistentChosenRequest req) {
+ void addToStarterQueue(ChosenRequest req) {
synchronized(starterQueue) {
starterQueue.add(req);
}
@@ -782,4 +786,29 @@
return clientContext;
}
+ /**
+ * @return True unless the key was already present.
+ */
+ public boolean addToFetching(Key key) {
+ return schedCore.addToFetching(key);
+ }
+
+ public void requeue(final ChosenRequest req) {
+ if(req.isPersistent()) {
+ this.clientContext.jobRunner.queue(new DBJob() {
+
+ public void run(ObjectContainer container,
ClientContext context) {
+ container.activate(req.request, 1);
+ if(req.request.isCancelled(container))
return;
+ addToStarterQueue(req);
+ }
+
+ }, NativeThread.HIGH_PRIORITY, false);
+ } else {
+ if(req.request.isCancelled(null)) return;
+ addToStarterQueue(req);
+ }
+ }
+
+
}
Modified:
branches/db4o/freenet/src/freenet/client/async/ClientRequestSchedulerCore.java
===================================================================
---
branches/db4o/freenet/src/freenet/client/async/ClientRequestSchedulerCore.java
2008-06-28 13:28:44 UTC (rev 20839)
+++
branches/db4o/freenet/src/freenet/client/async/ClientRequestSchedulerCore.java
2008-06-28 14:04:45 UTC (rev 20840)
@@ -190,11 +190,6 @@
continue;
}
sched.addToStarterQueue(req);
- if(!isInsertScheduler) {
- synchronized(keysFetching) {
- keysFetching.add(req.key);
- }
- }
}
}
@@ -269,11 +264,6 @@
} else {
ret = new ChosenRequest(req, token, key, ckey,
req.getPriorityClass(container));
}
- if(key != null) {
- if(logMINOR)
- Logger.minor(this, "Adding "+key+" for
"+ckey+" for "+ret+" for "+req+" to keysFetching");
- keysFetching.add(key);
- }
return ret;
}
}
@@ -557,6 +547,15 @@
return reg;
}
+ /**
+ * @return True unless the key was already present.
+ */
+ public boolean addToFetching(Key key) {
+ synchronized(keysFetching) {
+ return keysFetching.add(key);
+ }
+ }
+
public boolean hasKey(Key key) {
synchronized(keysFetching) {
return keysFetching.contains(key);
Modified: branches/db4o/freenet/src/freenet/node/RequestScheduler.java
===================================================================
--- branches/db4o/freenet/src/freenet/node/RequestScheduler.java
2008-06-28 13:28:44 UTC (rev 20839)
+++ branches/db4o/freenet/src/freenet/node/RequestScheduler.java
2008-06-28 14:04:45 UTC (rev 20840)
@@ -73,4 +73,8 @@
public ClientContext getContext();
+ public boolean addToFetching(Key key);
+
+ public void requeue(ChosenRequest req);
+
}
Modified: branches/db4o/freenet/src/freenet/node/RequestStarter.java
===================================================================
--- branches/db4o/freenet/src/freenet/node/RequestStarter.java 2008-06-28
13:28:44 UTC (rev 20839)
+++ branches/db4o/freenet/src/freenet/node/RequestStarter.java 2008-06-28
14:04:45 UTC (rev 20840)
@@ -218,8 +218,12 @@
}
if(usedReq || req == null)
sched.queueFillRequestStarterQueue();
- if(req == null)
if(req == null && logMINOR) Logger.minor(this, "No requests
found");
+ if(req != null) {
+ if(!sched.addToFetching(req.key)) {
+ sched.requeue(req);
+ }
+ }
return req;
}