This is an automated email from the ASF dual-hosted git repository. ravipesala pushed a commit to branch branch-1.6 in repository https://gitbox.apache.org/repos/asf/carbondata.git
commit 1943ddae258c754ab11c466557877378fb9a748e Author: ajantha-bhat <ajanthab...@gmail.com> AuthorDate: Thu Aug 22 17:42:12 2019 +0530 [CARBONDATA-3499] Fix insert failure with customFileProvider Problem: Below exception is thrown when the custom file system is used with first time insert randomly. IllegalArgumentException("Path belongs to unsupported file system") from FileFactory.getFileType() Cause: DefaultFileTypeProvider.initializeCustomFileProvider is called concurrently during insert. Hence one thread got the provider and other thread didn't get as flag is set to true. so other thread failed as it tried with default provider. Solution: synchronize the initialization of custom file provider. This closes #3362 --- .../datastore/impl/DefaultFileTypeProvider.java | 31 +++++++++++++--------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/core/src/main/java/org/apache/carbondata/core/datastore/impl/DefaultFileTypeProvider.java b/core/src/main/java/org/apache/carbondata/core/datastore/impl/DefaultFileTypeProvider.java index cdb1a20..4572cc4 100644 --- a/core/src/main/java/org/apache/carbondata/core/datastore/impl/DefaultFileTypeProvider.java +++ b/core/src/main/java/org/apache/carbondata/core/datastore/impl/DefaultFileTypeProvider.java @@ -43,7 +43,9 @@ public class DefaultFileTypeProvider implements FileTypeInterface { */ protected FileTypeInterface customFileTypeProvider = null; - protected boolean customFileTypeProviderInitialized = false; + protected Boolean customFileTypeProviderInitialized = false; + + private final Object lock = new Object(); public DefaultFileTypeProvider() { } @@ -52,17 +54,22 @@ public class DefaultFileTypeProvider implements FileTypeInterface { * This method is required apart from Constructor to handle the below circular dependency. * CarbonProperties-->FileFactory-->DefaultTypeProvider-->CarbonProperties */ - private void initializeCustomFileprovider() { + private void initializeCustomFileProvider() { if (!customFileTypeProviderInitialized) { - customFileTypeProviderInitialized = true; - String customFileProvider = - CarbonProperties.getInstance().getProperty(CarbonCommonConstants.CUSTOM_FILE_PROVIDER); - if (customFileProvider != null && !customFileProvider.trim().isEmpty()) { - try { - customFileTypeProvider = - (FileTypeInterface) Class.forName(customFileProvider).newInstance(); - } catch (Exception e) { - LOGGER.error("Unable load configured FileTypeInterface class. Ignored.", e); + // This initialization can happen in concurrent threads. + synchronized (lock) { + if (!customFileTypeProviderInitialized) { + String customFileProvider = CarbonProperties.getInstance() + .getProperty(CarbonCommonConstants.CUSTOM_FILE_PROVIDER); + if (customFileProvider != null && !customFileProvider.trim().isEmpty()) { + try { + customFileTypeProvider = + (FileTypeInterface) Class.forName(customFileProvider).newInstance(); + } catch (Exception e) { + LOGGER.error("Unable load configured FileTypeInterface class. Ignored.", e); + } + customFileTypeProviderInitialized = true; + } } } } @@ -77,7 +84,7 @@ public class DefaultFileTypeProvider implements FileTypeInterface { * @return true if supported by the custom */ @Override public boolean isPathSupported(String path) { - initializeCustomFileprovider(); + initializeCustomFileProvider(); if (customFileTypeProvider != null) { return customFileTypeProvider.isPathSupported(path); }