Author: toad
Date: 2007-02-22 00:38:16 +0000 (Thu, 22 Feb 2007)
New Revision: 11892

Modified:
   trunk/freenet/src/freenet/client/async/SplitFileFetcherSegment.java
   trunk/freenet/src/freenet/client/async/SplitFileFetcherSubSegment.java
   trunk/freenet/src/freenet/node/LowLevelGetException.java
Log:
Fix client request hang fetching some splitfiles with not enough blocks 
retrievable.

Modified: trunk/freenet/src/freenet/client/async/SplitFileFetcherSegment.java
===================================================================
--- trunk/freenet/src/freenet/client/async/SplitFileFetcherSegment.java 
2007-02-21 23:36:53 UTC (rev 11891)
+++ trunk/freenet/src/freenet/client/async/SplitFileFetcherSegment.java 
2007-02-22 00:38:16 UTC (rev 11892)
@@ -159,7 +159,7 @@
                        Logger.error(this, "Unrecognized block number: 
"+blockNo, new Exception("error"));
                fetchedBlocks++;
                parentFetcher.parent.completedBlock(dontNotify);
-               if(logMINOR) Logger.minor(this, "Fetched "+fetchedBlocks+" 
blocks");
+               if(logMINOR) Logger.minor(this, "Fetched "+fetchedBlocks+" 
blocks in onSuccess("+blockNo+")");
                if(fetchedBlocks >= minFetched)
                        startDecode();
        }
@@ -282,12 +282,11 @@
                                }
                                dataKeys[blockNo] = null;
                        } else if(blockNo < checkKeys.length + dataKeys.length) 
{
-                               blockNo -= dataKeys.length;
-                               if(checkKeys[blockNo] == null) {
+                               if(checkKeys[blockNo-dataKeys.length] == null) {
                                        Logger.error(this, "Check block already 
finished: "+blockNo);
                                        return;
                                }
-                               checkKeys[blockNo] = null;
+                               checkKeys[blockNo-dataKeys.length] = null;
                        } else
                                Logger.error(this, "Unrecognized block number: 
"+blockNo, new Exception("error"));
                        // :(
@@ -316,8 +315,7 @@
                                        return;
                                }
                        } else {
-                               blockNo -= dataKeys.length;
-                               tries = ++checkRetries[blockNo];
+                               tries = ++checkRetries[blockNo-dataKeys.length];
                                if(tries > maxTries && maxTries >= 0) {
                                        onFatalFailure(e, blockNo);
                                        return;
@@ -380,6 +378,8 @@
                                seg.add(i, true);

                        seg.schedule();
+                       if(logMINOR)
+                               Logger.minor(this, "scheduling "+seg+" : 
"+seg.blockNums);
                } catch (Throwable t) {
                        Logger.error(this, "Caught "+t+" scheduling "+this, t);
                        fail(new FetchException(FetchException.INTERNAL_ERROR, 
t));

Modified: trunk/freenet/src/freenet/client/async/SplitFileFetcherSubSegment.java
===================================================================
--- trunk/freenet/src/freenet/client/async/SplitFileFetcherSubSegment.java      
2007-02-21 23:36:53 UTC (rev 11891)
+++ trunk/freenet/src/freenet/client/async/SplitFileFetcherSubSegment.java      
2007-02-22 00:38:16 UTC (rev 11892)
@@ -75,9 +75,10 @@
                        return -1;
                }
                int x = ctx.random.nextInt(blockNums.size());
+               int ret = ((Integer) blockNums.remove(x)).intValue();
                if(logMINOR)
-                       Logger.minor(this, "Removing block "+x+" of 
"+blockNums.size());
-               return ((Integer) blockNums.remove(x)).intValue();
+                       Logger.minor(this, "Removing block "+x+" of 
"+(blockNums.size()+1)+ " : "+ret);
+               return ret;
        }

        public boolean ignoreStore() {
@@ -87,6 +88,8 @@
        // Translate it, then call the real onFailure
        // FIXME refactor this out to a common method; see 
SimpleSingleFileFetcher
        public void onFailure(LowLevelGetException e, int token) {
+               if(logMINOR)
+                       Logger.minor(this, "onFailure("+e+" , "+token);
                switch(e.code) {
                case LowLevelGetException.DATA_NOT_FOUND:
                        onFailure(new 
FetchException(FetchException.DATA_NOT_FOUND), token);
@@ -140,6 +143,7 @@
        }

        public void onSuccess(ClientKeyBlock block, boolean fromStore, int 
token) {
+               Bucket data = extract(block, token);
                if(fromStore) {
                        synchronized(this) {
                                for(int i=0;i<blockNums.size();i++) {
@@ -151,8 +155,6 @@
                                }
                        }
                }
-               Bucket data = extract(block, token);
-               if(data == null) return; // failed
                if(!block.isMetadata()) {
                        onSuccess(new FetchResult((ClientMetadata)null, data), 
fromStore, token);
                } else {

Modified: trunk/freenet/src/freenet/node/LowLevelGetException.java
===================================================================
--- trunk/freenet/src/freenet/node/LowLevelGetException.java    2007-02-21 
23:36:53 UTC (rev 11891)
+++ trunk/freenet/src/freenet/node/LowLevelGetException.java    2007-02-22 
00:38:16 UTC (rev 11892)
@@ -68,4 +68,8 @@
                this.code = reason;
        }

+       public String toString() {
+               return super.toString()+':'+getMessage(code);
+       }
+       
 }


Reply via email to