Browse Source

Add TableService flag for switching pattern cache

va-kuznecov 2 years ago
parent
commit
e3ffb0af25
3 changed files with 19 additions and 2 deletions
  1. 14 0
      ydb/core/kqp/rm/kqp_rm.cpp
  2. 2 1
      ydb/core/kqp/ut/kqp_service_ut.cpp
  3. 3 1
      ydb/core/protos/config.proto

+ 14 - 0
ydb/core/kqp/rm/kqp_rm.cpp

@@ -638,10 +638,24 @@ private:
         LOG_D("Subscribed for config changes");
     }
 
+    static void UpdatePatternCache(bool enable, std::shared_ptr<NMiniKQL::TComputationPatternLRUCache>& cache) {
+        if (enable) {
+            if (!cache) {
+                cache = std::make_shared<NMiniKQL::TComputationPatternLRUCache>();
+            }
+        } else {
+            cache.reset();
+        }
+    }
+
     void HandleWork(NConsole::TEvConsole::TEvConfigNotificationRequest::TPtr& ev) {
         auto& event = ev->Get()->Record;
         Send(ev->Sender, new NConsole::TEvConsole::TEvConfigNotificationResponse(event), IEventHandle::FlagTrackDelivery, ev->Cookie);
 
+        const auto& tsConfig = event.MutableConfig()->GetTableServiceConfig();
+        UpdatePatternCache(tsConfig.GetEnableKqpPatternCacheLiteral(), LiteralPatternCache);
+        UpdatePatternCache(tsConfig.GetEnableKqpPatternCacheCompute(), ComputeActorPatternCache);
+
         auto& config = *event.MutableConfig()->MutableTableServiceConfig()->MutableResourceManager();
 
 #define FORCE_VALUE(name) if (!config.Has ## name ()) config.Set ## name(config.Get ## name());

+ 2 - 1
ydb/core/kqp/ut/kqp_service_ut.cpp

@@ -227,7 +227,8 @@ Y_UNIT_TEST_SUITE(KqpService) {
     Y_UNIT_TEST_TWIN(PatternCache, UseCache) {
         auto settings = TKikimrSettings()
             .SetWithSampleTables(false);
-        settings.FeatureFlags.SetEnableKqpPatternCacheLiteral(UseCache);
+        settings.AppConfig.MutableTableServiceConfig()->SetEnableKqpPatternCacheLiteral(UseCache);
+        settings.AppConfig.MutableTableServiceConfig()->SetEnableKqpPatternCacheCompute(UseCache);
         auto kikimr = TKikimrRunner{settings};
         auto driver = kikimr.GetDriver();
 

+ 3 - 1
ydb/core/protos/config.proto

@@ -723,7 +723,7 @@ message TFeatureFlags {
     optional bool EnableKqpScanQueryStreamLookup = 66 [default = false];
     optional bool EnableKqpScanQueryMultipleOlapShardsReads = 67 [default = false];
     optional bool EnablePredicateExtractForDataQueries = 68 [default = true];
-    optional bool EnableKqpPatternCacheLiteral = 69 [default = false];
+    reserved 69; // optional bool EnableKqpPatternCacheLiteral = 69 [default = false];
     optional bool EnableMoveIndex = 70 [default = false];
     // enable http handle for self termination
     optional bool EnableFailureInjectionTermination = 71 [default = false];
@@ -1183,6 +1183,8 @@ message TTableServiceConfig {
     optional uint32 CompileQueryCacheTTLSec = 20 [default = 0];
     optional TQueryReplayConfig QueryReplayConfig = 21;
     reserved 23; // optional bool EnableKqpSessionActor = 23 [default = true];
+    optional bool EnableKqpPatternCacheLiteral = 24 [default = false];
+    optional bool EnableKqpPatternCacheCompute = 25 [default = false];
 };
 
 // Config describes immediate controls and allows