Update of /cvsroot/freenet/freenet/src/freenet/node
In directory sc8-pr-cvs1:/tmp/cvs-serv7338/freenet/src/freenet/node

Modified Files:
        FailureTable.java 
Log Message:
6300:
The removal of the functional checkpointing code in the FailureTable made things 
_very_ unhappy, so I put it back.  
This may not be the best way to handle it, but I think it'll be pretty effective for 
now.
If it needs to be taken back out, at least make sure it doesn't run-away checkpoint 
itself.

Index: FailureTable.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/node/FailureTable.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -w -r1.20 -r1.21
--- FailureTable.java   2 Nov 2003 03:18:46 -0000       1.20
+++ FailureTable.java   3 Nov 2003 00:40:49 -0000       1.21
@@ -81,6 +81,7 @@
     protected int maxSize;
        protected int maxItemsSize;
     protected long maxMillis;
+       protected long cpMillis;
     protected long lastCp = 0;
 
     protected Hashtable failedKeys; // of FailureEntry's
@@ -98,10 +99,12 @@
     public FailureTable(int size, int itemSize, long millis) {
         maxSize = size;
         maxMillis = millis;
+               cpMillis = millis;
         maxItemsSize = itemSize;
         failedKeys = new Hashtable();
         entries = new DoublyLinkedListImpl();
         items = new DoublyLinkedListImpl();
+        lastCp = System.currentTimeMillis();
     }
 
     /**
@@ -125,15 +128,6 @@
                fe.failed(hopsToLive, time);
                entries.push(fe);
         }
-        while (entries.size() > maxSize) {
-            fe = (FailureEntry) entries.shift();
-            failedKeys.remove(fe.key);
-            Core.diagnostics.occurrenceContinuous("failureTableBlocks",
-                                                  (double) fe.blocks);
-        }
-        while (items.size() > maxItemsSize) {
-               FailItem fi = (FailItem) items.shift();
-        }
     }
 
     /**
@@ -179,19 +173,26 @@
      * Purges the queue.
      */
     public synchronized void checkpoint() {
-       // Will need old stuff later, don't bother
-//        lastCp = System.currentTimeMillis();
-//        long thresh = lastCp - maxMillis;
-//        while (queue.size() > 0) {
-//            FailureEntry fe = (FailureEntry) queue.top();
-//            if (fe.time > thresh) {
-//                break;
-//            }
-//            queue.pop();
-//            failedKeys.remove(fe.key);
-//            Core.diagnostics.occurrenceContinuous("failureTableBlocks",
-//                                                  (double) fe.blocks);
-//        }
+               long lastCp = System.currentTimeMillis();
+               int numEntries = 0;
+               int numItems = 0;
+        FailureEntry fe;
+               while (entries.size() > maxSize) {
+                       numEntries++;
+                       fe = (FailureEntry) entries.shift();
+                       failedKeys.remove(fe.key);
+                       Core.diagnostics.occurrenceContinuous("failureTableBlocks",
+                                                                                      
           (double) fe.blocks);
+               }
+               while (items.size() > maxItemsSize) {
+                       numItems++;
+                       FailItem fi = (FailItem) items.shift();
+               }
+               long itemSubtract = (long)(( numItems - maxItemsSize*.10 ) * 1000);
+               long entrySubtract = (long)(( numEntries - maxSize*.10 ) * 1000);
+               long subtract = Math.max(Math.max(0,itemSubtract),entrySubtract);
+               cpMillis-=subtract==0?-1000:subtract;
+               cpMillis = Math.min(maxMillis,cpMillis);
     }
 
     public String getCheckpointName() {
@@ -199,14 +200,14 @@
     }
 
     public long nextCheckpoint() {
-        return Math.max(System.currentTimeMillis(),
-                        lastCp + maxMillis / 10);
+        return lastCp + cpMillis;
     }
 
     public synchronized void writeHtml(PrintWriter pw) {
         pw.println("<b>max size:</b> " + maxSize + "<br>");
         pw.println("<b>current size:</b> " + failedKeys.size() + "<br>");
-        pw.println("<b>seconds it lasts:</b> " + maxMillis / 1000 + "<br>");
+               pw.println("<b>seconds entries last:</b> " + maxMillis / 1000 + 
"<br>");
+               pw.println("<b>seconds between cleanings:</b> " + cpMillis / 1000 + 
"<br>");
         pw.println("<table border=1>");
         pw.println("<tr><th>Key</th><th>Blocked HTL</th>" 
                    + "<th>Age</th><th># of Blocks</th>" 

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

Reply via email to