Author: toad
Date: 2007-02-21 21:16:15 +0000 (Wed, 21 Feb 2007)
New Revision: 11887

Modified:
   trunk/freenet/src/freenet/client/FailureCodeTracker.java
   trunk/freenet/src/freenet/client/async/ClientGetter.java
   trunk/freenet/src/freenet/client/async/SplitFileFetcherSegment.java
   trunk/freenet/src/freenet/client/async/SplitFileFetcherSubSegment.java
   trunk/freenet/src/freenet/node/RequestStarter.java
   trunk/freenet/src/freenet/support/RandomGrabArray.java
   trunk/freenet/src/freenet/support/SectoredRandomGrabArray.java
Log:
Even more logging

Modified: trunk/freenet/src/freenet/client/FailureCodeTracker.java
===================================================================
--- trunk/freenet/src/freenet/client/FailureCodeTracker.java    2007-02-21 
20:14:58 UTC (rev 11886)
+++ trunk/freenet/src/freenet/client/FailureCodeTracker.java    2007-02-21 
21:16:15 UTC (rev 11887)
@@ -90,6 +90,22 @@
                return sb.toString();
        }

+       public synchronized String toString() {
+               StringBuffer sb = new StringBuffer(super.toString());
+               sb.append(':');
+               if(map.size() == 0) sb.append("empty");
+               else if(map.size() == 1) {
+                       sb.append("one:");
+                       Integer code = (Integer) (map.keySet().toArray())[0];
+                       sb.append(code);
+                       sb.append('=');
+                       sb.append(((Item) map.get(code)).x);
+               } else {
+                       sb.append(map.size());
+               }
+               return sb.toString();
+       }
+       
        /**
         * Merge codes from another tracker into this one.
         */

Modified: trunk/freenet/src/freenet/client/async/ClientGetter.java
===================================================================
--- trunk/freenet/src/freenet/client/async/ClientGetter.java    2007-02-21 
20:14:58 UTC (rev 11886)
+++ trunk/freenet/src/freenet/client/async/ClientGetter.java    2007-02-21 
21:16:15 UTC (rev 11887)
@@ -118,11 +118,17 @@
                client.onSuccess(result, this);
        }

