mirror of
https://github.com/ChronosX88/Influence-Bootstrap-Node.git
synced 2024-11-10 02:11:00 +00:00
Added key sorting in StorageBerkeleyDB
This commit is contained in:
parent
eb1f703d4f
commit
8aacb71152
@ -0,0 +1,14 @@
|
||||
package io.github.chronosx88.dhtBootstrap;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Comparator;
|
||||
|
||||
public class CompareLong implements Comparator<byte[]>, Serializable {
|
||||
@Override
|
||||
public int compare(byte[] o1, byte[] o2) {
|
||||
Serializer<Long> serializer = new Serializer<>();
|
||||
Long num1 = serializer.deserialize(o1);
|
||||
Long num2 = serializer.deserialize(o2);
|
||||
return num1.compareTo(num2);
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package io.github.chronosx88.dhtBootstrap;
|
||||
|
||||
import net.tomp2p.peers.Number640;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Comparator;
|
||||
|
||||
public class CompareNumber640 implements Comparator<byte[]>, Serializable {
|
||||
@Override
|
||||
public int compare(byte[] o1, byte[] o2) {
|
||||
Serializer<Number640> serializer = new Serializer<>();
|
||||
Number640 num1 = serializer.deserialize(o1);
|
||||
Number640 num2 = serializer.deserialize(o2);
|
||||
return num1.compareTo(num2);
|
||||
}
|
||||
}
|
@ -47,16 +47,24 @@ class StorageBerkeleyDB(peerId: Number160, path : File, signatureFactory: Signat
|
||||
val envConfig = EnvironmentConfig()
|
||||
envConfig.allowCreate = true
|
||||
dbEnvironment = Environment(path, envConfig)
|
||||
val dbConfig = DatabaseConfig()
|
||||
dbConfig.allowCreate = true
|
||||
val configMap : HashMap<String, com.sleepycat.je.DatabaseConfig> = HashMap()
|
||||
|
||||
dataMapDB = dbEnvironment.openDatabase(null, "dataMap_$peerId", dbConfig)
|
||||
timeoutMapDB = dbEnvironment.openDatabase(null, "timeoutMap_$peerId", dbConfig)
|
||||
timeoutMapRevDB = dbEnvironment.openDatabase(null, "timeoutMapRev_$peerId", dbConfig)
|
||||
protectedDomainMapDB = dbEnvironment.openDatabase(null, "protectedDomainMap_$peerId", dbConfig)
|
||||
protectedEntryMapDB = dbEnvironment.openDatabase(null, "protectedEntryMap_$peerId", dbConfig)
|
||||
responsibilityMapDB = dbEnvironment.openDatabase(null, "responsibilityMap_$peerId", dbConfig)
|
||||
responsibilityMapRevDB = dbEnvironment.openDatabase(null, "responsibilityMapRev_$peerId", dbConfig)
|
||||
val compareNumber640 = CompareNumber640()
|
||||
val compareLong = CompareLong()
|
||||
configMap["dataMapConfig"] = DatabaseConfig().setBtreeComparator(compareNumber640)
|
||||
configMap["dataMapConfig"]!!.allowCreate = true
|
||||
configMap["timeoutMapRevConfig"] = DatabaseConfig().setBtreeComparator(compareLong)
|
||||
configMap["timeoutMapRevConfig"]!!.allowCreate = true
|
||||
configMap["other"] = DatabaseConfig()
|
||||
configMap["other"]!!.allowCreate = true
|
||||
|
||||
dataMapDB = dbEnvironment.openDatabase(null, "dataMap_$peerId", configMap["dataMapConfig"])
|
||||
timeoutMapDB = dbEnvironment.openDatabase(null, "timeoutMap_$peerId", configMap["other"])
|
||||
timeoutMapRevDB = dbEnvironment.openDatabase(null, "timeoutMapRev_$peerId", configMap["timeoutMapRevConfig"])
|
||||
protectedDomainMapDB = dbEnvironment.openDatabase(null, "protectedDomainMap_$peerId", configMap["other"])
|
||||
protectedEntryMapDB = dbEnvironment.openDatabase(null, "protectedEntryMap_$peerId", configMap["other"])
|
||||
responsibilityMapDB = dbEnvironment.openDatabase(null, "responsibilityMap_$peerId", configMap["other"])
|
||||
responsibilityMapRevDB = dbEnvironment.openDatabase(null, "responsibilityMapRev_$peerId", configMap["other"])
|
||||
|
||||
storageCheckIntervalMillis = 60 * 1000
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user