111
111
#include < library/cpp/lfalloc/alloc_profiler/profiler.h>
112
112
#endif
113
113
114
+ #ifdef __unix__
115
+ #include < sys/resource.h>
116
+ #endif
117
+
114
118
using namespace NKikimr ;
115
119
using namespace NYql ;
116
120
@@ -545,6 +549,7 @@ int RunMain(int argc, const char* argv[])
545
549
TQContext qContext;
546
550
TString ysonAttrs;
547
551
TVector<TString> pqFileList;
552
+ size_t memLimit = 0 ;
548
553
549
554
NLastGetopt::TOpts opts = NLastGetopt::TOpts::Default ();
550
555
opts.AddLongOption (' p' , " program" , " Program to execute (use '-' to read from stdin)" )
@@ -555,6 +560,9 @@ int RunMain(int argc, const char* argv[])
555
560
.Optional ()
556
561
.NoArgument ()
557
562
.SetFlag (&runOptions.Sql );
563
+ opts.AddLongOption (" mem-limit" , " Resource (memory) limit, mb" )
564
+ .Optional ()
565
+ .StoreResult (&memLimit);
558
566
opts.AddLongOption (" pg" , " Program has PG syntax" ).NoArgument ().SetFlag (&runOptions.Pg );
559
567
opts.AddLongOption (' t' , " table" , " table@file" ).AppendTo (&tablesMappingList);
560
568
opts.AddLongOption (' C' , " cluster" , " set cluster to service mapping" ).RequiredArgument (" name@service" ).Handler (new TStoreMappingFunctor (&clusterMapping));
@@ -719,6 +727,24 @@ int RunMain(int argc, const char* argv[])
719
727
720
728
NLastGetopt::TOptsParseResult res (&opts, argc, argv);
721
729
730
+ if (memLimit > 0 ) {
731
+ #ifdef __unix__
732
+ struct rlimit rl;
733
+
734
+ if (getrlimit (RLIMIT_AS, &rl)) {
735
+ ythrow TSystemError () << " Cannot getrlimit(RLIMIT_RSS)" ;
736
+ }
737
+
738
+ rl.rlim_cur = memLimit * 1024 * 1024 ;
739
+ if (auto v = setrlimit (RLIMIT_AS, &rl)) {
740
+ ythrow TSystemError () << " Cannot setrlimit(RLIMIT_AS) to " << memLimit << " mbytes " << v;
741
+ }
742
+ #else
743
+ Cerr << " Memory limit can not be set on this platfrom" << Endl;
744
+ return 1 ;
745
+ #endif
746
+ }
747
+
722
748
if (!res.Has (" program" ) && !res.Has (" replay" )) {
723
749
YQL_LOG (ERROR) << " Either program or replay option should be specified" ;
724
750
return 1 ;
@@ -824,7 +850,7 @@ int RunMain(int argc, const char* argv[])
824
850
Y_ABORT_UNLESS (NKikimr::ParsePBFromFile (pgExtConfig, &config));
825
851
TVector<NYql::NPg::TExtensionDesc> extensions;
826
852
PgExtensionsFromProto (config, extensions);
827
- NYql::NPg::RegisterExtensions (extensions, false ,
853
+ NYql::NPg::RegisterExtensions (extensions, qContext. CanRead () ,
828
854
*NSQLTranslationPG::CreateExtensionSqlParser (),
829
855
NKikimr::NMiniKQL::CreateExtensionLoader().get());
830
856
}
0 commit comments