@@ -9,14 +9,35 @@ using namespace NYdb;
9
9
using namespace NYdb ::NTable;
10
10
11
11
namespace {
12
- ui64 CountSubstr (const TString& str, const TString& substr) {
13
- ui64 count = 0 ;
14
- for (auto pos = str.find (substr); pos != TString::npos; pos = str.find (substr, pos + substr.size ())) {
15
- ++count;
12
+
13
+ void CheckRegexMatch (
14
+ const TString& str,
15
+ const TVector<std::pair<TString, ui64>>& regexToMatchCount)
16
+ {
17
+ for (auto & [regexString, expectedMatchCount]: regexToMatchCount) {
18
+ std::regex expression (regexString.c_str ());
19
+
20
+ auto matchCount = std::distance (
21
+ std::sregex_iterator (str.begin (), str.end (), expression),
22
+ std::sregex_iterator ());
23
+
24
+ UNIT_ASSERT_VALUES_EQUAL (expectedMatchCount, matchCount);
16
25
}
17
- return count;
18
26
}
19
- }
27
+
28
+ TString ConstructRegexToCheckLogs (
29
+ const TString& logLevel,
30
+ const TString& component)
31
+ {
32
+ TStringBuilder builder;
33
+
34
+ // [\\w]+\\.[A-Za-z]+:[0-9]+ match filename and line number
35
+ builder << " DATA_INTEGRITY " << logLevel
36
+ << " : [\\ w]+\\ .[A-Za-z]+:[0-9]+: Component: " << component;
37
+ return builder;
38
+ }
39
+
40
+ } // namespace
20
41
21
42
Y_UNIT_TEST_SUITE (KqpDataIntegrityTrails) {
22
43
Y_UNIT_TEST_QUAD (Upsert, LogEnabled, UseSink) {
@@ -32,7 +53,7 @@ Y_UNIT_TEST_SUITE(KqpDataIntegrityTrails) {
32
53
if (LogEnabled) {
33
54
kikimr.GetTestServer ().GetRuntime ()->SetLogPriority (NKikimrServices::DATA_INTEGRITY, NLog::PRI_TRACE);
34
55
}
35
-
56
+
36
57
auto db = kikimr.GetTableClient ();
37
58
auto session = db.CreateSession ().GetValueSync ().GetSession ();
38
59
@@ -47,19 +68,29 @@ Y_UNIT_TEST_SUITE(KqpDataIntegrityTrails) {
47
68
UNIT_ASSERT_VALUES_EQUAL_C (result.GetStatus (), EStatus::SUCCESS, result.GetIssues ().ToString ());
48
69
}
49
70
71
+ TVector<std::pair<TString, ui64>> regexToMatchCount{
72
+ // check session actor logs
73
+ {ConstructRegexToCheckLogs (" DEBUG" , " SessionActor" ),
74
+ LogEnabled ? 2 : 0 },
75
+ // check grpc logs
76
+ {ConstructRegexToCheckLogs (" TRACE" , " Grpc" ), LogEnabled ? 2 : 0 },
77
+ // check datashard logs
78
+ {ConstructRegexToCheckLogs (" INFO" , " DataShard" ), LogEnabled ? 2 : 0 },
79
+ };
80
+
50
81
if (UseSink) {
51
82
// check write actor logs
52
- UNIT_ASSERT_VALUES_EQUAL (CountSubstr (ss.Str (), " DATA_INTEGRITY INFO: Component: WriteActor" ), LogEnabled ? 1 : 0 );
83
+ regexToMatchCount.emplace_back (
84
+ ConstructRegexToCheckLogs (" INFO" , " WriteActor" ),
85
+ LogEnabled ? 1 : 0 );
53
86
} else {
54
87
// check executer logs
55
- UNIT_ASSERT_VALUES_EQUAL (CountSubstr (ss.Str (), " DATA_INTEGRITY INFO: Component: Executer" ), LogEnabled ? 2 : 0 );
88
+ regexToMatchCount.emplace_back (
89
+ ConstructRegexToCheckLogs (" INFO" , " Executer" ),
90
+ LogEnabled ? 2 : 0 );
56
91
}
57
- // check session actor logs
58
- UNIT_ASSERT_VALUES_EQUAL (CountSubstr (ss.Str (), " DATA_INTEGRITY DEBUG: Component: SessionActor" ), LogEnabled ? 2 : 0 );
59
- // check grpc logs
60
- UNIT_ASSERT_VALUES_EQUAL (CountSubstr (ss.Str (), " DATA_INTEGRITY TRACE: Component: Grpc" ), LogEnabled ? 2 : 0 );
61
- // check datashard logs
62
- UNIT_ASSERT_VALUES_EQUAL (CountSubstr (ss.Str (), " DATA_INTEGRITY INFO: Component: DataShard" ), LogEnabled ? 2 : 0 );
92
+
93
+ CheckRegexMatch (ss.Str (), regexToMatchCount);
63
94
}
64
95
65
96
Y_UNIT_TEST_QUAD (UpsertEvWriteQueryService, isOlap, useOltpSink) {
@@ -103,38 +134,37 @@ Y_UNIT_TEST_SUITE(KqpDataIntegrityTrails) {
103
134
UNIT_ASSERT_VALUES_EQUAL_C (result.GetStatus (), EStatus::SUCCESS, result.GetIssues ().ToString ());
104
135
}
105
136
137
+ TVector<std::pair<TString, ui64>> regexToMatchCount;
106
138
if (!isOlap) {
139
+ regexToMatchCount = {
140
+ {ConstructRegexToCheckLogs (" DEBUG" , " SessionActor" ), 2 },
141
+ {ConstructRegexToCheckLogs (" TRACE" , " Grpc" ), 2 },
142
+ {ConstructRegexToCheckLogs (" INFO" , " DataShard" ), 2 },
143
+ };
144
+
107
145
if (useOltpSink) {
108
146
// check write actor logs
109
- UNIT_ASSERT_VALUES_EQUAL (CountSubstr (ss.Str (), " DATA_INTEGRITY INFO: Component: WriteActor" ), 1 );
147
+ regexToMatchCount.emplace_back (
148
+ ConstructRegexToCheckLogs (" INFO" , " WriteActor" ),
149
+ 1 );
110
150
} else {
111
151
// check executer logs
112
- UNIT_ASSERT_VALUES_EQUAL (CountSubstr (ss.Str (), " DATA_INTEGRITY INFO: Component: Executer" ), 2 );
152
+ regexToMatchCount.emplace_back (
153
+ ConstructRegexToCheckLogs (" INFO" , " Executer" ),
154
+ 2 );
113
155
}
114
- // check session actor logs
115
- UNIT_ASSERT_VALUES_EQUAL (CountSubstr (ss.Str (), " DATA_INTEGRITY DEBUG: Component: SessionActor" ), 2 );
116
- // check grpc logs
117
- UNIT_ASSERT_VALUES_EQUAL (CountSubstr (ss.Str (), " DATA_INTEGRITY TRACE: Component: Grpc" ), 2 );
118
- // check datashard logs
119
- UNIT_ASSERT_VALUES_EQUAL (CountSubstr (ss.Str (), " DATA_INTEGRITY INFO: Component: DataShard" ), 2 );
120
156
} else {
121
- // check write actor logs
122
- UNIT_ASSERT_VALUES_EQUAL (CountSubstr (ss.Str (), " DATA_INTEGRITY INFO: Component: WriteActor" ), 3 );
123
- if (useOltpSink) {
124
- // check executer logs
125
- UNIT_ASSERT_VALUES_EQUAL (CountSubstr (ss.Str (), " DATA_INTEGRITY INFO: Component: Executer" ), 1 );
126
- } else {
127
- // check executer logs
128
- UNIT_ASSERT_VALUES_EQUAL (CountSubstr (ss.Str (), " DATA_INTEGRITY INFO: Component: Executer" ), 11 );
129
- }
130
- // check session actor logs
131
- UNIT_ASSERT_VALUES_EQUAL (CountSubstr (ss.Str (), " DATA_INTEGRITY DEBUG: Component: SessionActor" ), 2 );
132
- // check grpc logs
133
- UNIT_ASSERT_VALUES_EQUAL (CountSubstr (ss.Str (), " DATA_INTEGRITY TRACE: Component: Grpc" ), 2 );
134
- // check columnshard logs
157
+ regexToMatchCount = {
158
+ {ConstructRegexToCheckLogs (" INFO" , " WriteActor" ), 3 },
159
+ {ConstructRegexToCheckLogs (" DEBUG" , " SessionActor" ), 2 },
160
+ {ConstructRegexToCheckLogs (" TRACE" , " Grpc" ), 2 },
161
+ {ConstructRegexToCheckLogs (" INFO" , " Executer" ),
162
+ useOltpSink ? 1 : 11 }};
163
+
135
164
// ColumnShard doesn't have integrity logs.
136
- // UNIT_ASSERT_VALUES_EQUAL(CountSubstr(ss.Str(), "DATA_INTEGRITY INFO: Component: ColumnShard"), 6);
137
165
}
166
+
167
+ CheckRegexMatch (ss.Str (), regexToMatchCount);
138
168
}
139
169
140
170
Y_UNIT_TEST (Ddl) {
@@ -149,7 +179,7 @@ Y_UNIT_TEST_SUITE(KqpDataIntegrityTrails) {
149
179
150
180
auto result = session.ExecuteSchemeQuery (R"(
151
181
--!syntax_v1
152
-
182
+
153
183
CREATE TABLE `/Root/Tmp` (
154
184
Key Uint64,
155
185
Value String,
@@ -159,14 +189,14 @@ Y_UNIT_TEST_SUITE(KqpDataIntegrityTrails) {
159
189
UNIT_ASSERT_VALUES_EQUAL_C (result.GetStatus (), EStatus::SUCCESS, result.GetIssues ().ToString ());
160
190
}
161
191
162
- // check executer logs
163
- UNIT_ASSERT_VALUES_EQUAL ( CountSubstr (ss. Str (), " DATA_INTEGRITY INFO: Component: Executer" ), 0 );
164
- // check session actor logs
165
- UNIT_ASSERT_VALUES_EQUAL ( CountSubstr (ss. Str (), " DATA_INTEGRITY DEBUG: Component: SessionActor " ), 0 );
166
- // check grpc logs
167
- UNIT_ASSERT_VALUES_EQUAL ( CountSubstr (ss. Str (), " DATA_INTEGRITY TRACE: Component: Grpc " ), 0 ) ;
168
- // check datashard logs
169
- UNIT_ASSERT_VALUES_EQUAL ( CountSubstr ( ss.Str (), " DATA_INTEGRITY INFO: Component: DataShard " ), 0 );
192
+ TVector<std::pair<TString, ui64>> regexToMatchCount{
193
+ { ConstructRegexToCheckLogs ( " INFO " , " Executer" ), 0 },
194
+ { ConstructRegexToCheckLogs ( " DEBUG " , " SessionActor " ), 0 },
195
+ { ConstructRegexToCheckLogs ( " TRACE " , " Grpc " ), 0 },
196
+ { ConstructRegexToCheckLogs ( " INFO " , " DataShard " ), 0 },
197
+ } ;
198
+
199
+ CheckRegexMatch ( ss.Str (), regexToMatchCount );
170
200
}
171
201
172
202
Y_UNIT_TEST (Select) {
@@ -187,14 +217,20 @@ Y_UNIT_TEST_SUITE(KqpDataIntegrityTrails) {
187
217
UNIT_ASSERT_VALUES_EQUAL_C (result.GetStatus (), EStatus::SUCCESS, result.GetIssues ().ToString ());
188
218
}
189
219
190
- // check executer logs (should be 1, because executer only logs result for read actor)
191
- UNIT_ASSERT_VALUES_EQUAL (CountSubstr (ss.Str (), " DATA_INTEGRITY INFO: Component: Executer" ), 1 );
192
- // check session actor logs
193
- UNIT_ASSERT_VALUES_EQUAL (CountSubstr (ss.Str (), " DATA_INTEGRITY DEBUG: Component: SessionActor" ), 2 );
194
- // check grpc logs
195
- UNIT_ASSERT_VALUES_EQUAL (CountSubstr (ss.Str (), " DATA_INTEGRITY TRACE: Component: Grpc" ), 2 );
196
- // check datashard logs (should be empty, because DataShard only logs modification operations)
197
- UNIT_ASSERT_VALUES_EQUAL (CountSubstr (ss.Str (), " DATA_INTEGRITY INFO: Component: DataShard" ), 0 );
220
+ TVector<std::pair<TString, ui64>> regexToMatchCount{
221
+ // check executer logs (should be 1, because executer only logs
222
+ // result for read actor)
223
+ {ConstructRegexToCheckLogs (" INFO" , " Executer" ), 1 },
224
+ // check session actor logs
225
+ {ConstructRegexToCheckLogs (" DEBUG" , " SessionActor" ), 2 },
226
+ // check grpc logs
227
+ {ConstructRegexToCheckLogs (" TRACE" , " Grpc" ), 2 },
228
+ // check datashard logs (should be empty, because DataShard only
229
+ // logs modification operations)
230
+ {ConstructRegexToCheckLogs (" INFO" , " DataShard" ), 0 },
231
+ };
232
+
233
+ CheckRegexMatch (ss.Str (), regexToMatchCount);
198
234
}
199
235
200
236
Y_UNIT_TEST_TWIN (BrokenReadLock, UseSink) {
@@ -261,7 +297,7 @@ Y_UNIT_TEST_SUITE(KqpDataIntegrityTrails) {
261
297
std::smatch lockIdMatch;
262
298
UNIT_ASSERT_C (std::regex_search (row.data (), lockIdMatch, lockIdRegex) || lockIdMatch.size () != 2 , " failed to extract broken lock id" );
263
299
brokenLock = lockIdMatch[1 ].str ();
264
- }
300
+ }
265
301
}
266
302
267
303
UNIT_ASSERT_C (!readLock.empty () && readLock == brokenLock, " read lock should be broken" );
@@ -333,7 +369,7 @@ Y_UNIT_TEST_SUITE(KqpDataIntegrityTrails) {
333
369
std::smatch lockIdMatch;
334
370
UNIT_ASSERT_C (std::regex_search (row.data (), lockIdMatch, lockIdRegex) || lockIdMatch.size () != 2 , " failed to extract broken lock id" );
335
371
brokenLock = lockIdMatch[1 ].str ();
336
- }
372
+ }
337
373
}
338
374
339
375
UNIT_ASSERT_C (!readLock.empty () && readLock == brokenLock, " read lock should be broken" );
0 commit comments