gortiz commented on code in PR #10192: URL: https://github.com/apache/pinot/pull/10192#discussion_r1136809377
########## 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) { Review Comment: I can imagine that most times, in production, IndexService is going to be created using the `ServiceLoader`. But I can imagine several scenarios where that is not going to happen: 1. Tests: If we want to test how some code behaves in case some index type is not present, if we don't have this method we either has to create our own classpath (which is tricky) or heavily use mocks (which is also tricky). Instead, with this constructor we can create our own `IndexService` with a limited number of index types. 2. Special distributions: The default idea of enabling all index types in the classpath seems correct for most distributions, but we can imagine a case when even if there is an index in the classpath, we want to disable it. For example, we could add an startup property with a list that filters-in or filters-out some index types. In that case, we should call this constructor at startup. * For example, a customer don't want to use a specific index type because they know that it may produce problems in their environment. If the customer is not that large, they can decide to do not use it and that's it. But if the customer is large and it is difficult to coordinate all people that creates tables, they may decide to do not load at that index at startup time. -- 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: commits-unsubscr...@pinot.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For additional commands, e-mail: commits-h...@pinot.apache.org