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


##########
server/src/main/java/org/apache/druid/query/lookup/LookupReferencesManager.java:
##########
@@ -373,9 +376,24 @@ 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();
+    LookupLoadingSpec lookupLoadingSpec = 
lookupListeningAnnouncerConfig.getLookupLoadingSpec();
+    List<LookupBean> lookupBeanList;
+    if (lookupLoadingSpec.getLookupLoadingMode() == 
LookupLoadingSpec.LookupLoadingMode.NONE) {
+      lookupBeanList = Collections.emptyList();

Review Comment:
   Seems like this should be assigned `null` to short-circuit the next if-else 
below.



##########
server/src/main/java/org/apache/druid/server/lookup/cache/LookupLoadingSpec.java:
##########
@@ -0,0 +1,67 @@
+/*
+ * 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 java.util.List;
+
+public class LookupLoadingSpec
+{
+  /**
+   * This class defines the spec for loading of lookups for a given task. It 
contains 2 fields:
+   * <ol>
+   *   <li>{@link LookupLoadingSpec#lookupLoadingMode}: 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 enum LookupLoadingMode
+  {
+    ALL, NONE, PARTIAL
+  }
+
+  public LookupLoadingMode lookupLoadingMode;
+  public List<String> lookupsToLoad;
+
+  public LookupLoadingSpec(LookupLoadingMode lookupLoadingMode, List<String> 
lookupsToLoad)

Review Comment:
   This constructor should be private.



##########
server/src/main/java/org/apache/druid/server/lookup/cache/LookupLoadingSpec.java:
##########
@@ -0,0 +1,67 @@
+/*
+ * 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 java.util.List;
+
+public class LookupLoadingSpec
+{
+  /**
+   * This class defines the spec for loading of lookups for a given task. It 
contains 2 fields:
+   * <ol>
+   *   <li>{@link LookupLoadingSpec#lookupLoadingMode}: 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 enum LookupLoadingMode
+  {
+    ALL, NONE, PARTIAL
+  }
+
+  public LookupLoadingMode lookupLoadingMode;
+  public List<String> lookupsToLoad;
+
+  public LookupLoadingSpec(LookupLoadingMode lookupLoadingMode, List<String> 
lookupsToLoad)
+  {
+    this.lookupLoadingMode = lookupLoadingMode;
+    this.lookupsToLoad = lookupsToLoad;
+  }
+
+  public LookupLoadingSpec()

Review Comment:
   Additionally, the implementation of this method could verify that the passed 
list is non-null.



##########
server/src/main/java/org/apache/druid/server/lookup/cache/LookupLoadingSpec.java:
##########
@@ -0,0 +1,67 @@
+/*
+ * 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 java.util.List;
+
+public class LookupLoadingSpec
+{
+  /**
+   * This class defines the spec for loading of lookups for a given task. It 
contains 2 fields:
+   * <ol>
+   *   <li>{@link LookupLoadingSpec#lookupLoadingMode}: 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 enum LookupLoadingMode

Review Comment:
   Just calling it `Mode` should be fine because we will typically use it 
qualified with `LookupLoadingSpec`, i.e. `LookupLoadingSpec.Mode`.
   ```suggestion
     public enum Mode
   ```



##########
server/src/main/java/org/apache/druid/server/lookup/cache/LookupLoadingSpec.java:
##########
@@ -0,0 +1,67 @@
+/*
+ * 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 java.util.List;
+
+public class LookupLoadingSpec
+{
+  /**
+   * This class defines the spec for loading of lookups for a given task. It 
contains 2 fields:

Review Comment:
   This javadoc should be for `LookupLoadingSpec` rather than the mode enum.



##########
server/src/main/java/org/apache/druid/server/lookup/cache/LookupLoadingSpec.java:
##########
@@ -0,0 +1,67 @@
+/*
+ * 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 java.util.List;
+
+public class LookupLoadingSpec
+{
+  /**
+   * This class defines the spec for loading of lookups for a given task. It 
contains 2 fields:
+   * <ol>
+   *   <li>{@link LookupLoadingSpec#lookupLoadingMode}: 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 enum LookupLoadingMode
+  {
+    ALL, NONE, PARTIAL
+  }
+
+  public LookupLoadingMode lookupLoadingMode;
+  public List<String> lookupsToLoad;
+
+  public LookupLoadingSpec(LookupLoadingMode lookupLoadingMode, List<String> 
lookupsToLoad)
+  {
+    this.lookupLoadingMode = lookupLoadingMode;
+    this.lookupsToLoad = lookupsToLoad;
+  }
+
+  public LookupLoadingSpec()

Review Comment:
   Convert this into a static utility method which is used only to build a 
partial loading spec. For the other two, we should use the constants.
   
   ```suggestion
     public static LookupLoadingSpec partial(List<String> lookupsToLoad)
   ```



##########
server/src/main/java/org/apache/druid/server/lookup/cache/LookupLoadingSpec.java:
##########
@@ -0,0 +1,67 @@
+/*
+ * 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 java.util.List;
+
+public class LookupLoadingSpec

Review Comment:
   This class should also contain two constants for ease of use.
   
   ```
   public static final LookupLoadingSpec ALL = new LookupLoadingSpec(Mode.ALL, 
null);
   public static final LookupLoadingSpec NONE = new 
LookupLoadingSpec(Mode.NONE, null);
   ```



##########
indexing-service/src/main/java/org/apache/druid/indexing/common/task/KillUnusedSegmentsTask.java:
##########
@@ -339,4 +341,10 @@ private NavigableMap<DateTime, List<TaskLock>> 
getNonRevokedTaskLockMap(TaskActi
     );
     return taskLockMap;
   }
+
+  @Override
+  public LookupLoadingSpec getLookupLoadingSpec()
+  {
+    return new LookupLoadingSpec(LookupLoadingSpec.LookupLoadingMode.NONE, 
Collections.emptyList());

Review Comment:
   ```suggestion
       return LookupLoadingSpec.NONE;
   ```



##########
server/src/main/java/org/apache/druid/server/lookup/cache/LookupLoadingSpec.java:
##########
@@ -0,0 +1,67 @@
+/*
+ * 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 java.util.List;
+
+public class LookupLoadingSpec
+{
+  /**
+   * This class defines the spec for loading of lookups for a given task. It 
contains 2 fields:
+   * <ol>
+   *   <li>{@link LookupLoadingSpec#lookupLoadingMode}: 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 enum LookupLoadingMode
+  {
+    ALL, NONE, PARTIAL
+  }
+
+  public LookupLoadingMode lookupLoadingMode;
+  public List<String> lookupsToLoad;
+
+  public LookupLoadingSpec(LookupLoadingMode lookupLoadingMode, List<String> 
lookupsToLoad)
+  {
+    this.lookupLoadingMode = lookupLoadingMode;
+    this.lookupsToLoad = lookupsToLoad;
+  }
+
+  public LookupLoadingSpec()
+  {
+    this.lookupLoadingMode = LookupLoadingMode.ALL;
+  }
+
+  public LookupLoadingMode getLookupLoadingMode()

Review Comment:
   ```suggestion
     public Mode getMode()
   ```



##########
indexing-service/src/main/java/org/apache/druid/indexing/common/task/Task.java:
##########
@@ -331,4 +333,15 @@ static TaskInfo<TaskIdentifier, TaskStatus> 
toTaskIdentifierInfo(TaskInfo<Task,
         taskInfo.getTask().getMetadata()
     );
   }
+
+  /**
+   * Returns the {@link LookupLoadingSpec} for the given task, which can be 
used to determine the list of lookups to be loaded.
+   *
+   * @return {@link LookupLoadingSpec}
+   */
+  @Nullable
+  default LookupLoadingSpec getLookupLoadingSpec()
+  {
+    return new LookupLoadingSpec();

Review Comment:
   ```suggestion
       return LookupLoadingSpec.ALL;
   ```



##########
server/src/main/java/org/apache/druid/server/lookup/cache/LookupLoadingSpec.java:
##########
@@ -0,0 +1,67 @@
+/*
+ * 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 java.util.List;
+
+public class LookupLoadingSpec
+{
+  /**
+   * This class defines the spec for loading of lookups for a given task. It 
contains 2 fields:
+   * <ol>
+   *   <li>{@link LookupLoadingSpec#lookupLoadingMode}: 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 enum LookupLoadingMode
+  {
+    ALL, NONE, PARTIAL
+  }
+
+  public LookupLoadingMode lookupLoadingMode;

Review Comment:
   Fields should be private and final.



##########
indexing-service/src/main/java/org/apache/druid/indexing/common/task/Task.java:
##########
@@ -331,4 +333,15 @@ static TaskInfo<TaskIdentifier, TaskStatus> 
toTaskIdentifierInfo(TaskInfo<Task,
         taskInfo.getTask().getMetadata()
     );
   }
+
+  /**
+   * Returns the {@link LookupLoadingSpec} for the given task, which can be 
used to determine the list of lookups to be loaded.
+   *
+   * @return {@link LookupLoadingSpec}

Review Comment:
   This can be removed as it does not add any new info.



-- 
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