Search in sources :

Example 6 with CarbonThreadFactory

use of org.apache.carbondata.core.util.CarbonThreadFactory in project carbondata by apache.

the class CarbonRowDataWriterProcessorStepImpl method execute.

@Override
public Iterator<CarbonRowBatch>[] execute() throws CarbonDataLoadingException {
    final Iterator<CarbonRowBatch>[] iterators = child.execute();
    tableIdentifier = configuration.getTableIdentifier().getCarbonTableIdentifier();
    tableName = tableIdentifier.getTableName();
    try {
        readCounter = new long[iterators.length];
        writeCounter = new long[iterators.length];
        dimensionWithComplexCount = configuration.getDimensionCount();
        noDictWithComplextCount = configuration.getNoDictionaryCount() + configuration.getComplexDictionaryColumnCount() + configuration.getComplexNonDictionaryColumnCount();
        directDictionaryDimensionCount = configuration.getDimensionCount() - noDictWithComplextCount;
        isNoDictionaryDimensionColumn = CarbonDataProcessorUtil.getNoDictionaryMapping(configuration.getDataFields());
        measureCount = configuration.getMeasureCount();
        CarbonTimeStatisticsFactory.getLoadStatisticsInstance().recordDictionaryValue2MdkAdd2FileTime(CarbonTablePath.DEPRECATED_PARTITION_ID, System.currentTimeMillis());
        if (configuration.getDataLoadProperty(DataLoadProcessorConstants.NO_REARRANGE_OF_ROWS) != null) {
            initializeNoReArrangeIndexes();
        }
        if (iterators.length == 1) {
            doExecute(iterators[0], 0);
        } else {
            executorService = Executors.newFixedThreadPool(iterators.length, new CarbonThreadFactory("NoSortDataWriterPool:" + configuration.getTableIdentifier().getCarbonTableIdentifier().getTableName(), true));
            Future[] futures = new Future[iterators.length];
            for (int i = 0; i < iterators.length; i++) {
                futures[i] = executorService.submit(new DataWriterRunnable(iterators[i], i));
            }
            for (Future future : futures) {
                future.get();
            }
        }
    } catch (CarbonDataWriterException e) {
        LOGGER.error("Failed for table: " + tableName + " in DataWriterProcessorStepImpl", e);
        throw new CarbonDataLoadingException("Error while initializing data handler : " + e.getMessage(), e);
    } catch (Exception e) {
        LOGGER.error("Failed for table: " + tableName + " in DataWriterProcessorStepImpl", e);
        if (e instanceof BadRecordFoundException) {
            throw new BadRecordFoundException(e.getMessage(), e);
        }
        throw new CarbonDataLoadingException(e.getMessage(), e);
    }
    return null;
}
Also used : CarbonDataLoadingException(org.apache.carbondata.processing.loading.exception.CarbonDataLoadingException) Iterator(java.util.Iterator) CarbonThreadFactory(org.apache.carbondata.core.util.CarbonThreadFactory) Future(java.util.concurrent.Future) CarbonDataWriterException(org.apache.carbondata.core.datastore.exception.CarbonDataWriterException) CarbonDataWriterException(org.apache.carbondata.core.datastore.exception.CarbonDataWriterException) BadRecordFoundException(org.apache.carbondata.processing.loading.exception.BadRecordFoundException) IOException(java.io.IOException) CarbonDataLoadingException(org.apache.carbondata.processing.loading.exception.CarbonDataLoadingException) BadRecordFoundException(org.apache.carbondata.processing.loading.exception.BadRecordFoundException)

Example 7 with CarbonThreadFactory

use of org.apache.carbondata.core.util.CarbonThreadFactory in project carbondata by apache.

the class InputProcessorStepImpl method initialize.

@Override
public void initialize() throws IOException {
    super.initialize();
    rowParser = new RowParserImpl(getOutput(), configuration);
    executorService = Executors.newCachedThreadPool(new CarbonThreadFactory("InputProcessorPool:" + configuration.getTableIdentifier().getCarbonTableIdentifier().getTableName(), true));
    // if logger is enabled then raw data will be required.
    this.isRawDataRequired = CarbonDataProcessorUtil.isRawDataRequired(configuration);
}
Also used : CarbonThreadFactory(org.apache.carbondata.core.util.CarbonThreadFactory) RowParserImpl(org.apache.carbondata.processing.loading.parser.impl.RowParserImpl)

Example 8 with CarbonThreadFactory

use of org.apache.carbondata.core.util.CarbonThreadFactory in project carbondata by apache.

the class CarbonTableOutputFormat method getRecordWriter.

