navina commented on code in PR #10192:
URL: https://github.com/apache/pinot/pull/10192#discussion_r1137597984


##########
pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/index/IndexService.java:
##########
@@ -0,0 +1,83 @@
+/**
+ * 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.pinot.segment.spi.index;
+
+import com.google.common.collect.Sets;
+import java.util.HashSet;
+import java.util.Optional;
+import java.util.ServiceLoader;
+import java.util.Set;
+
+
+/**
+ * This is the entry point of the Index SPI.
+ *
+ * Ideally, if we used some kind of injection system, this class should be 
injected into a Pinot context all classes can
+ * receive when they are built. Given that Pinot doesn't have that, we have to 
relay on static fields.
+ *
+ * By default, this class will be initialized by reading all ServiceLoader SPI 
services that implement
+ * {@link IndexPlugin}, adding all the {@link IndexType} that can be found in 
that way.
+ *
+ * In case we want to change the instance to be used at runtime, the method 
{@link #setInstance(IndexService)} can be
+ * called.

Review Comment:
   Thanks for the detailed explanation. I unfortunately agree with the lack of 
a contextual instance in the architecture. I think we had discussed on similar 
lines in my metrics registry for plugins. 
   
   Glad that you have thought this through and had to make this choice :) 
   
   Curious if you had considered introducing this PinotContext object as part 
of index spi changes. Guessing it will be a lot more disruptive changes to the 
code?
   
   nit: Please add javadoc / annotation about the need for thread safety 
guarantees for implementations of this interface 



##########
pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/index/IndexService.java:
##########
@@ -0,0 +1,83 @@
+/**
+ * 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.pinot.segment.spi.index;
+
+import com.google.common.collect.Sets;
+import java.util.HashSet;
+import java.util.Optional;
+import java.util.ServiceLoader;
+import java.util.Set;
+
+
+/**
+ * This is the entry point of the Index SPI.
+ *
+ * Ideally, if we used some kind of injection system, this class should be 
injected into a Pinot context all classes can
+ * receive when they are built. Given that Pinot doesn't have that, we have to 
relay on static fields.
+ *
+ * By default, this class will be initialized by reading all ServiceLoader SPI 
services that implement
+ * {@link IndexPlugin}, adding all the {@link IndexType} that can be found in 
that way.
+ *
+ * In case we want to change the instance to be used at runtime, the method 
{@link #setInstance(IndexService)} can be
+ * called.
+ */
+public class IndexService {
+
+  private static volatile IndexService _instance = fromServiceLoader();
+
+  private final Set<IndexType<?, ?, ?>> _allIndexes;
+
+  public IndexService(Set<IndexPlugin<?>> allPlugins) {
+    _allIndexes = Sets.newHashSetWithExpectedSize(allPlugins.size());
+
+    for (IndexPlugin<?> plugin : allPlugins) {
+      _allIndexes.add(plugin.getIndexType());
+    }
+  }
+
+  public static IndexService getInstance() {
+    return _instance;
+  }
+
+  public static void setInstance(IndexService other) {
+    _instance = other;
+  }
+
+  public static IndexService fromServiceLoader() {
+    Set<IndexPlugin<?>> pluginList = new HashSet<>();
+    for (IndexPlugin indexPlugin : ServiceLoader.load(IndexPlugin.class)) {
+      pluginList.add(indexPlugin);
+    }
+    return new IndexService(pluginList);
+  }
+
+  public Set<IndexType<?, ?, ?>> getAllIndexes() {
+    return _allIndexes;
+  }
+
+  public Optional<IndexType<?, ?, ?>> getIndexTypeById(String indexId) {
+    return getAllIndexes().stream().filter(indexType -> 
indexType.getId().equalsIgnoreCase(indexId)).findAny();
+  }
+
+  public IndexType<?, ?, ?> getIndexTypeByIdOrThrow(String indexId) {
+    return getIndexTypeById(indexId)
+        .orElseThrow(() -> new IllegalArgumentException("Unknown index id: " + 
indexId));
+  }

Review Comment:
   I wouldn't go with 1. as returning `null` has been plaguing the codebase and 
not a good practice anyway.  I don't like option 2 as it requires the caller to 
handle exceptions and this is a method that might be used frequently in many 
parts of the codebase. 
   
   I didn't think the overhead with optional (in Option #3) would be that much 
of a problem.  
   I like your last proposal - `get`  -> throws if IndexType is not there; 
`getOptional` -> may return an optional reference.



##########
pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/index/IndexService.java:
##########
@@ -0,0 +1,83 @@
+/**
+ * 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.pinot.segment.spi.index;
+
+import com.google.common.collect.Sets;
+import java.util.HashSet;
+import java.util.Optional;
+import java.util.ServiceLoader;
+import java.util.Set;
+
+
+/**
+ * This is the entry point of the Index SPI.
+ *
+ * Ideally, if we used some kind of injection system, this class should be 
injected into a Pinot context all classes can
+ * receive when they are built. Given that Pinot doesn't have that, we have to 
relay on static fields.

Review Comment:
   I think it is well-known to a Pinot developer that we don't use a standard 
injection mechanism across the codebase.  My comment was specifically for these 
2 lines:
   
   ```Ideally, if we used some kind of injection system, this class should be 
injected into a Pinot context all classes can receive when they are built. 
Given that Pinot doesn't have that, we have to relay on static fields.``` 
   
   It is not clear what static field you are talking about. When the interface 
evolves in the future, this comment might no longer be relevant. 
   
   Imo, it seems out of place as it doesn't talk about the usability of the 
interface. It pertains to the current choice of implementation that is not 
required for any caller or even implementer to know because it is well-known to 
a developer that Pinot doesn't use a standard injection mechanism across the 
codebase. 
   
   If you want to emphasize the usability of this interface, you should just 
literally explain how to use it in the javadoc. The future improvements can be 
annotated as a TODO or Note. 
   
   An example could be:
   
   ``` 
   This is the entry point of the Index SPI.
    
    By default, this service will be initialized by reading all ServiceLoader 
SPI services 
   that implement {@link IndexPlugin}, adding all the {@link IndexType} that 
can be found in 
   that way. A caller can iterate it by invoking 
`IndexService.getInstance().getAllIndexes()` 
    
   The interface allows changing the singleton instance at runtime using the 
method {@link #setInstance(IndexService)}. 
   
   Note:  Since Pinot doesn't support injection mechanism, we have to rely on 
static fields (singleton pattern) like `_instance`. With an injection 
mechanism, this instance can be part of a `PinotContext` object that is 
accessible in all components.
   
   ```
   
   I still think those 2 lines in the javadoc are out of place and me, as a 
pinot developer, don't find it useful. Will let others chime in. 



##########
pinot-spi/src/main/java/org/apache/pinot/spi/config/table/BloomFilterConfig.java:
##########
@@ -21,20 +21,27 @@
 import com.fasterxml.jackson.annotation.JsonCreator;
 import com.fasterxml.jackson.annotation.JsonProperty;
 import com.google.common.base.Preconditions;
-import org.apache.pinot.spi.config.BaseJsonConfig;
+import java.util.Objects;
 
 
-public class BloomFilterConfig extends BaseJsonConfig {
+public class BloomFilterConfig extends IndexConfig {
   public static final double DEFAULT_FPP = 0.05;
+  private static final BloomFilterConfig DEFAULT = new 
BloomFilterConfig(BloomFilterConfig.DEFAULT_FPP, 0, false);
+  public static final BloomFilterConfig DISABLED = new 
BloomFilterConfig(false, BloomFilterConfig.DEFAULT_FPP, 0,

Review Comment:
   makes sense. Agree it is not always possible to assign a default / invalid 
value for a type. But it wasn't obvious from reading the code that the caller 
should always check if an index is enabled or not before trying to fetch the 
config values. 
   
   It's fine for now. Will probably become easier to understand as index-spi 
feature implementation continues.



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