Skip to content

Commit

Permalink
Unit tests for database shards
Browse files Browse the repository at this point in the history
  • Loading branch information
p2peer authored and manojsdoshi committed May 30, 2020
1 parent 728651b commit 93bf77b
Show file tree
Hide file tree
Showing 8 changed files with 1,063 additions and 17 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
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
- 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
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
src/test/nodestore/Database_test.cpp
src/test/nodestore/Timing_test.cpp
src/test/nodestore/import_test.cpp
Expand Down
16 changes: 9 additions & 7 deletions src/ripple/nodestore/impl/DatabaseShardImp.cpp
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());
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
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_;

// Average storage space required by a shard (in bytes)
std::uint64_t avgShardFileSz_;
Expand Down
16 changes: 11 additions & 5 deletions src/test/jtx/Env.h
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
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
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

0 comments on commit 93bf77b

Please sign in to comment.