Update of /cvsroot/freenet/freenet/src/freenet/fs/dir
In directory sc8-pr-cvs1:/tmp/cvs-serv25857/src/freenet/fs/dir

Modified Files:
      Tag: stable
        Buffer.java CircularBuffer.java FSDirectory.java 
        FileNumber.java NativeFSDirectory.java NullBuffer.java 
Log Message:
5029: Merge from unstable after months of work. MASSIVE changes.
Highlights:
* Next Generation Routing, massive related changes
* Major changes to handling of messages and connections (PeerHandler and related 
changes)
* Even more non-blocking I/O
* Documentation improvements
* Lots of new diagnostics and config options
* Lots of bug fixes and performance tweaking
* Probably lots of new bugs too!


Index: Buffer.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/fs/dir/Buffer.java,v
retrieving revision 1.2
retrieving revision 1.2.6.1
diff -u -w -r1.2 -r1.2.6.1
--- Buffer.java 12 Sep 2002 16:05:52 -0000      1.2
+++ Buffer.java 28 Oct 2003 20:20:31 -0000      1.2.6.1
@@ -10,6 +10,11 @@
 
     long length();
 
+    /**
+     * Current length of buffer - number of bytes IN CACHE
+     */
+    long realLength();
+    
     boolean failed();
 
     InputStream getInputStream() throws IOException;

Index: CircularBuffer.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/fs/dir/CircularBuffer.java,v
retrieving revision 1.17.4.1
retrieving revision 1.17.4.2
diff -u -w -r1.17.4.1 -r1.17.4.2
--- CircularBuffer.java 4 Jul 2003 02:45:07 -0000       1.17.4.1
+++ CircularBuffer.java 28 Oct 2003 20:20:31 -0000      1.17.4.2
@@ -24,6 +24,8 @@
     
     protected DoublyLinkedList readers = new DoublyLinkedListImpl();
 
+    CircularOutputStream cos = null;
+    
     /**
      * @param lapbuf   buffer to do laps over
      * @param vlength  virtual length -- total length of tunneled data
@@ -199,7 +201,7 @@
      */
     public OutputStream getOutputStream() throws IOException,
                                                  BufferException {
-        return new CircularOutputStream();
+        return cos = new CircularOutputStream();
     }    
 
     boolean outAtStart = false;
@@ -327,6 +329,11 @@
         protected void finalize() throws Throwable {
             kick();
         }
+    }
+    
+    public long realLength() {
+       if(cos == null) return vlength;
+       return (lap+1) * lapbuf.length() - cos.wlim;
     }
 }
 

Index: FSDirectory.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/fs/dir/FSDirectory.java,v
retrieving revision 1.6.4.1.2.4
retrieving revision 1.6.4.1.2.5
diff -u -w -r1.6.4.1.2.4 -r1.6.4.1.2.5
--- FSDirectory.java    1 Jul 2003 02:27:13 -0000       1.6.4.1.2.4
+++ FSDirectory.java    28 Oct 2003 20:20:31 -0000      1.6.4.1.2.5
@@ -517,6 +517,10 @@
             return length;
         }
 
+       public final long realLength() {
+           throw new UnsupportedOperationException();
+       }
+       
         public final boolean failed() {
             return failed;
         }

Index: FileNumber.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/fs/dir/FileNumber.java,v
retrieving revision 1.4.4.2
retrieving revision 1.4.4.2.2.1
diff -u -w -r1.4.4.2 -r1.4.4.2.2.1
--- FileNumber.java     9 Feb 2003 04:03:26 -0000       1.4.4.2
+++ FileNumber.java     28 Oct 2003 20:20:31 -0000      1.4.4.2.2.1
@@ -15,8 +15,8 @@
     
     final int dirID;
     final byte[] key;
