Search in sources :

Example 96 with CarbonFile

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

the class CarbonDataMergerUtil method compactBlockDeleteDeltaFiles.

/**
   * method to compact Delete Delta files in case of IUD Compaction.
   *
   * @param seg
   * @param blockName
   * @param absoluteTableIdentifier
   * @param segmentUpdateDetails
   * @param timestamp
   * @return
   * @throws IOException
   */
public static List<CarbonDataMergerUtilResult> compactBlockDeleteDeltaFiles(String seg, String blockName, AbsoluteTableIdentifier absoluteTableIdentifier, SegmentUpdateDetails[] segmentUpdateDetails, Long timestamp) throws IOException {
    SegmentUpdateStatusManager segmentUpdateStatusManager = new SegmentUpdateStatusManager(absoluteTableIdentifier);
    List<CarbonDataMergerUtilResult> resultList = new ArrayList<CarbonDataMergerUtilResult>(1);
    // set the update status.
    segmentUpdateStatusManager.setUpdateStatusDetails(segmentUpdateDetails);
    CarbonFile[] deleteDeltaFiles = segmentUpdateStatusManager.getDeleteDeltaFilesList(seg, blockName);
    String destFileName = blockName + "-" + timestamp.toString() + CarbonCommonConstants.DELETE_DELTA_FILE_EXT;
    String fullBlockFilePath = deleteDeltaFiles[0].getParentFile().getCanonicalPath() + CarbonCommonConstants.FILE_SEPARATOR + destFileName;
    List<String> deleteFilePathList = new ArrayList<String>();
    for (CarbonFile cFile : deleteDeltaFiles) {
        deleteFilePathList.add(cFile.getCanonicalPath());
    }
    CarbonDataMergerUtilResult blockDetails = new CarbonDataMergerUtilResult();
    blockDetails.setBlockName(blockName);
    blockDetails.setSegmentName(seg);
    blockDetails.setDeleteDeltaStartTimestamp(timestamp.toString());
    blockDetails.setDeleteDeltaEndTimestamp(timestamp.toString());
    try {
        if (startCompactionDeleteDeltaFiles(deleteFilePathList, blockName, fullBlockFilePath)) {
            blockDetails.setCompactionStatus(true);
        } else {
            blockDetails.setCompactionStatus(false);
        }
        resultList.add(blockDetails);
    } catch (IOException e) {
        LOGGER.error("Compaction of Delete Delta Files failed. The complete file path is " + fullBlockFilePath);
        throw new IOException();
    }
    return resultList;
}
Also used : SegmentUpdateStatusManager(org.apache.carbondata.core.statusmanager.SegmentUpdateStatusManager) CarbonFile(org.apache.carbondata.core.datastore.filesystem.CarbonFile) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Example 97 with CarbonFile

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

the class HdfsFileLock method unlock.

/* (non-Javadoc)
   * @see org.apache.carbondata.core.locks.ICarbonLock#unlock()
   */
@Override
public boolean unlock() {
    boolean status = false;
    if (null != dataOutputStream) {
        try {
            dataOutputStream.close();
            status = true;
        } catch (IOException e) {
            status = false;
        } finally {
            CarbonFile carbonFile = FileFactory.getCarbonFile(location, FileFactory.getFileType(location));
            if (carbonFile.exists()) {
                if (carbonFile.delete()) {
                    LOGGER.info("Deleted the lock file " + location);
                } else {
                    LOGGER.error("Not able to delete the lock file " + location);
                    status = false;
                }
            } else {
                LOGGER.error("Not able to delete the lock file because " + "it is not existed in location " + location);
                status = false;
            }
        }
    }
    return status;
}
Also used : CarbonFile(org.apache.carbondata.core.datastore.filesystem.CarbonFile) IOException(java.io.IOException)

Example 98 with CarbonFile

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

the class LocalFileLock method unlock.

/**
   * Unlock API for unlocking of the acquired lock.
   *
   * @return
   */
@Override
public boolean unlock() {
    boolean status;
    try {
        if (null != fileLock) {
            fileLock.release();
        }
        status = true;
    } catch (IOException e) {
        status = false;
    } finally {
        if (null != fileOutputStream) {
            try {
                fileOutputStream.close();
                // deleting the lock file after releasing the lock.
                CarbonFile lockFile = FileFactory.getCarbonFile(lockFilePath, FileFactory.getFileType(lockFilePath));
                if (!lockFile.exists() || lockFile.delete()) {
                    LOGGER.info("Successfully deleted the lock file " + lockFilePath);
                } else {
                    LOGGER.error("Not able to delete the lock file " + lockFilePath);
                    status = false;
                }
            } catch (IOException e) {
                LOGGER.error(e.getMessage());
            }
        }
    }
    return status;
}
Also used : CarbonFile(org.apache.carbondata.core.datastore.filesystem.CarbonFile) IOException(java.io.IOException)

Example 99 with CarbonFile

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

the class CarbonFooterWriterTest method deleteFile.

/**
   * this method will delete file
   */
private void deleteFile() {
    FileFactory.FileType fileType = FileFactory.getFileType(this.filePath);
    CarbonFile carbonFile = FileFactory.getCarbonFile(this.filePath, fileType);
    carbonFile.delete();
}
Also used : CarbonFile(org.apache.carbondata.core.datastore.filesystem.CarbonFile) FileFactory(org.apache.carbondata.core.datastore.impl.FileFactory)

Example 100 with CarbonFile

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

the class CarbonUtil method getFileSize.

/**
 * This method will return the size of a given file
 */
public static long getFileSize(String filePath) {
    FileFactory.FileType fileType = FileFactory.getFileType(filePath);
    CarbonFile carbonFile = FileFactory.getCarbonFile(filePath, fileType);
    return carbonFile.getSize();
}
Also used : CarbonFile(org.apache.carbondata.core.datastore.filesystem.CarbonFile) FileFactory(org.apache.carbondata.core.datastore.impl.FileFactory)

Aggregations

CarbonFile (org.apache.carbondata.core.datastore.filesystem.CarbonFile)161 IOException (java.io.IOException)47 CarbonFileFilter (org.apache.carbondata.core.datastore.filesystem.CarbonFileFilter)45 ArrayList (java.util.ArrayList)38 HashMap (java.util.HashMap)20 FileFactory (org.apache.carbondata.core.datastore.impl.FileFactory)18 CarbonTablePath (org.apache.carbondata.core.util.path.CarbonTablePath)18 Path (org.apache.hadoop.fs.Path)15 List (java.util.List)11 CarbonTable (org.apache.carbondata.core.metadata.schema.table.CarbonTable)11 Map (java.util.Map)10 HashSet (java.util.HashSet)9 LoadMetadataDetails (org.apache.carbondata.core.statusmanager.LoadMetadataDetails)9 LinkedList (java.util.LinkedList)6 BlockIndex (org.apache.carbondata.format.BlockIndex)6 Segment (org.apache.carbondata.core.index.Segment)5 CarbonIndexFileReader (org.apache.carbondata.core.reader.CarbonIndexFileReader)5 Configuration (org.apache.hadoop.conf.Configuration)5 FileSystem (org.apache.hadoop.fs.FileSystem)5 Test (org.junit.Test)5