use of org.apache.carbondata.core.datastore.filesystem.CarbonFile in project carbondata by apache.
the class TrashUtil method emptyTrash.
/**
* The below method deletes all the files and folders in the trash folder of a carbon table.
* Returns an array in which the first element contains the size freed in case of clean files
* operation or size that can be freed in case of dry run and the second element contains the
* remaining size.
*/
public static long[] emptyTrash(String tablePath, Boolean isDryRun, Boolean showStats) {
CarbonFile trashFolder = FileFactory.getCarbonFile(CarbonTablePath.getTrashFolderPath(tablePath));
// if the trash folder exists delete the contents of the trash folder
long sizeFreed = 0;
long[] sizeStatistics = new long[] { 0, 0 };
try {
if (trashFolder.isFileExist()) {
CarbonFile[] carbonFileList = trashFolder.listFiles();
List<CarbonFile> filesToDelete = new ArrayList<>();
for (CarbonFile carbonFile : carbonFileList) {
// true with actual operation
if (isDryRun || showStats) {
sizeFreed += FileFactory.getDirectorySize(carbonFile.getAbsolutePath());
}
filesToDelete.add(carbonFile);
}
sizeStatistics[0] = sizeFreed;
if (!isDryRun) {
for (CarbonFile carbonFile : filesToDelete) {
FileFactory.deleteAllCarbonFilesOfDir(carbonFile);
}
LOGGER.info("Trash Folder has been emptied for table: " + tablePath);
if (showStats) {
sizeStatistics[1] = FileFactory.getDirectorySize(trashFolder.getAbsolutePath());
}
} else {
sizeStatistics[1] = FileFactory.getDirectorySize(trashFolder.getAbsolutePath()) - sizeFreed;
}
}
} catch (IOException e) {
LOGGER.error("Error while emptying the trash folder", e);
}
return sizeStatistics;
}
use of org.apache.carbondata.core.datastore.filesystem.CarbonFile in project carbondata by apache.
the class TrashUtil method copyFileToTrashFolder.
/**
* The below method copies the complete a file to the trash folder.
*
* @param filePathToCopy the files which are to be moved to the trash folder
* @param trashFolderWithTimestamp timestamp, partition folder(if any) and segment number
*/
public static void copyFileToTrashFolder(String filePathToCopy, String trashFolderWithTimestamp) throws IOException {
CarbonFile carbonFileToCopy = FileFactory.getCarbonFile(filePathToCopy);
String destinationPath = trashFolderWithTimestamp + CarbonCommonConstants.FILE_SEPARATOR + carbonFileToCopy.getName();
try {
if (!FileFactory.isFileExist(destinationPath)) {
copyToTrashFolder(filePathToCopy, destinationPath);
}
} catch (IOException e) {
// in case there is any issue while copying the file to the trash folder, we need to delete
// the complete segment folder from the trash folder. The trashFolderWithTimestamp contains
// the segment folder too. Delete the folder as it is.
FileFactory.deleteFile(trashFolderWithTimestamp);
LOGGER.error("Error while checking trash folder: " + destinationPath + " or copying" + " file: " + filePathToCopy + " to the trash folder at path", e);
throw e;
}
}
use of org.apache.carbondata.core.datastore.filesystem.CarbonFile in project carbondata by apache.
the class TrashUtil method copySegmentToTrash.
/**
* The below method copies the complete segment folder to the trash folder. Here, the data files
* in segment are listed and copied one by one to the trash folder.
*
* @param segmentPath the folder which are to be moved to the trash folder
* @param trashFolderWithTimestamp trashfolderpath with complete timestamp and segment number
*/
public static void copySegmentToTrash(CarbonFile segmentPath, String trashFolderWithTimestamp) throws IOException {
try {
if (segmentPath.isFileExist()) {
if (!FileFactory.isFileExist(trashFolderWithTimestamp)) {
FileFactory.mkdirs(trashFolderWithTimestamp);
}
CarbonFile[] dataFiles = segmentPath.listFiles();
for (CarbonFile carbonFile : dataFiles) {
copyFileToTrashFolder(carbonFile.getAbsolutePath(), trashFolderWithTimestamp);
}
LOGGER.info("Segment: " + segmentPath.getAbsolutePath() + " has been copied to" + " the trash folder successfully. Total files copied: " + dataFiles.length);
} else {
LOGGER.info("Segment: " + segmentPath.getName() + " does not exist");
}
} catch (IOException e) {
LOGGER.error("Error while copying the segment: " + segmentPath.getName() + " to the trash" + " Folder: " + trashFolderWithTimestamp, e);
throw e;
}
}
use of org.apache.carbondata.core.datastore.filesystem.CarbonFile in project carbondata by apache.
the class CarbonTablePath method getCarbonIndexFilePath.
/**
* Below method will be used to get the index file present in the segment folder
* based on task id
*
* @param taskId task id of the file
* @param segmentId segment number
* @return full qualified carbon index path
*/
private static String getCarbonIndexFilePath(final String tablePath, final String taskId, final String segmentId, final String bucketNumber) {
String segmentDir = getSegmentPath(tablePath, segmentId);
CarbonFile carbonFile = FileFactory.getCarbonFile(segmentDir);
CarbonFile[] files = carbonFile.listFiles(new CarbonFileFilter() {
@Override
public boolean accept(CarbonFile file) {
if (bucketNumber.equals("-1")) {
return file.getName().startsWith(taskId) && file.getName().endsWith(INDEX_FILE_EXT);
}
return file.getName().startsWith(taskId + DASH + bucketNumber) && file.getName().endsWith(INDEX_FILE_EXT);
}
});
if (files.length > 0) {
return files[0].getAbsolutePath();
} else {
throw new RuntimeException("Missing Carbon index file for Segment[" + segmentId + "], " + "taskId[" + taskId + "]");
}
}
use of org.apache.carbondata.core.datastore.filesystem.CarbonFile in project carbondata by apache.
the class CarbonTablePath method getActualSchemaFilePath.
private static String getActualSchemaFilePath(String tablePath, Configuration hadoopConf) {
String metaPath = tablePath + CarbonCommonConstants.FILE_SEPARATOR + METADATA_DIR;
CarbonFile carbonFile;
if (hadoopConf != null) {
carbonFile = FileFactory.getCarbonFile(metaPath, hadoopConf);
} else {
carbonFile = FileFactory.getCarbonFile(metaPath);
}
CarbonFile[] schemaFile = carbonFile.listFiles(new CarbonFileFilter() {
@Override
public boolean accept(CarbonFile file) {
return file.getName().startsWith(SCHEMA_FILE);
}
});
if (schemaFile != null && schemaFile.length > 0 && FileFactory.getFileType(tablePath) != FileFactory.FileType.ALLUXIO) {
return schemaFile[0].getAbsolutePath();
} else {
return metaPath + CarbonCommonConstants.FILE_SEPARATOR + SCHEMA_FILE;
}
}
Aggregations