diff options
author | alexvru <alexvru@ydb.tech> | 2022-09-09 18:51:14 +0300 |
---|---|---|
committer | alexvru <alexvru@ydb.tech> | 2022-09-09 18:51:14 +0300 |
commit | d27978150581c97592110c7bcbf00e45bc2e4cdd (patch) | |
tree | 8faeaa141556420ddc99ba5b3dc0164088d030f2 | |
parent | 35d11d7f064bf324e236e14500a05cd7b69a6b9a (diff) | |
download | ydb-d27978150581c97592110c7bcbf00e45bc2e4cdd.tar.gz |
Improve TestShard by replacing MD5 with t1ha
-rw-r--r-- | ydb/core/protos/services.proto | 2 | ||||
-rw-r--r-- | ydb/core/test_tablet/CMakeLists.txt | 1 | ||||
-rw-r--r-- | ydb/core/test_tablet/defs.h | 3 | ||||
-rw-r--r-- | ydb/core/test_tablet/load_actor_impl.cpp | 5 | ||||
-rw-r--r-- | ydb/core/test_tablet/load_actor_impl.h | 6 | ||||
-rw-r--r-- | ydb/core/test_tablet/load_actor_read_validate.cpp | 13 | ||||
-rw-r--r-- | ydb/core/test_tablet/load_actor_write.cpp | 10 | ||||
-rw-r--r-- | ydb/core/test_tablet/scheme.h | 9 | ||||
-rw-r--r-- | ydb/core/test_tablet/test_shard_impl.h | 1 | ||||
-rw-r--r-- | ydb/core/test_tablet/tx_initialize.cpp | 5 | ||||
-rw-r--r-- | ydb/core/test_tablet/tx_load_everything.cpp | 2 | ||||
-rw-r--r-- | ydb/core/util/lz4_data_generator.h | 16 |
12 files changed, 47 insertions, 26 deletions
diff --git a/ydb/core/protos/services.proto b/ydb/core/protos/services.proto index d661e5ef9c3..edfdc741af7 100644 --- a/ydb/core/protos/services.proto +++ b/ydb/core/protos/services.proto @@ -912,5 +912,7 @@ message TActivity { LB_CM_FOLDER_ACTOR = 579; BLOB_DEPOT_ASSIMILATOR_ACTOR = 580; BLOB_DEPOT_BLOCKS_PROCESSOR_ACTOR = 581; + TEST_SHARD_LOAD_ACTOR = 582; + TEST_SHARD_VALIDATION_ACTOR = 583; }; }; diff --git a/ydb/core/test_tablet/CMakeLists.txt b/ydb/core/test_tablet/CMakeLists.txt index 5ba717aa12e..bd8e7e61c59 100644 --- a/ydb/core/test_tablet/CMakeLists.txt +++ b/ydb/core/test_tablet/CMakeLists.txt @@ -11,6 +11,7 @@ add_library(ydb-core-test_tablet) target_link_libraries(ydb-core-test_tablet PUBLIC contrib-libs-cxxsupp yutil + contrib-libs-t1ha cpp-digest-md5 ydb-core-keyvalue ydb-core-protos diff --git a/ydb/core/test_tablet/defs.h b/ydb/core/test_tablet/defs.h index 12f33fe5910..2d67514a1ef 100644 --- a/ydb/core/test_tablet/defs.h +++ b/ydb/core/test_tablet/defs.h @@ -2,9 +2,10 @@ #include <ydb/core/keyvalue/keyvalue_flat_impl.h> #include <ydb/core/tablet_flat/flat_cxx_database.h> +#include <ydb/core/util/lz4_data_generator.h> #include <ydb/core/util/stlog.h> #include <ydb/core/protos/counters_testshard.pb.h> #include <ydb/core/protos/test_shard.pb.h> #include <library/cpp/actors/core/actor_coroutine.h> #include <library/cpp/actors/interconnect/poller_actor.h> -#include <library/cpp/digest/md5/md5.h> +#include <contrib/libs/t1ha/t1ha.h> diff --git a/ydb/core/test_tablet/load_actor_impl.cpp b/ydb/core/test_tablet/load_actor_impl.cpp index e0dea392639..91d4e253993 100644 --- a/ydb/core/test_tablet/load_actor_impl.cpp +++ b/ydb/core/test_tablet/load_actor_impl.cpp @@ -53,8 +53,11 @@ namespace NKikimr::NTestShard { RunValidation(false); } } else { // resume load - while (WritesInFlight.size() < Settings.GetMaxInFlight()) { // write until there is space in inflight + if (WritesInFlight.size() < Settings.GetMaxInFlight()) { // write until there is space in inflight IssueWrite(); + if (WritesInFlight.size() < Settings.GetMaxInFlight()) { + TActivationContext::Send(new IEventHandle(EvDoSomeAction, 0, SelfId(), {}, nullptr, 0)); + } } if (BytesOfData > Settings.GetMaxDataBytes()) { // delete some data if needed IssueDelete(); diff --git a/ydb/core/test_tablet/load_actor_impl.h b/ydb/core/test_tablet/load_actor_impl.h index 2da3b1f07ac..390baa47ac7 100644 --- a/ydb/core/test_tablet/load_actor_impl.h +++ b/ydb/core/test_tablet/load_actor_impl.h @@ -30,6 +30,7 @@ namespace NKikimr::NTestShard { enum { EvValidationFinished = EventSpaceBegin(TEvents::ES_PRIVATE), + EvDoSomeAction, }; struct TEvValidationFinished : TEventLocal<TEvValidationFinished, EvValidationFinished> { @@ -43,6 +44,10 @@ namespace NKikimr::NTestShard { }; public: + static constexpr NKikimrServices::TActivity::EType ActorActivityType() { + return NKikimrServices::TActivity::TEST_SHARD_LOAD_ACTOR; + } + TLoadActor(ui64 tabletId, ui32 generation, const TActorId tablet, const NKikimrClient::TTestShardControlRequest::TCmdInitialize& settings); void Bootstrap(const TActorId& parentId); @@ -57,6 +62,7 @@ namespace NKikimr::NTestShard { hFunc(TEvStateServerStatus, Handle); hFunc(TEvStateServerWriteResult, Handle); hFunc(TEvValidationFinished, Handle); + cFunc(EvDoSomeAction, Action); cFunc(TEvents::TSystem::Poison, PassAway); cFunc(TEvents::TSystem::Wakeup, HandleWakeup); ) diff --git a/ydb/core/test_tablet/load_actor_read_validate.cpp b/ydb/core/test_tablet/load_actor_read_validate.cpp index 4b45f033338..70cf5f97d4c 100644 --- a/ydb/core/test_tablet/load_actor_read_validate.cpp +++ b/ydb/core/test_tablet/load_actor_read_validate.cpp @@ -1,4 +1,5 @@ #include "load_actor_impl.h" +#include "scheme.h" namespace NKikimr::NTestShard { @@ -37,6 +38,10 @@ namespace NKikimr::NTestShard { }; public: + static constexpr NKikimrServices::TActivity::EType ActorActivityType() { + return NKikimrServices::TActivity::TEST_SHARD_VALIDATION_ACTOR; + } + TValidationActor(TLoadActor& self, bool initialCheck) : Settings(self.Settings) , TabletId(self.TabletId) @@ -150,8 +155,8 @@ namespace NKikimr::NTestShard { const TString& value = res.GetValue(); const bool inserted = Keys.try_emplace(key, value.size()).second; Y_VERIFY(inserted); - Y_VERIFY_S(MD5::Calc(value) == key, "TabletId# " << TabletId << " Key# " << key << " digest mismatch" - " actual# " << MD5::Calc(value) << " len# " << value.size()); + Y_VERIFY_S(HashForValue(value) == key, "TabletId# " << TabletId << " Key# " << key << " digest mismatch" + " actual# " << HashForValue(value) << " len# " << value.size()); STLOG(PRI_DEBUG, TEST_SHARD, TS16, "read key", (TabletId, TabletId), (Key, key)); } else { WaitedReadRangesViaEvResponse--; @@ -210,8 +215,8 @@ namespace NKikimr::NTestShard { const TString& value = record.value(); const bool inserted = Keys.try_emplace(key, value.size()).second; Y_VERIFY(inserted); - Y_VERIFY_S(MD5::Calc(value) == key, "TabletId# " << TabletId << " Key# " << key << " digest mismatch" - " actual# " << MD5::Calc(value) << " len# " << value.size()); + Y_VERIFY_S(HashForValue(value) == key, "TabletId# " << TabletId << " Key# " << key << " digest mismatch" + " actual# " << HashForValue(value) << " len# " << value.size()); STLOG(PRI_DEBUG, TEST_SHARD, TS25, "read key", (TabletId, TabletId), (Key, key)); FinishIfPossible(); } diff --git a/ydb/core/test_tablet/load_actor_write.cpp b/ydb/core/test_tablet/load_actor_write.cpp index 719a0a334cb..20db6b1b5b6 100644 --- a/ydb/core/test_tablet/load_actor_write.cpp +++ b/ydb/core/test_tablet/load_actor_write.cpp @@ -1,6 +1,5 @@ #include "load_actor_impl.h" - -#include <ydb/core/util/lz4_data_generator.h> +#include "scheme.h" namespace NKikimr::NTestShard { @@ -8,11 +7,8 @@ namespace NKikimr::NTestShard { const size_t len = GenerateRandomSize(Settings.GetSizes(), isInline) + sizeof(ui64); ui64 seed = TAppData::RandomProvider->GenRand64(); TString data = FastGenDataForLZ4(len, seed); - char *charData = data.Detach(); - for (size_t i = 0; i < Min<size_t>(sizeof(seed), data.size()); ++i) { - charData[i] = *(reinterpret_cast<char*>(&seed) + i); - } - *key = MD5::Calc(data); + memcpy(data.Detach(), &seed, Min(data.size(), sizeof(seed))); + *key = HashForValue(data); *value = std::move(data); } diff --git a/ydb/core/test_tablet/scheme.h b/ydb/core/test_tablet/scheme.h index 1c32514c1ff..8e8f76214be 100644 --- a/ydb/core/test_tablet/scheme.h +++ b/ydb/core/test_tablet/scheme.h @@ -8,13 +8,18 @@ namespace NKikimr::NTestShard { struct State : Table<100> { struct Key : Column<1, NScheme::NTypeIds::Bool> { static constexpr Type Default = {}; }; struct Settings : Column<2, NScheme::NTypeIds::String> {}; - struct Digest : Column<3, NScheme::NTypeIds::String> {}; using TKey = TableKey<Key>; - using TColumns = TableColumns<Key, Settings, Digest>; + using TColumns = TableColumns<Key, Settings>; }; using TTables = SchemaTables<State>; }; + inline TString HashForValue(const TString& value) { + uint64_t data[2]; + data[0] = t1ha2_atonce128(&data[1], value.data(), value.size(), 1); + return HexEncode(data, sizeof(data)); + } + } // NKikimr::NTestShard diff --git a/ydb/core/test_tablet/test_shard_impl.h b/ydb/core/test_tablet/test_shard_impl.h index 78b8e77fd3c..4ef0a685f2a 100644 --- a/ydb/core/test_tablet/test_shard_impl.h +++ b/ydb/core/test_tablet/test_shard_impl.h @@ -59,6 +59,7 @@ namespace NKikimr::NTestShard { } bool HandleHook(STFUNC_SIG) override { + SetActivityType(NKikimrServices::TActivity::TEST_SHARD_ACTOR); switch (ev->GetTypeRewrite()) { HFunc(TEvControlRequest, Handle); HFunc(TEvSwitchMode, Handle); diff --git a/ydb/core/test_tablet/tx_initialize.cpp b/ydb/core/test_tablet/tx_initialize.cpp index 70614cd3e90..cc04f65e60a 100644 --- a/ydb/core/test_tablet/tx_initialize.cpp +++ b/ydb/core/test_tablet/tx_initialize.cpp @@ -22,12 +22,9 @@ namespace NKikimr::NTestShard { const bool success = Cmd.SerializeToString(&settings); Y_VERIFY(success); - const TString digest = MD5::CalcRaw(settings); - NIceDb::TNiceDb db(txc.DB); db.Table<Schema::State>().Key(Schema::State::Key::Default).Update( - NIceDb::TUpdate<Schema::State::Settings>(settings), - NIceDb::TUpdate<Schema::State::Digest>(digest)); + NIceDb::TUpdate<Schema::State::Settings>(settings)); return true; } diff --git a/ydb/core/test_tablet/tx_load_everything.cpp b/ydb/core/test_tablet/tx_load_everything.cpp index b00a3dada11..66136ca9978 100644 --- a/ydb/core/test_tablet/tx_load_everything.cpp +++ b/ydb/core/test_tablet/tx_load_everything.cpp @@ -18,8 +18,6 @@ namespace NKikimr::NTestShard { return false; } else if (table.IsValid()) { const TString settings = table.GetValue<T::Settings>(); - const TString digest = table.GetValue<T::Digest>(); - Y_VERIFY(digest == MD5::CalcRaw(settings)); Self->Settings.emplace(); const bool success = Self->Settings->ParseFromString(settings); Y_VERIFY(success); diff --git a/ydb/core/util/lz4_data_generator.h b/ydb/core/util/lz4_data_generator.h index d0fbdfe602e..1c979bb9bd2 100644 --- a/ydb/core/util/lz4_data_generator.h +++ b/ydb/core/util/lz4_data_generator.h @@ -16,21 +16,27 @@ inline TString GenDataForLZ4(const ui64 size, const ui64 seed = 0) { return data; } -inline TString FastGenDataForLZ4(i64 size, ui64 seed) { +inline TString FastGenDataForLZ4(size_t size, ui64 seed) { TString data = TString::Uninitialized(size); TReallyFastRng32 rng(seed); constexpr size_t minRunLen = 32; constexpr size_t maxRunLen = 64; - const size_t runLen = minRunLen + rng() % (maxRunLen - minRunLen + 1); + const size_t runLen = minRunLen + sizeof(ui32) * rng() % ((maxRunLen - minRunLen) / sizeof(ui32) + 1); char run[maxRunLen]; - std::generate(run, run + runLen, rng); + ui32 i; + for (i = 0; i < runLen; i += sizeof(ui32)) { + reinterpret_cast<ui32&>(i[run]) = rng(); + } + Y_VERIFY_DEBUG(i == runLen); - for (char *ptr = data.Detach(); size > 0; ptr += runLen, size -= runLen) { - memcpy(ptr, run, Min<size_t>(size, runLen)); + char *ptr = data.Detach(); + for (; size >= runLen; size -= runLen, ptr += runLen) { + memcpy(ptr, run, runLen); } + memcpy(ptr, run, size); return data; } |