Author: toad
Date: 2007-04-14 15:05:42 +0000 (Sat, 14 Apr 2007)
New Revision: 12685

Modified:
   trunk/freenet/src/freenet/store/BerkeleyDBFreenetStore.java
Log:
Logging.
Auto-delete when find a block off the end of the store file.

Modified: trunk/freenet/src/freenet/store/BerkeleyDBFreenetStore.java
===================================================================
--- trunk/freenet/src/freenet/store/BerkeleyDBFreenetStore.java 2007-04-14 
14:04:36 UTC (rev 12684)
+++ trunk/freenet/src/freenet/store/BerkeleyDBFreenetStore.java 2007-04-14 
15:05:42 UTC (rev 12685)
@@ -595,9 +595,9 @@
                        System.out.println("Keys in store: db 
"+chkBlocksInDatabase+" file "+chkBlocksFromFile+" / max "+maxChkBlocks);

                        if(chkBlocksInDatabase > chkBlocksFromFile) {
-                               System.out.println("More keys in database than 
in store, checking for holes...");
-                               dontCheckForHolesShrinking = true;
-                               checkForHoles(chkBlocksFromFile, false);
+                               System.out.println("More keys in database than 
in store!");
+                               //throw new DatabaseException("More keys in 
database than in store!");
+                               // FIXME reinstate if handling code doesn't work
                        }

                        if(((chkBlocksInStore == 0) && (chkBlocksFromFile != 
0)) ||
@@ -612,7 +612,7 @@
                                        }
                                        throw new DatabaseException("Keys in 
database: "+chkBlocksInStore+" but keys in file: "+chkBlocksFromFile);
                                } else if(!noCheck) {
-                                       long len = 
checkForHoles(chkBlocksFromFile, false);
+                                       long len = 
checkForHoles(chkBlocksFromFile, true);
                                        dontCheckForHolesShrinking = true;
                                        if(len < chkBlocksFromFile) {
                                                System.err.println("Truncating 
to "+len+" from "+chkBlocksFromFile+" as no non-holes after that point");
@@ -1339,11 +1339,12 @@
                try{
                        byte[] header = new byte[headerBlockSize];
                        byte[] data = new byte[dataBlockSize];
+                       try {
                        synchronized(chkStore) {
                                long seekTarget = 
storeBlock.offset*(long)(dataBlockSize+headerBlockSize);
                                try {
-                                       chkStore.seek(seekTarget);
-                               } catch (IOException ioe) {
+                                       chkStore.seek(seekTarget);
+                               } catch (IOException ioe) {
                                        if(seekTarget > (2l*1024*1024*1024)) {
                                                Logger.error(this, "Environment 
does not support files bigger than 2 GB?");
                                                System.out.println("Environment 
does not support files bigger than 2 GB? (exception to follow)");
@@ -1354,6 +1355,16 @@
                                chkStore.readFully(header);
                                chkStore.readFully(data);
                        }
+                       } catch (EOFException e) {
+                               Logger.error(this, "No block");
+                       c.close();
+                       c = null;
+                       chkDB.delete(t, routingkeyDBE);
+                       t.commit();
+                       t = null;
+                       addFreeBlock(storeBlock.offset, true, "Data off end of 
store file");
+                       return null;
+                       }


                        block = new CHKBlock(data,header,chk);
@@ -1456,11 +1467,22 @@
                try{
                        byte[] header = new byte[headerBlockSize];
                        byte[] data = new byte[dataBlockSize];
+                       try {
                        synchronized(chkStore) {
                                
chkStore.seek(storeBlock.offset*(long)(dataBlockSize+headerBlockSize));
                                chkStore.readFully(header);
                                chkStore.readFully(data);
                        }
+                       } catch (EOFException e) {
+                               Logger.error(this, "No block");
+                       c.close();
+                       c = null;
+                       chkDB.delete(t, routingkeyDBE);
+                       t.commit();
+                       t = null;
+                       addFreeBlock(storeBlock.offset, true, "Data off end of 
store file");
+                       return null;
+                       }


                        block = new SSKBlock(data,header,chk, true);
@@ -1580,10 +1602,21 @@
                byte[] data = new byte[dataBlockSize];
                if(logMINOR) Logger.minor(this, "Reading from store... 
"+storeBlock.offset+" ("+storeBlock.recentlyUsed+ ')');
                // When will java have pread/pwrite? :(
+               try {
                synchronized(chkStore) {
-                       
chkStore.seek(storeBlock.offset*(long)(dataBlockSize+headerBlockSize));
+                       
chkStore.seek(storeBlock.offset*(long)(dataBlockSize+headerBlockSize));
                        chkStore.readFully(data);
                }
+                       } catch (EOFException e) {
+                               Logger.error(this, "No block");
+                       c.close();
+                       c = null;
+                       chkDB.delete(t, routingkeyDBE);
+                       t.commit();
+                       t = null;
+                       addFreeBlock(storeBlock.offset, true, "Data off end of 
store file");
+                       return null;
+                       }
                if(logMINOR) Logger.minor(this, "Read");

                try {


Reply via email to