Update of /cvsroot/freenet/freenet/src/freenet/support
In directory sc8-pr-cvs1:/tmp/cvs-serv15810/src/freenet/support

Modified Files:
        RandomAccessFilePool.java 
Log Message:
6249:
Iakin's fix for Request.java - nasty bug, may have caused requests from recent nodes 
to fail.
Try to fix lock contention in RandomAccessFilePool. Code review would be appreciated. 
Catch Throwables when closing files.
Reduce outLimitCutoff to 80%. Thus the node will reject all queries if it is using 
more than 80% of outbound bandwidth. The previous 90% figure conflicted with the hard 
bandwidth limit of 120%, which (because it is deliberately conservative), was 
preventing it from going over 90%.
Implement removal of PeerHandlers from OCM, when either
a) No connections and no contact details, and not in routing table, regardless of 
whether we have queued messages or
b) No connections, no messages.
- Some tricky concurrency issues, hence the new RemovingPeerHandlerException
Track number and last event time for outbound connection attempts, successes, and 
failures, in PeerHandler.
Add PeerHandler.probablyNotConnectable()
Don't queue messages if we are unlikely to be able to open a connection and we have no 
current connections
Diagnostics - messageSendTime* especially. Added messageSendTime{Request,NonRequest}, 
fixed messageSendTimeNoQR.
Make sending a QR because of a loop in RequestDone asynchronous.
Don't add PeerHandlers with null IDs in OCM (probably not used).
Lots of logging, a few toString()'s, indenting
- remove some spurious logging, for example, Accepted before SendFinished is okay 
unless it's a lot before it, or the SendFinished is unsuccessful


Index: RandomAccessFilePool.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/support/RandomAccessFilePool.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -w -r1.1 -r1.2
--- RandomAccessFilePool.java   13 Oct 2003 15:42:01 -0000      1.1
+++ RandomAccessFilePool.java   15 Oct 2003 21:15:49 -0000      1.2
@@ -1,6 +1,7 @@
 package freenet.support;
 
 import java.io.*;
+import freenet.Core;
 
 /**
  * A pool of PooledRandomAccessFiles. These are similar to 
@@ -45,19 +46,28 @@
        
        synchronized void reopen() throws IOException {
            if(raf == null) {
-               if(closed) throw new IOException("Already closed or failed to save 
position");
+               if(closed) 
+                   throw new IOException("Already closed or failed to save position");
+               boolean firstIteration = true;
+               while(totalOpenFiles <= maxOpenFiles) {
+                   PooledRandomAccessFile fClose = null;
                synchronized(RandomAccessFilePool.this) {
-                   totalOpenFiles++;
+                       if(firstIteration) {
+                           totalOpenFiles++; // the one we are about to open
                    queue.push(this);
+                           firstIteration = false;
+                       }
+                       // Do it here to try to avoid livelock
+                       
                    if(totalOpenFiles > maxOpenFiles) {
-                       PooledRandomAccessFile fClose =
-                           (PooledRandomAccessFile)(queue.pop());
+                           fClose = (PooledRandomAccessFile)(queue.pop());
+                       }
+                   }
                        // Close LRU
-                       // Since this is LRU we shouldn't have lock contention
+                   // Since this is MRU we shouldn't have lock contention
                        if(fClose == this)
                            throw new IllegalStateException("aaaaargh! Popped self!");
-                       fClose.closeRAF();
-                   }
+                   if(fClose != null) fClose.closeRAF();
                }
                raf = new RandomAccessFile(filename, mode);
                if(position != 0) {
@@ -129,10 +139,19 @@
                position = raf.getFilePointer();
            } catch (IOException e) {
                closed = true;
+               position = 0;
+           } catch (Throwable t) {
+               Core.logger.log(this, "Caught "+t+" saving file pointer for "+
+                               raf, Logger.ERROR);
            }
            try {
                raf.close();
-           } catch (IOException e) {}
+           } catch (IOException e) {
+           } catch (Throwable t) {
+               Core.logger.log(this, "Caught "+t+" closing "+raf, 
+                               Logger.ERROR);
+               // assume it is closed...
+           }
            synchronized(RandomAccessFilePool.this) {
                totalOpenFiles--;
            }

_______________________________________________
cvs mailing list
[EMAIL PROTECTED]
http://dodo.freenetproject.org/cgi-bin/mailman/listinfo/cvs

Reply via email to