-
-    final long hashCode;
+    final int hashCode;
+    final long longHashCode;
 
     /**
      * Wrap a FileNumber as a FileNumber (with a different dirID)
@@ -26,6 +26,7 @@
     FileNumber(int dirID, FileNumber fn) {
         this.dirID = dirID;
         this.key = fn.key;
+        longHashCode = fn.longHashCode;
         hashCode = fn.hashCode;
     }
     
@@ -37,7 +38,9 @@
     FileNumber(int dirID, byte[] key) {
         this.dirID = dirID;
         this.key = key;
-        hashCode = Fields.longHashCode(key);
+       longHashCode = Fields.longHashCode(key);
+
+       hashCode = (int)((longHashCode >>> 32) ^ longHashCode);
     }
 
     /**
@@ -114,13 +117,11 @@
     }
 
     public final long longHashCode() {
-       return hashCode;
+       return longHashCode;
     }
     
     public final int hashCode() {
-       long x = ((long)hashCode) & 0xFFFFFFFFL; // sixteen ones in binary
-       long y = hashCode >>> 32;
-       return (int)(x ^ y);
+       return hashCode;
     }
     
     /** get directory ID

Index: NativeFSDirectory.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/fs/dir/NativeFSDirectory.java,v
retrieving revision 1.66.2.16.2.23
retrieving revision 1.66.2.16.2.24
diff -u -w -r1.66.2.16.2.23 -r1.66.2.16.2.24
--- NativeFSDirectory.java      15 Aug 2003 03:05:45 -0000      1.66.2.16.2.23
+++ NativeFSDirectory.java      28 Oct 2003 20:20:31 -0000      1.66.2.16.2.24
@@ -23,6 +23,8 @@
 import freenet.support.ReversibleSortedMap;
 import freenet.support.SkiplistWithHashMap;
 import freenet.support.IteratorEnumeration;
+import freenet.support.RandomAccessFilePool;
+import freenet.support.PooledRandomAccessFile;
 
 import freenet.Key;
 import freenet.Storables;
@@ -53,6 +55,7 @@
     long tempSpaceUsed = 0;
     long maxTempSpaceUsed;
     final Object spaceUsedSync = new Object();
+       public final RandomAccessFilePool rafpool;
 
     NativeBuffer leastRecentlyUsed;
     NativeBuffer mostRecentlyUsed;
@@ -678,7 +681,8 @@
      * @param blockSize the number of bytes in a block in the underlying FS
      */
     public NativeFSDirectory(File root, long size, int blockSize, 
-                             boolean doIndex, float maxTempFraction)
+                             boolean doIndex, float maxTempFraction,
+                                                        int maxFilesOpen)
         throws IOException {
         this.doIndex = doIndex;
         System.gc();
@@ -704,8 +708,9 @@
         this.getFileBuffer.append(rootAsString);
         this.getFileBuffer.append(File.separator);
         this.getFileResetLength = rootAsString.length() + seplen;
+               this.rafpool = new RandomAccessFilePool(maxFilesOpen);
         // FIXME: 64 above.
-        logDEBUG = Core.logger.shouldLog(Logger.DEBUG); // FIXME: EVIL
+        logDEBUG = Core.logger.shouldLog(Logger.DEBUG,this); // FIXME: EVIL
         if(!root.isDirectory() && !root.mkdir())
             throw new IOException("couldn't create native directory: 
"+root.getCanonicalPath());
         File temp = new File(root, "temp");
@@ -1121,7 +1126,7 @@
      */
     public File getTempFile(FileNumber fn)
     {
-        return getTempFile(fn, Core.randSource.nextLong());
+        return getTempFile(fn, Core.getRandSource().nextLong());
     }
 
     public File getTempFile(FileNumber fn, long rand)
@@ -1513,6 +1518,10 @@
             return (buffer==null) ? -1 : buffer.length();
         }
 
+               public long realLength() {
+                       return (buffer==null) ? 0 : buffer.realLength();
+               }
+               
         public boolean failed() {
             return (buffer==null) ? false : buffer.failed();
         }
@@ -1631,7 +1640,7 @@
     protected void verifyList(boolean force) {
         //Core.logger.log(this, "Verifying LRU list", Logger.DEBUG);
         if(!force) {
-            if(verifyMode != ALWAYS && Core.randSource.nextInt() != 1) return;
+            if(verifyMode != ALWAYS && Core.getRandSource().nextInt() != 1) return;
             if(verifyMode == NEVER) return;
         }
         NativeBuffer b = leastRecentlyUsed;
@@ -1668,6 +1677,15 @@
         }
     }
     
+       public int totalOpenFiles() {
+               synchronized(totalOpenFilesSync) {
+                       return totalOpenFiles;
+               }
+       }
+       
+       Object totalOpenFilesSync = new Object();
+       int totalOpenFiles = 0;
+       
     class NativeBuffer implements Buffer, Comparable {
         FileNumber fn;
         byte status = 0;
@@ -1678,7 +1696,7 @@
         static final byte ALMOSTCOMMITTED = 3;
         long size = 0;
         long tempRand = -1;
-        RandomAccessFile raf;
+        PooledRandomAccessFile raf;
         final Object rafSync = new Object();
         Object insSync;
         Object outsSync;
@@ -1768,7 +1786,7 @@
                                             ") for " + out + " to " +
                                             " move from " + pos+
                                             " max was "+ newLen + " on " +
-                                            fn, Logger.DEBUG);
+                                            fn+" x = "+x, Logger.DEBUG);
                         newLen = x;
                     }
                 }
@@ -1859,7 +1877,7 @@
             }
             else {
                 status = TEMPORARY;
-                tempRand = Core.randSource.nextLong();
+                tempRand = Core.getRandSource().nextLong();
             }
             File f = getFile();
             //         if(logDEBUG)
