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

Adds RocksDB support #2197

Merged
merged 14 commits into from
Aug 28, 2019
Merged
Show file tree
Hide file tree
Changes from 6 commits
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
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ set (NANO_SECURE_RPC OFF CACHE BOOL "")
set (NANO_ROCKSDB OFF CACHE BOOL "")
set (NANO_WARN_TO_ERR OFF CACHE BOOL "")

if (NANO_ROCKSDB)
add_definitions (-DNANO_ROCKSDB=1)
endif ()
option(NANO_ASAN_INT "Enable ASan+UBSan+Integer overflow" OFF)
option(NANO_ASAN "Enable ASan+UBSan" OFF)
option(NANO_TSAN "Enable TSan" OFF)
Expand Down
2 changes: 2 additions & 0 deletions ci/build-travis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ else
SANITIZERS=""
fi

ulimit -S -n 8192

cmake \
-G'Unix Makefiles' \
-DACTIVE_NETWORK=nano_test_network \
Expand Down
2 changes: 1 addition & 1 deletion ci/test.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash

build_dir=${1-${PWD}}
TIMEOUT_DEFAULT=180
TIMEOUT_DEFAULT=360

BUSYBOX_BASH=${BUSYBOX_BASH-0}

Expand Down
7 changes: 6 additions & 1 deletion docker/ci/Dockerfile-clang
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
FROM nanocurrency/nano-env:base

RUN apt-get update -qq && apt-get install -yqq \
clang-3.9 lldb-3.9 librocksdb-dev
clang-3.9 lldb-3.9 git

RUN git clone https://github.com/facebook/rocksdb.git && \
cd rocksdb && \
make static_lib && \
make install

ENV CXX=/usr/bin/clang++
ENV CC=/usr/bin/clang
Expand Down
7 changes: 6 additions & 1 deletion docker/ci/Dockerfile-gcc
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
FROM nanocurrency/nano-env:base

RUN apt-get install -yqq librocksdb-dev
RUN apt-get install -yqq git

RUN git clone https://github.com/facebook/rocksdb.git && \
cd rocksdb && \
make static_lib && \
make install

ENV BOOST_ROOT=/usr/local
ADD util/build_prep/bootstrap_boost.sh bootstrap_boost.sh
Expand Down
9 changes: 2 additions & 7 deletions nano/core_test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
if (NANO_ROCKSDB)
set (rocksdb_test rocksdb_test.cpp)
set (rocksdb_libs ${ROCKSDB_LIBRARIES} ${ZLIB_LIBRARIES})
endif ()

add_executable (core_test
core_test_main.cc
testutil.hpp
Expand All @@ -23,11 +18,11 @@ add_executable (core_test
memory_pool.cpp
processor_service.cpp
peer_container.cpp
${rocksdb_test}
signing.cpp
socket.cpp
timer.cpp
uint256_union.cpp
utility.cpp
versioning.cpp
wallet.cpp
wallets.cpp
Expand All @@ -41,4 +36,4 @@ target_compile_definitions(core_test
-DNANO_VERSION_PATCH=${CPACK_PACKAGE_VERSION_PATCH}
-DGIT_COMMIT_HASH=${GIT_COMMIT_HASH}
-DBOOST_PROCESS_SUPPORTED=${BOOST_PROCESS_SUPPORTED})
target_link_libraries (core_test node secure gtest libminiupnpc-static Boost::boost ${rocksdb_libs})
target_link_libraries (core_test node secure gtest libminiupnpc-static Boost::boost)
12 changes: 9 additions & 3 deletions nano/core_test/block_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -613,13 +613,15 @@ TEST (block_store, latest_find)
ASSERT_EQ (second, find3);
}

#if !NANO_ROCKSDB
TEST (block_store, bad_path)
{
nano::logger_mt logger;
bool init (false);
auto store = nano::make_store (init, logger, boost::filesystem::path ("///"));
ASSERT_TRUE (init);
}
#endif

TEST (block_store, DISABLED_already_open) // File can be shared
{
Expand Down Expand Up @@ -1746,14 +1748,18 @@ TEST (block_store, incompatible_version)

// Put version to an unreachable number so that it should always be incompatible
auto transaction (store->tx_begin_write ());
store->version_put (transaction, std::numeric_limits<unsigned>::max ());
store->version_put (transaction, std::numeric_limits<int>::max ());
}

// Now try and read it, should give an error
{
auto error (false);
auto store = nano::make_store (error, logger, path);
auto store = nano::make_store (error, logger, path, true);
ASSERT_TRUE (error);

auto transaction = store->tx_begin_read ();
auto version_l = store->version_get (transaction);
ASSERT_EQ (version_l, std::numeric_limits<int>::max ());
}
}

