cryptoe commented on code in PR #16328:
URL: https://github.com/apache/druid/pull/16328#discussion_r1581790375


##########
server/src/main/java/org/apache/druid/query/lookup/LookupReferencesManager.java:
##########
@@ -373,10 +376,25 @@ private void takeSnapshot(Map<String, 
LookupExtractorFactoryContainer> lookupMap
     }
   }
 
-  private void loadAllLookupsAndInitStateRef()
+  /**
+   * Load a set of lookups based on the injected value in {@link 
DataSourceTaskIdHolder#getLookupLoadingSpec()}.
+   */
+  private void loadLookupsAndInitStateRef()
   {
-    List<LookupBean> lookupBeanList = getLookupsList();
-    if (lookupBeanList != null) {
+    LookupLoadingSpec lookupLoadingSpec = 
lookupListeningAnnouncerConfig.getLookupLoadingSpec();
+    List<LookupBean> lookupBeanList;
+    if (lookupLoadingSpec.getMode() == LookupLoadingSpec.Mode.NONE) {
+      lookupBeanList = Collections.emptyList();

Review Comment:
   Should we change this logging to info mentioning no lookups are loaded?



##########
server/src/main/java/org/apache/druid/server/lookup/cache/LookupLoadingSpec.java:
##########
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.druid.server.lookup.cache;
+
+import org.apache.druid.java.util.common.ISE;
+
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * This class defines the spec for loading of lookups for a given task. It 
contains 2 fields:
+ * <ol>
+ *   <li>{@link LookupLoadingSpec#mode}: This mode defines whether lookups 
need to be
+ *   loaded for the given task, or not. It can take 3 values: </li>
+ *   <ul>
+ *    <li> ALL: Load all the lookups.</li>
+ *    <li> NONE: Load no lookups. </li>
+ *    <li> PARTIAL: Load only the lookups defined in lookupsToLoad </li>
+ *   </ul>
+ * <li>{@link LookupLoadingSpec#lookupsToLoad}: Defines the lookups to load 
when the lookupLoadingMode is set to PARTIAL.</li>
+ * </ol>
+ */
+public class LookupLoadingSpec
+{
+  public enum Mode
+  {
+    ALL, NONE, PARTIAL
+  }
+
+  private final Mode mode;
+  private final List<String> lookupsToLoad;
+
+  public static final LookupLoadingSpec ALL = new LookupLoadingSpec(Mode.ALL, 
null);

Review Comment:
   Love the pojo. 
   Nit: I would just make take in a list and change it to a immutable and then 
return an immutable list in the getter. 



##########
server/src/main/java/org/apache/druid/query/lookup/LookupReferencesManager.java:
##########
@@ -373,10 +376,25 @@ private void takeSnapshot(Map<String, 
LookupExtractorFactoryContainer> lookupMap
     }
   }
 
-  private void loadAllLookupsAndInitStateRef()
+  /**
+   * Load a set of lookups based on the injected value in {@link 
DataSourceTaskIdHolder#getLookupLoadingSpec()}.
+   */
+  private void loadLookupsAndInitStateRef()
   {
-    List<LookupBean> lookupBeanList = getLookupsList();
-    if (lookupBeanList != null) {
+    LookupLoadingSpec lookupLoadingSpec = 
lookupListeningAnnouncerConfig.getLookupLoadingSpec();
+    List<LookupBean> lookupBeanList;
+    if (lookupLoadingSpec.getMode() == LookupLoadingSpec.Mode.NONE) {
+      lookupBeanList = Collections.emptyList();
+    } else {
+      lookupBeanList = getLookupsList();
+      if (lookupLoadingSpec.getMode() == LookupLoadingSpec.Mode.PARTIAL && 
lookupBeanList != null) {
+        lookupBeanList = lookupBeanList.stream()
+                                       .filter(lookupBean -> 
lookupLoadingSpec.getLookupsToLoad().contains(lookupBean.getName()))
+                                       .collect(Collectors.toList());
+      }
+    }
+

Review Comment:
   Nit: Lets add info log if no lookups were loaded or which lookups were 
filtered. Once we have more confidence we can switch the log levels to debug. 
   @kfaraz wdyt ?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to