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

Unit tests for database shards #3332

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,8 @@ cache:
- $CACHE_DIR

before_install:
- if [ "$(uname)" = "Darwin" ] ; then export NUM_PROCESSORS=$(sysctl -n hw.physicalcpu); else export NUM_PROCESSORS=$(nproc); fi
# NUM_PROCESSORS was set to 1 due to problems in parallel launch of unit tests on Mac platform
- if [ "$(uname)" = "Darwin" ] ; then export NUM_PROCESSORS=1; else export NUM_PROCESSORS=$(nproc); fi
seelabs marked this conversation as resolved.
Show resolved Hide resolved
- echo "NUM PROC is ${NUM_PROCESSORS}"
- if [ "$(uname)" = "Linux" ] ; then docker pull ${DOCKER_IMAGE}; fi
- if [ "${MATRIX_EVAL}" != "" ] ; then eval "${MATRIX_EVAL}"; fi
Expand Down
1 change: 1 addition & 0 deletions Builds/CMake/RippledCore.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,7 @@ target_sources (rippled PRIVATE
#]===============================]
src/test/nodestore/Backend_test.cpp
src/test/nodestore/Basics_test.cpp
src/test/nodestore/DatabaseShard_test.cpp
undertome marked this conversation as resolved.
Show resolved Hide resolved
src/test/nodestore/Database_test.cpp
src/test/nodestore/Timing_test.cpp
src/test/nodestore/import_test.cpp
Expand Down
2 changes: 1 addition & 1 deletion Builds/CMake/deps/Findlz4.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
find_package (PkgConfig)
if (PKG_CONFIG_FOUND)
pkg_search_module (lz4_PC QUIET liblz4>=1.8)
pkg_search_module (lz4_PC QUIET liblz4>=1.9)
endif ()

if(static)
Expand Down
2 changes: 1 addition & 1 deletion Builds/CMake/deps/Lz4.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ else()
ExternalProject_Add (lz4
PREFIX ${nih_cache_path}
GIT_REPOSITORY https://github.com/lz4/lz4.git
GIT_TAG v1.8.2
GIT_TAG v1.9.2
SOURCE_SUBDIR contrib/cmake_unofficial
CMAKE_ARGS
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
Expand Down
16 changes: 9 additions & 7 deletions src/ripple/nodestore/impl/DatabaseShardImp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,12 @@ DatabaseShardImp::init()
std::make_unique<Shard>(app_, *this, shardIndex, j_)};
if (!shard->open(scheduler_, *ctx_))
{
if (!shard->isLegacy())
return false;

// Remove legacy shard
// Remove corrupted or legacy shard
shard->removeOnDestroy();
JLOG(j_.warn())
<< "shard " << shardIndex << " removed, legacy shard";
<< "shard " << shardIndex << " removed, "
<< (shard->isLegacy() ? "legacy" : "corrupted")
<< " shard";
continue;
}

Expand Down Expand Up @@ -276,11 +275,11 @@ DatabaseShardImp::prepareShard(std::uint32_t shardIndex)
// is greater or equal to the current shard.
auto seqCheck = [&](std::uint32_t seq) {
// seq will be greater than zero if valid
if (seq > earliestLedgerSeq() && shardIndex >= seqToShardIndex(seq))
if (seq >= earliestLedgerSeq() && shardIndex >= seqToShardIndex(seq))
return fail("has an invalid index");
return true;
};
if (!seqCheck(app_.getLedgerMaster().getValidLedgerIndex()) ||
if (!seqCheck(app_.getLedgerMaster().getValidLedgerIndex() + 1) ||
!seqCheck(app_.getLedgerMaster().getCurrentLedgerIndex()))
{
return false;
Expand Down Expand Up @@ -1100,6 +1099,9 @@ DatabaseShardImp::initConfig(std::lock_guard<std::mutex>&)
ledgersPerShard_ = get<std::uint32_t>(section, "ledgers_per_shard");
if (ledgersPerShard_ == 0 || ledgersPerShard_ % 256 != 0)
return fail("'ledgers_per_shard' must be a multiple of 256");

earliestShardIndex_ = seqToShardIndex(earliestLedgerSeq());
undertome marked this conversation as resolved.
Show resolved Hide resolved
avgShardFileSz_ = ledgersPerShard_ * kilobytes(192);
}

// NuDB is the default and only supported permanent storage backend
Expand Down
2 changes: 1 addition & 1 deletion src/ripple/nodestore/impl/DatabaseShardImp.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ class DatabaseShardImp : public DatabaseShard
std::uint32_t ledgersPerShard_ = ledgersPerShardDefault;

// The earliest shard index
std::uint32_t const earliestShardIndex_;
std::uint32_t earliestShardIndex_;
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like you removed the const qualifier in order to set earliestShardIndex_ in DatabaseShardImp::initConfig. Why is that necessary when this variable gets initialized during the constructor?

Copy link
Author

Choose a reason for hiding this comment

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

See previous comment.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I understand why you did this - it's a consequence of the two phase initialization and testing. I'm OK with the change, but I'd add a comment explaining why this is not const.


// Average storage space required by a shard (in bytes)
std::uint64_t avgShardFileSz_;
Expand Down
9 changes: 4 additions & 5 deletions src/ripple/nodestore/impl/codec.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,12 @@ lz4_decompress(void const* in, std::size_t in_size, BufferFactory&& bf)
Throw<std::runtime_error>("lz4 decompress: n == 0");
void* const out = bf(result.second);
result.first = out;
if (LZ4_decompress_fast(
if (LZ4_decompress_safe(
reinterpret_cast<char const*>(in) + n,
reinterpret_cast<char*>(out),
result.second) +
n !=
in_size)
Throw<std::runtime_error>("lz4 decompress: LZ4_decompress_fast");
in_size - n,
result.second) != result.second)
Throw<std::runtime_error>("lz4 decompress: LZ4_decompress_safe");
return result;
}

Expand Down
16 changes: 11 additions & 5 deletions src/test/jtx/Env.h
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,10 @@ class Env

The Application network time is set to
the close time of the resulting ledger.

@return true if no error, false if error
*/
void
bool
seelabs marked this conversation as resolved.
Show resolved Hide resolved
close(
NetClock::time_point closeTime,
boost::optional<std::chrono::milliseconds> consensusDelay =
Expand All @@ -336,25 +338,29 @@ class Env

The time is calculated as the duration from
the previous ledger closing time.

@return true if no error, false if error
*/
template <class Rep, class Period>
void
bool
close(std::chrono::duration<Rep, Period> const& elapsed)
{
// VFALCO Is this the correct time?
close(now() + elapsed);
return close(now() + elapsed);
}

/** Close and advance the ledger.

The time is calculated as five seconds from
the previous ledger closing time.

@return true if no error, false if error
*/
void
bool
close()
{
// VFALCO Is this the correct time?
close(std::chrono::seconds(5));
return close(std::chrono::seconds(5));
}

/** Turn on JSON tracing.
Expand Down
14 changes: 11 additions & 3 deletions src/test/jtx/impl/Env.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,14 @@ Env::closed()
return app().getLedgerMaster().getClosedLedger();
}

void
bool
Env::close(
NetClock::time_point closeTime,
boost::optional<std::chrono::milliseconds> consensusDelay)
{
// Round up to next distinguishable value
using namespace std::chrono_literals;
bool res = true;
closeTime += closed()->info().closeTimeResolution - 1s;
timeKeeper().set(closeTime);
// Go through the rpc interface unless we need to simulate
Expand All @@ -122,10 +123,17 @@ Env::close(
app().getOPs().acceptLedger(consensusDelay);
else
{
rpc("ledger_accept");
// VFALCO No error check?
auto resp = rpc("ledger_accept");
if (resp["result"]["status"] != std::string("success"))
{
JLOG(journal.error())
<< "Env::close() failed: " << resp["result"]["status"]
<< std::endl;
res = false;
}
}
timeKeeper().set(closed()->info().closeTime);
return res;
}

void
Expand Down
Loading