@@ -1886,8 +1904,11 @@
                 if(status == FAILED) throw new DirectoryException
                                          ("Trying to open failed buffer"+fn);
                 if(raf == null) {
+                                       synchronized(totalOpenFilesSync) {
+                                               totalOpenFiles++;
+                                       }
                     rafPos = -1;
-                    raf = new RandomAccessFile(getFile(), "rw");
+                    raf = rafpool.open(getFile(), "rw");
                 }
             }
             touch();
@@ -1926,8 +1947,11 @@
                         if(raf != null)
                             try {
                                 rafPos = -1;
-                                raf.getFD().sync();
+                                raf.sync();
                                 raf.close();
+                                                               
synchronized(totalOpenFilesSync) {
+                                                                       
totalOpenFiles--;
+                                                               }
                                 raf = null;
                             } catch (IOException e) {
                                 if (Core.logger.shouldLog(Core.logger.ERROR))
@@ -1949,7 +1973,7 @@
         public void flush() throws java.io.IOException {
             synchronized(rafSync) {
                 if(raf != null)
-                    raf.getFD().sync();
+                    raf.sync();
             }
             touch();
         }
@@ -1959,6 +1983,13 @@
          */
         public long length() { return size; }
     
+               /**
+                * Current length of file - the number of bytes we actually have cached
+                */
+               public long realLength() {
+                       return getFile().length();
+               }
+               
         public boolean failed() { return status == FAILED; }
 
         /**
@@ -2157,7 +2188,7 @@
                 try { // We can't have the status change while we are sync'ing
                     synchronized(rafSync) { // locking: take this first
                         if(raf != null)
-                            raf.getFD().sync();
+                            raf.sync();
                     }
                 } catch (IOException e) {
                     Core.logger.log(this, "IOException trying to sync in commit()",
@@ -2194,8 +2225,12 @@
                         boolean b = (raf != null);
                         rafPos = -1;
                         try {
-                            if(b)
+                            if(b) {
+                                                               
synchronized(totalOpenFilesSync) {
+                                                                       
totalOpenFiles--;
+                                                               }
                                 raf.close();
+                                                       }
                             raf = null;
                         } catch (IOException e) {
                             Core.logger.log(this, "IOException while closing in "
@@ -2206,7 +2241,6 @@
                         finally {
                             raf = null;
                         }
-                        raf = null;
                         if(status != ALMOSTCOMMITTED)
                             throw new DirectoryException("reallyCommit() called on 
file "+
                                                          "not ALMOSTCOMMITTED");
@@ -2225,12 +2259,17 @@
                                 DirectoryException("finalizing rename failed");
                         }
                         try {
-                            if(b)
-                                raf = new RandomAccessFile(g, "rw");
+                            if(b) {
+                                                               raf = rafpool.open(g, 
"rw");
+                                                               
synchronized(totalOpenFilesSync) {
+                                                                       
totalOpenFiles++;
+                                                               }
+                                                       }
                         } catch (IOException e) {
                             Core.logger.log(this, "IOException reopening"+
                                             " file in commit()", e, 
                                             Core.logger.NORMAL);
+                                                       raf = null;
                             throw new DirectoryException
                                 ("IOException reopening file in commit()");
                         }
@@ -2310,9 +2349,14 @@
                 touch();
                 synchronized(rafSync) {
                     rafPos = -1;
-                    if(raf != null) raf.close();
+                    if(raf != null) {
+                                               synchronized(totalOpenFilesSync) {
+                                                       totalOpenFiles--;
+                                               }
+                                               raf.close();
+                                       }
                     File f = getFile();
-                    tempRand = Core.randSource.nextLong();
+                    tempRand = Core.getRandSource().nextLong();
                     File g = getTempFile(fn, tempRand);
                     try {
                         if(!f.renameTo(g)) {
@@ -2341,7 +2385,10 @@
                             tempSpaceUsed += x;
                         }
                     }
-                    raf = new RandomAccessFile(g, "rw");
+                                       raf = rafpool.open(g, "rw");
+                                       synchronized(totalOpenFilesSync) {
+                                               totalOpenFiles++;
+                                       }
                 }
             }
         }
@@ -2841,7 +2888,7 @@
             public void flush() throws java.io.IOException {
                 if(dead()) return;
                 synchronized(rafSync) {
-                    raf.getFD().sync();
+                    raf.sync();
                 }
             }
 

Index: NullBuffer.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/fs/dir/NullBuffer.java,v
retrieving revision 1.1.1.1
retrieving revision 1.1.1.1.6.1
diff -u -w -r1.1.1.1 -r1.1.1.1.6.1
--- NullBuffer.java     13 Jan 2002 05:24:36 -0000      1.1.1.1
+++ NullBuffer.java     28 Oct 2003 20:20:32 -0000      1.1.1.1.6.1
@@ -19,6 +19,10 @@
         return 0;
     }
 
+    public final long realLength() {
+       return 0;
+    }
+    
     public final boolean failed() {
         return false;
     }

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

Reply via email to