Skip to content
This repository has been archived by the owner on Aug 23, 2020. It is now read-only.

Feature: Allow users to tinker with RocksDB configuration via file; Upgrade RocksDb #1638

Merged
merged 15 commits into from
Nov 6, 2019
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
<dependency>
<groupId>org.rocksdb</groupId>
<artifactId>rocksdbjni</artifactId>
<version>5.17.2</version>
<version>6.2.2</version>
</dependency>

<!-- json support -->
Expand Down Expand Up @@ -396,7 +396,7 @@
commons-io:commons-io:2.5:jar:null:compile:2852e6e05fbb95076fc091f6d1780f1f8fe35e0f
</urn>
<urn>
org.rocksdb:rocksdbjni:5.17.2:jar:null:compile:bca52276cabe91a3b97cc18e50fa2eabc2986f58
org.rocksdb:rocksdbjni:6.2.2:jar:null:compile:5337051b43477a3fb345889378abbba5bdb29830
</urn>
<urn>
com.google.code.gson:gson:2.8.1:jar:null:compile:02a8e0aa38a2e21cb39e2f5a7d6704cbdc941da0
Expand Down
26 changes: 16 additions & 10 deletions src/main/java/com/iota/iri/Iota.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
package com.iota.iri;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.NotImplementedException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.iota.iri.conf.IotaConfig;
import com.iota.iri.controllers.TipsViewModel;
import com.iota.iri.controllers.TransactionViewModel;
Expand All @@ -8,7 +15,11 @@
import com.iota.iri.network.TransactionRequester;
import com.iota.iri.network.pipeline.TransactionProcessingPipeline;
import com.iota.iri.service.ledger.LedgerService;
import com.iota.iri.service.milestone.*;
import com.iota.iri.service.milestone.LatestMilestoneTracker;
import com.iota.iri.service.milestone.LatestSolidMilestoneTracker;
import com.iota.iri.service.milestone.MilestoneService;
import com.iota.iri.service.milestone.MilestoneSolidifier;
import com.iota.iri.service.milestone.SeenMilestonesRetriever;
import com.iota.iri.service.snapshot.LocalSnapshotManager;
import com.iota.iri.service.snapshot.SnapshotException;
import com.iota.iri.service.snapshot.SnapshotProvider;
Expand All @@ -26,13 +37,6 @@
import com.iota.iri.utils.Pair;
import com.iota.iri.zmq.ZmqMessageQueueProvider;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.NotImplementedException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
*
* The main class of IRI. This will propagate transactions into and throughout the network. This data is stored as a
Expand Down Expand Up @@ -259,6 +263,7 @@ private void initializeTangle() {
tangle.addPersistenceProvider(createRocksDbProvider(
configuration.getDbPath(),
configuration.getDbLogPath(),
configuration.getDbConfigFile(),
configuration.getDbCacheSize(),
Tangle.COLUMN_FAMILIES,
Tangle.METADATA_COLUMN_FAMILY)
Expand All @@ -279,16 +284,17 @@ private void initializeTangle() {
*
* @param path The location where the database will be stored
* @param log The location where the log files will be stored
* @param configFile The location where the RocksDB config is read from
* @param cacheSize the size of the cache used by the database implementation
* @param columnFamily A map of the names related to their Persistable class
* @param metadata Map of metadata used by the Persistable class, can be <code>null</code>
* @return A new Persistance provider
*/
private PersistenceProvider createRocksDbProvider(String path, String log, int cacheSize,
private PersistenceProvider createRocksDbProvider(String path, String log, String configFile, int cacheSize,
Map<String, Class<? extends Persistable>> columnFamily,
Map.Entry<String, Class<? extends Persistable>> metadata) {
return new RocksDBPersistenceProvider(
path, log, cacheSize, columnFamily, metadata);
path, log, configFile, cacheSize, columnFamily, metadata);
}

}
10 changes: 6 additions & 4 deletions src/main/java/com/iota/iri/MainInjectionConfiguration.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package com.iota.iri;

import java.security.SecureRandom;
import java.util.HashMap;

import javax.annotation.Nullable;

import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import com.google.inject.Singleton;
Expand Down Expand Up @@ -50,10 +55,6 @@
import com.iota.iri.storage.Tangle;
import com.iota.iri.storage.rocksDB.RocksDBPersistenceProvider;

import javax.annotation.Nullable;
import java.security.SecureRandom;
import java.util.HashMap;

/**
* Guice module. Configuration class for dependency injection.
*/
Expand Down Expand Up @@ -82,6 +83,7 @@ SpentAddressesProvider provideSpentAddressesProvider() {
PersistenceProvider persistenceProvider = new RocksDBPersistenceProvider(
configuration.getSpentAddressesDbPath(),
configuration.getSpentAddressesDbLogPath(),
configuration.getDbConfigFile(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So mainnet-db and spent-addresses-db uses the same name?
IIUC it is just the name but there are still separate locations

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea same config. i dont really think there will be added value of splitting the 2 apart, unless we hire a rocksdb expert who can tinker enough to make a difference. But assuming we will work on a new persistence layer anyways, i doubt it will happen soon :)

1000,
new HashMap<String, Class<? extends Persistable>>(1)
{{put("spent-addresses", SpentAddress.class);}}, null);
Expand Down
26 changes: 19 additions & 7 deletions src/main/java/com/iota/iri/conf/BaseIotaConfig.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
package com.iota.iri.conf;

import com.iota.iri.crypto.SpongeFactory;
import com.iota.iri.model.Hash;
import com.iota.iri.model.HashFactory;
import com.iota.iri.utils.IotaUtils;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

import org.apache.commons.lang3.ArrayUtils;

import com.beust.jcommander.JCommander;
import com.beust.jcommander.Parameter;
import com.beust.jcommander.ParameterException;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;

import org.apache.commons.lang3.ArrayUtils;
import com.iota.iri.crypto.SpongeFactory;
import com.iota.iri.model.Hash;
import com.iota.iri.model.HashFactory;
import com.iota.iri.utils.IotaUtils;

/**
Note: the fields in this class are being deserialized from Jackson so they must follow Java Bean convention.
Expand Down Expand Up @@ -63,6 +62,7 @@ public abstract class BaseIotaConfig implements IotaConfig {
//DB
protected String dbPath = Defaults.DB_PATH;
protected String dbLogPath = Defaults.DB_LOG_PATH;
protected String dbConfigFile = Defaults.DB_CONFIG_FILE;
protected int dbCacheSize = Defaults.DB_CACHE_SIZE; //KB
protected String mainDb = Defaults.MAIN_DB;
protected boolean revalidate = Defaults.REVALIDATE;
Expand Down Expand Up @@ -405,6 +405,17 @@ public String getDbLogPath() {
protected void setDbLogPath(String dbLogPath) {
this.dbLogPath = dbLogPath;
}

@Override
public String getDbConfigFile() {
return dbConfigFile;
}

@JsonProperty
@Parameter(names = {"--db-config-file"}, description = DbConfig.Descriptions.DB_CONFIG_FILE)
protected void setDbConfigFile(String dbConfigFile) {
this.dbConfigFile = dbConfigFile;
}

@Override
public int getDbCacheSize() {
Expand Down Expand Up @@ -864,6 +875,7 @@ public interface Defaults {
//DB
String DB_PATH = "mainnetdb";
String DB_LOG_PATH = "mainnet.log";
String DB_CONFIG_FILE = "rocksdb-config.properties";
int DB_CACHE_SIZE = 100_000;
String MAIN_DB = "rocksdb";
boolean REVALIDATE = false;
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/iota/iri/conf/DbConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ public interface DbConfig extends Config {
* @return {@value DbConfig.Descriptions#DB_LOG_PATH}
*/
String getDbLogPath();

/**
* Default Value: {@value BaseIotaConfig.Defaults#DB_CONFIG_FILE}
*
* @return {@value DbConfig.Descriptions#DB_CONFIG_FILE}
*/
String getDbConfigFile();

/**
* Default Value: {@value BaseIotaConfig.Defaults#DB_CACHE_SIZE}
Expand Down Expand Up @@ -56,5 +63,6 @@ interface Descriptions {
String REVALIDATE = "Reload from the db data about confirmed transaction (milestones), state of the ledger, " +
"and transaction metadata.";
String RESCAN_DB = "Rescan all transaction metadata (Approvees, Bundles, and Tags)";
String DB_CONFIG_FILE = "The location of the RocksDB configuration file";
}
}
4 changes: 2 additions & 2 deletions src/main/java/com/iota/iri/conf/TestnetConfig.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.iota.iri.conf;

import java.util.Objects;

import com.beust.jcommander.Parameter;
import com.beust.jcommander.ParameterException;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.iota.iri.crypto.SpongeFactory;
import com.iota.iri.model.Hash;
import com.iota.iri.model.HashFactory;

import java.util.Objects;

public class TestnetConfig extends BaseIotaConfig {

protected Hash coordinator = Defaults.COORDINATOR_ADDRESS;
Expand Down
Loading