Skip to content

Commit 57677f2

Browse files
authored
Kv tracing ut (#992)
* KeyValue tablet tracing unit-test * Read tests * ya.make cleanup * UT implementation cleanup * Includes cleanup
1 parent 6814405 commit 57677f2

File tree

7 files changed

+370
-169
lines changed

7 files changed

+370
-169
lines changed
+154
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
#include <ydb/core/keyvalue/keyvalue.h>
2+
#include <ydb/core/keyvalue/keyvalue_events.h>
3+
#include <ydb/core/keyvalue/protos/events.pb.h>
4+
#include <ydb/core/testlib/basics/helpers.h>
5+
#include <ydb/core/testlib/basics/runtime.h>
6+
#include <ydb/core/testlib/tablet_helpers.h>
7+
#include <ydb/library/actors/wilson/test_util/fake_wilson_uploader.h>
8+
9+
#include <library/cpp/testing/unittest/registar.h>
10+
11+
using namespace NActors;
12+
using namespace NKikimr;
13+
14+
struct TTestEnvironment {
15+
THolder<TTestBasicRuntime> Runtime;
16+
const ui32 NodeCount;
17+
TActorId Edge;
18+
const ui64 TabletId = MakeTabletID(0, 0, 1);
19+
const TTabletTypes::EType TabletType = TTabletTypes::KeyValue;
20+
NWilson::TFakeWilsonUploader* WilsonUploader = nullptr;
21+
22+
TTestEnvironment(ui32 nodeCount): NodeCount(nodeCount) {
23+
}
24+
25+
void Prepare() {
26+
SetupRuntime();
27+
InitializeRuntime();
28+
29+
Edge = Runtime->AllocateEdgeActor();
30+
CreateTestBootstrapper(*Runtime,
31+
CreateTestTabletInfo(TabletId, TabletType, TErasureType::ErasureNone),
32+
&CreateKeyValueFlat);
33+
SetupFakeWilson();
34+
35+
TDispatchOptions options;
36+
options.FinalEvents.push_back(TDispatchOptions::TFinalEventCondition(TEvTablet::EvBoot));
37+
Runtime->DispatchEvents(options);
38+
}
39+
40+
void InitializeRuntime() {
41+
TAppPrepare app;
42+
app.AddDomain(TDomainsInfo::TDomain::ConstructEmptyDomain("dc-1").Release());
43+
SetupTabletServices(*Runtime, &app);
44+
}
45+
46+
void SetupRuntime() {
47+
Runtime = MakeHolder<TTestBasicRuntime>(NodeCount, 1u);
48+
49+
for (ui32 i = 0; i < NodeCount; ++i) {
50+
SetupStateStorage(*Runtime, i, 0, true);
51+
SetupTabletResolver(*Runtime, i);
52+
}
53+
}
54+
55+
void SetupFakeWilson() {
56+
WilsonUploader = new NWilson::TFakeWilsonUploader;
57+
auto actorId = Runtime->Register(WilsonUploader);
58+
Runtime->RegisterService(NWilson::MakeWilsonUploaderId(), actorId);
59+
}
60+
61+
template<class TRequest>
62+
auto DoKVRequest(THolder<TRequest> request) {
63+
Runtime->SendToPipe(TabletId, Edge, request.Release(), 0, NTabletPipe::TClientConfig(), TActorId(),
64+
0, NWilson::TTraceId::NewTraceId(15, 4095));
65+
TAutoPtr<IEventHandle> handle;
66+
auto response = Runtime->GrabEdgeEventRethrow<typename TRequest::TResponse>(handle);
67+
UNIT_ASSERT(response);
68+
auto& record = response->Record;
69+
UNIT_ASSERT_EQUAL(record.status(), NKikimrKeyValue::Statuses::RSTATUS_OK);
70+
71+
return std::move(record);
72+
}
73+
};
74+
75+
THolder<TEvKeyValue::TEvExecuteTransaction> CreateWrite(TString key, TString value) {
76+
auto request = MakeHolder<TEvKeyValue::TEvExecuteTransaction>();
77+
auto write = request->Record.add_commands()->mutable_write();
78+
write->set_key(std::move(key));
79+
write->set_value(std::move(value));
80+
return request;
81+
}
82+
83+
THolder<TEvKeyValue::TEvRead> CreateRead(TString key) {
84+
auto request = MakeHolder<TEvKeyValue::TEvRead>();
85+
auto& record = request->Record;
86+
record.set_key(std::move(key));
87+
record.set_offset(0);
88+
record.set_size(0);
89+
record.set_limit_bytes(0);
90+
return request;
91+
}
92+
93+
void TestOneWrite(TString value, TString expectedTrace) {
94+
TTestEnvironment env(8);
95+
env.Prepare();
96+
97+
env.DoKVRequest(CreateWrite("key", std::move(value)));
98+
99+
UNIT_ASSERT(env.WilsonUploader->BuildTraceTrees());
100+
UNIT_ASSERT_EQUAL(env.WilsonUploader->Traces.size(), 1);
101+
auto& trace = env.WilsonUploader->Traces.begin()->second;
102+
103+
UNIT_ASSERT_EQUAL(trace.ToString(), expectedTrace);
104+
}
105+
106+
void TestOneRead(TString value, TString expectedTrace) {
107+
TTestEnvironment env(8);
108+
env.Prepare();
109+
110+
env.DoKVRequest(CreateWrite("key", value));
111+
env.WilsonUploader->Clear();
112+
113+
auto response = env.DoKVRequest(CreateRead("key"));
114+
UNIT_ASSERT_EQUAL(response.value(), value);
115+
116+
UNIT_ASSERT(env.WilsonUploader->BuildTraceTrees());
117+
UNIT_ASSERT_EQUAL(env.WilsonUploader->Traces.size(), 1);
118+
auto& trace = env.WilsonUploader->Traces.begin()->second;
119+
120+
UNIT_ASSERT_EQUAL(trace.ToString(), expectedTrace);
121+
}
122+
123+
Y_UNIT_TEST_SUITE(TKeyValueTracingTest) {
124+
const TString SmallValue = "value";
125+
const TString HugeValue = TString(1 << 20, 'v');
126+
127+
Y_UNIT_TEST(WriteSmall) {
128+
TString canon = "(KeyValue.Intermediate -> [(KeyValue.StorageRequest -> [(DSProxy.Put -> [(Backpressure.InFlight "
129+
"-> [(VDisk.Log.Put)])])]) , (Tablet.Transaction -> [(Tablet.Transaction.Execute) , (Tablet.WriteLog -> "
130+
"[(Tablet.WriteLog.LogEntry -> [(DSProxy.Put -> [(Backpressure.InFlight -> [(VDisk.Log.Put)])])])])])])";
131+
TestOneWrite(SmallValue, std::move(canon));
132+
}
133+
134+
Y_UNIT_TEST(WriteHuge) {
135+
TString canon = "(KeyValue.Intermediate -> [(KeyValue.StorageRequest -> [(DSProxy.Put -> [(Backpressure.InFlight "
136+
"-> [(VDisk.HugeBlobKeeper.Write -> [(VDisk.Log.PutHuge)])])])]) , (Tablet.Transaction -> "
137+
"[(Tablet.Transaction.Execute) , (Tablet.WriteLog -> [(Tablet.WriteLog.LogEntry -> [(DSProxy.Put -> "
138+
"[(Backpressure.InFlight -> [(VDisk.Log.Put)])])])])])])";
139+
TestOneWrite(HugeValue, std::move(canon));
140+
}
141+
142+
Y_UNIT_TEST(ReadSmall) {
143+
TString canon = "(KeyValue.Intermediate -> [(KeyValue.StorageReadRequest -> [(DSProxy.Get -> [(Backpressure.InFlight -> "
144+
"[(VDisk.LevelIndexExtremeQueryViaBatcherMergeData)])])])])";
145+
TestOneRead(SmallValue, std::move(canon));
146+
}
147+
148+
Y_UNIT_TEST(ReadHuge) {
149+
TString canon = "(KeyValue.Intermediate -> [(KeyValue.StorageReadRequest -> [(DSProxy.Get -> [(Backpressure.InFlight -> "
150+
"[(VDisk.LevelIndexExtremeQueryViaBatcherMergeData -> [(VDisk.Query.ReadBatcher)])])])])])";
151+
TestOneRead(HugeValue, std::move(canon));
152+
}
153+
154+
}

ydb/core/keyvalue/ut_trace/ya.make

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
UNITTEST_FOR(ydb/core/keyvalue)
2+
3+
FORK_SUBTESTS()
4+
5+
SPLIT_FACTOR(5)
6+
7+
IF (SANITIZER_TYPE == "thread" OR WITH_VALGRIND)
8+
TIMEOUT(1800)
9+
SIZE(LARGE)
10+
TAG(ya:fat)
11+
ELSE()
12+
TIMEOUT(600)
13+
SIZE(MEDIUM)
14+
ENDIF()
15+
16+
PEERDIR(
17+
ydb/core/testlib/default
18+
)
19+
20+
SRCS(
21+
keyvalue_ut_trace.cpp
22+
)
23+
24+
REQUIREMENTS(ram:16)
25+
26+
END()

ydb/core/keyvalue/ya.make

+1
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,5 @@ RECURSE(
6262

6363
RECURSE_FOR_TESTS(
6464
ut
65+
ut_trace
6566
)

0 commit comments

Comments
 (0)