@@ -44,25 +44,29 @@ struct TExecutionOptions {
44
44
std::vector<TString> TraceIds;
45
45
std::vector<TString> PoolIds;
46
46
std::vector<TString> UserSIDs;
47
+ ui64 ResultsRowsLimit = 0 ;
47
48
48
49
const TString DefaultTraceId = " kqprun" ;
49
50
50
51
bool HasResults () const {
51
- if (ScriptQueries.empty ()) {
52
- return false ;
53
- }
54
-
55
- for (size_t i = 0 ; i < ExecutionCases.size (); ++i) {
52
+ for (size_t i = 0 ; i < ScriptQueries.size (); ++i) {
56
53
if (GetScriptQueryAction (i) != NKikimrKqp::EQueryAction::QUERY_ACTION_EXECUTE) {
57
54
continue ;
58
55
}
59
- if (ExecutionCases[i] != EExecutionCase::AsyncQuery) {
56
+ if (GetExecutionCase (i) != EExecutionCase::AsyncQuery) {
60
57
return true ;
61
58
}
62
59
}
63
60
return false ;
64
61
}
65
62
63
+ bool HasExecutionCase (EExecutionCase executionCase) const {
64
+ if (ExecutionCases.empty ()) {
65
+ return executionCase == EExecutionCase::GenericScript;
66
+ }
67
+ return std::find (ExecutionCases.begin (), ExecutionCases.end (), executionCase) != ExecutionCases.end ();
68
+ }
69
+
66
70
EExecutionCase GetExecutionCase (size_t index) const {
67
71
return GetValue (index, ExecutionCases, EExecutionCase::GenericScript);
68
72
}
@@ -106,6 +110,113 @@ struct TExecutionOptions {
106
110
};
107
111
}
108
112
113
+ void Validate (const NKqpRun::TRunnerOptions& runnerOptions) const {
114
+ if (!SchemeQuery && ScriptQueries.empty () && !runnerOptions.YdbSettings .MonitoringEnabled && !runnerOptions.YdbSettings .GrpcEnabled ) {
115
+ ythrow yexception () << " Nothing to execute and is not running as daemon" ;
116
+ }
117
+
118
+ ValidateOptionsSizes ();
119
+ ValidateSchemeQueryOptions (runnerOptions);
120
+ ValidateScriptExecutionOptions (runnerOptions);
121
+ ValidateAsyncOptions (runnerOptions.YdbSettings .AsyncQueriesSettings );
122
+ ValidateTraceOpt (runnerOptions.TraceOptType );
123
+ }
124
+
125
+ private:
126
+ void ValidateOptionsSizes () const {
127
+ const auto checker = [numberQueries = ScriptQueries.size ()](size_t checkSize, const TString& optionName) {
128
+ if (checkSize > numberQueries) {
129
+ ythrow yexception () << " Too many " << optionName << " . Specified " << checkSize << " , when number of queries is " << numberQueries;
130
+ }
131
+ };
132
+
133
+ checker (ExecutionCases.size (), " execution cases" );
134
+ checker (ScriptQueryActions.size (), " script query actions" );
135
+ checker (Databases.size (), " databases" );
136
+ checker (TraceIds.size (), " trace ids" );
137
+ checker (PoolIds.size (), " pool ids" );
138
+ checker (UserSIDs.size (), " user SIDs" );
139
+ }
140
+
141
+ void ValidateSchemeQueryOptions (const NKqpRun::TRunnerOptions& runnerOptions) const {
142
+ if (SchemeQuery) {
143
+ return ;
144
+ }
145
+ if (runnerOptions.SchemeQueryAstOutput ) {
146
+ ythrow yexception () << " Scheme query AST output can not be used without scheme query" ;
147
+ }
148
+ }
149
+
150
+ void ValidateScriptExecutionOptions (const NKqpRun::TRunnerOptions& runnerOptions) const {
151
+ // Script specific
152
+ if (HasExecutionCase (EExecutionCase::GenericScript)) {
153
+ return ;
154
+ }
155
+ if (ForgetExecution) {
156
+ ythrow yexception () << " Forget execution can not be used without generic script queries" ;
157
+ }
158
+ if (runnerOptions.ScriptCancelAfter ) {
159
+ ythrow yexception () << " Cancel after can not be used without generic script queries" ;
160
+ }
161
+
162
+ // Script/Query specific
163
+ if (HasExecutionCase (EExecutionCase::GenericQuery)) {
164
+ return ;
165
+ }
166
+ if (ResultsRowsLimit) {
167
+ ythrow yexception () << " Result rows limit can not be used without script queries" ;
168
+ }
169
+ if (runnerOptions.InProgressStatisticsOutputFile ) {
170
+ ythrow yexception () << " Script statistics can not be used without script queries" ;
171
+ }
172
+
173
+ // Common specific
174
+ if (HasExecutionCase (EExecutionCase::YqlScript)) {
175
+ return ;
176
+ }
177
+ if (runnerOptions.ScriptQueryAstOutput ) {
178
+ ythrow yexception () << " Script query AST output can not be used without script/yql queries" ;
179
+ }
180
+ if (runnerOptions.ScriptQueryPlanOutput ) {
181
+ ythrow yexception () << " Script query plan output can not be used without script/yql queries" ;
182
+ }
183
+ }
184
+
185
+ void ValidateAsyncOptions (const NKqpRun::TAsyncQueriesSettings& asyncQueriesSettings) const {
186
+ if (asyncQueriesSettings.InFlightLimit && !HasExecutionCase (EExecutionCase::AsyncQuery)) {
187
+ ythrow yexception () << " In flight limit can not be used without async queries" ;
188
+ }
189
+
190
+ NColorizer::TColors colors = NColorizer::AutoColors (Cout);
191
+ if (LoopCount && asyncQueriesSettings.InFlightLimit && asyncQueriesSettings.InFlightLimit > ScriptQueries.size () * LoopCount) {
192
+ Cout << colors.Red () << " Warning: inflight limit is " << asyncQueriesSettings.InFlightLimit << " , that is larger than max possible number of queries " << ScriptQueries.size () * LoopCount << colors.Default () << Endl;
193
+ }
194
+ }
195
+
196
+ void ValidateTraceOpt (NKqpRun::TRunnerOptions::ETraceOptType traceOptType) const {
197
+ switch (traceOptType) {
198
+ case NKqpRun::TRunnerOptions::ETraceOptType::Scheme: {
199
+ if (!SchemeQuery) {
200
+ ythrow yexception () << " Trace opt type scheme cannot be used without scheme query" ;
201
+ }
202
+ break ;
203
+ }
204
+ case NKqpRun::TRunnerOptions::ETraceOptType::Script: {
205
+ if (ScriptQueries.empty ()) {
206
+ ythrow yexception () << " Trace opt type script cannot be used without script queries" ;
207
+ }
208
+ }
209
+ case NKqpRun::TRunnerOptions::ETraceOptType::All: {
210
+ if (!SchemeQuery && ScriptQueries.empty ()) {
211
+ ythrow yexception () << " Trace opt type all cannot be used without any queries" ;
212
+ }
213
+ }
214
+ case NKqpRun::TRunnerOptions::ETraceOptType::Disabled: {
215
+ break ;
216
+ }
217
+ }
218
+ }
219
+
109
220
private:
110
221
template <typename TValue>
111
222
static TValue GetValue (size_t index, const std::vector<TValue>& values, TValue defaultValue) {
@@ -278,7 +389,6 @@ class TMain : public TMainClassArgs {
278
389
TVector<TString> UdfsPaths;
279
390
TString UdfsDirectory;
280
391
bool ExcludeLinkedUdfs = false ;
281
- ui64 ResultsRowsLimit = 1000 ;
282
392
bool EmulateYt = false ;
283
393
284
394
static TString LoadFile (const TString& file) {
@@ -415,8 +525,8 @@ class TMain : public TMainClassArgs {
415
525
.StoreMappedResultT <TString>(&RunnerOptions.ResultOutput , &GetDefaultOutput);
416
526
options.AddLongOption (' L' , " result-rows-limit" , " Rows limit for script execution results" )
417
527
.RequiredArgument (" uint" )
418
- .DefaultValue (ResultsRowsLimit )
419
- .StoreResult (&ResultsRowsLimit);
528
+ .DefaultValue (0 )
529
+ .StoreResult (&ExecutionOptions. ResultsRowsLimit );
420
530
TChoices<NKqpRun::TRunnerOptions::EResultOutputFormat> resultFormat ({
421
531
{" rows" , NKqpRun::TRunnerOptions::EResultOutputFormat::RowsJson},
422
532
{" full-json" , NKqpRun::TRunnerOptions::EResultOutputFormat::FullJson},
@@ -441,7 +551,12 @@ class TMain : public TMainClassArgs {
441
551
.StoreMappedResultT <TString>(&RunnerOptions.ScriptQueryPlanOutput , &GetDefaultOutput);
442
552
options.AddLongOption (" script-statistics" , " File with script inprogress statistics" )
443
553
.RequiredArgument (" file" )
444
- .StoreResult (&RunnerOptions.InProgressStatisticsOutputFile );
554
+ .StoreMappedResultT <TString>(&RunnerOptions.InProgressStatisticsOutputFile , [](const TString& file) {
555
+ if (file == " -" ) {
556
+ ythrow yexception () << " Script in progress statistics cannot be printed to stdout, please specify file name" ;
557
+ }
558
+ return file;
559
+ });
445
560
TChoices<NYdb::NConsoleClient::EDataFormat> planFormat ({
446
561
{" pretty" , NYdb::NConsoleClient::EDataFormat::Pretty},
447
562
{" table" , NYdb::NConsoleClient::EDataFormat::PrettyTable},
@@ -453,6 +568,15 @@ class TMain : public TMainClassArgs {
453
568
.Choices (planFormat.GetChoices ())
454
569
.StoreMappedResultT <TString>(&RunnerOptions.PlanOutputFormat , planFormat);
455
570
571
+ options.AddLongOption (" script-timeline-file" , " File with script query timline in svg format" )
572
+ .RequiredArgument (" file" )
573
+ .StoreMappedResultT <TString>(&RunnerOptions.ScriptQueryTimelineFile , [](const TString& file) {
574
+ if (file == " -" ) {
575
+ ythrow yexception () << " Script timline cannot be printed to stdout, please specify file name" ;
576
+ }
577
+ return file;
578
+ });
579
+
456
580
// Pipeline settings
457
581
458
582
TChoices<TExecutionOptions::EExecutionCase> executionCase ({
@@ -463,7 +587,6 @@ class TMain : public TMainClassArgs {
463
587
});
464
588
options.AddLongOption (' C' , " execution-case" , " Type of query for -p argument" )
465
589
.RequiredArgument (" query-type" )
466
- .DefaultValue (" script" )
467
590
.Choices (executionCase.GetChoices ())
468
591
.Handler1 ([this , executionCase](const NLastGetopt::TOptsParser* option) {
469
592
TString choice (option->CurValOrDef ());
@@ -489,13 +612,16 @@ class TMain : public TMainClassArgs {
489
612
});
490
613
options.AddLongOption (' A' , " script-action" , " Script query execute action" )
491
614
.RequiredArgument (" script-action" )
492
- .DefaultValue (" execute" )
493
615
.Choices (scriptAction.GetChoices ())
494
616
.Handler1 ([this , scriptAction](const NLastGetopt::TOptsParser* option) {
495
617
TString choice (option->CurValOrDef ());
496
618
ExecutionOptions.ScriptQueryActions .emplace_back (scriptAction (choice));
497
619
});
498
620
621
+ options.AddLongOption (" timeout" , " Reauests timeout in milliseconds" )
622
+ .RequiredArgument (" uint" )
623
+ .StoreMappedResultT <ui64>(&RunnerOptions.YdbSettings .RequestsTimeout , &TDuration::MilliSeconds<ui64>);
624
+
499
625
options.AddLongOption (" cancel-after" , " Cancel script execution operation after specified delay in milliseconds" )
500
626
.RequiredArgument (" uint" )
501
627
.StoreMappedResultT <ui64>(&RunnerOptions.ScriptCancelAfter , &TDuration::MilliSeconds<ui64>);
@@ -510,7 +636,7 @@ class TMain : public TMainClassArgs {
510
636
.StoreResult (&ExecutionOptions.LoopCount );
511
637
options.AddLongOption (" loop-delay" , " Delay in milliseconds between loop steps" )
512
638
.RequiredArgument (" uint" )
513
- .DefaultValue (1000 )
639
+ .DefaultValue (0 )
514
640
.StoreMappedResultT <ui64>(&ExecutionOptions.LoopDelay , &TDuration::MilliSeconds<ui64>);
515
641
516
642
options.AddLongOption (' D' , " database" , " Database path for -p queries" )
@@ -576,6 +702,21 @@ class TMain : public TMainClassArgs {
576
702
.RequiredArgument (" path" )
577
703
.InsertTo (&RunnerOptions.YdbSettings .ServerlessTenants );
578
704
705
+ options.AddLongOption (" storage-size" , " Domain storage size in gigabytes" )
706
+ .RequiredArgument (" uint" )
707
+ .DefaultValue (32 )
708
+ .StoreMappedResultT <ui32>(&RunnerOptions.YdbSettings .DiskSize , [](ui32 diskSize) {
709
+ return static_cast <ui64>(diskSize) << 30 ;
710
+ });
711
+
712
+ options.AddLongOption (" real-pdisks" , " Use real PDisks instead of in memory PDisks (also disable disk mock)" )
713
+ .NoArgument ()
714
+ .SetFlag (&RunnerOptions.YdbSettings .UseRealPDisks );
715
+
716
+ options.AddLongOption (" disable-disk-mock" , " Disable disk mock on single node cluster" )
717
+ .NoArgument ()
718
+ .SetFlag (&RunnerOptions.YdbSettings .DisableDiskMock );
719
+
579
720
TChoices<std::function<void ()>> backtrace ({
580
721
{" heavy" , &NKikimr::EnableYDBBacktraceFormat},
581
722
{" light" , []() { SetFormatBackTraceFn (FormatBackTrace); }}
@@ -591,13 +732,17 @@ class TMain : public TMainClassArgs {
591
732
}
592
733
593
734
int DoRun (NLastGetopt::TOptsParseResult&&) override {
594
- if (!ExecutionOptions.SchemeQuery && ExecutionOptions.ScriptQueries .empty () && !RunnerOptions.YdbSettings .MonitoringEnabled && !RunnerOptions.YdbSettings .GrpcEnabled ) {
595
- ythrow yexception () << " Nothing to execute" ;
735
+ ExecutionOptions.Validate (RunnerOptions);
736
+
737
+ if (RunnerOptions.YdbSettings .DisableDiskMock && RunnerOptions.YdbSettings .NodeCount + RunnerOptions.YdbSettings .SharedTenants .size () + RunnerOptions.YdbSettings .DedicatedTenants .size () > 1 ) {
738
+ ythrow yexception () << " Disable disk mock cannot be used for multi node clusters" ;
596
739
}
597
740
598
741
RunnerOptions.YdbSettings .YqlToken = YqlToken;
599
742
RunnerOptions.YdbSettings .FunctionRegistry = CreateFunctionRegistry (UdfsDirectory, UdfsPaths, ExcludeLinkedUdfs).Get ();
600
- RunnerOptions.YdbSettings .AppConfig .MutableQueryServiceConfig ()->SetScriptResultRowsLimit (ResultsRowsLimit);
743
+ if (ExecutionOptions.ResultsRowsLimit ) {
744
+ RunnerOptions.YdbSettings .AppConfig .MutableQueryServiceConfig ()->SetScriptResultRowsLimit (ExecutionOptions.ResultsRowsLimit );
745
+ }
601
746
602
747
if (EmulateYt) {
603
748
const auto & fileStorageConfig = RunnerOptions.YdbSettings .AppConfig .GetQueryServiceConfig ().GetFileStorage ();
0 commit comments