Search in sources :

Example 16 with CarbonFileFilter

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

the class DeleteLoadFolders method physicalFactAndMeasureMetadataDeletion.

private static boolean physicalFactAndMeasureMetadataDeletion(String path) {
    boolean status = false;
    try {
        if (FileFactory.isFileExist(path, FileFactory.getFileType(path))) {
            CarbonFile file = FileFactory.getCarbonFile(path, FileFactory.getFileType(path));
            CarbonFile[] filesToBeDeleted = file.listFiles(new CarbonFileFilter() {

                @Override
                public boolean accept(CarbonFile file) {
                    return (CarbonTablePath.isCarbonDataFile(file.getName()) || CarbonTablePath.isCarbonIndexFile(file.getName()));
                }
            });
            //entry in metadata.
            if (filesToBeDeleted.length == 0) {
                status = true;
            } else {
                for (CarbonFile eachFile : filesToBeDeleted) {
                    if (!eachFile.delete()) {
                        LOGGER.warn("Unable to delete the file as per delete command " + eachFile.getAbsolutePath());
                        status = false;
                    } else {
                        status = true;
                    }
                }
            }
            // need to delete the complete folder.
            if (status) {
                if (!file.delete()) {
                    LOGGER.warn("Unable to delete the folder as per delete command " + file.getAbsolutePath());
                    status = false;
                }
            }
        } else {
            status = false;
        }
    } catch (IOException e) {
        LOGGER.warn("Unable to delete the file as per delete command " + path);
    }
    return status;
}
Also used : CarbonFile(org.apache.carbondata.core.datastore.filesystem.CarbonFile) CarbonFileFilter(org.apache.carbondata.core.datastore.filesystem.CarbonFileFilter) IOException(java.io.IOException)

Example 17 with CarbonFileFilter

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

the class CarbonDataProcessorUtil method renameBadRecordsFromInProgressToNormal.

/**
   * @param storeLocation
   */
public static void renameBadRecordsFromInProgressToNormal(String storeLocation) {
    // get the base store location
    String badLogStoreLocation = CarbonProperties.getInstance().getProperty(CarbonCommonConstants.CARBON_BADRECORDS_LOC);
    badLogStoreLocation = badLogStoreLocation + File.separator + storeLocation;
    FileType fileType = FileFactory.getFileType(badLogStoreLocation);
    try {
        if (!FileFactory.isFileExist(badLogStoreLocation, fileType)) {
            return;
        }
    } catch (IOException e1) {
        LOGGER.info("bad record folder does not exist");
    }
    CarbonFile carbonFile = FileFactory.getCarbonFile(badLogStoreLocation, fileType);
    CarbonFile[] listFiles = carbonFile.listFiles(new CarbonFileFilter() {

        @Override
        public boolean accept(CarbonFile pathname) {
            if (pathname.getName().indexOf(CarbonCommonConstants.FILE_INPROGRESS_STATUS) > -1) {
                return true;
            }
            return false;
        }
    });
    String badRecordsInProgressFileName = null;
    String changedFileName = null;
    for (CarbonFile badFiles : listFiles) {
        badRecordsInProgressFileName = badFiles.getName();
        changedFileName = badLogStoreLocation + File.separator + badRecordsInProgressFileName.substring(0, badRecordsInProgressFileName.lastIndexOf('.'));
        badFiles.renameTo(changedFileName);
        if (badFiles.exists()) {
            if (!badFiles.delete()) {
                LOGGER.error("Unable to delete File : " + badFiles.getName());
            }
        }
    }
}
Also used : CarbonFile(org.apache.carbondata.core.datastore.filesystem.CarbonFile) CarbonFileFilter(org.apache.carbondata.core.datastore.filesystem.CarbonFileFilter) FileType(org.apache.carbondata.core.datastore.impl.FileFactory.FileType) IOException(java.io.IOException)

Aggregations

CarbonFile (org.apache.carbondata.core.datastore.filesystem.CarbonFile)17 CarbonFileFilter (org.apache.carbondata.core.datastore.filesystem.CarbonFileFilter)17 CarbonTablePath (org.apache.carbondata.core.util.path.CarbonTablePath)7 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)2 FileType (org.apache.carbondata.core.datastore.impl.FileFactory.FileType)2 CarbonTable (org.apache.carbondata.core.metadata.schema.table.CarbonTable)2 LoadMetadataDetails (org.apache.carbondata.core.statusmanager.LoadMetadataDetails)2 CarbonTableIdentifier (org.apache.carbondata.core.carbon.CarbonTableIdentifier)1 FileHolder (org.apache.carbondata.core.datastorage.store.FileHolder)1 AbsoluteTableIdentifier (org.apache.carbondata.core.metadata.AbsoluteTableIdentifier)1 SegmentUpdateDetails (org.apache.carbondata.core.mutate.SegmentUpdateDetails)1 CarbonFooterReader (org.apache.carbondata.core.reader.CarbonFooterReader)1 SegmentStatusManager (org.apache.carbondata.core.statusmanager.SegmentStatusManager)1 SegmentUpdateStatusManager (org.apache.carbondata.core.statusmanager.SegmentUpdateStatusManager)1 Before (org.junit.Before)1