@@ -36,6 +36,7 @@ struct TExecutionOptions {
36
36
37
37
ui32 LoopCount = 1 ;
38
38
TDuration LoopDelay;
39
+ bool ContinueAfterFail = false ;
39
40
40
41
bool ForgetExecution = false ;
41
42
std::vector<EExecutionCase> ExecutionCases;
@@ -44,6 +45,7 @@ struct TExecutionOptions {
44
45
std::vector<TString> TraceIds;
45
46
std::vector<TString> PoolIds;
46
47
std::vector<TString> UserSIDs;
48
+ std::vector<TDuration> Timeouts;
47
49
ui64 ResultsRowsLimit = 0 ;
48
50
49
51
const TString DefaultTraceId = " kqprun" ;
@@ -87,7 +89,8 @@ struct TExecutionOptions {
87
89
.TraceId = DefaultTraceId,
88
90
.PoolId = " " ,
89
91
.UserSID = BUILTIN_ACL_ROOT,
90
- .Database = " "
92
+ .Database = " " ,
93
+ .Timeout = TDuration::Zero ()
91
94
};
92
95
}
93
96
@@ -106,7 +109,8 @@ struct TExecutionOptions {
106
109
.TraceId = TStringBuilder () << GetValue (index , TraceIds, DefaultTraceId) << " -" << startTime.ToString (),
107
110
.PoolId = GetValue (index , PoolIds, TString ()),
108
111
.UserSID = GetValue (index , UserSIDs, TString (BUILTIN_ACL_ROOT)),
109
- .Database = GetValue (index , Databases, TString ())
112
+ .Database = GetValue (index , Databases, TString ()),
113
+ .Timeout = GetValue (index , Timeouts, TDuration::Zero ())
110
114
};
111
115
}
112
116
@@ -136,6 +140,7 @@ struct TExecutionOptions {
136
140
checker (TraceIds.size (), " trace ids" );
137
141
checker (PoolIds.size (), " pool ids" );
138
142
checker (UserSIDs.size (), " user SIDs" );
143
+ checker (Timeouts.size (), " timeouts" );
139
144
}
140
145
141
146
void ValidateSchemeQueryOptions (const NKqpRun::TRunnerOptions& runnerOptions) const {
@@ -148,6 +153,10 @@ struct TExecutionOptions {
148
153
}
149
154
150
155
void ValidateScriptExecutionOptions (const NKqpRun::TRunnerOptions& runnerOptions) const {
156
+ if (runnerOptions.YdbSettings .SameSession && HasExecutionCase (EExecutionCase::AsyncQuery)) {
157
+ ythrow yexception () << " Same session can not be used with async quries" ;
158
+ }
159
+
151
160
// Script specific
152
161
if (HasExecutionCase (EExecutionCase::GenericScript)) {
153
162
return ;
@@ -180,6 +189,9 @@ struct TExecutionOptions {
180
189
if (runnerOptions.ScriptQueryPlanOutput ) {
181
190
ythrow yexception () << " Script query plan output can not be used without script/yql queries" ;
182
191
}
192
+ if (runnerOptions.YdbSettings .SameSession ) {
193
+ ythrow yexception () << " Same session can not be used without script/yql queries" ;
194
+ }
183
195
}
184
196
185
197
void ValidateAsyncOptions (const NKqpRun::TAsyncQueriesSettings& asyncQueriesSettings) const {
@@ -237,6 +249,49 @@ struct TExecutionOptions {
237
249
};
238
250
239
251
252
+ void RunArgumentQuery (size_t index, size_t queryId, TInstant startTime, const TExecutionOptions& executionOptions, NKqpRun::TKqpRunner& runner) {
253
+ NColorizer::TColors colors = NColorizer::AutoColors (Cout);
254
+
255
+ switch (executionOptions.GetExecutionCase (index )) {
256
+ case TExecutionOptions::EExecutionCase::GenericScript: {
257
+ if (!runner.ExecuteScript (executionOptions.GetScriptQueryOptions (index , queryId, startTime))) {
258
+ ythrow yexception () << TInstant::Now ().ToIsoStringLocal () << " Script execution failed" ;
259
+ }
260
+ Cout << colors.Yellow () << TInstant::Now ().ToIsoStringLocal () << " Fetching script results..." << colors.Default () << Endl;
261
+ if (!runner.FetchScriptResults ()) {
262
+ ythrow yexception () << TInstant::Now ().ToIsoStringLocal () << " Fetch script results failed" ;
263
+ }
264
+ if (executionOptions.ForgetExecution ) {
265
+ Cout << colors.Yellow () << TInstant::Now ().ToIsoStringLocal () << " Forgetting script execution operation..." << colors.Default () << Endl;
266
+ if (!runner.ForgetExecutionOperation ()) {
267
+ ythrow yexception () << TInstant::Now ().ToIsoStringLocal () << " Forget script execution operation failed" ;
268
+ }
269
+ }
270
+ break ;
271
+ }
272
+
273
+ case TExecutionOptions::EExecutionCase::GenericQuery: {
274
+ if (!runner.ExecuteQuery (executionOptions.GetScriptQueryOptions (index , queryId, startTime))) {
275
+ ythrow yexception () << TInstant::Now ().ToIsoStringLocal () << " Query execution failed" ;
276
+ }
277
+ break ;
278
+ }
279
+
280
+ case TExecutionOptions::EExecutionCase::YqlScript: {
281
+ if (!runner.ExecuteYqlScript (executionOptions.GetScriptQueryOptions (index , queryId, startTime))) {
282
+ ythrow yexception () << TInstant::Now ().ToIsoStringLocal () << " Yql script execution failed" ;
283
+ }
284
+ break ;
285
+ }
286
+
287
+ case TExecutionOptions::EExecutionCase::AsyncQuery: {
288
+ runner.ExecuteQueryAsync (executionOptions.GetScriptQueryOptions (index , queryId, startTime));
289
+ break ;
290
+ }
291
+ }
292
+ }
293
+
294
+
240
295
void RunArgumentQueries (const TExecutionOptions& executionOptions, NKqpRun::TKqpRunner& runner) {
241
296
NColorizer::TColors colors = NColorizer::AutoColors (Cout);
242
297
@@ -256,8 +311,7 @@ void RunArgumentQueries(const TExecutionOptions& executionOptions, NKqpRun::TKqp
256
311
}
257
312
258
313
const TInstant startTime = TInstant::Now ();
259
- const auto executionCase = executionOptions.GetExecutionCase (id);
260
- if (executionCase != TExecutionOptions::EExecutionCase::AsyncQuery) {
314
+ if (executionOptions.GetExecutionCase (id) != TExecutionOptions::EExecutionCase::AsyncQuery) {
261
315
Cout << colors.Yellow () << startTime.ToIsoStringLocal () << " Executing script" ;
262
316
if (numberQueries > 1 ) {
263
317
Cout << " " << id;
@@ -268,41 +322,17 @@ void RunArgumentQueries(const TExecutionOptions& executionOptions, NKqpRun::TKqp
268
322
Cout << " ..." << colors.Default () << Endl;
269
323
}
270
324
271
- switch (executionCase) {
272
- case TExecutionOptions::EExecutionCase::GenericScript:
273
- if (!runner.ExecuteScript (executionOptions.GetScriptQueryOptions (id, queryId, startTime))) {
274
- ythrow yexception () << TInstant::Now ().ToIsoStringLocal () << " Script execution failed" ;
275
- }
276
- Cout << colors.Yellow () << TInstant::Now ().ToIsoStringLocal () << " Fetching script results..." << colors.Default () << Endl;
277
- if (!runner.FetchScriptResults ()) {
278
- ythrow yexception () << TInstant::Now ().ToIsoStringLocal () << " Fetch script results failed" ;
279
- }
280
- if (executionOptions.ForgetExecution ) {
281
- Cout << colors.Yellow () << TInstant::Now ().ToIsoStringLocal () << " Forgetting script execution operation..." << colors.Default () << Endl;
282
- if (!runner.ForgetExecutionOperation ()) {
283
- ythrow yexception () << TInstant::Now ().ToIsoStringLocal () << " Forget script execution operation failed" ;
284
- }
285
- }
286
- break ;
287
-
288
- case TExecutionOptions::EExecutionCase::GenericQuery:
289
- if (!runner.ExecuteQuery (executionOptions.GetScriptQueryOptions (id, queryId, startTime))) {
290
- ythrow yexception () << TInstant::Now ().ToIsoStringLocal () << " Query execution failed" ;
291
- }
292
- break ;
293
-
294
- case TExecutionOptions::EExecutionCase::YqlScript:
295
- if (!runner.ExecuteYqlScript (executionOptions.GetScriptQueryOptions (id, queryId, startTime))) {
296
- ythrow yexception () << TInstant::Now ().ToIsoStringLocal () << " Yql script execution failed" ;
325
+ try {
326
+ RunArgumentQuery (id, queryId, startTime, executionOptions, runner);
327
+ } catch (const yexception& exception ) {
328
+ if (executionOptions.ContinueAfterFail ) {
329
+ Cerr << colors.Red () << CurrentExceptionMessage () << colors.Default () << Endl;
330
+ } else {
331
+ throw exception ;
297
332
}
298
- break ;
299
-
300
- case TExecutionOptions::EExecutionCase::AsyncQuery:
301
- runner.ExecuteQueryAsync (executionOptions.GetScriptQueryOptions (id, queryId, startTime));
302
- break ;
303
333
}
304
334
}
305
- runner.WaitAsyncQueries ();
335
+ runner.FinalizeRunner ();
306
336
307
337
if (executionOptions.HasResults ()) {
308
338
try {
@@ -612,9 +642,11 @@ class TMain : public TMainClassArgs {
612
642
ExecutionOptions.ScriptQueryActions .emplace_back (scriptAction (choice));
613
643
});
614
644
615
- options.AddLongOption (" timeout" , " Reauests timeout in milliseconds" )
645
+ options.AddLongOption (" timeout" , " Timeout in milliseconds for -p queries " )
616
646
.RequiredArgument (" uint" )
617
- .StoreMappedResultT <ui64>(&RunnerOptions.YdbSettings .RequestsTimeout , &TDuration::MilliSeconds<ui64>);
647
+ .Handler1 ([this ](const NLastGetopt::TOptsParser* option) {
648
+ ExecutionOptions.Timeouts .emplace_back (TDuration::MilliSeconds<ui64>(FromString (option->CurValOrDef ())));
649
+ });
618
650
619
651
options.AddLongOption (" cancel-after" , " Cancel script execution operation after specified delay in milliseconds" )
620
652
.RequiredArgument (" uint" )
@@ -632,6 +664,9 @@ class TMain : public TMainClassArgs {
632
664
.RequiredArgument (" uint" )
633
665
.DefaultValue (0 )
634
666
.StoreMappedResultT <ui64>(&ExecutionOptions.LoopDelay , &TDuration::MilliSeconds<ui64>);
667
+ options.AddLongOption (" continue-after-fail" , " Don't not stop requests execution after fails" )
668
+ .NoArgument ()
669
+ .SetFlag (&ExecutionOptions.ContinueAfterFail );
635
670
636
671
options.AddLongOption (' D' , " database" , " Database path for -p queries" )
637
672
.RequiredArgument (" path" )
@@ -645,6 +680,10 @@ class TMain : public TMainClassArgs {
645
680
.RequiredArgument (" pool-id" )
646
681
.EmplaceTo (&ExecutionOptions.PoolIds );
647
682
683
+ options.AddLongOption (" same-session" , " Run all -p requests in one session" )
684
+ .NoArgument ()
685
+ .SetFlag (&RunnerOptions.YdbSettings .SameSession );
686
+
648
687
// Cluster settings
649
688
650
689
options.AddLongOption (' N' , " node-count" , " Number of nodes to create" )
0 commit comments