Author: j16sdiz
Date: 2008-07-31 11:40:49 +0000 (Thu, 31 Jul 2008)
New Revision: 21525
Modified:
branches/saltedhashstore/freenet/src/freenet/node/Node.java
branches/saltedhashstore/freenet/src/freenet/store/saltedhash/SaltedHashFreenetStore.java
branches/saltedhashstore/freenet/src/freenet/support/BinaryBloomFilter.java
branches/saltedhashstore/freenet/src/freenet/support/BloomFilter.java
branches/saltedhashstore/freenet/src/freenet/support/CountingBloomFilter.java
branches/saltedhashstore/freenet/src/freenet/support/NullBloomFilter.java
Log:
increase max k, make counting filter configurable
Modified: branches/saltedhashstore/freenet/src/freenet/node/Node.java
===================================================================
--- branches/saltedhashstore/freenet/src/freenet/node/Node.java 2008-07-31
11:37:25 UTC (rev 21524)
+++ branches/saltedhashstore/freenet/src/freenet/node/Node.java 2008-07-31
11:40:49 UTC (rev 21525)
@@ -1410,32 +1410,32 @@
System.out.println("Initializing CHK Datastore
(" + maxStoreKeys + " keys)");
chkDatastore = new CHKStore();
SaltedHashFreenetStore chkDataFS =
SaltedHashFreenetStore.construct(storeDir, "CHK-store",
- chkDatastore, this, maxStoreKeys,
0x4800000, shutdownHook);
+ chkDatastore, this, maxStoreKeys,
0x4800000, true, shutdownHook);
Logger.normal(this, "Initializing CHK
Datacache");
System.out.println("Initializing CHK Datacache
(" + maxCacheKeys + ':' + maxCacheKeys + " keys)");
chkDatacache = new CHKStore();
SaltedHashFreenetStore chkCacheFS =
SaltedHashFreenetStore.construct(storeDir, "CHK-cache",
- chkDatacache, this, maxCacheKeys,
0x4800000, shutdownHook);
+ chkDatacache, this, maxCacheKeys,
0x4800000, true, shutdownHook);
Logger.normal(this, "Initializing pubKey
Datastore");
System.out.println("Initializing pubKey
Datastore");
pubKeyDatastore = new PubkeyStore();
SaltedHashFreenetStore pubkeyDataFS =
SaltedHashFreenetStore.construct(storeDir, "PUBKEY-store",
- pubKeyDatastore, this, maxStoreKeys,
0x4800000, shutdownHook);
+ pubKeyDatastore, this, maxStoreKeys,
0x4800000, true, shutdownHook);
Logger.normal(this, "Initializing pubKey
Datacache");
System.out.println("Initializing pubKey
Datacache (" + maxCacheKeys + " keys)");
pubKeyDatacache = new PubkeyStore();
SaltedHashFreenetStore pubkeyCacheFS =
SaltedHashFreenetStore.construct(storeDir, "PUBKEY-cache",
- pubKeyDatacache, this, maxCacheKeys,
0x4800000, shutdownHook);
+ pubKeyDatacache, this, maxCacheKeys,
0x4800000, true, shutdownHook);
Logger.normal(this, "Initializing SSK
Datastore");
System.out.println("Initializing SSK
Datastore");
sskDatastore = new SSKStore(this);
SaltedHashFreenetStore sskDataFS =
SaltedHashFreenetStore.construct(storeDir, "SSK-store",
- sskDatastore, this, maxStoreKeys,
0x4800000, shutdownHook);
+ sskDatastore, this, maxStoreKeys,
0x4800000, true, shutdownHook);
Logger.normal(this, "Initializing SSK
Datacache");
System.out.println("Initializing SSK Datacache
(" + maxCacheKeys + " keys)");
sskDatacache = new SSKStore(this);
SaltedHashFreenetStore sskCacheFS =
SaltedHashFreenetStore.construct(storeDir, "SSK-cache",
- sskDatacache, this, maxCacheKeys,
0x4800000, shutdownHook);
+ sskDatacache, this, maxCacheKeys,
0x4800000, true, shutdownHook);
File migrationFile = new File(storeDir,
"migrated");
if (!migrationFile.exists()) {
Modified:
branches/saltedhashstore/freenet/src/freenet/store/saltedhash/SaltedHashFreenetStore.java
===================================================================
---
branches/saltedhashstore/freenet/src/freenet/store/saltedhash/SaltedHashFreenetStore.java
2008-07-31 11:37:25 UTC (rev 21524)
+++
branches/saltedhashstore/freenet/src/freenet/store/saltedhash/SaltedHashFreenetStore.java
2008-07-31 11:40:49 UTC (rev 21525)
@@ -37,7 +37,6 @@
import freenet.store.StorableBlock;
import freenet.store.StoreCallback;
import freenet.support.BloomFilter;
-import freenet.support.CountingBloomFilter;
import freenet.support.Fields;
import freenet.support.HTMLNode;
import freenet.support.HexUtil;
@@ -81,13 +80,14 @@
private int flags;
public static SaltedHashFreenetStore construct(File baseDir, String
name, StoreCallback callback, Node node,
- long maxKeys, int bloomFilterSize, SemiOrderedShutdownHook
shutdownHook)
+ long maxKeys, int bloomFilterSize, boolean bloomCounting,
SemiOrderedShutdownHook shutdownHook)
throws IOException {
- return new SaltedHashFreenetStore(baseDir, name, callback,
node, maxKeys, bloomFilterSize, shutdownHook);
+ return new SaltedHashFreenetStore(baseDir, name, callback,
node, maxKeys, bloomFilterSize, bloomCounting,
+ shutdownHook);
}
private SaltedHashFreenetStore(File baseDir, String name, StoreCallback
callback, Node node, long maxKeys,
- int bloomFilterSize, SemiOrderedShutdownHook shutdownHook)
+ int bloomFilterSize, boolean bloomCounting,
SemiOrderedShutdownHook shutdownHook)
throws IOException {
logMINOR = Logger.shouldLog(Logger.MINOR, this);
logDEBUG = Logger.shouldLog(Logger.DEBUG, this);
@@ -117,7 +117,7 @@
newStore |= openStoreFiles(baseDir, name);
File bloomFile = new File(this.baseDir, name + ".bloom");
- bloomFilter = new CountingBloomFilter(bloomFile,
bloomFilterSize, bloomFilterK);
+ bloomFilter = BloomFilter.createFilter(bloomFile,
bloomFilterSize, bloomFilterK, bloomCounting);
if ((flags & FLAG_DIRTY) != 0)
System.err.println("Datastore(" + name + ") is dirty.");
Modified:
branches/saltedhashstore/freenet/src/freenet/support/BinaryBloomFilter.java
===================================================================
--- branches/saltedhashstore/freenet/src/freenet/support/BinaryBloomFilter.java
2008-07-31 11:37:25 UTC (rev 21524)
+++ branches/saltedhashstore/freenet/src/freenet/support/BinaryBloomFilter.java
2008-07-31 11:40:49 UTC (rev 21525)
@@ -19,7 +19,7 @@
* @param length
* length in bits
*/
- public BinaryBloomFilter(int length, int k) {
+ protected BinaryBloomFilter(int length, int k) {
super(length, k);
filter = ByteBuffer.allocate(length / 8);
}
@@ -33,7 +33,7 @@
* length in bits
* @throws IOException
*/
- public BinaryBloomFilter(File file, int length, int k) throws
IOException {
+ protected BinaryBloomFilter(File file, int length, int k) throws
IOException {
super(length, k);
if (!file.exists() || file.length() != length / 8)
needRebuild = true;
Modified: branches/saltedhashstore/freenet/src/freenet/support/BloomFilter.java
===================================================================
--- branches/saltedhashstore/freenet/src/freenet/support/BloomFilter.java
2008-07-31 11:37:25 UTC (rev 21524)
+++ branches/saltedhashstore/freenet/src/freenet/support/BloomFilter.java
2008-07-31 11:40:49 UTC (rev 21525)
@@ -1,5 +1,7 @@
package freenet.support;
+import java.io.File;
+import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.MappedByteBuffer;
import java.util.Random;
@@ -17,6 +19,15 @@
protected ReadWriteLock lock = new ReentrantReadWriteLock();
+ public static BloomFilter createFilter(File file, int length, int k,
boolean counting) throws IOException {
+ if (k == 0 || length == 0)
+ return new NullBloomFilter(length, k);
+ if (counting)
+ return new CountingBloomFilter(file, length, k);
+ else
+ return new BinaryBloomFilter(file, length, k);
+ }
+
protected BloomFilter(int length, int k) {
if (length % 8 != 0)
throw new IllegalArgumentException();
@@ -127,14 +138,13 @@
* @param maxKey
* @return optimal K
*/
+ // may return 0 if the length is too short
public static int optimialK(int filterLength, long maxKey) {
long k = Math.round(Math.log(2) * filterLength / maxKey);
+
+ if (k > 64)
+ k = 64;
- if (k < 1)
- k = 1;
- if (k > 32)
- k = 32;
-
return (int) k;
}
Modified:
branches/saltedhashstore/freenet/src/freenet/support/CountingBloomFilter.java
===================================================================
---
branches/saltedhashstore/freenet/src/freenet/support/CountingBloomFilter.java
2008-07-31 11:37:25 UTC (rev 21524)
+++
branches/saltedhashstore/freenet/src/freenet/support/CountingBloomFilter.java
2008-07-31 11:40:49 UTC (rev 21525)
@@ -19,7 +19,7 @@
* @param length
* length in bits
*/
- public CountingBloomFilter(int length, int k) {
+ protected CountingBloomFilter(int length, int k) {
super(length, k);
filter = ByteBuffer.allocate(length / 8 * 2);
}
@@ -33,7 +33,7 @@
* length in bits
* @throws IOException
*/
- public CountingBloomFilter(File file, int length, int k) throws
IOException {
+ protected CountingBloomFilter(File file, int length, int k) throws
IOException {
super(length, k);
int fileLength = length / 8 * 2;
if (!file.exists() || file.length() != fileLength)
Modified:
branches/saltedhashstore/freenet/src/freenet/support/NullBloomFilter.java
===================================================================
--- branches/saltedhashstore/freenet/src/freenet/support/NullBloomFilter.java
2008-07-31 11:37:25 UTC (rev 21524)
+++ branches/saltedhashstore/freenet/src/freenet/support/NullBloomFilter.java
2008-07-31 11:40:49 UTC (rev 21525)
@@ -7,7 +7,7 @@
* @author sdiz
*/
public class NullBloomFilter extends BloomFilter {
- public NullBloomFilter(int length, int k) {
+ protected NullBloomFilter(int length, int k) {
super(length, k);
}