diff options
author | apovetkin <apovetkin@yandex-team.ru> | 2022-02-10 16:52:26 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:52:26 +0300 |
commit | 795ef07e62ab2a6ebfaf974c8b045408e757fc63 (patch) | |
tree | 9d3e479fdde134c76c3223e1b870ade5a1903aae | |
parent | a0c9e748d8da41213a0a097927866b28c7974893 (diff) | |
download | ydb-795ef07e62ab2a6ebfaf974c8b045408e757fc63.tar.gz |
Restoring authorship annotation for <apovetkin@yandex-team.ru>. Commit 1 of 2.
-rw-r--r-- | ydb/core/base/statestorage.cpp | 36 | ||||
-rw-r--r-- | ydb/core/base/statestorage.h | 2 | ||||
-rw-r--r-- | ydb/core/base/statestorage_ut.cpp | 130 | ||||
-rw-r--r-- | ydb/core/protos/config.proto | 4 |
4 files changed, 86 insertions, 86 deletions
diff --git a/ydb/core/base/statestorage.cpp b/ydb/core/base/statestorage.cpp index de39a327ae..021a73bedb 100644 --- a/ydb/core/base/statestorage.cpp +++ b/ydb/core/base/statestorage.cpp @@ -94,11 +94,11 @@ TActorId TStateStorageInfo::TRing::SelectReplica(ui32 hash) const { return Replicas[0]; Y_VERIFY(!Replicas.empty()); - if (UseRingSpecificNodeSelection) { - return Replicas[CombineHashes(hash, ContentHash()) % Replicas.size()]; - } else { - return Replicas[hash % Replicas.size()]; - } + if (UseRingSpecificNodeSelection) { + return Replicas[CombineHashes(hash, ContentHash()) % Replicas.size()]; + } else { + return Replicas[hash % Replicas.size()]; + } } TList<TActorId> TStateStorageInfo::SelectAllReplicas() const { @@ -202,22 +202,22 @@ static void CopyStateStorageRingInfo( serviceId[depth] = (iring + 1); const NKikimrConfig::TDomainsConfig::TStateStorage::TRing &ring = source.GetRing(iring); - info->Rings[iring].UseRingSpecificNodeSelection = ring.GetUseRingSpecificNodeSelection(); - if (ring.GetUseSingleNodeActorId()) { - Y_VERIFY(ring.NodeSize() == 1); + info->Rings[iring].UseRingSpecificNodeSelection = ring.GetUseRingSpecificNodeSelection(); + if (ring.GetUseSingleNodeActorId()) { + Y_VERIFY(ring.NodeSize() == 1); - const TActorId replicaActorID = TActorId(ring.GetNode(0), TStringBuf(serviceId, serviceId + 12)); + const TActorId replicaActorID = TActorId(ring.GetNode(0), TStringBuf(serviceId, serviceId + 12)); info->Rings[iring].Replicas.push_back(replicaActorID); } - else { - Y_VERIFY(ring.NodeSize() > 0); - - for (ui32 inode = 0, enode = ring.NodeSize(); inode != enode; ++inode) { - serviceId[depth + 1] = (inode + 1); - const TActorId replicaActorID = TActorId(ring.GetNode(inode), TStringBuf(serviceId, serviceId + 12)); - info->Rings[iring].Replicas.push_back(replicaActorID); - } - } + else { + Y_VERIFY(ring.NodeSize() > 0); + + for (ui32 inode = 0, enode = ring.NodeSize(); inode != enode; ++inode) { + serviceId[depth + 1] = (inode + 1); + const TActorId replicaActorID = TActorId(ring.GetNode(inode), TStringBuf(serviceId, serviceId + 12)); + info->Rings[iring].Replicas.push_back(replicaActorID); + } + } // reset for next ring serviceId[depth + 1] = char(); } diff --git a/ydb/core/base/statestorage.h b/ydb/core/base/statestorage.h index 9b3e3b6b1b..f278f3e906 100644 --- a/ydb/core/base/statestorage.h +++ b/ydb/core/base/statestorage.h @@ -472,7 +472,7 @@ struct TStateStorageInfo : public TThrRefBase { }; struct TRing { - bool UseRingSpecificNodeSelection; + bool UseRingSpecificNodeSelection; TVector<TActorId> Replicas; TActorId SelectReplica(ui32 hash) const; diff --git a/ydb/core/base/statestorage_ut.cpp b/ydb/core/base/statestorage_ut.cpp index 94a49082db..0fe4fcd50e 100644 --- a/ydb/core/base/statestorage_ut.cpp +++ b/ydb/core/base/statestorage_ut.cpp @@ -7,7 +7,7 @@ namespace NKikimr { Y_UNIT_TEST_SUITE(TStateStorageConfig) { - void FillStateStorageInfo(TStateStorageInfo *info, ui32 replicas, ui32 nToSelect, ui32 replicasInRing, bool useRingSpecificNodeSelection) { + void FillStateStorageInfo(TStateStorageInfo *info, ui32 replicas, ui32 nToSelect, ui32 replicasInRing, bool useRingSpecificNodeSelection) { info->StateStorageGroup = 1; info->NToSelect = nToSelect; @@ -15,16 +15,16 @@ Y_UNIT_TEST_SUITE(TStateStorageConfig) { for (ui32 i : xrange(replicas)) { for (ui32 j : xrange(replicasInRing)) { info->Rings[i].Replicas.push_back(TActorId(i, i, i + j, i)); - info->Rings[i].UseRingSpecificNodeSelection = useRingSpecificNodeSelection; + info->Rings[i].UseRingSpecificNodeSelection = useRingSpecificNodeSelection; } } } - ui64 StabilityRun(ui32 replicas, ui32 nToSelect, ui32 replicasInRing, bool useRingSpecificNodeSelection) { + ui64 StabilityRun(ui32 replicas, ui32 nToSelect, ui32 replicasInRing, bool useRingSpecificNodeSelection) { ui64 retHash = 0; TStateStorageInfo info; - FillStateStorageInfo(&info, replicas, nToSelect, replicasInRing, useRingSpecificNodeSelection); + FillStateStorageInfo(&info, replicas, nToSelect, replicasInRing, useRingSpecificNodeSelection); TStateStorageInfo::TSelection selection; for (ui64 tabletId = 8000000; tabletId < 9000000; ++tabletId) { @@ -36,64 +36,64 @@ Y_UNIT_TEST_SUITE(TStateStorageConfig) { return retHash; } - double UniqueCombinationsRun(ui32 replicas, ui32 nToSelect, ui32 replicasInRing, bool useRingSpecificNodeSelection) { - const ui64 tabletStartId = 8000000; - const ui64 tabletCount = 1000000; - TStateStorageInfo info; - FillStateStorageInfo(&info, replicas, nToSelect, replicasInRing, useRingSpecificNodeSelection); - - THashSet<ui64> hashes; - - TStateStorageInfo::TSelection selection; - for (ui64 tabletId = tabletStartId; tabletId < tabletStartId + tabletCount; ++tabletId) { - ui64 selectionHash = 0; - info.SelectReplicas(tabletId, &selection); - Y_VERIFY(nToSelect == selection.Sz); - for (ui32 idx : xrange(nToSelect)) - selectionHash = CombineHashes<ui64>(selectionHash, selection.SelectedReplicas[idx].Hash()); - hashes.insert(selectionHash); - } - return static_cast<double>(hashes.size()) / static_cast<double>(tabletCount); - } - + double UniqueCombinationsRun(ui32 replicas, ui32 nToSelect, ui32 replicasInRing, bool useRingSpecificNodeSelection) { + const ui64 tabletStartId = 8000000; + const ui64 tabletCount = 1000000; + TStateStorageInfo info; + FillStateStorageInfo(&info, replicas, nToSelect, replicasInRing, useRingSpecificNodeSelection); + + THashSet<ui64> hashes; + + TStateStorageInfo::TSelection selection; + for (ui64 tabletId = tabletStartId; tabletId < tabletStartId + tabletCount; ++tabletId) { + ui64 selectionHash = 0; + info.SelectReplicas(tabletId, &selection); + Y_VERIFY(nToSelect == selection.Sz); + for (ui32 idx : xrange(nToSelect)) + selectionHash = CombineHashes<ui64>(selectionHash, selection.SelectedReplicas[idx].Hash()); + hashes.insert(selectionHash); + } + return static_cast<double>(hashes.size()) / static_cast<double>(tabletCount); + } + Y_UNIT_TEST(TestReplicaSelection) { - UNIT_ASSERT(StabilityRun(3, 3, 1, false) == 17606246762804570019ULL); - UNIT_ASSERT(StabilityRun(13, 3, 1, false) == 421354124534079828ULL); - UNIT_ASSERT(StabilityRun(13, 9, 1, false) == 10581416019959162949ULL); - UNIT_ASSERT(StabilityRun(3, 3, 1, true) == 17606246762804570019ULL); - UNIT_ASSERT(StabilityRun(13, 3, 1, true) == 421354124534079828ULL); - UNIT_ASSERT(StabilityRun(13, 9, 1, true) == 10581416019959162949ULL); + UNIT_ASSERT(StabilityRun(3, 3, 1, false) == 17606246762804570019ULL); + UNIT_ASSERT(StabilityRun(13, 3, 1, false) == 421354124534079828ULL); + UNIT_ASSERT(StabilityRun(13, 9, 1, false) == 10581416019959162949ULL); + UNIT_ASSERT(StabilityRun(3, 3, 1, true) == 17606246762804570019ULL); + UNIT_ASSERT(StabilityRun(13, 3, 1, true) == 421354124534079828ULL); + UNIT_ASSERT(StabilityRun(13, 9, 1, true) == 10581416019959162949ULL); } Y_UNIT_TEST(TestMultiReplicaFailDomains) { - UNIT_ASSERT(StabilityRun(3, 3, 3, false) == 12043409773822600429ULL); - UNIT_ASSERT(StabilityRun(13, 3, 5, false) == 3265154396592024904ULL); - UNIT_ASSERT(StabilityRun(13, 9, 8, false) == 12079940289459527060ULL); - UNIT_ASSERT(StabilityRun(3, 3, 3, true) == 7845257406715748850ULL); - UNIT_ASSERT(StabilityRun(13, 3, 5, true) == 1986618578793030392ULL); - UNIT_ASSERT(StabilityRun(13, 9, 8, true) == 6173011524598124144ULL); - } - - Y_UNIT_TEST(TestReplicaSelectionUniqueCombinations) { - UNIT_ASSERT_DOUBLES_EQUAL(UniqueCombinationsRun(13, 3, 1, false), 0.000206, 1e-7); - UNIT_ASSERT_DOUBLES_EQUAL(UniqueCombinationsRun(13, 3, 3, false), 0.000519, 1e-7); - UNIT_ASSERT_DOUBLES_EQUAL(UniqueCombinationsRun(113, 3, 1, false), 0.009091, 1e-7); - UNIT_ASSERT_DOUBLES_EQUAL(UniqueCombinationsRun(113, 3, 5, false), 0.045251, 1e-7); - UNIT_ASSERT_DOUBLES_EQUAL(UniqueCombinationsRun(113, 9, 1, false), 0.009237, 1e-7); - UNIT_ASSERT_DOUBLES_EQUAL(UniqueCombinationsRun(113, 9, 8, false), 0.01387, 1e-7); - UNIT_ASSERT_DOUBLES_EQUAL(UniqueCombinationsRun(13, 3, 1, true), 0.000206, 1e-7); - UNIT_ASSERT_DOUBLES_EQUAL(UniqueCombinationsRun(13, 3, 3, true), 0.004263, 1e-7); - UNIT_ASSERT_DOUBLES_EQUAL(UniqueCombinationsRun(113, 3, 1, true), 0.009091, 1e-7); - UNIT_ASSERT_DOUBLES_EQUAL(UniqueCombinationsRun(113, 3, 5, true), 0.63673, 1e-7); - UNIT_ASSERT_DOUBLES_EQUAL(UniqueCombinationsRun(113, 9, 1, true), 0.009237, 1e-7); - UNIT_ASSERT_DOUBLES_EQUAL(UniqueCombinationsRun(113, 9, 8, true), 0.072514, 1e-7); + UNIT_ASSERT(StabilityRun(3, 3, 3, false) == 12043409773822600429ULL); + UNIT_ASSERT(StabilityRun(13, 3, 5, false) == 3265154396592024904ULL); + UNIT_ASSERT(StabilityRun(13, 9, 8, false) == 12079940289459527060ULL); + UNIT_ASSERT(StabilityRun(3, 3, 3, true) == 7845257406715748850ULL); + UNIT_ASSERT(StabilityRun(13, 3, 5, true) == 1986618578793030392ULL); + UNIT_ASSERT(StabilityRun(13, 9, 8, true) == 6173011524598124144ULL); } - double UniformityRun(ui32 replicas, ui32 nToSelect, ui32 replicasInRing, bool useRingSpecificNodeSelection) { + Y_UNIT_TEST(TestReplicaSelectionUniqueCombinations) { + UNIT_ASSERT_DOUBLES_EQUAL(UniqueCombinationsRun(13, 3, 1, false), 0.000206, 1e-7); + UNIT_ASSERT_DOUBLES_EQUAL(UniqueCombinationsRun(13, 3, 3, false), 0.000519, 1e-7); + UNIT_ASSERT_DOUBLES_EQUAL(UniqueCombinationsRun(113, 3, 1, false), 0.009091, 1e-7); + UNIT_ASSERT_DOUBLES_EQUAL(UniqueCombinationsRun(113, 3, 5, false), 0.045251, 1e-7); + UNIT_ASSERT_DOUBLES_EQUAL(UniqueCombinationsRun(113, 9, 1, false), 0.009237, 1e-7); + UNIT_ASSERT_DOUBLES_EQUAL(UniqueCombinationsRun(113, 9, 8, false), 0.01387, 1e-7); + UNIT_ASSERT_DOUBLES_EQUAL(UniqueCombinationsRun(13, 3, 1, true), 0.000206, 1e-7); + UNIT_ASSERT_DOUBLES_EQUAL(UniqueCombinationsRun(13, 3, 3, true), 0.004263, 1e-7); + UNIT_ASSERT_DOUBLES_EQUAL(UniqueCombinationsRun(113, 3, 1, true), 0.009091, 1e-7); + UNIT_ASSERT_DOUBLES_EQUAL(UniqueCombinationsRun(113, 3, 5, true), 0.63673, 1e-7); + UNIT_ASSERT_DOUBLES_EQUAL(UniqueCombinationsRun(113, 9, 1, true), 0.009237, 1e-7); + UNIT_ASSERT_DOUBLES_EQUAL(UniqueCombinationsRun(113, 9, 8, true), 0.072514, 1e-7); + } + + double UniformityRun(ui32 replicas, ui32 nToSelect, ui32 replicasInRing, bool useRingSpecificNodeSelection) { THashMap<TActorId, ui32> history; TStateStorageInfo info; - FillStateStorageInfo(&info, replicas, nToSelect, replicasInRing, useRingSpecificNodeSelection); + FillStateStorageInfo(&info, replicas, nToSelect, replicasInRing, useRingSpecificNodeSelection); TStateStorageInfo::TSelection selection; for (ui64 tabletId = 8000000; tabletId < 9000000; ++tabletId) { @@ -118,18 +118,18 @@ Y_UNIT_TEST_SUITE(TStateStorageConfig) { } Y_UNIT_TEST(UniformityTest) { - UNIT_ASSERT(UniformityRun(13, 3, 1, false) < 0.10); - UNIT_ASSERT(UniformityRun(13, 3, 3, false) < 0.10); - UNIT_ASSERT(UniformityRun(113, 3, 1, false) < 0.10); - UNIT_ASSERT(UniformityRun(113, 3, 5, false) < 0.10); - UNIT_ASSERT(UniformityRun(113, 9, 1, false) < 0.10); - UNIT_ASSERT(UniformityRun(113, 9, 8, false) < 0.10); - UNIT_ASSERT(UniformityRun(13, 3, 1, true) < 0.10); - UNIT_ASSERT(UniformityRun(13, 3, 3, true) < 0.10); - UNIT_ASSERT(UniformityRun(113, 3, 1, true) < 0.10); - UNIT_ASSERT(UniformityRun(113, 3, 5, true) < 0.10); - UNIT_ASSERT(UniformityRun(113, 9, 1, true) < 0.10); - UNIT_ASSERT(UniformityRun(113, 9, 8, true) < 0.10); + UNIT_ASSERT(UniformityRun(13, 3, 1, false) < 0.10); + UNIT_ASSERT(UniformityRun(13, 3, 3, false) < 0.10); + UNIT_ASSERT(UniformityRun(113, 3, 1, false) < 0.10); + UNIT_ASSERT(UniformityRun(113, 3, 5, false) < 0.10); + UNIT_ASSERT(UniformityRun(113, 9, 1, false) < 0.10); + UNIT_ASSERT(UniformityRun(113, 9, 8, false) < 0.10); + UNIT_ASSERT(UniformityRun(13, 3, 1, true) < 0.10); + UNIT_ASSERT(UniformityRun(13, 3, 3, true) < 0.10); + UNIT_ASSERT(UniformityRun(113, 3, 1, true) < 0.10); + UNIT_ASSERT(UniformityRun(113, 3, 5, true) < 0.10); + UNIT_ASSERT(UniformityRun(113, 9, 1, true) < 0.10); + UNIT_ASSERT(UniformityRun(113, 9, 8, true) < 0.10); } } diff --git a/ydb/core/protos/config.proto b/ydb/core/protos/config.proto index d64169d4fc..9729a9ced5 100644 --- a/ydb/core/protos/config.proto +++ b/ydb/core/protos/config.proto @@ -160,8 +160,8 @@ message TDomainsConfig { optional uint32 NToSelect = 1; repeated TRing Ring = 2; repeated uint32 Node = 3; - optional bool UseSingleNodeActorId = 4; - optional bool UseRingSpecificNodeSelection = 5; + optional bool UseSingleNodeActorId = 4; + optional bool UseRingSpecificNodeSelection = 5; } optional uint32 SSId = 1; |