Search in sources :

Example 11 with CarbonFile

use of org.apache.carbondata.core.datastore.filesystem.CarbonFile in project carbondata by apache.

the class CarbonLoaderUtil method isValidSegment.

/**
   * the method returns true if the segment has carbondata file else returns false.
   *
   * @param loadModel
   * @param currentLoad
   * @return
   */
public static boolean isValidSegment(CarbonLoadModel loadModel, int currentLoad) {
    CarbonTable carbonTable = loadModel.getCarbonDataLoadSchema().getCarbonTable();
    CarbonTablePath carbonTablePath = CarbonStorePath.getCarbonTablePath(loadModel.getStorePath(), carbonTable.getCarbonTableIdentifier());
    int fileCount = 0;
    int partitionCount = carbonTable.getPartitionCount();
    for (int i = 0; i < partitionCount; i++) {
        String segmentPath = carbonTablePath.getCarbonDataDirectoryPath(i + "", currentLoad + "");
        CarbonFile carbonFile = FileFactory.getCarbonFile(segmentPath, FileFactory.getFileType(segmentPath));
        CarbonFile[] files = carbonFile.listFiles(new CarbonFileFilter() {

            @Override
            public boolean accept(CarbonFile file) {
                return file.getName().endsWith(CarbonTablePath.getCarbonIndexExtension()) || file.getName().endsWith(CarbonTablePath.getCarbonDataExtension());
            }
        });
        fileCount += files.length;
        if (files.length > 0) {
            return true;
        }
    }
    if (fileCount == 0) {
        return false;
    }
    return true;
}
Also used : CarbonTable(org.apache.carbondata.core.metadata.schema.table.CarbonTable) CarbonFile(org.apache.carbondata.core.datastore.filesystem.CarbonFile) CarbonFileFilter(org.apache.carbondata.core.datastore.filesystem.CarbonFileFilter) CarbonTablePath(org.apache.carbondata.core.util.path.CarbonTablePath)

Example 12 with CarbonFile

use of org.apache.carbondata.core.datastore.filesystem.CarbonFile in project carbondata by apache.

the class CarbonLoaderUtil method deleteStorePath.

private static void deleteStorePath(String path) {
    try {
        FileType fileType = FileFactory.getFileType(path);
        if (FileFactory.isFileExist(path, fileType)) {
            CarbonFile carbonFile = FileFactory.getCarbonFile(path, fileType);
            CarbonUtil.deleteFoldersAndFiles(carbonFile);
        }
    } catch (IOException | InterruptedException e) {
        LOGGER.error("Unable to delete the given path :: " + e.getMessage());
    }
}
Also used : CarbonFile(org.apache.carbondata.core.datastore.filesystem.CarbonFile) FileType(org.apache.carbondata.core.datastore.impl.FileFactory.FileType) IOException(java.io.IOException)

Example 13 with CarbonFile

use of org.apache.carbondata.core.datastore.filesystem.CarbonFile in project carbondata by apache.

the class CarbonDataMergerUtil method checkUpdateDeltaFilesInSeg.

/**
   * This method traverses Update Delta Files inside the seg and return true
   * if UpdateDelta Files are more than IUD Compaction threshold.
   *
   * @param seg
   * @param absoluteTableIdentifier
   * @param segmentUpdateStatusManager
   * @param numberDeltaFilesThreshold
   * @return
   */
public static Boolean checkUpdateDeltaFilesInSeg(String seg, AbsoluteTableIdentifier absoluteTableIdentifier, SegmentUpdateStatusManager segmentUpdateStatusManager, int numberDeltaFilesThreshold) {
    CarbonFile[] updateDeltaFiles = null;
    Set<String> uniqueBlocks = new HashSet<String>();
    CarbonTablePath carbonTablePath = CarbonStorePath.getCarbonTablePath(absoluteTableIdentifier.getStorePath(), absoluteTableIdentifier.getCarbonTableIdentifier());
    String segmentPath = carbonTablePath.getCarbonDataDirectoryPath("0", seg);
    CarbonFile segDir = FileFactory.getCarbonFile(segmentPath, FileFactory.getFileType(segmentPath));
    CarbonFile[] allSegmentFiles = segDir.listFiles();
    updateDeltaFiles = segmentUpdateStatusManager.getUpdateDeltaFilesForSegment(seg, true, CarbonCommonConstants.UPDATE_DELTA_FILE_EXT, false, allSegmentFiles);
    if (updateDeltaFiles == null) {
        return false;
    }
    // Spill Over Blocks will choose files with unique taskID.
    for (CarbonFile blocks : updateDeltaFiles) {
        // Get Task ID and the Timestamp from the Block name for e.g.
        // part-0-3-1481084721319.carbondata => "3-1481084721319"
        String task = CarbonTablePath.DataFileUtil.getTaskNo(blocks.getName());
        String timestamp = CarbonTablePath.DataFileUtil.getTimeStampFromDeleteDeltaFile(blocks.getName());
        String taskAndTimeStamp = task + "-" + timestamp;
        uniqueBlocks.add(taskAndTimeStamp);
    }
    if (uniqueBlocks.size() > numberDeltaFilesThreshold) {
        return true;
    } else {
        return false;
    }
}
Also used : CarbonFile(org.apache.carbondata.core.datastore.filesystem.CarbonFile) CarbonTablePath(org.apache.carbondata.core.util.path.CarbonTablePath) HashSet(java.util.HashSet)

