Author: toad
Date: 2008-03-11 15:00:44 +0000 (Tue, 11 Mar 2008)
New Revision: 18459

Modified:
   trunk/freenet/src/freenet/store/BerkeleyDBFreenetStore.java
Log:
Logging. Track running fetches to make it easier to identify database stalls.

Modified: trunk/freenet/src/freenet/store/BerkeleyDBFreenetStore.java
===================================================================
--- trunk/freenet/src/freenet/store/BerkeleyDBFreenetStore.java 2008-03-11 
14:59:23 UTC (rev 18458)
+++ trunk/freenet/src/freenet/store/BerkeleyDBFreenetStore.java 2008-03-11 
15:00:44 UTC (rev 18459)
@@ -1214,19 +1214,23 @@
                }
        }

+       private int runningFetches;
+       
        /**
         * Retrieve a block.
         * @param dontPromote If true, don't promote data to the top of the LRU 
if we fetch it.
         * @return null if there is no such block stored, otherwise the block.
         */
        public StorableBlock fetch(byte[] routingkey, byte[] fullKey, boolean 
dontPromote) throws IOException {
+               DatabaseEntry routingkeyDBE = new DatabaseEntry(routingkey);
+               DatabaseEntry blockDBE = new DatabaseEntry();
+               int running;
                synchronized(this) {
                        if(closed)
                                return null;
+                       running = runningFetches++;
                }

-               DatabaseEntry routingkeyDBE = new DatabaseEntry(routingkey);
-               DatabaseEntry blockDBE = new DatabaseEntry();
                Cursor c = null;
                Transaction t = null;
                try {
@@ -1241,7 +1245,7 @@
                        * take the write lock. Neither can relinquish the read 
in order for the other to
                        * take the write, so we're screwed.
                        */
-                       if(logMINOR) Logger.minor(this, "Fetching 
"+HexUtil.bytesToHex(routingkey)+" dontPromote="+dontPromote+" for "+callback);
+                       if(logMINOR) Logger.minor(this, "Fetching 
"+HexUtil.bytesToHex(routingkey)+" dontPromote="+dontPromote+" for "+callback+" 
running fetches: "+running);
                        if(c.getSearchKey(routingkeyDBE,blockDBE,LockMode.RMW)
                                        !=OperationStatus.SUCCESS) {
                                c.close();
@@ -1251,6 +1255,7 @@
                                synchronized(this) {
                                        misses++;
                                }
+                               if(logMINOR) Logger.minor(this, "Not found");
                                return null;
                        }

@@ -1258,6 +1263,7 @@

                        StorableBlock block = null;

+                       if(logMINOR) Logger.minor(this, "Reading block 
"+storeBlock.offset+"...");
                        try {
                                byte[] header = new byte[headerBlockSize];
                                byte[] data = new byte[dataBlockSize];
@@ -1338,6 +1344,12 @@
                        Logger.error(this, "Caught "+ex, ex);
                        ex.printStackTrace();
                        throw new IOException(ex.getMessage());
+               } finally {
+                       int x;
+                       synchronized(this) {
+                               x = runningFetches--;
+                       }
+                       if(logMINOR) Logger.minor(this, "Running fetches now 
"+x);
                }
        }



Reply via email to