Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDK-166 - add custom storage names parameter to DbTool #435

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions qa/SidechainTestFramework/scutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def launch_bootstrap_tool(command_name, json_parameters):
raise Exception("Bootstrap tool error occurred")


def launch_db_tool(dirName, command_name, json_parameters):
def launch_db_tool(dirName, storageNames, command_name, json_parameters):
'''
we use "blockchain" postfix for specifying the dataDir (see qa/resources/template.conf:
dataDir = "%(DIRECTORY)s/sc_node%(NODE_NUMBER)s/blockchain"
Expand All @@ -143,7 +143,7 @@ def launch_db_tool(dirName, command_name, json_parameters):
java_ps = subprocess.Popen(["java", "-jar",
os.getenv("SIDECHAIN_SDK",
"..") + "/tools/dbtool/target/sidechains-sdk-dbtools-0.4.0-SNAPSHOT.jar",
storagesPath, command_name, json_param], stdout=subprocess.PIPE)
storagesPath, storageNames, command_name, json_param], stdout=subprocess.PIPE)
db_tool_output = java_ps.communicate()[0]
try:
jsone_node = json.loads(db_tool_output)
Expand Down
11 changes: 6 additions & 5 deletions qa/sc_storage_recovery_with_csw.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,14 @@
"""

WITHDRAWAL_EPOCH_LENGTH = 10
CUSTOM_STORAGE_NAMES = "appState1,appState2,appWallet1,appWallet2"


def checkStoragesVersion(node, storages_list, expectedVersion):
for name in storages_list:
# get the last version of the storage
json_params = {"storage": name}
ret = launch_db_tool(node.dataDir, "lastVersionID", json_params)
ret = launch_db_tool(node.dataDir, CUSTOM_STORAGE_NAMES, "lastVersionID", json_params)
version = ret['version']
#print("{} --> {}".format(name, version))
# check we got the expected version
Expand All @@ -71,13 +72,13 @@ def rollbackStorages(node, storages_list, numberOfVersionsToRollback):
for name in storages_list:
# get the version list up to the desired number
json_params = {"storage": name, "numberOfVersionToRetrieve": numberOfVersionsToRollback}
versionsList = launch_db_tool(node.dataDir, "versionsList", json_params)["versionsList"]
versionsList = launch_db_tool(node.dataDir, CUSTOM_STORAGE_NAMES, "versionsList", json_params)["versionsList"]

# get the target version to rollback to
rollbackVersion = versionsList[-1]
json_params = {"storage": name, "versionToRollback": rollbackVersion}
print("...Rollbacking storage \"{}\" to version {}".format(name, rollbackVersion))
ret = launch_db_tool(node.dataDir, "rollback", json_params)
ret = launch_db_tool(node.dataDir, CUSTOM_STORAGE_NAMES, "rollback", json_params)
#print("{} --> {}".format(name, rollbackVersion))
# check that we did it correctly
assert_equal(ret["versionCurrent"], rollbackVersion)
Expand Down Expand Up @@ -183,7 +184,7 @@ def run_test(self):
# Check that wallet forging stake has the same block id in the rollback versions and precisely
# one commit behind
json_params = {"storage": "walletForgingStake", "numberOfVersionToRetrieve": 2}
versionsList = launch_db_tool(sc_node2.dataDir, "versionsList", json_params)["versionsList"]
versionsList = launch_db_tool(sc_node2.dataDir, CUSTOM_STORAGE_NAMES, "versionsList", json_params)["versionsList"]
assert_true(genesis_sc_block_id in versionsList)
assert_equal(genesis_sc_block_id, versionsList[-1])

Expand Down Expand Up @@ -317,7 +318,7 @@ def run_test(self):
checkStoragesVersion(sc_node2, ["wallet"], rolbackBlockVersionId)

json_params = {"storage": "walletForgingStake", "numberOfVersionToRetrieve": 2}
versionsList = launch_db_tool(sc_node2.dataDir, "versionsList", json_params)["versionsList"]
versionsList = launch_db_tool(sc_node2.dataDir, CUSTOM_STORAGE_NAMES, "versionsList", json_params)["versionsList"]
assert_true(rolbackBlockVersionId in versionsList)
# -- wallet forging stake is ahead by one version
assert_equal(rolbackBlockVersionId, versionsList[-1])
Expand Down
22 changes: 14 additions & 8 deletions tools/dbtool/src/main/java/com/horizen/DbTool.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.horizen;
import java.io.File;
import java.util.*;

import com.horizen.settings.SettingsReader;
import com.horizen.tools.utils.ConsolePrinter;
import com.horizen.tools.utils.MessagePrinter;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.io.File;
import java.util.*;

public class DbTool {
public static final Set<String> storageNames = new HashSet<>(Arrays.asList(
"secret",
Expand All @@ -19,8 +19,7 @@ public class DbTool {
"stateForgerBox",
"stateUtxoMerkleTree",
"history",
"consensusData",
"appState1", "appState2", "appWallet1", "appWallet2" // simple app tests
"consensusData"
));

public static void main(String args[]) {
Expand All @@ -35,6 +34,7 @@ public static void main(String args[]) {

Logger log = LogManager.getLogger(com.horizen.DbTool.class);

// read database folder path from input arguments
if (args.length == 0) {
log.error("Please provide DB folder path as first parameter!");
return;
Expand All @@ -45,12 +45,18 @@ public static void main(String args[]) {
}
String dataDirAbsolutePath = args[0];

// read custom storage names list from input arguments
List<String> customStorageNames = Arrays.asList(args[1].split(","));
for(String customStorageName: customStorageNames) {
storageNames.add(customStorageName);
}

MessagePrinter printer = new ConsolePrinter();
DbToolCommandProcessor processor = new DbToolCommandProcessor(printer, dataDirAbsolutePath, log);
if(args.length > 1)
if(args.length > 2)
try {
StringBuilder cmd = new StringBuilder(args[1]);
for(int i=2; i<args.length; i++)
StringBuilder cmd = new StringBuilder(args[2]);
for(int i=3; i<args.length; i++)
cmd.append(" ").append(args[i]);
log.info("Starting db tool with cmd input: " + cmd);
processor.processCommand(cmd.toString());
Expand Down