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

Modified Files:
        NativeFSDirectory.java 
Log Message:
6236:
Add support for a maximum number of FDs used for open files by NativeFSDir, with 
pooling.
Remove reference to BlackLRUQueue in OCM - not used any more, was a dirty hack.
Throw an NPE slightly earlier in some code tracking bug in.


Index: NativeFSDirectory.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/fs/dir/NativeFSDirectory.java,v
retrieving revision 1.162
retrieving revision 1.163
diff -u -r1.162 -r1.163
--- NativeFSDirectory.java      11 Oct 2003 20:00:18 -0000      1.162
+++ NativeFSDirectory.java      13 Oct 2003 15:42:00 -0000      1.163
@@ -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();
+       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,6 +708,7 @@
         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,this); // FIXME: EVIL
         if(!root.isDirectory() && !root.mkdir())
@@ -1687,7 +1692,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;
@@ -1899,7 +1904,7 @@
                                                totalOpenFiles++;
                                        }
                     rafPos = -1;
-                    raf = new RandomAccessFile(getFile(), "rw");
+                    raf = rafpool.open(getFile(), "rw");
                 }
             }
             touch();
@@ -1938,7 +1943,7 @@
                         if(raf != null)
                             try {
                                 rafPos = -1;
-                                raf.getFD().sync();
+                                raf.sync();
                                 raf.close();
                                                                
synchronized(totalOpenFilesSync) {
                                                                        
totalOpenFiles--;
@@ -1964,7 +1969,7 @@
         public void flush() throws java.io.IOException {
             synchronized(rafSync) {
                 if(raf != null)
-                    raf.getFD().sync();
+                    raf.sync();
             }
             touch();
         }
@@ -2172,7 +2177,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()",
@@ -2244,7 +2249,7 @@
                         }
                         try {
                             if(b) {
-                                raf = new RandomAccessFile(g, "rw");
+                                                               raf = rafpool.open(g, 
"rw");
                                                                
synchronized(totalOpenFilesSync) {
                                                                        
totalOpenFiles++;
                                                                }
@@ -2369,7 +2374,7 @@
                             tempSpaceUsed += x;
                         }
                     }
-                                       raf = new RandomAccessFile(g, "rw");
+                                       raf = rafpool.open(g, "rw");
                                        synchronized(totalOpenFilesSync) {
                                                totalOpenFiles++;
                                        }
@@ -2872,7 +2877,7 @@
             public void flush() throws java.io.IOException {
                 if(dead()) return;
                 synchronized(rafSync) {
-                    raf.getFD().sync();
+                    raf.sync();
                 }
             }
 

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

Reply via email to