Expand Down Expand Up @@ -1798,7 +1804,7 @@ void modify_account_info_to_v13 (nano::mdb_store & store, nano::transaction cons
nano::account_info info;
ASSERT_FALSE (store.account_get (transaction_a, account, info));
nano::account_info_v13 account_info_v13 (info.head, info.rep_block, info.open_block, info.balance, info.modified, info.block_count, info.epoch);
auto status (mdb_put (store.env.tx (transaction_a), store.get_account_db (info.epoch) == nano::block_store_partial<MDB_val, nano::mdb_store>::tables::accounts_v0 ? store.accounts_v0 : store.accounts_v1, nano::mdb_val (account), nano::mdb_val (account_info_v13), 0));
auto status (mdb_put (store.env.tx (transaction_a), store.get_account_db (info.epoch) == nano::tables::accounts_v0 ? store.accounts_v0 : store.accounts_v1, nano::mdb_val (account), nano::mdb_val (account_info_v13), 0));
(void)status;
assert (status == 0);
}
Expand Down
4 changes: 3 additions & 1 deletion nano/core_test/ledger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@

using namespace std::chrono_literals;

#if !NANO_ROCKSDB
// Init returns an error if it can't open files at the path
TEST (ledger, store_error)
{
nano::logger_mt logger;
bool init (false);
auto store = nano::make_store (init, logger, boost::filesystem::path ("///"));
ASSERT_FALSE (!init);
ASSERT_TRUE (init);
nano::stat stats;
nano::ledger ledger (*store, stats);
}
#endif

// Ledger can be initialized and returns a basic query for an empty account
TEST (ledger, empty)
Expand Down
2 changes: 1 addition & 1 deletion nano/core_test/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1544,7 +1544,7 @@ TEST (confirmation_height, single)
ASSERT_NO_ERROR (system.poll ());
}

auto transaction = node->store.tx_begin_read ();
auto transaction = node->store.tx_begin_write ();
ASSERT_FALSE (node->store.confirmation_height_get (transaction, nano::test_genesis_key.pub, confirmation_height));
ASSERT_EQ (2, confirmation_height);

