Author: toad
Date: 2008-07-01 17:14:16 +0000 (Tue, 01 Jul 2008)
New Revision: 20918

Modified:
   branches/db4o/freenet/src/freenet/client/async/ClientRequestScheduler.java
Log:
tripPending() and succeeded() must run at the same high priority, because if 
succeeded() completes first we end up rerunning the request (through the 
recently-succeeded mechanism).

Modified: 
branches/db4o/freenet/src/freenet/client/async/ClientRequestScheduler.java
===================================================================
--- branches/db4o/freenet/src/freenet/client/async/ClientRequestScheduler.java  
2008-07-01 16:36:38 UTC (rev 20917)
+++ branches/db4o/freenet/src/freenet/client/async/ClientRequestScheduler.java  
2008-07-01 17:14:16 UTC (rev 20918)
@@ -507,6 +507,7 @@
                        ChosenRequest req = null;
                        synchronized(starterQueue) {
                                int size = starterQueue.size();
+                               if(logMINOR) Logger.minor(this, "Queue size: 
"+size);
                                if(size >= MAX_STARTER_QUEUE_SIZE) {
                                        if(size >= WARNING_STARTER_QUEUE_SIZE)
                                                Logger.error(this, "Queue 
already full: "+starterQueue.size());
@@ -600,6 +601,14 @@
                return choosenPriorityScheduler;
        }

+       /*
+        * tripPendingKey() callbacks must run quickly, since we've found a 
block.
+        * succeeded() must run quickly, since we delete the 
PersistentChosenRequest.
+        * tripPendingKey() must run before succeeded() so we don't choose the 
same
+        * request again, then remove it from pendingKeys before it completes! 
+        */
+       static final short TRIP_PENDING_PRIORITY = NativeThread.HIGH_PRIORITY-1;
+       
        public synchronized void succeeded(final BaseSendableGet succeeded, 
final ChosenRequest req) {
                if(req.isPersistent()) {
                        jobRunner.queue(new DBJob() {
@@ -609,7 +618,7 @@
                                        
container.delete((PersistentChosenRequest)req);
                                }

-                       }, NativeThread.HIGH_PRIORITY-1, false);
+                       }, TRIP_PENDING_PRIORITY, false);
                        // Boost the priority so the PersistentChosenRequest 
gets deleted reasonably quickly.
                } else
                        schedTransient.succeeded(succeeded, null);
@@ -674,7 +683,7 @@
                                if(logMINOR) Logger.minor(this, "Finished 
running callbacks");
                        }

-               }, NativeThread.NORM_PRIORITY, false);
+               }, TRIP_PENDING_PRIORITY, false);

        }



Reply via email to