Search in sources :

Example 21 with CarbonDataWriterException

use of org.apache.carbondata.core.datastore.exception.CarbonDataWriterException in project carbondata by apache.

the class SingleThreadFinalSortFilesMerger method startSorting.

/**
 * Below method will be used to start storing process This method will get
 * all the temp files present in sort temp folder then it will create the
 * record holder heap and then it will read first record from each file and
 * initialize the heap
 *
 * @throws CarbonSortKeyAndGroupByException
 */
private void startSorting(List<File> files) throws CarbonDataWriterException {
    if (files.size() == 0) {
        LOGGER.info("No files to merge sort");
        return;
    }
    LOGGER.info("Started Final Merge");
    LOGGER.info("Number of temp file: " + files.size());
    // create record holder heap
    createRecordHolderQueue(files.size());
    // iterate over file list and create chunk holder and add to heap
    LOGGER.info("Started adding first record from each file");
    this.executorService = Executors.newFixedThreadPool(maxThreadForSorting);
    for (final File tempFile : files) {
        Callable<Void> callable = new Callable<Void>() {

            @Override
            public Void call() {
                // create chunk holder
                SortTempFileChunkHolder sortTempFileChunkHolder = new SortTempFileChunkHolder(tempFile, sortParameters, tableName, true);
                try {
                    // initialize
                    sortTempFileChunkHolder.initialize();
                    sortTempFileChunkHolder.readRow();
                } catch (CarbonSortKeyAndGroupByException ex) {
                    sortTempFileChunkHolder.closeStream();
                    notifyFailure(ex);
                }
                synchronized (LOCKOBJECT) {
                    recordHolderHeapLocal.add(sortTempFileChunkHolder);
                }
                return null;
            }
        };
        mergerTask.add(executorService.submit(callable));
    }
    executorService.shutdown();
    try {
        executorService.awaitTermination(2, TimeUnit.HOURS);
    } catch (Exception e) {
        throw new CarbonDataWriterException(e);
    }
    checkFailure();
    LOGGER.info("final merger Heap Size" + this.recordHolderHeapLocal.size());
}
Also used : CarbonSortKeyAndGroupByException(org.apache.carbondata.processing.sort.exception.CarbonSortKeyAndGroupByException) File(java.io.File) CarbonDataWriterException(org.apache.carbondata.core.datastore.exception.CarbonDataWriterException) Callable(java.util.concurrent.Callable) CarbonSortKeyAndGroupByException(org.apache.carbondata.processing.sort.exception.CarbonSortKeyAndGroupByException) CarbonDataWriterException(org.apache.carbondata.core.datastore.exception.CarbonDataWriterException) NoSuchElementException(java.util.NoSuchElementException) ExecutionException(java.util.concurrent.ExecutionException)

Example 22 with CarbonDataWriterException

use of org.apache.carbondata.core.datastore.exception.CarbonDataWriterException in project carbondata by apache.

the class SecondaryIndexQueryResultProcessor method initDataHandler.

/**
 * initialise carbon data writer instance
 */
private void initDataHandler() throws SecondaryIndexException {
    String carbonStoreLocation = CarbonDataProcessorUtil.createCarbonStoreLocation(this.indexTable, segmentId);
    CarbonFactDataHandlerModel carbonFactDataHandlerModel = CarbonFactDataHandlerModel.getCarbonFactDataHandlerModel(carbonLoadModel, indexTable, segmentProperties, indexTable.getTableName(), tempStoreLocation, carbonStoreLocation);
    carbonFactDataHandlerModel.setSchemaUpdatedTimeStamp(indexTable.getTableLastUpdatedTime());
    CarbonDataFileAttributes carbonDataFileAttributes = new CarbonDataFileAttributes(Integer.parseInt(carbonLoadModel.getTaskNo()), carbonLoadModel.getFactTimeStamp());
    carbonFactDataHandlerModel.setCarbonDataFileAttributes(carbonDataFileAttributes);
    dataHandler = CarbonFactHandlerFactory.createCarbonFactHandler(carbonFactDataHandlerModel);
    try {
        dataHandler.initialise();
    } catch (CarbonDataWriterException e) {
        this.sortDataRows.close();
        LOGGER.error(e);
        throw new SecondaryIndexException("Problem initialising data handler while creating secondary index: " + e.getMessage());
    }
}
Also used : CarbonDataFileAttributes(org.apache.carbondata.processing.store.CarbonDataFileAttributes) CarbonFactDataHandlerModel(org.apache.carbondata.processing.store.CarbonFactDataHandlerModel) SecondaryIndexException(org.apache.spark.sql.secondaryindex.exception.SecondaryIndexException) CarbonDataWriterException(org.apache.carbondata.core.datastore.exception.CarbonDataWriterException)

Example 23 with CarbonDataWriterException

use of org.apache.carbondata.core.datastore.exception.CarbonDataWriterException in project carbondata by apache.

the class CarbonUtil method completeRemainingHdfsReplicas.

/**
 * This method will complete the remaining hdfs replications
 *
 * @param fileName hdfs file name
 * @param fileType filetype
 * @throws CarbonDataWriterException if error occurs
 */
public static void completeRemainingHdfsReplicas(String fileName, FileFactory.FileType fileType) throws CarbonDataWriterException {
    try {
        long startTime = System.currentTimeMillis();
        short replication = FileFactory.getDefaultReplication(fileName, fileType);
        if (1 == replication) {
            return;
        }
        boolean replicateFlag = FileFactory.setReplication(fileName, fileType, replication);
        if (!replicateFlag) {
            LOGGER.error("Failed to set replication for " + fileName + " with factor " + replication);
        }
        LOGGER.info("Total copy time (ms) to copy file " + fileName + " is " + (System.currentTimeMillis() - startTime));
    } catch (IOException e) {
        throw new CarbonDataWriterException("Problem while completing remaining HDFS backups", e);
    }
}
Also used : CarbonDataWriterException(org.apache.carbondata.core.datastore.exception.CarbonDataWriterException)