-       public synchronized void onFailure(FetchException e, ClientGetState 
state) {
+       public void onFailure(FetchException e, ClientGetState state) {
                while(true) {
                        if(e.mode == FetchException.ARCHIVE_RESTART) {
-                               archiveRestarts++;
-                               if(archiveRestarts > ctx.maxArchiveRestarts)
+                               int ar;
+                               synchronized(this) {
+                                       archiveRestarts++;
+                                       ar = archiveRestarts;
+                               }
+                               if(Logger.shouldLog(Logger.MINOR, this))
+                                       Logger.minor(this, "Archive restart on 
"+this+" ar="+ar);
+                               if(ar > ctx.maxArchiveRestarts)
                                        e = new 
FetchException(FetchException.TOO_MANY_ARCHIVE_RESTARTS);
                                else {
                                        try {
@@ -134,10 +140,14 @@
                                        return;
                                }
                        }
-                       finished = true;
+                       synchronized(this) {
+                               finished = true;
+                       }
+                       if(e.errorCodes.isOneCodeOnly())
+                               e = new 
FetchException(e.errorCodes.getFirstCode(), e);
                        if(e.mode == FetchException.DATA_NOT_FOUND && 
super.successfulBlocks > 0)
                                e = new FetchException(e, 
FetchException.ALL_DATA_NOT_FOUND);
-                       Logger.minor(this, "onFailure("+e+", "+state+")", e);
+                       Logger.minor(this, "onFailure("+e+", "+state+") ", e);
                        client.onFailure(e, this);
                        return;
                }

Modified: trunk/freenet/src/freenet/client/async/SplitFileFetcherSegment.java
===================================================================
--- trunk/freenet/src/freenet/client/async/SplitFileFetcherSegment.java 
2007-02-21 20:14:58 UTC (rev 11886)
+++ trunk/freenet/src/freenet/client/async/SplitFileFetcherSegment.java 
2007-02-21 21:16:15 UTC (rev 11887)
@@ -326,6 +326,8 @@
                }
                // If we are here we are going to retry
                SplitFileFetcherSubSegment sub = getSubSegment(tries);
+               if(logMINOR)
+                       Logger.minor(this, "Retrying block "+blockNo+" on 
"+this+" : tries="+tries+" : "+sub);
                sub.add(blockNo, false);
        }


Modified: trunk/freenet/src/freenet/client/async/SplitFileFetcherSubSegment.java
===================================================================
--- trunk/freenet/src/freenet/client/async/SplitFileFetcherSubSegment.java      
2007-02-21 20:14:58 UTC (rev 11886)
+++ trunk/freenet/src/freenet/client/async/SplitFileFetcherSubSegment.java      
2007-02-21 21:16:15 UTC (rev 11887)
@@ -27,6 +27,7 @@
        final SplitFileFetcherSegment segment;
        final Vector blockNums;
        final FetchContext ctx;
+       private static boolean logMINOR;

        SplitFileFetcherSubSegment(SplitFileFetcherSegment segment, int 
retryCount) {
                super(segment.parentFetcher.parent);
@@ -34,6 +35,7 @@
                this.retryCount = retryCount;
                ctx = segment.blockFetchContext;
                blockNums = new Vector();
+               logMINOR = Logger.shouldLog(Logger.MINOR, this);
        }

        public boolean dontCache() {
@@ -62,8 +64,15 @@
        }

        private synchronized int removeRandomBlockNum() {
-               if(blockNums.isEmpty()) return -1;
+               logMINOR = Logger.shouldLog(Logger.MINOR, this);
+               if(blockNums.isEmpty()) {
+                       if(logMINOR)
+                               Logger.minor(this, "No blocks to remove");
+                       return -1;
+               }
                int x = ctx.random.nextInt(blockNums.size());
+               if(logMINOR)
+                       Logger.minor(this, "Removing block "+x+" of 
"+blockNums.size());
                return ((Integer) blockNums.remove(x)).intValue();
        }

@@ -197,6 +206,8 @@

        public synchronized boolean canRemove() {
                if(blockNums.isEmpty()) {
+                       if(Logger.shouldLog(Logger.MINOR, this))
+                               Logger.minor(this, "Removing "+this+" in 
canRemove()");
                        segment.removeSeg(this);
                        return true;
                } else return false;
@@ -212,11 +223,16 @@
        }

        public void add(int blockNo, boolean dontSchedule) {
+               boolean logMINOR = Logger.shouldLog(Logger.MINOR, this);
+               if(logMINOR) Logger.minor(this, "Adding block "+blockNo+" to 
"+this+" dontSchedule="+dontSchedule);
                if(blockNo < 0) throw new IllegalArgumentException();
                Integer i = new Integer(blockNo);
                synchronized(this) {
                        blockNums.add(i);
-                       if(blockNums.size() > 1) return;
+                       if(blockNums.size() > 1) {
+                               if(logMINOR) Logger.minor(this, "Other blocks 
queued, not scheduling: "+blockNums.size()+" : "+blockNums);
+                               return;
+                       }
                        if(dontSchedule) return;
                }
                if(!dontSchedule) schedule();

Modified: trunk/freenet/src/freenet/node/RequestStarter.java
===================================================================
--- trunk/freenet/src/freenet/node/RequestStarter.java  2007-02-21 20:14:58 UTC 
(rev 11886)
+++ trunk/freenet/src/freenet/node/RequestStarter.java  2007-02-21 21:16:15 UTC 
(rev 11887)
@@ -163,6 +163,8 @@

                public void run() {
                        req.send(core); // FIXME check return value?
+                       if(Logger.shouldLog(Logger.MINOR, this)) 
+                               Logger.minor(this, "Finished "+req);
                }

        }

Modified: trunk/freenet/src/freenet/support/RandomGrabArray.java
===================================================================
--- trunk/freenet/src/freenet/support/RandomGrabArray.java      2007-02-21 
20:14:58 UTC (rev 11886)
+++ trunk/freenet/src/freenet/support/RandomGrabArray.java      2007-02-21 
21:16:15 UTC (rev 11887)
@@ -46,8 +46,12 @@
        }

        public synchronized RandomGrabArrayItem removeRandom() {
+               boolean logMINOR = Logger.shouldLog(Logger.MINOR, this);
                while(true) {
-                       if(index == 0) return null;
+                       if(index == 0) {
+                               if(logMINOR) Logger.minor(this, "All null on 
"+this);
+                               return null;
+                       }
                        int i = rand.nextInt(index);
                        RandomGrabArrayItem ret = reqs[i];
                        if(ret != null && !ret.canRemove()) return ret;

Modified: trunk/freenet/src/freenet/support/SectoredRandomGrabArray.java
===================================================================
--- trunk/freenet/src/freenet/support/SectoredRandomGrabArray.java      
2007-02-21 20:14:58 UTC (rev 11886)
+++ trunk/freenet/src/freenet/support/SectoredRandomGrabArray.java      
2007-02-21 21:16:15 UTC (rev 11887)
@@ -67,7 +67,8 @@
                                Logger.minor(this, "Picked "+x+" of 
"+grabArrays.length+" : "+rga+" : "+rga.getClient());
                        RandomGrabArrayItem item = rga.removeRandom();
                        if(logMINOR)
-                               Logger.minor(this, "RGA has picked "+item);
+                               Logger.minor(this, "RGA has picked "+item+
+                                               (item==null ? "" : (" 
cancelled="+item.isCancelled()+")"))+" rga.isEmpty="+rga.isEmpty());
                        if(rga.isEmpty() || (item == null) || 
item.isCancelled()) {
                                if(logMINOR)
                                        Logger.minor(this, "Removing "+x);


Reply via email to