Example 14 with CarbonFile

use of org.apache.carbondata.core.datastore.filesystem.CarbonFile in project carbondata by apache.

the class CarbonDataMergerUtil method getSizeOfSegment.

/**
   * For calculating the size of the specified segment
   * @param storeLocation
   * @param tableIdentifier
   * @param segId
   * @return
   */
private static long getSizeOfSegment(String storeLocation, CarbonTableIdentifier tableIdentifier, String segId) {
    String loadPath = getStoreLocation(storeLocation, tableIdentifier, segId);
    CarbonFile segmentFolder = FileFactory.getCarbonFile(loadPath, FileFactory.getFileType(loadPath));
    return getSizeOfFactFileInLoad(segmentFolder);
}
Also used : CarbonFile(org.apache.carbondata.core.datastore.filesystem.CarbonFile)

Example 15 with CarbonFile

use of org.apache.carbondata.core.datastore.filesystem.CarbonFile in project carbondata by apache.

the class CarbonUpdateUtil method getLatestTaskIdForSegment.

public static long getLatestTaskIdForSegment(String segmentId, String tablePath) {
    String segmentDirPath = CarbonTablePath.getSegmentPath(tablePath, segmentId);
    // scan all the carbondata files and get the latest task ID.
    CarbonFile segment = FileFactory.getCarbonFile(segmentDirPath, FileFactory.getFileType(segmentDirPath));
    CarbonFile[] dataFiles = segment.listFiles(new CarbonFileFilter() {

        @Override
        public boolean accept(CarbonFile file) {
            if (file.getName().endsWith(CarbonCommonConstants.FACT_FILE_EXT)) {
                return true;
            }
            return false;
        }
    });
    long max = 0;
    if (null != dataFiles) {
        for (CarbonFile file : dataFiles) {
            long taskNumber = Long.parseLong(CarbonTablePath.DataFileUtil.getTaskNo(file.getName()).split("_")[0]);
            if (taskNumber > max) {
                max = taskNumber;
            }
        }
    }
    // return max task No
    return max;
}
Also used : CarbonFile(org.apache.carbondata.core.datastore.filesystem.CarbonFile) CarbonFileFilter(org.apache.carbondata.core.datastore.filesystem.CarbonFileFilter)

Aggregations

CarbonFile (org.apache.carbondata.core.datastore.filesystem.CarbonFile)91 CarbonFileFilter (org.apache.carbondata.core.datastore.filesystem.CarbonFileFilter)32 IOException (java.io.IOException)24 FileFactory (org.apache.carbondata.core.datastore.impl.FileFactory)17 ArrayList (java.util.ArrayList)14 CarbonTablePath (org.apache.carbondata.core.util.path.CarbonTablePath)11 HashMap (java.util.HashMap)7 Path (org.apache.hadoop.fs.Path)7 LoadMetadataDetails (org.apache.carbondata.core.statusmanager.LoadMetadataDetails)6 Map (java.util.Map)5 Segment (org.apache.carbondata.core.datamap.Segment)5 FileType (org.apache.carbondata.core.datastore.impl.FileFactory.FileType)5 BlockIndex (org.apache.carbondata.format.BlockIndex)5 HashSet (java.util.HashSet)4 CarbonIndexFileReader (org.apache.carbondata.core.reader.CarbonIndexFileReader)4 SegmentIndexFileStore (org.apache.carbondata.core.indexstore.blockletindex.SegmentIndexFileStore)3 AbsoluteTableIdentifier (org.apache.carbondata.core.metadata.AbsoluteTableIdentifier)3 SegmentFileStore (org.apache.carbondata.core.metadata.SegmentFileStore)3 SegmentUpdateDetails (org.apache.carbondata.core.mutate.SegmentUpdateDetails)3 SegmentUpdateStatusManager (org.apache.carbondata.core.statusmanager.SegmentUpdateStatusManager)3