Search in sources :

Example 1 with CaseInsensitivePersistentStore

use of org.apache.drill.exec.store.sys.CaseInsensitivePersistentStore in project drill by apache.

the class StoragePluginStoreImpl method initPluginsSystemTable.

/**
 * <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) {
        throw new DrillRuntimeException("Failure while reading and loading storage plugin configuration.");
    }
}
Also used : Entry(java.util.Map.Entry) CaseInsensitivePersistentStore(org.apache.drill.exec.store.sys.CaseInsensitivePersistentStore) StoragePluginConfig(org.apache.drill.common.logical.StoragePluginConfig) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException) StoreException(org.apache.drill.exec.exception.StoreException)

Aggregations

Entry (java.util.Map.Entry)1 DrillRuntimeException (org.apache.drill.common.exceptions.DrillRuntimeException)1 StoragePluginConfig (org.apache.drill.common.logical.StoragePluginConfig)1 StoreException (org.apache.drill.exec.exception.StoreException)1 CaseInsensitivePersistentStore (org.apache.drill.exec.store.sys.CaseInsensitivePersistentStore)1