Define config for key/val datasource selection
This commit is contained in:
parent
193f217b81
commit
3fd0b47b1c
|
@ -49,6 +49,8 @@ public class SystemProperties {
|
|||
private static Boolean DEFAULT_VM_TRACE = false;
|
||||
private static String DEFAULT_VM_TRACE_DIR = "dmp";
|
||||
private static int DEFAULT_PEER_LISTEN_PORT = 30303;
|
||||
private static String DEFAULT_KEY_VALUE_DATA_SOURCE = "leveldb";
|
||||
|
||||
|
||||
/* Testing */
|
||||
private static Boolean DEFAULT_VMTEST_LOAD_LOCAL = false;
|
||||
|
@ -270,6 +272,12 @@ public class SystemProperties {
|
|||
if (prop.isEmpty()) return DEFAULT_PEER_LISTEN_PORT;
|
||||
return Integer.parseInt(prop.getProperty("peer.listen.port"));
|
||||
}
|
||||
|
||||
|
||||
public String getKeyValueDataSource(){
|
||||
if (prop.isEmpty()) return DEFAULT_KEY_VALUE_DATA_SOURCE;
|
||||
return prop.getProperty("keyvalue.datasource");
|
||||
}
|
||||
|
||||
public void setListenPort(Integer port) {
|
||||
prop.setProperty("peer.listen.port", port.toString());
|
||||
|
|
|
@ -8,6 +8,8 @@ import redis.clients.jedis.Pipeline;
|
|||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static org.ethereum.config.SystemProperties.CONFIG;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author: Roman Mandeleil
|
||||
|
@ -27,7 +29,9 @@ public class RedisDataSource implements KeyValueDataSource{
|
|||
|
||||
if (name == null) throw new NullPointerException("no name set to the db");
|
||||
this.jedis = new Jedis("localhost"); // todo: config.redisHost, config.redisPort
|
||||
this.jedis.flushAll(); // todo: if config.reset so reset.
|
||||
|
||||
if (CONFIG.databaseReset())
|
||||
this.jedis.flushAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
package org.ethereum.db;
|
||||
|
||||
import org.ethereum.config.SystemProperties;
|
||||
import org.ethereum.datasource.KeyValueDataSource;
|
||||
import org.ethereum.datasource.LevelDbDataSource;
|
||||
import org.ethereum.datasource.RedisDataSource;
|
||||
import org.ethereum.util.ByteUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -11,6 +13,8 @@ import java.util.ArrayList;
|
|||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.ethereum.config.SystemProperties.CONFIG;
|
||||
|
||||
/**
|
||||
* Generic interface for Ethereum database
|
||||
*
|
||||
|
@ -26,10 +30,23 @@ public class DatabaseImpl implements Database {
|
|||
private KeyValueDataSource dataSource;
|
||||
|
||||
public DatabaseImpl(String name) {
|
||||
// Initialize Database
|
||||
dataSource = new LevelDbDataSource();
|
||||
dataSource.setName(name);
|
||||
dataSource.init();
|
||||
|
||||
if (CONFIG.getKeyValueDataSource().equals("redis") ){
|
||||
dataSource = new RedisDataSource();
|
||||
dataSource.setName(name);
|
||||
dataSource.init();
|
||||
return;
|
||||
}
|
||||
|
||||
if (CONFIG.getKeyValueDataSource().equals("leveldb") ){
|
||||
dataSource = new LevelDbDataSource();
|
||||
dataSource.setName(name);
|
||||
dataSource.init();
|
||||
return;
|
||||
}
|
||||
|
||||
logger.info("Key/Value datasource was not configured.");
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -151,3 +151,5 @@ root.hash.start = -1
|
|||
# The protocols supported by peer
|
||||
peer.capabilities = eth, shh
|
||||
|
||||
# Key value data source values: [leveldb/redis]
|
||||
keyvalue.datasource = "leveldb"
|
|
@ -139,4 +139,7 @@ hello.phrase = Dev
|
|||
root.hash.start = -1
|
||||
|
||||
# if set true, json tests will be loaded from local repository
|
||||
GitHubTests.VMTest.loadLocal = false
|
||||
GitHubTests.VMTest.loadLocal = false
|
||||
|
||||
# Key value data source values: [leveldb/redis]
|
||||
keyvalue.datasource = "leveldb"
|
Loading…
Reference in New Issue