Skip to content

Commit 7bd8eb1

Browse files
authored
Add dqrun rlimit (#9897)
1 parent 01c8e9f commit 7bd8eb1

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

ydb/library/yql/parser/pg_catalog/catalog.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3679,7 +3679,7 @@ void RegisterExtensions(const TVector<TExtensionDesc>& extensions, bool typesOnl
36793679
throw yexception() << "Duplicated extension install name: " << e.InstallName;
36803680
}
36813681

3682-
if (e.LibraryMD5.empty()) {
3682+
if (e.LibraryMD5.empty() && !e.LibraryPath.empty()) {
36833683
e.LibraryMD5 = MD5::File(e.LibraryPath);
36843684
}
36853685

@@ -3691,7 +3691,7 @@ void RegisterExtensions(const TVector<TExtensionDesc>& extensions, bool typesOnl
36913691
}
36923692

36933693
parser.Parse(i + 1, sqls, catalog);
3694-
if (loader && !e.TypesOnly) {
3694+
if (loader && !e.TypesOnly && !e.LibraryPath.empty()) {
36953695
loader->Load(i + 1, e.Name, e.LibraryPath);
36963696
}
36973697
}

ydb/library/yql/tools/dqrun/dqrun.cpp

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@
111111
#include <library/cpp/lfalloc/alloc_profiler/profiler.h>
112112
#endif
113113

114+
#ifdef __unix__
115+
#include <sys/resource.h>
116+
#endif
117+
114118
using namespace NKikimr;
115119
using namespace NYql;
116120

@@ -545,6 +549,7 @@ int RunMain(int argc, const char* argv[])
545549
TQContext qContext;
546550
TString ysonAttrs;
547551
TVector<TString> pqFileList;
552+
size_t memLimit = 0;
548553

549554
NLastGetopt::TOpts opts = NLastGetopt::TOpts::Default();
550555
opts.AddLongOption('p', "program", "Program to execute (use '-' to read from stdin)")
@@ -555,6 +560,9 @@ int RunMain(int argc, const char* argv[])
555560
.Optional()
556561
.NoArgument()
557562
.SetFlag(&runOptions.Sql);
563+
opts.AddLongOption("mem-limit", "Resource (memory) limit, mb")
564+
.Optional()
565+
.StoreResult(&memLimit);
558566
opts.AddLongOption("pg", "Program has PG syntax").NoArgument().SetFlag(&runOptions.Pg);
559567
opts.AddLongOption('t', "table", "table@file").AppendTo(&tablesMappingList);
560568
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[])
719727

720728
NLastGetopt::TOptsParseResult res(&opts, argc, argv);
721729

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+
722748
if (!res.Has("program") && !res.Has("replay")) {
723749
YQL_LOG(ERROR) << "Either program or replay option should be specified";
724750
return 1;
@@ -824,7 +850,7 @@ int RunMain(int argc, const char* argv[])
824850
Y_ABORT_UNLESS(NKikimr::ParsePBFromFile(pgExtConfig, &config));
825851
TVector<NYql::NPg::TExtensionDesc> extensions;
826852
PgExtensionsFromProto(config, extensions);
827-
NYql::NPg::RegisterExtensions(extensions, false,
853+
NYql::NPg::RegisterExtensions(extensions, qContext.CanRead(),
828854
*NSQLTranslationPG::CreateExtensionSqlParser(),
829855
NKikimr::NMiniKQL::CreateExtensionLoader().get());
830856
}

ydb/library/yql/tools/dqrun/ya.make

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ IF (PROFILE_MEMORY_ALLOCATIONS)
55
ALLOCATOR(LF_DBG)
66
CFLAGS(-DPROFILE_MEMORY_ALLOCATIONS)
77
ELSE()
8-
IF (OS_LINUX)
8+
IF (OS_LINUX AND NOT DISABLE_TCMALLOC)
99
ALLOCATOR(TCMALLOC_256K)
1010
ELSE()
1111
ALLOCATOR(J)

0 commit comments

Comments
 (0)