Example 24 with CarbonDataWriterException

use of org.apache.carbondata.core.datastore.exception.CarbonDataWriterException in project carbondata by apache.

the class CompactionResultSortProcessor method readAndLoadDataFromSortTempFiles.

/**
 * This method will read sort temp files, perform merge sort and add it to store for data loading
 */
private void readAndLoadDataFromSortTempFiles() throws Exception {
    try {
        intermediateFileMerger.finish();
        finalMerger.startFinalMerge();
        while (finalMerger.hasNext()) {
            Object[] row = finalMerger.next();
            dataHandler.addDataToStore(new CarbonRow(row));
        }
        dataHandler.finish();
    } catch (CarbonDataWriterException e) {
        LOGGER.error(e);
        throw new Exception("Problem loading data during compaction.", e);
    } catch (Exception e) {
        LOGGER.error(e);
        throw new Exception("Problem loading data during compaction.", e);
    } finally {
        if (null != dataHandler) {
            try {
                dataHandler.closeHandler();
            } catch (CarbonDataWriterException e) {
                LOGGER.error(e, "Error in close data handler");
                throw new Exception("Error in close data handler", e);
            }
        }
    }
}
Also used : CarbonRow(org.apache.carbondata.core.datastore.row.CarbonRow) CarbonDataWriterException(org.apache.carbondata.core.datastore.exception.CarbonDataWriterException) CarbonSortKeyAndGroupByException(org.apache.carbondata.processing.sort.exception.CarbonSortKeyAndGroupByException) CarbonDataWriterException(org.apache.carbondata.core.datastore.exception.CarbonDataWriterException) IOException(java.io.IOException)

Example 25 with CarbonDataWriterException

use of org.apache.carbondata.core.datastore.exception.CarbonDataWriterException in project carbondata by apache.

the class CompactionResultSortProcessor method initDataHandler.

/**
 * initialise carbon data writer instance
 */
private void initDataHandler() throws Exception {
    String carbonStoreLocation;
    if (partitionSpec != null) {
        carbonStoreLocation = partitionSpec.getLocation().toString() + CarbonCommonConstants.FILE_SEPARATOR + carbonLoadModel.getFactTimeStamp() + ".tmp";
    } else {
        carbonStoreLocation = CarbonDataProcessorUtil.createCarbonStoreLocation(carbonLoadModel.getCarbonDataLoadSchema().getCarbonTable(), carbonLoadModel.getSegmentId());
    }
    CarbonFactDataHandlerModel carbonFactDataHandlerModel = CarbonFactDataHandlerModel.getCarbonFactDataHandlerModel(carbonLoadModel, carbonTable, segmentProperties, tableName, tempStoreLocation, carbonStoreLocation);
    carbonFactDataHandlerModel.setSegmentId(carbonLoadModel.getSegmentId());
    carbonFactDataHandlerModel.setBucketId(carbonLoadModel.getBucketId());
    setDataFileAttributesInModel(carbonLoadModel, compactionType, carbonFactDataHandlerModel);
    this.noDicAndComplexColumns = carbonFactDataHandlerModel.getNoDictAndComplexColumns();
    dataHandler = CarbonFactHandlerFactory.createCarbonFactHandler(carbonFactDataHandlerModel);
    try {
        dataHandler.initialise();
    } catch (CarbonDataWriterException e) {
        LOGGER.error(e.getMessage(), e);
        throw new Exception("Problem initialising data handler during compaction: " + e.getMessage(), e);
    }
}
Also used : CarbonFactDataHandlerModel(org.apache.carbondata.processing.store.CarbonFactDataHandlerModel) CarbonDataWriterException(org.apache.carbondata.core.datastore.exception.CarbonDataWriterException) CarbonSortKeyAndGroupByException(org.apache.carbondata.processing.sort.exception.CarbonSortKeyAndGroupByException) CarbonDataWriterException(org.apache.carbondata.core.datastore.exception.CarbonDataWriterException) IOException(java.io.IOException)

Aggregations

CarbonDataWriterException (org.apache.carbondata.core.datastore.exception.CarbonDataWriterException)33 IOException (java.io.IOException)17 CarbonSortKeyAndGroupByException (org.apache.carbondata.processing.sort.exception.CarbonSortKeyAndGroupByException)9 CarbonDataLoadingException (org.apache.carbondata.processing.loading.exception.CarbonDataLoadingException)6 ArrayList (java.util.ArrayList)5 Iterator (java.util.Iterator)5 CarbonRow (org.apache.carbondata.core.datastore.row.CarbonRow)5 ByteBuffer (java.nio.ByteBuffer)4 CarbonThreadFactory (org.apache.carbondata.core.util.CarbonThreadFactory)4 HashMap (java.util.HashMap)3 NoSuchElementException (java.util.NoSuchElementException)3 ExecutionException (java.util.concurrent.ExecutionException)3 CarbonIterator (org.apache.carbondata.common.CarbonIterator)3 CarbonFile (org.apache.carbondata.core.datastore.filesystem.CarbonFile)3 GenericDataType (org.apache.carbondata.processing.datatypes.GenericDataType)3 CarbonRowBatch (org.apache.carbondata.processing.loading.row.CarbonRowBatch)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 DataOutputStream (java.io.DataOutputStream)2 File (java.io.File)2 Future (java.util.concurrent.Future)2