use of org.apache.carbondata.core.metadata.AbsoluteTableIdentifier in project carbondata by apache.
the class CarbonDataMergerUtil method identifySegmentsToBeMergedBasedOnIUD.
/**
* method to identify the segments qualified for merging in case of IUD Compaction.
*
* @param segments
* @param carbonLoadModel
* @return
*/
private static List<LoadMetadataDetails> identifySegmentsToBeMergedBasedOnIUD(List<LoadMetadataDetails> segments, CarbonLoadModel carbonLoadModel) {
List<LoadMetadataDetails> validSegments = new ArrayList<>(segments.size());
AbsoluteTableIdentifier absoluteTableIdentifier = carbonLoadModel.getCarbonDataLoadSchema().getCarbonTable().getAbsoluteTableIdentifier();
int numberUpdateDeltaFilesThreshold = CarbonProperties.getInstance().getNoUpdateDeltaFilesThresholdForIUDCompaction();
for (LoadMetadataDetails seg : segments) {
if ((isSegmentValid(seg)) && checkUpdateDeltaFilesInSeg(seg.getLoadName(), absoluteTableIdentifier, carbonLoadModel.getSegmentUpdateStatusManager(), numberUpdateDeltaFilesThreshold)) {
validSegments.add(seg);
}
}
return validSegments;
}
use of org.apache.carbondata.core.metadata.AbsoluteTableIdentifier in project carbondata by apache.
the class CarbonDataMergerUtil method updateLoadMetadataIUDUpdateDeltaMergeStatus.
/**
* Update Both Segment Update Status and Table Status for the case of IUD Delete
* delta compaction.
*
* @param loadsToMerge
* @param metaDataFilepath
* @param carbonLoadModel
* @return
*/
public static boolean updateLoadMetadataIUDUpdateDeltaMergeStatus(List<LoadMetadataDetails> loadsToMerge, String metaDataFilepath, CarbonLoadModel carbonLoadModel) {
boolean status = false;
boolean updateLockStatus = false;
boolean tableLockStatus = false;
String timestamp = "" + carbonLoadModel.getFactTimeStamp();
List<String> updatedDeltaFilesList = new ArrayList<>(CarbonCommonConstants.DEFAULT_COLLECTION_SIZE);
// This routine updateLoadMetadataIUDCompactionMergeStatus is suppose to update
// two files as it is only called during IUD_UPDDEL_DELTA_COMPACTION. Along with
// Table Status Metadata file (For Update Block Compaction) it has to update the
// Table Update Status Metadata File (For corresponding Delete Delta File).
// As the IUD_UPDDEL_DELTA_COMPACTION going to write in the same segment therefore in
// A) Table Update Status Metadata File (Block Level)
// * For each blocks which is being compacted Mark 'Compacted' as the Status.
// B) Table Status Metadata file (Segment Level)
// * loadStatus won't be changed to "compacted'
// * UpdateDeltaStartTime and UpdateDeltaEndTime will be both set to current
// timestamp (which is being passed from driver)
// First the Table Update Status Metadata File should be updated as we need to get
// the updated blocks for the segment from Table Status Metadata Update Delta Start and
// End Timestamp.
// Table Update Status Metadata Update.
AbsoluteTableIdentifier absoluteTableIdentifier = carbonLoadModel.getCarbonDataLoadSchema().getCarbonTable().getAbsoluteTableIdentifier();
CarbonTablePath carbonTablePath = CarbonStorePath.getCarbonTablePath(absoluteTableIdentifier.getStorePath(), absoluteTableIdentifier.getCarbonTableIdentifier());
SegmentUpdateStatusManager segmentUpdateStatusManager = new SegmentUpdateStatusManager(absoluteTableIdentifier);
SegmentStatusManager segmentStatusManager = new SegmentStatusManager(absoluteTableIdentifier);
ICarbonLock updateLock = segmentUpdateStatusManager.getTableUpdateStatusLock();
ICarbonLock statusLock = segmentStatusManager.getTableStatusLock();
// Update the Compacted Blocks with Compacted Status.
try {
updatedDeltaFilesList = segmentUpdateStatusManager.getUpdateDeltaFiles(loadsToMerge.get(0).getLoadName().toString());
} catch (Exception e) {
LOGGER.error("Error while getting the Update Delta Blocks.");
status = false;
return status;
}
if (updatedDeltaFilesList.size() > 0) {
try {
updateLockStatus = updateLock.lockWithRetries();
tableLockStatus = statusLock.lockWithRetries();
List<String> blockNames = new ArrayList<>(updatedDeltaFilesList.size());
for (String compactedBlocks : updatedDeltaFilesList) {
// Try to BlockName
int endIndex = compactedBlocks.lastIndexOf(File.separator);
String blkNoExt = compactedBlocks.substring(endIndex + 1, compactedBlocks.lastIndexOf("-"));
blockNames.add(blkNoExt);
}
if (updateLockStatus && tableLockStatus) {
SegmentUpdateDetails[] updateLists = segmentUpdateStatusManager.readLoadMetadata();
for (String compactedBlocks : blockNames) {
// Check is the compactedBlocks name matches with oldDetails
for (int i = 0; i < updateLists.length; i++) {
if (updateLists[i].getBlockName().equalsIgnoreCase(compactedBlocks) && !CarbonCommonConstants.COMPACTED.equalsIgnoreCase(updateLists[i].getStatus()) && !CarbonCommonConstants.MARKED_FOR_DELETE.equalsIgnoreCase(updateLists[i].getStatus())) {
updateLists[i].setStatus(CarbonCommonConstants.COMPACTED);
}
}
}
LoadMetadataDetails[] loadDetails = segmentStatusManager.readLoadMetadata(metaDataFilepath);
for (LoadMetadataDetails loadDetail : loadDetails) {
if (loadsToMerge.contains(loadDetail)) {
loadDetail.setUpdateDeltaStartTimestamp(timestamp);
loadDetail.setUpdateDeltaEndTimestamp(timestamp);
if (loadDetail.getLoadName().equalsIgnoreCase("0")) {
loadDetail.setUpdateStatusFileName(CarbonUpdateUtil.getUpdateStatusFileName(timestamp));
}
}
}
try {
segmentUpdateStatusManager.writeLoadDetailsIntoFile(Arrays.asList(updateLists), timestamp);
segmentStatusManager.writeLoadDetailsIntoFile(carbonTablePath.getTableStatusFilePath(), loadDetails);
status = true;
} catch (IOException e) {
LOGGER.error("Error while writing metadata. The metadata file path is " + carbonTablePath.getMetadataDirectoryPath());
status = false;
}
} else {
LOGGER.error("Not able to acquire the lock.");
status = false;
}
} catch (Exception e) {
LOGGER.error("Error while updating metadata. The metadata file path is " + carbonTablePath.getMetadataDirectoryPath());
status = false;
} finally {
if (updateLockStatus) {
if (updateLock.unlock()) {
LOGGER.info("Unlock the segment update lock successfully.");
} else {
LOGGER.error("Not able to unlock the segment update lock.");
}
}
if (tableLockStatus) {
if (statusLock.unlock()) {
LOGGER.info("Unlock the table status lock successfully.");
} else {
LOGGER.error("Not able to unlock the table status lock.");
}
}
}
}
return status;
}
use of org.apache.carbondata.core.metadata.AbsoluteTableIdentifier in project carbondata by apache.
the class CarbonDataMergerUtil method updateLoadMetadataWithMergeStatus.
/**
* method to update table status in case of IUD Update Delta Compaction.
* @param loadsToMerge
* @param metaDataFilepath
* @param MergedLoadName
* @param carbonLoadModel
* @param compactionType
* @return
*/
public static boolean updateLoadMetadataWithMergeStatus(List<LoadMetadataDetails> loadsToMerge, String metaDataFilepath, String MergedLoadName, CarbonLoadModel carbonLoadModel, long mergeLoadStartTime, CompactionType compactionType) {
boolean tableStatusUpdationStatus = false;
AbsoluteTableIdentifier absoluteTableIdentifier = carbonLoadModel.getCarbonDataLoadSchema().getCarbonTable().getAbsoluteTableIdentifier();
SegmentStatusManager segmentStatusManager = new SegmentStatusManager(absoluteTableIdentifier);
ICarbonLock carbonLock = segmentStatusManager.getTableStatusLock();
try {
if (carbonLock.lockWithRetries()) {
LOGGER.info("Acquired lock for the table " + carbonLoadModel.getDatabaseName() + "." + carbonLoadModel.getTableName() + " for table status updation ");
CarbonTablePath carbonTablePath = CarbonStorePath.getCarbonTablePath(absoluteTableIdentifier.getStorePath(), absoluteTableIdentifier.getCarbonTableIdentifier());
String statusFilePath = carbonTablePath.getTableStatusFilePath();
LoadMetadataDetails[] loadDetails = SegmentStatusManager.readLoadMetadata(metaDataFilepath);
String mergedLoadNumber = MergedLoadName.substring(MergedLoadName.lastIndexOf(CarbonCommonConstants.LOAD_FOLDER) + CarbonCommonConstants.LOAD_FOLDER.length(), MergedLoadName.length());
long modificationOrDeletionTimeStamp = CarbonUpdateUtil.readCurrentTime();
for (LoadMetadataDetails loadDetail : loadDetails) {
// check if this segment is merged.
if (loadsToMerge.contains(loadDetail)) {
// then need to discard the compaction process and treat it as failed compaction.
if (loadDetail.getLoadStatus().equalsIgnoreCase(CarbonCommonConstants.MARKED_FOR_DELETE)) {
LOGGER.error("Compaction is aborted as the segment " + loadDetail.getLoadName() + " is deleted after the compaction is started.");
return false;
}
loadDetail.setLoadStatus(CarbonCommonConstants.COMPACTED);
loadDetail.setModificationOrdeletionTimesStamp(modificationOrDeletionTimeStamp);
loadDetail.setMergedLoadName(mergedLoadNumber);
}
}
// create entry for merged one.
LoadMetadataDetails loadMetadataDetails = new LoadMetadataDetails();
loadMetadataDetails.setPartitionCount(carbonLoadModel.getPartitionId());
loadMetadataDetails.setLoadStatus(CarbonCommonConstants.STORE_LOADSTATUS_SUCCESS);
long loadEnddate = CarbonUpdateUtil.readCurrentTime();
loadMetadataDetails.setLoadEndTime(loadEnddate);
loadMetadataDetails.setLoadName(mergedLoadNumber);
loadMetadataDetails.setLoadStartTime(mergeLoadStartTime);
loadMetadataDetails.setPartitionCount("0");
// if this is a major compaction then set the segment as major compaction.
if (compactionType == CompactionType.MAJOR_COMPACTION) {
loadMetadataDetails.setMajorCompacted("true");
}
List<LoadMetadataDetails> updatedDetailsList = new ArrayList<>(Arrays.asList(loadDetails));
// put the merged folder entry
updatedDetailsList.add(loadMetadataDetails);
try {
SegmentStatusManager.writeLoadDetailsIntoFile(statusFilePath, updatedDetailsList.toArray(new LoadMetadataDetails[updatedDetailsList.size()]));
tableStatusUpdationStatus = true;
} catch (IOException e) {
LOGGER.error("Error while writing metadata");
tableStatusUpdationStatus = false;
}
} else {
LOGGER.error("Could not able to obtain lock for table" + carbonLoadModel.getDatabaseName() + "." + carbonLoadModel.getTableName() + "for table status updation");
}
} finally {
if (carbonLock.unlock()) {
LOGGER.info("Table unlocked successfully after table status updation" + carbonLoadModel.getDatabaseName() + "." + carbonLoadModel.getTableName());
} else {
LOGGER.error("Unable to unlock Table lock for table" + carbonLoadModel.getDatabaseName() + "." + carbonLoadModel.getTableName() + " during table status updation");
}
}
return tableStatusUpdationStatus;
}
use of org.apache.carbondata.core.metadata.AbsoluteTableIdentifier in project carbondata by apache.
the class InMemoryBTreeIndex method filter.
@Override
public List<Block> filter(JobContext job, FilterResolverIntf filter) throws IOException {
List<Block> result = new LinkedList<>();
FilterExpressionProcessor filterExpressionProcessor = new FilterExpressionProcessor();
AbsoluteTableIdentifier identifier = null;
//for this segment fetch blocks matching filter in BTree
List<DataRefNode> dataRefNodes = getDataBlocksOfSegment(job, filterExpressionProcessor, identifier, filter);
for (DataRefNode dataRefNode : dataRefNodes) {
BlockBTreeLeafNode leafNode = (BlockBTreeLeafNode) dataRefNode;
TableBlockInfo tableBlockInfo = leafNode.getTableBlockInfo();
result.add(new CarbonInputSplit(segment.getId(), new Path(tableBlockInfo.getFilePath()), tableBlockInfo.getBlockOffset(), tableBlockInfo.getBlockLength(), tableBlockInfo.getLocations(), tableBlockInfo.getBlockletInfos().getNoOfBlockLets(), tableBlockInfo.getVersion()));
}
return result;
}
use of org.apache.carbondata.core.metadata.AbsoluteTableIdentifier in project carbondata by apache.
the class CarbonLoaderUtil method recordLoadMetadata.
/**
* This API will write the load level metadata for the loadmanagement module inorder to
* manage the load and query execution management smoothly.
*
* @param loadCount
* @param loadMetadataDetails
* @param loadModel
* @param loadStatus
* @param startLoadTime
* @return boolean which determines whether status update is done or not.
* @throws IOException
*/
public static boolean recordLoadMetadata(int loadCount, LoadMetadataDetails loadMetadataDetails, CarbonLoadModel loadModel, String loadStatus, long startLoadTime) throws IOException {
boolean status = false;
String metaDataFilepath = loadModel.getCarbonDataLoadSchema().getCarbonTable().getMetaDataFilepath();
AbsoluteTableIdentifier absoluteTableIdentifier = loadModel.getCarbonDataLoadSchema().getCarbonTable().getAbsoluteTableIdentifier();
CarbonTablePath carbonTablePath = CarbonStorePath.getCarbonTablePath(absoluteTableIdentifier.getStorePath(), absoluteTableIdentifier.getCarbonTableIdentifier());
String tableStatusPath = carbonTablePath.getTableStatusFilePath();
SegmentStatusManager segmentStatusManager = new SegmentStatusManager(absoluteTableIdentifier);
ICarbonLock carbonLock = segmentStatusManager.getTableStatusLock();
try {
if (carbonLock.lockWithRetries()) {
LOGGER.info("Acquired lock for table" + loadModel.getDatabaseName() + "." + loadModel.getTableName() + " for table status updation");
LoadMetadataDetails[] listOfLoadFolderDetailsArray = SegmentStatusManager.readLoadMetadata(metaDataFilepath);
long loadEnddate = CarbonUpdateUtil.readCurrentTime();
loadMetadataDetails.setLoadEndTime(loadEnddate);
loadMetadataDetails.setLoadStatus(loadStatus);
loadMetadataDetails.setLoadName(String.valueOf(loadCount));
loadMetadataDetails.setLoadStartTime(startLoadTime);
List<LoadMetadataDetails> listOfLoadFolderDetails = new ArrayList<>(CarbonCommonConstants.DEFAULT_COLLECTION_SIZE);
if (null != listOfLoadFolderDetailsArray) {
Collections.addAll(listOfLoadFolderDetails, listOfLoadFolderDetailsArray);
}
listOfLoadFolderDetails.add(loadMetadataDetails);
SegmentStatusManager.writeLoadDetailsIntoFile(tableStatusPath, listOfLoadFolderDetails.toArray(new LoadMetadataDetails[listOfLoadFolderDetails.size()]));
status = true;
} else {
LOGGER.error("Not able to acquire the lock for Table status updation for table " + loadModel.getDatabaseName() + "." + loadModel.getTableName());
}
} finally {
if (carbonLock.unlock()) {
LOGGER.info("Table unlocked successfully after table status updation" + loadModel.getDatabaseName() + "." + loadModel.getTableName());
} else {
LOGGER.error("Unable to unlock Table lock for table" + loadModel.getDatabaseName() + "." + loadModel.getTableName() + " during table status updation");
}
}
return status;
}
Aggregations