Expand Down
11 changes: 6 additions & 5 deletions nano/core_test/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ TEST (node, auto_bootstrap)
node1->network.send_keepalive (channel);
node1->start ();
system.nodes.push_back (node1);
system.deadline_set (10s);
while (!node1->bootstrap_initiator.in_progress ())
{
ASSERT_NO_ERROR (system.poll ());
Expand Down Expand Up @@ -497,7 +498,7 @@ TEST (node, confirm_locked)
{
nano::system system (24000, 1);
system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv);
auto transaction (system.nodes[0]->store.tx_begin_read ());
auto transaction (system.wallet (0)->wallets.tx_begin_read ());
system.wallet (0)->enter_password (transaction, "1");
auto block (std::make_shared<nano::send_block> (0, 0, 0, nano::keypair ().prv, 0, 0));
system.nodes[0]->network.flood_block (block);
Expand Down Expand Up @@ -2937,15 +2938,15 @@ TEST (node, dont_write_lock_node)
std::thread ([&path, &write_lock_held_promise, &finished_promise]() {
nano::logger_mt logger;
bool init (false);
nano::mdb_store store (init, logger, path / "data.ldb");
auto store = nano::make_store (init, logger, path, false, true);
nano::genesis genesis;
{
auto transaction (store.tx_begin_write ());
store.initialize (transaction, genesis);
auto transaction (store->tx_begin_write ());
store->initialize (transaction, genesis);
}

// Hold write lock open until main thread is done needing it
auto transaction (store.tx_begin_write ());
auto transaction (store->tx_begin_write ());
write_lock_held_promise.set_value ();
finished_promise.get_future ().wait ();
})
Expand Down
31 changes: 0 additions & 31 deletions nano/core_test/rocksdb_test.cpp

This file was deleted.

2 changes: 1 addition & 1 deletion nano/core_test/socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ using namespace std::chrono_literals;

TEST (socket, concurrent_writes)
{
nano::inactive_node inactivenode;
nano::inactive_node inactivenode (nano::working_path (), 24000, false);
auto node = inactivenode.node;

// This gives more realistic execution than using system#poll, allowing writes to
Expand Down
54 changes: 54 additions & 0 deletions nano/core_test/utility.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include <nano/lib/utility.hpp>
#include <nano/secure/utility.hpp>

#include <gtest/gtest.h>

TEST (filesystem, remove_all_files)
{
auto path = nano::unique_path ();
auto dummy_directory = path / "tmp";
boost::filesystem::create_directories (dummy_directory);

auto dummy_file1 = path / "my_file1.txt";
auto dummy_file2 = path / "my_file2.txt";
std::ofstream (dummy_file1.string ());
std::ofstream (dummy_file2.string ());

// Check all exist
ASSERT_TRUE (boost::filesystem::exists (dummy_directory));
ASSERT_TRUE (boost::filesystem::exists (dummy_file1));
ASSERT_TRUE (boost::filesystem::exists (dummy_file2));

// Should remove only the files
nano::remove_all_files_in_dir (path);

ASSERT_TRUE (boost::filesystem::exists (dummy_directory));
ASSERT_FALSE (boost::filesystem::exists (dummy_file1));
ASSERT_FALSE (boost::filesystem::exists (dummy_file2));
}

TEST (filesystem, move_all_files)
{
auto path = nano::unique_path ();
auto dummy_directory = path / "tmp";
boost::filesystem::create_directories (dummy_directory);

auto dummy_file1 = dummy_directory / "my_file1.txt";
auto dummy_file2 = dummy_directory / "my_file2.txt";
std::ofstream (dummy_file1.string ());
std::ofstream (dummy_file2.string ());

// Check all exist
ASSERT_TRUE (boost::filesystem::exists (dummy_directory));
ASSERT_TRUE (boost::filesystem::exists (dummy_file1));
ASSERT_TRUE (boost::filesystem::exists (dummy_file2));

// Should move only the files
nano::move_all_files_to_dir (dummy_directory, path);

ASSERT_TRUE (boost::filesystem::exists (dummy_directory));
ASSERT_TRUE (boost::filesystem::exists (path / "my_file1.txt"));
ASSERT_TRUE (boost::filesystem::exists (path / "my_file2.txt"));
ASSERT_FALSE (boost::filesystem::exists (dummy_file1));
ASSERT_FALSE (boost::filesystem::exists (dummy_file2));
}
4 changes: 3 additions & 1 deletion nano/core_test/wallets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ TEST (wallets, remove)
}
}

