arina-ielchiieva commented on a change in pull request #1988: DRILL-7590: Refactor plugin registry URL: https://github.com/apache/drill/pull/1988#discussion_r383987320
########## File path: exec/java-exec/src/main/java/org/apache/drill/exec/store/StoragePluginStoreImpl.java ########## @@ -0,0 +1,147 @@ +/* + * 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.drill.exec.store; + +import static org.apache.drill.shaded.guava.com.google.common.base.Preconditions.checkNotNull; + +import java.util.Iterator; +import java.util.Map; +import java.util.Map.Entry; + +import org.apache.drill.common.config.LogicalPlanPersistence; +import org.apache.drill.common.exceptions.DrillRuntimeException; +import org.apache.drill.common.logical.StoragePluginConfig; +import org.apache.drill.exec.exception.StoreException; +import org.apache.drill.exec.planner.logical.StoragePlugins; +import org.apache.drill.exec.server.DrillbitContext; +import org.apache.drill.exec.store.sys.CaseInsensitivePersistentStore; +import org.apache.drill.exec.store.sys.PersistentStore; +import org.apache.drill.exec.store.sys.PersistentStoreConfig; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Concrete storage plugin (configuration) store based on the + * {@link PersistentStore} abstraction. + */ +public class StoragePluginStoreImpl implements StoragePluginStore { + private static final Logger logger = LoggerFactory.getLogger(StoragePluginStoreImpl.class); + + private final PersistentStore<StoragePluginConfig> pluginSystemTable; + + public StoragePluginStoreImpl(DrillbitContext context) { + this.pluginSystemTable = initPluginsSystemTable(context, + checkNotNull(context.getLpPersistence())); + } + + /** + * <ol> + * <li>Initializes persistent store for storage plugins.</li> + * <li>Since storage plugins names are case-insensitive in Drill, to ensure backward compatibility, + * re-writes those not stored in lower case with lower case names, for duplicates issues warning. </li> + * <li>Wraps plugin system table into case insensitive wrapper.</li> + * </ol> + * + * @param context drillbit context + * @param lpPersistence deserialization mapper provider + * @return persistent store for storage plugins + */ + private PersistentStore<StoragePluginConfig> initPluginsSystemTable( + DrillbitContext context, LogicalPlanPersistence lpPersistence) { + try { + PersistentStore<StoragePluginConfig> pluginSystemTable = context + .getStoreProvider() + .getOrCreateStore(PersistentStoreConfig + .newJacksonBuilder(lpPersistence.getMapper(), StoragePluginConfig.class) + .name(StoragePluginRegistryImpl.PSTORE_NAME) + .build()); + + Iterator<Entry<String, StoragePluginConfig>> storedPlugins = pluginSystemTable.getAll(); + while (storedPlugins.hasNext()) { + Entry<String, StoragePluginConfig> entry = storedPlugins.next(); + String pluginName = entry.getKey(); + if (!pluginName.equals(pluginName.toLowerCase())) { + logger.debug("Replacing plugin name {} with its lower case equivalent.", pluginName); + pluginSystemTable.delete(pluginName); + if (!pluginSystemTable.putIfAbsent(pluginName.toLowerCase(), entry.getValue())) { + logger.warn("Duplicated storage plugin name [{}] is found. Duplicate is deleted from persistent storage.", pluginName); + } + } + } + + return new CaseInsensitivePersistentStore<>(pluginSystemTable); + } catch (StoreException e) { + String msg = "Failure while reading and loading storage plugin configuration."; + logger.error(msg, e); Review comment: No need to log an error since we are already failing. ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
