mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-01 16:05:52 +00:00
Unit tests for database shards
This commit is contained in:
@@ -408,7 +408,8 @@ cache:
|
|||||||
- $CACHE_DIR
|
- $CACHE_DIR
|
||||||
|
|
||||||
before_install:
|
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}"
|
- echo "NUM PROC is ${NUM_PROCESSORS}"
|
||||||
- if [ "$(uname)" = "Linux" ] ; then docker pull ${DOCKER_IMAGE}; fi
|
- if [ "$(uname)" = "Linux" ] ; then docker pull ${DOCKER_IMAGE}; fi
|
||||||
- if [ "${MATRIX_EVAL}" != "" ] ; then eval "${MATRIX_EVAL}"; fi
|
- if [ "${MATRIX_EVAL}" != "" ] ; then eval "${MATRIX_EVAL}"; fi
|
||||||
|
|||||||
@@ -844,6 +844,7 @@ target_sources (rippled PRIVATE
|
|||||||
#]===============================]
|
#]===============================]
|
||||||
src/test/nodestore/Backend_test.cpp
|
src/test/nodestore/Backend_test.cpp
|
||||||
src/test/nodestore/Basics_test.cpp
|
src/test/nodestore/Basics_test.cpp
|
||||||
|
src/test/nodestore/DatabaseShard_test.cpp
|
||||||
src/test/nodestore/Database_test.cpp
|
src/test/nodestore/Database_test.cpp
|
||||||
src/test/nodestore/Timing_test.cpp
|
src/test/nodestore/Timing_test.cpp
|
||||||
src/test/nodestore/import_test.cpp
|
src/test/nodestore/import_test.cpp
|
||||||
|
|||||||
@@ -135,13 +135,12 @@ DatabaseShardImp::init()
|
|||||||
std::make_unique<Shard>(app_, *this, shardIndex, j_)};
|
std::make_unique<Shard>(app_, *this, shardIndex, j_)};
|
||||||
if (!shard->open(scheduler_, *ctx_))
|
if (!shard->open(scheduler_, *ctx_))
|
||||||
{
|
{
|
||||||
if (!shard->isLegacy())
|
// Remove corrupted or legacy shard
|
||||||
return false;
|
|
||||||
|
|
||||||
// Remove legacy shard
|
|
||||||
shard->removeOnDestroy();
|
shard->removeOnDestroy();
|
||||||
JLOG(j_.warn())
|
JLOG(j_.warn())
|
||||||
<< "shard " << shardIndex << " removed, legacy shard";
|
<< "shard " << shardIndex << " removed, "
|
||||||
|
<< (shard->isLegacy() ? "legacy" : "corrupted")
|
||||||
|
<< " shard";
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -276,11 +275,11 @@ DatabaseShardImp::prepareShard(std::uint32_t shardIndex)
|
|||||||
// is greater or equal to the current shard.
|
// is greater or equal to the current shard.
|
||||||
auto seqCheck = [&](std::uint32_t seq) {
|
auto seqCheck = [&](std::uint32_t seq) {
|
||||||
// seq will be greater than zero if valid
|
// 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 fail("has an invalid index");
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
if (!seqCheck(app_.getLedgerMaster().getValidLedgerIndex()) ||
|
if (!seqCheck(app_.getLedgerMaster().getValidLedgerIndex() + 1) ||
|
||||||
!seqCheck(app_.getLedgerMaster().getCurrentLedgerIndex()))
|
!seqCheck(app_.getLedgerMaster().getCurrentLedgerIndex()))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
@@ -1100,6 +1099,9 @@ DatabaseShardImp::initConfig(std::lock_guard<std::mutex>&)
|
|||||||
ledgersPerShard_ = get<std::uint32_t>(section, "ledgers_per_shard");
|
ledgersPerShard_ = get<std::uint32_t>(section, "ledgers_per_shard");
|
||||||
if (ledgersPerShard_ == 0 || ledgersPerShard_ % 256 != 0)
|
if (ledgersPerShard_ == 0 || ledgersPerShard_ % 256 != 0)
|
||||||
return fail("'ledgers_per_shard' must be a multiple of 256");
|
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
|
// NuDB is the default and only supported permanent storage backend
|
||||||
|
|||||||
@@ -234,7 +234,7 @@ private:
|
|||||||
std::uint32_t ledgersPerShard_ = ledgersPerShardDefault;
|
std::uint32_t ledgersPerShard_ = ledgersPerShardDefault;
|
||||||
|
|
||||||
// The earliest shard index
|
// The earliest shard index
|
||||||
std::uint32_t const earliestShardIndex_;
|
std::uint32_t earliestShardIndex_;
|
||||||
|
|
||||||
// Average storage space required by a shard (in bytes)
|
// Average storage space required by a shard (in bytes)
|
||||||
std::uint64_t avgShardFileSz_;
|
std::uint64_t avgShardFileSz_;
|
||||||
|
|||||||
@@ -325,8 +325,10 @@ public:
|
|||||||
|
|
||||||
The Application network time is set to
|
The Application network time is set to
|
||||||
the close time of the resulting ledger.
|
the close time of the resulting ledger.
|
||||||
|
|
||||||
|
@return true if no error, false if error
|
||||||
*/
|
*/
|
||||||
void
|
bool
|
||||||
close(
|
close(
|
||||||
NetClock::time_point closeTime,
|
NetClock::time_point closeTime,
|
||||||
boost::optional<std::chrono::milliseconds> consensusDelay =
|
boost::optional<std::chrono::milliseconds> consensusDelay =
|
||||||
@@ -336,25 +338,29 @@ public:
|
|||||||
|
|
||||||
The time is calculated as the duration from
|
The time is calculated as the duration from
|
||||||
the previous ledger closing time.
|
the previous ledger closing time.
|
||||||
|
|
||||||
|
@return true if no error, false if error
|
||||||
*/
|
*/
|
||||||
template <class Rep, class Period>
|
template <class Rep, class Period>
|
||||||
void
|
bool
|
||||||
close(std::chrono::duration<Rep, Period> const& elapsed)
|
close(std::chrono::duration<Rep, Period> const& elapsed)
|
||||||
{
|
{
|
||||||
// VFALCO Is this the correct time?
|
// VFALCO Is this the correct time?
|
||||||
close(now() + elapsed);
|
return close(now() + elapsed);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Close and advance the ledger.
|
/** Close and advance the ledger.
|
||||||
|
|
||||||
The time is calculated as five seconds from
|
The time is calculated as five seconds from
|
||||||
the previous ledger closing time.
|
the previous ledger closing time.
|
||||||
|
|
||||||
|
@return true if no error, false if error
|
||||||
*/
|
*/
|
||||||
void
|
bool
|
||||||
close()
|
close()
|
||||||
{
|
{
|
||||||
// VFALCO Is this the correct time?
|
// VFALCO Is this the correct time?
|
||||||
close(std::chrono::seconds(5));
|
return close(std::chrono::seconds(5));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Turn on JSON tracing.
|
/** Turn on JSON tracing.
|
||||||
|
|||||||
@@ -107,13 +107,14 @@ Env::closed()
|
|||||||
return app().getLedgerMaster().getClosedLedger();
|
return app().getLedgerMaster().getClosedLedger();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
bool
|
||||||
Env::close(
|
Env::close(
|
||||||
NetClock::time_point closeTime,
|
NetClock::time_point closeTime,
|
||||||
boost::optional<std::chrono::milliseconds> consensusDelay)
|
boost::optional<std::chrono::milliseconds> consensusDelay)
|
||||||
{
|
{
|
||||||
// Round up to next distinguishable value
|
// Round up to next distinguishable value
|
||||||
using namespace std::chrono_literals;
|
using namespace std::chrono_literals;
|
||||||
|
bool res = true;
|
||||||
closeTime += closed()->info().closeTimeResolution - 1s;
|
closeTime += closed()->info().closeTimeResolution - 1s;
|
||||||
timeKeeper().set(closeTime);
|
timeKeeper().set(closeTime);
|
||||||
// Go through the rpc interface unless we need to simulate
|
// Go through the rpc interface unless we need to simulate
|
||||||
@@ -122,10 +123,17 @@ Env::close(
|
|||||||
app().getOPs().acceptLedger(consensusDelay);
|
app().getOPs().acceptLedger(consensusDelay);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
rpc("ledger_accept");
|
auto resp = rpc("ledger_accept");
|
||||||
// VFALCO No error check?
|
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);
|
timeKeeper().set(closed()->info().closeTime);
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
1019
src/test/nodestore/DatabaseShard_test.cpp
Normal file
1019
src/test/nodestore/DatabaseShard_test.cpp
Normal file
File diff suppressed because it is too large
Load Diff
@@ -167,6 +167,9 @@ public:
|
|||||||
section.set("path", tempDir.path());
|
section.set("path", tempDir.path());
|
||||||
section.set("max_size_gb", "100");
|
section.set("max_size_gb", "100");
|
||||||
section.set("ledgers_per_shard", "256");
|
section.set("ledgers_per_shard", "256");
|
||||||
|
section.set("earliest_seq", "257");
|
||||||
|
auto& sectionNode = c->section(ConfigSection::nodeDatabase());
|
||||||
|
sectionNode.set("earliest_seq", "257");
|
||||||
c->setupControl(true, true, true);
|
c->setupControl(true, true, true);
|
||||||
|
|
||||||
jtx::Env env(*this, std::move(c));
|
jtx::Env env(*this, std::move(c));
|
||||||
@@ -262,6 +265,9 @@ public:
|
|||||||
section.set("path", tempDir.path());
|
section.set("path", tempDir.path());
|
||||||
section.set("max_size_gb", "100");
|
section.set("max_size_gb", "100");
|
||||||
section.set("ledgers_per_shard", "256");
|
section.set("ledgers_per_shard", "256");
|
||||||
|
section.set("earliest_seq", "257");
|
||||||
|
auto& sectionNode = c->section(ConfigSection::nodeDatabase());
|
||||||
|
sectionNode.set("earliest_seq", "257");
|
||||||
c->setupControl(true, true, true);
|
c->setupControl(true, true, true);
|
||||||
|
|
||||||
jtx::Env env(*this, std::move(c));
|
jtx::Env env(*this, std::move(c));
|
||||||
@@ -358,6 +364,9 @@ public:
|
|||||||
section.set("ledgers_per_shard", "256");
|
section.set("ledgers_per_shard", "256");
|
||||||
section.set("shard_verification_retry_interval", "1");
|
section.set("shard_verification_retry_interval", "1");
|
||||||
section.set("shard_verification_max_attempts", "10000");
|
section.set("shard_verification_max_attempts", "10000");
|
||||||
|
section.set("earliest_seq", "257");
|
||||||
|
auto& sectionNode = c->section(ConfigSection::nodeDatabase());
|
||||||
|
sectionNode.set("earliest_seq", "257");
|
||||||
c->setupControl(true, true, true);
|
c->setupControl(true, true, true);
|
||||||
|
|
||||||
jtx::Env env(*this, std::move(c));
|
jtx::Env env(*this, std::move(c));
|
||||||
|
|||||||
Reference in New Issue
Block a user