Author: toad
Date: 2006-11-11 17:05:05 +0000 (Sat, 11 Nov 2006)
New Revision: 10887

Modified:
   trunk/freenet/src/freenet/node/Node.java
   trunk/freenet/src/freenet/store/BerkeleyDBFreenetStore.java
Log:
More store refactoring. Delete old "if no store, move cache to store" hack.

Modified: trunk/freenet/src/freenet/node/Node.java
===================================================================
--- trunk/freenet/src/freenet/node/Node.java    2006-11-11 16:30:23 UTC (rev 
10886)
+++ trunk/freenet/src/freenet/node/Node.java    2006-11-11 17:05:05 UTC (rev 
10887)
@@ -1093,39 +1093,6 @@
                        throw new NodeInitException(EXIT_STORE_OTHER, msg);
                }

-               
-               String chkStorePath = 
storeDir.getPath()+File.separator+"store-"+portNumber;
-               String chkCachePath = 
storeDir.getPath()+File.separator+"cache-"+portNumber;
-               String pkStorePath  = 
storeDir.getPath()+File.separator+"pubkeystore-"+portNumber;
-               String pkCachePath  = 
storeDir.getPath()+File.separator+"pubkeycache-"+portNumber;
-               String sskStorePath = 
storeDir.getPath()+File.separator+"sskstore-"+portNumber;
-               String sskCachePath = 
storeDir.getPath()+File.separator+"sskcache-"+portNumber;
-               File chkStoreFile = new File(chkStorePath);
-               File chkCacheFile = new File(chkCachePath);
-               File pkStoreFile = new File(pkStorePath);
-               File pkCacheFile = new File(pkCachePath);
-               File sskStoreFile = new File(sskStorePath);
-               File sskCacheFile = new File(sskCachePath);
-               
-               // Upgrade
-               if(this.lastVersion < 927) {
-                       if(chkStoreFile.exists() && !chkCacheFile.exists()) {
-                               System.err.println("Renaming CHK store to CHK 
cache.");
-                               if(!chkStoreFile.renameTo(chkCacheFile))
-                                       throw new 
NodeInitException(EXIT_STORE_OTHER, "Could not migrate to two level cache: 
Could not rename "+chkStoreFile+" to "+chkCacheFile);
-                       }
-                       if(pkStoreFile.exists() && !pkCacheFile.exists()) {
-                               System.err.println("Renaming PK store to PK 
cache.");
-                               if(!pkStoreFile.renameTo(pkCacheFile))
-                                       throw new 
NodeInitException(EXIT_STORE_OTHER, "Could not migrate to two level cache: 
Could not rename "+pkStoreFile+" to "+pkCacheFile);
-                       }
-                       if(sskStoreFile.exists() && !sskCacheFile.exists()) {
-                               System.err.println("Renaming SSK store to SSK 
cache.");
-                               if(!sskStoreFile.renameTo(sskCacheFile))
-                                       throw new 
NodeInitException(EXIT_STORE_OTHER, "Could not migrate to two level cache: 
Could not rename "+sskStoreFile+" to "+sskCacheFile);
-                       }
-               }
-
                maxStoreKeys = maxTotalKeys / 2;
                maxCacheKeys = maxTotalKeys - maxStoreKeys;

@@ -1171,26 +1138,34 @@

                
envMutableConfig.setCacheSize(nodeConfig.getLong("databaseMaxMemory"));

+               String suffix = "-" + portNumber;
+               
                try {
                        Logger.normal(this, "Initializing CHK Datastore");
                        System.out.println("Initializing CHK Datastore 
("+maxStoreKeys+" keys)");
-                       chkDatastore = 
BerkeleyDBFreenetStore.construct(lastVersion, "", chkStorePath, maxStoreKeys, 
CHKBlock.DATA_LENGTH, CHKBlock.TOTAL_HEADERS_LENGTH, true, 
BerkeleyDBFreenetStore.TYPE_CHK);
+                       chkDatastore = 
BerkeleyDBFreenetStore.construct(lastVersion, "", storeDir, true, suffix, 
maxStoreKeys, 
+                                       CHKBlock.DATA_LENGTH, 
CHKBlock.TOTAL_HEADERS_LENGTH, true, BerkeleyDBFreenetStore.TYPE_CHK);
                        Logger.normal(this, "Initializing CHK Datacache");
                        System.out.println("Initializing CHK Datacache 
("+maxCacheKeys+":"+maxCacheKeys+" keys)");
-                       chkDatacache = 
BerkeleyDBFreenetStore.construct(lastVersion, "", chkCachePath, maxCacheKeys, 
CHKBlock.DATA_LENGTH, CHKBlock.TOTAL_HEADERS_LENGTH, true, 
BerkeleyDBFreenetStore.TYPE_CHK);
+                       chkDatacache = 
BerkeleyDBFreenetStore.construct(lastVersion, "", storeDir, false, suffix, 
maxCacheKeys, 
+                                       CHKBlock.DATA_LENGTH, 
CHKBlock.TOTAL_HEADERS_LENGTH, true, BerkeleyDBFreenetStore.TYPE_CHK);
                        Logger.normal(this, "Initializing pubKey Datastore");
                        System.out.println("Initializing pubKey Datastore");
-                       pubKeyDatastore = 
BerkeleyDBFreenetStore.construct(lastVersion, "", pkStorePath, maxStoreKeys, 
DSAPublicKey.PADDED_SIZE, 0, true, BerkeleyDBFreenetStore.TYPE_PUBKEY);
+                       pubKeyDatastore = 
BerkeleyDBFreenetStore.construct(lastVersion, "", storeDir, true, suffix, 
maxStoreKeys, 
+                                       DSAPublicKey.PADDED_SIZE, 0, true, 
BerkeleyDBFreenetStore.TYPE_PUBKEY);
                        Logger.normal(this, "Initializing pubKey Datacache");
                        System.out.println("Initializing pubKey Datacache 
("+maxCacheKeys+" keys)");
-                       pubKeyDatacache = 
BerkeleyDBFreenetStore.construct(lastVersion, "", pkCachePath, maxCacheKeys, 
DSAPublicKey.PADDED_SIZE, 0, true, BerkeleyDBFreenetStore.TYPE_PUBKEY);
+                       pubKeyDatacache = 
BerkeleyDBFreenetStore.construct(lastVersion, "", storeDir, false, suffix, 
maxCacheKeys, 
+                                       DSAPublicKey.PADDED_SIZE, 0, true, 
BerkeleyDBFreenetStore.TYPE_PUBKEY);
                        // FIXME can't auto-fix SSK stores.
                        Logger.normal(this, "Initializing SSK Datastore");
                        System.out.println("Initializing SSK Datastore");
-                       sskDatastore = 
BerkeleyDBFreenetStore.construct(lastVersion, "", sskStorePath, maxStoreKeys, 
SSKBlock.DATA_LENGTH, SSKBlock.TOTAL_HEADERS_LENGTH, false, 
BerkeleyDBFreenetStore.TYPE_SSK);
+                       sskDatastore = 
BerkeleyDBFreenetStore.construct(lastVersion, "", storeDir, true, suffix, 
maxStoreKeys, 
+                                       SSKBlock.DATA_LENGTH, 
SSKBlock.TOTAL_HEADERS_LENGTH, false, BerkeleyDBFreenetStore.TYPE_SSK);
                        Logger.normal(this, "Initializing SSK Datacache");
                        System.out.println("Initializing SSK Datacache 
("+maxCacheKeys+" keys)");
-                       sskDatacache = 
BerkeleyDBFreenetStore.construct(lastVersion, "", sskCachePath, maxStoreKeys, 
SSKBlock.DATA_LENGTH, SSKBlock.TOTAL_HEADERS_LENGTH, false, 
BerkeleyDBFreenetStore.TYPE_SSK);
+                       sskDatacache = 
BerkeleyDBFreenetStore.construct(lastVersion, "", storeDir, true, suffix, 
maxStoreKeys, 
+                                       SSKBlock.DATA_LENGTH, 
SSKBlock.TOTAL_HEADERS_LENGTH, false, BerkeleyDBFreenetStore.TYPE_SSK);
                } catch (FileNotFoundException e1) {
                        String msg = "Could not open datastore: "+e1;
                        Logger.error(this, msg, e1);

Modified: trunk/freenet/src/freenet/store/BerkeleyDBFreenetStore.java
===================================================================
--- trunk/freenet/src/freenet/store/BerkeleyDBFreenetStore.java 2006-11-11 
16:30:23 UTC (rev 10886)
+++ trunk/freenet/src/freenet/store/BerkeleyDBFreenetStore.java 2006-11-11 
17:05:05 UTC (rev 10887)
@@ -83,9 +83,12 @@
        private boolean closed;
        private final static byte[] dummy = new byte[0];

-       public static BerkeleyDBFreenetStore construct(int lastVersion, String 
prefix, String storeDir, long maxStoreKeys, int blockSize, int headerSize, 
boolean throwOnTooFewKeys, short type) throws Exception {
+       public static BerkeleyDBFreenetStore construct(int lastVersion, String 
prefix, File baseStoreDir, boolean isStore, 
+                       String suffix, long maxStoreKeys, int blockSize, int 
headerSize, boolean throwOnTooFewKeys, short type) throws Exception {

-               File dir = new File(storeDir);
+               File dir = new File(baseStoreDir, 
+                               typeName(type) + (isStore ? "store" : "cache") 
+ suffix); 
+               
                if(!dir.exists())
                        dir.mkdir();

@@ -157,11 +160,21 @@

                        env = new Environment(dbDir, envConfig);

-                       tmp = new BerkeleyDBFreenetStore(env, dir, dbDir, 
storeDir, maxStoreKeys, blockSize, headerSize, type);
+                       tmp = new BerkeleyDBFreenetStore(env, dir, dbDir, 
maxStoreKeys, blockSize, headerSize, type);
                }
                return tmp;
        }

+       private static String typeName(short type) {
+               if(type == TYPE_CHK)
+                       return "";
+               else if(type == TYPE_SSK)
+                       return "ssk";
+               else if(type == TYPE_PUBKEY)
+                       return "pubkey";
+               else throw new Error("No such type "+type);
+       }
+
        public static BerkeleyDBFreenetStore construct(String prefix, String 
storeDir, long maxChkBlocks, int blockSize, int headerSize, boolean 
throwOnTooFewKeys) throws IOException, DatabaseException {

                File dir = new File(storeDir);
@@ -629,7 +642,7 @@
      * @param the directory where the store is located
      * @throws FileNotFoundException if the dir does not exist and could not 
be created
      */
-       public BerkeleyDBFreenetStore(Environment env, File dir, File dbDir, 
String storeDir, long maxChkBlocks, int blockSize, int headerSize, short type) 
throws Exception {
+       public BerkeleyDBFreenetStore(Environment env, File dir, File dbDir, 
long maxChkBlocks, int blockSize, int headerSize, short type) throws Exception {
                logMINOR = Logger.shouldLog(Logger.MINOR, this);
                this.dataBlockSize = blockSize;
                this.headerBlockSize = headerSize;
@@ -643,7 +656,7 @@
                dbConfig.setTransactional(true);
                chkDB = environment.openDatabase(null,"CHK",dbConfig);

-               fixSecondaryFile = new File(storeDir, "recreate_secondary_db");
+               fixSecondaryFile = new File(dir, "recreate_secondary_db");
                fixSecondaryFile.delete();

                // Initialize secondary CHK database sorted on accesstime


Reply via email to