@Override
public RecordWriter<NullWritable, ObjectArrayWritable> getRecordWriter(final TaskAttemptContext taskAttemptContext) throws IOException {
    final CarbonLoadModel loadModel = getLoadModel(taskAttemptContext.getConfiguration());
    loadModel.setMetrics(new DataLoadMetrics());
    String appName = taskAttemptContext.getConfiguration().get(CarbonCommonConstants.CARBON_WRITTEN_BY_APPNAME);
    if (null != appName) {
        CarbonProperties.getInstance().addProperty(CarbonCommonConstants.CARBON_WRITTEN_BY_APPNAME, appName);
    }
    // if loadModel having taskNo already(like in SDK) then no need to overwrite
    short sdkWriterCores = loadModel.getSdkWriterCores();
    int itrSize = (sdkWriterCores > 0) ? sdkWriterCores : 1;
    final CarbonOutputIteratorWrapper[] iterators = new CarbonOutputIteratorWrapper[itrSize];
    for (int i = 0; i < itrSize; i++) {
        iterators[i] = new CarbonOutputIteratorWrapper();
    }
    if (null == loadModel.getTaskNo() || loadModel.getTaskNo().isEmpty()) {
        loadModel.setTaskNo(taskAttemptContext.getConfiguration().get("carbon.outputformat.taskno", String.valueOf(DEFAULT_TASK_NO.getAndIncrement())));
    }
    loadModel.setDataWritePath(taskAttemptContext.getConfiguration().get("carbon.outputformat.writepath"));
    final String[] tempStoreLocations = getTempStoreLocations(taskAttemptContext);
    DataTypeUtil.clearFormatter();
    final DataLoadExecutor dataLoadExecutor = new DataLoadExecutor();
    final ExecutorService executorService = Executors.newFixedThreadPool(1, new CarbonThreadFactory("CarbonRecordWriter:" + loadModel.getTableName(), true));
    // It should be started in new thread as the underlying iterator uses blocking queue.
    Future future = executorService.submit(() -> {
        ThreadLocalSessionInfo.getOrCreateCarbonSessionInfo().getNonSerializableExtraInfo().put("carbonConf", taskAttemptContext.getConfiguration());
        try {
            dataLoadExecutor.execute(loadModel, tempStoreLocations, iterators);
        } catch (Exception e) {
            executorService.shutdownNow();
            for (CarbonOutputIteratorWrapper iterator : iterators) {
                iterator.closeWriter(true);
            }
            try {
                dataLoadExecutor.close();
            } catch (Exception ex) {
                // As already exception happened before close() send that exception.
                throw new RuntimeException(e);
            }
            throw new RuntimeException(e);
        } finally {
            ThreadLocalSessionInfo.unsetAll();
        }
    });
    if (sdkWriterCores > 0) {
        // CarbonMultiRecordWriter handles the load balancing of the write rows in round robin.
        return new CarbonMultiRecordWriter(iterators, dataLoadExecutor, loadModel, future, executorService);
    } else {
        return new CarbonRecordWriter(iterators[0], dataLoadExecutor, loadModel, future, executorService);
    }
}
Also used : DataLoadMetrics(org.apache.carbondata.core.util.DataLoadMetrics) IOException(java.io.IOException) DeprecatedFeatureException(org.apache.carbondata.common.exceptions.DeprecatedFeatureException) ExecutionException(java.util.concurrent.ExecutionException) CarbonOutputIteratorWrapper(org.apache.carbondata.processing.loading.iterator.CarbonOutputIteratorWrapper) CarbonLoadModel(org.apache.carbondata.processing.loading.model.CarbonLoadModel) ExecutorService(java.util.concurrent.ExecutorService) CarbonThreadFactory(org.apache.carbondata.core.util.CarbonThreadFactory) Future(java.util.concurrent.Future) DataLoadExecutor(org.apache.carbondata.processing.loading.DataLoadExecutor)

Example 9 with CarbonThreadFactory

use of org.apache.carbondata.core.util.CarbonThreadFactory in project carbondata by apache.

the class TableProcessingOperations method deleteLocalDataLoadFolderLocation.

/**
 * This method will delete the local data load folder location after data load is complete
 *
 * @param tempLocationKey temporary location set in carbon properties
 * @param tableName
 */
public static void deleteLocalDataLoadFolderLocation(String tempLocationKey, String tableName) {
    // form local store location
    final String localStoreLocations = CarbonProperties.getInstance().getProperty(tempLocationKey);
    if (localStoreLocations == null) {
        throw new RuntimeException("Store location not set for the key " + tempLocationKey);
    }
    // submit local folder clean up in another thread so that main thread execution is not blocked
    ExecutorService localFolderDeletionService = Executors.newFixedThreadPool(1, new CarbonThreadFactory("LocalFolderDeletionPool:" + tableName, true));
    try {
        localFolderDeletionService.submit(new Callable<Void>() {

            @Override
            public Void call() {
                long startTime = System.currentTimeMillis();
                String[] locArray = StringUtils.split(localStoreLocations, File.pathSeparator);
                for (String loc : locArray) {
                    try {
                        CarbonUtil.deleteFoldersAndFiles(new File(loc));
                    } catch (IOException | InterruptedException e) {
                        LOGGER.error("Failed to delete local data load folder location: " + loc, e);
                    }
                }
                LOGGER.info("Deleted the local store location: " + localStoreLocations + " : Time taken: " + (System.currentTimeMillis() - startTime));
                return null;
            }
        });
    } finally {
        CarbonProperties.getInstance().removeProperty(tempLocationKey);
        if (null != localFolderDeletionService) {
            localFolderDeletionService.shutdown();
        }
    }
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) CarbonThreadFactory(org.apache.carbondata.core.util.CarbonThreadFactory) File(java.io.File)