#if !NANO_ROCKSDB
TEST (wallets, upgrade)
{
nano::system system (24000, 1);
Expand All @@ -99,7 +100,7 @@ TEST (wallets, upgrade)
nano::account_info info;
ASSERT_FALSE (mdb_store.account_get (transaction_destination, nano::genesis_account, info));
nano::account_info_v13 account_info_v13 (info.head, info.rep_block, info.open_block, info.balance, info.modified, info.block_count, info.epoch);
auto status (mdb_put (mdb_store.env.tx (transaction_destination), mdb_store.get_account_db (info.epoch) == nano::block_store_partial<MDB_val, nano::mdb_store>::tables::accounts_v0 ? mdb_store.accounts_v0 : mdb_store.accounts_v1, nano::mdb_val (nano::test_genesis_key.pub), nano::mdb_val (account_info_v13), 0));
auto status (mdb_put (mdb_store.env.tx (transaction_destination), mdb_store.get_account_db (info.epoch) == nano::tables::accounts_v0 ? mdb_store.accounts_v0 : mdb_store.accounts_v1, nano::mdb_val (nano::test_genesis_key.pub), nano::mdb_val (account_info_v13), 0));
(void)status;
assert (status == 0);
}
Expand All @@ -116,6 +117,7 @@ TEST (wallets, upgrade)
MDB_dbi new_handle;
ASSERT_EQ (0, mdb_dbi_open (tx_new, id.pub.to_string ().c_str (), 0, &new_handle));
}
#endif

// Keeps breaking whenever we add new DBs
TEST (wallets, DISABLED_wallet_create_max)
Expand Down
2 changes: 2 additions & 0 deletions nano/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ add_library (nano_lib
blocks.cpp
config.hpp
config.cpp
diagnosticsconfig.hpp
diagnosticsconfig.cpp
errors.hpp
errors.cpp
ipc.hpp
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <nano/lib/diagnosticsconfig.hpp>
#include <nano/lib/jsonconfig.hpp>
#include <nano/node/diagnosticsconfig.hpp>

nano::error nano::diagnostics_config::serialize_json (nano::jsonconfig & json) const
{
Expand Down
File renamed without changes.
24 changes: 24 additions & 0 deletions nano/lib/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,30 @@ void nano::thread_runner::stop_event_processing ()
io_guard.get_executor ().context ().stop ();
}

void nano::remove_all_files_in_dir (boost::filesystem::path const & dir)
{
for (auto & p : boost::filesystem::directory_iterator (dir))
{
auto path = p.path ();
if (boost::filesystem::is_regular_file (path))
{
boost::filesystem::remove (path);
}
}
}

void nano::move_all_files_to_dir (boost::filesystem::path const & from, boost::filesystem::path const & to)
{
for (auto & p : boost::filesystem::directory_iterator (from))
{
auto path = p.path ();
if (boost::filesystem::is_regular_file (path))
{
boost::filesystem::rename (path, to / path.filename ());
}
}
}

/*
* Backing code for "release_assert", which is itself a macro
*/
Expand Down
3 changes: 3 additions & 0 deletions nano/lib/utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,9 @@ inline std::unique_ptr<seq_con_info_component> collect_seq_con_info (observer_se
composite->add_component (std::make_unique<seq_con_info_leaf> (seq_con_info{ "observers", count, sizeof_element }));
return composite;
}

void remove_all_files_in_dir (boost::filesystem::path const & dir);
void move_all_files_to_dir (boost::filesystem::path const & from, boost::filesystem::path const & to);
}

void release_assert_internal (bool check, const char * check_expr, const char * file, unsigned int line);
Expand Down
4 changes: 2 additions & 2 deletions nano/node/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
if (NANO_ROCKSDB)
set (rocksdb_libs ${ROCKSDB_LIBRARIES} ${ZLIB_LIBRARIES})
set (rocksdb_sources rocksdb/rocksdb.hpp rocksdb/rocksdb.cpp rocksdb/rocksdb_iterator.hpp rocksdb/rocksdb_txn.hpp rocksdb/rocksdb_txn.cpp)
endif ()

if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
Expand All @@ -20,6 +21,7 @@ endif ()

add_library (node
${platform_sources}
${rocksdb_sources}
active_transactions.hpp
active_transactions.cpp
blockprocessor.cpp
Expand All @@ -35,8 +37,6 @@ add_library (node
confirmation_height_processor.cpp
daemonconfig.hpp
daemonconfig.cpp
diagnosticsconfig.hpp
diagnosticsconfig.cpp
election.hpp
election.cpp
gap_cache.hpp
Expand Down
Loading