Example 10 with CarbonThreadFactory

use of org.apache.carbondata.core.util.CarbonThreadFactory in project carbondata by apache.

the class ExtendedBlockletWrapperContainer method getExtendedBlocklets.

public List<ExtendedBlocklet> getExtendedBlocklets(IndexInputFormat indexInputFormat) throws IOException {
    if (!isFallbackJob) {
        int numOfThreads = CarbonProperties.getNumOfThreadsForPruning();
        ExecutorService executorService = Executors.newFixedThreadPool(numOfThreads, new CarbonThreadFactory("SplitDeseralizerPool", true));
        int numberOfWrapperPerThread = extendedBlockletWrappers.length / numOfThreads;
        int leftOver = extendedBlockletWrappers.length % numOfThreads;
        int[] split = null;
        if (numberOfWrapperPerThread > 0) {
            split = new int[numOfThreads];
        } else {
            split = new int[leftOver];
        }
        Arrays.fill(split, numberOfWrapperPerThread);
        for (int i = 0; i < leftOver; i++) {
            split[i] += 1;
        }
        int start = 0;
        int end = 0;
        List<Future<List<ExtendedBlocklet>>> futures = new ArrayList<>();
        for (int value : split) {
            end += value;
            futures.add(executorService.submit(new ExtendedBlockletDeserializerThread(start, end, indexInputFormat.getCarbonTable().getTablePath(), indexInputFormat.getQueryId(), indexInputFormat.isCountStarJob(), indexInputFormat.getCdcVO())));
            start += value;
        }
        executorService.shutdown();
        try {
            executorService.awaitTermination(1, TimeUnit.HOURS);
        } catch (InterruptedException e) {
            LOGGER.error(e);
            throw new RuntimeException(e);
        }
        List<ExtendedBlocklet> extendedBlocklets = new ArrayList<>();
        for (int i = 0; i < futures.size(); i++) {
            try {
                extendedBlocklets.addAll(futures.get(i).get());
            } catch (InterruptedException | ExecutionException e) {
                LOGGER.error(e);
                throw new RuntimeException(e);
            }
        }
        return extendedBlocklets;
    } else {
        List<ExtendedBlocklet> extendedBlocklets = new ArrayList<>();
        for (ExtendedBlockletWrapper extendedBlockletWrapper : extendedBlockletWrappers) {
            extendedBlocklets.addAll(extendedBlockletWrapper.readBlocklet(indexInputFormat.getCarbonTable().getTablePath(), indexInputFormat.getQueryId(), indexInputFormat.isCountStarJob(), indexInputFormat.getCdcVO()));
        }
        return extendedBlocklets;
    }
}
Also used : ArrayList(java.util.ArrayList) ExecutorService(java.util.concurrent.ExecutorService) CarbonThreadFactory(org.apache.carbondata.core.util.CarbonThreadFactory) Future(java.util.concurrent.Future) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

CarbonThreadFactory (org.apache.carbondata.core.util.CarbonThreadFactory)10 Iterator (java.util.Iterator)4 Future (java.util.concurrent.Future)4 CarbonDataWriterException (org.apache.carbondata.core.datastore.exception.CarbonDataWriterException)4 CarbonDataLoadingException (org.apache.carbondata.processing.loading.exception.CarbonDataLoadingException)4 IOException (java.io.IOException)3 ExecutionException (java.util.concurrent.ExecutionException)3 ExecutorService (java.util.concurrent.ExecutorService)3 CarbonRowBatch (org.apache.carbondata.processing.loading.row.CarbonRowBatch)3 ArrayList (java.util.ArrayList)2 Semaphore (java.util.concurrent.Semaphore)2 CarbonIterator (org.apache.carbondata.common.CarbonIterator)2 CarbonRow (org.apache.carbondata.core.datastore.row.CarbonRow)2 CarbonSortKeyAndGroupByException (org.apache.carbondata.processing.sort.exception.CarbonSortKeyAndGroupByException)2 File (java.io.File)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 DeprecatedFeatureException (org.apache.carbondata.common.exceptions.DeprecatedFeatureException)1 CarbonTableIdentifier (org.apache.carbondata.core.metadata.CarbonTableIdentifier)1 DataLoadMetrics (org.apache.carbondata.core.util.DataLoadMetrics)1