use of org.apache.carbondata.core.datastore.block.SegmentTaskIndexWrapper in project carbondata by apache.
the class SegmentTaskIndexStore method loadAndGetTaskIdToSegmentsMap.
/**
* Below method will be used to load the segment of segments
* One segment may have multiple task , so table segment will be loaded
* based on task id and will return the map of taksId to table segment
* map
*
* @param segmentToTableBlocksInfos segment id to block info
* @param absoluteTableIdentifier absolute table identifier
* @return map of taks id to segment mapping
* @throws IOException
*/
private SegmentTaskIndexWrapper loadAndGetTaskIdToSegmentsMap(Map<String, List<TableBlockInfo>> segmentToTableBlocksInfos, AbsoluteTableIdentifier absoluteTableIdentifier, TableSegmentUniqueIdentifier tableSegmentUniqueIdentifier) throws IOException {
// task id to segment map
Iterator<Map.Entry<String, List<TableBlockInfo>>> iteratorOverSegmentBlocksInfos = segmentToTableBlocksInfos.entrySet().iterator();
Map<TaskBucketHolder, AbstractIndex> taskIdToSegmentIndexMap = null;
SegmentTaskIndexWrapper segmentTaskIndexWrapper = null;
SegmentUpdateStatusManager updateStatusManager = new SegmentUpdateStatusManager(absoluteTableIdentifier);
String segmentId = null;
TaskBucketHolder taskBucketHolder = null;
try {
while (iteratorOverSegmentBlocksInfos.hasNext()) {
// segment id to table block mapping
Map.Entry<String, List<TableBlockInfo>> next = iteratorOverSegmentBlocksInfos.next();
// group task id to table block info mapping for the segment
Map<TaskBucketHolder, List<TableBlockInfo>> taskIdToTableBlockInfoMap = mappedAndGetTaskIdToTableBlockInfo(segmentToTableBlocksInfos);
segmentId = next.getKey();
// get the existing map of task id to table segment map
UpdateVO updateVO = updateStatusManager.getInvalidTimestampRange(segmentId);
// check if segment is already loaded, if segment is already loaded
//no need to load the segment block
String lruCacheKey = tableSegmentUniqueIdentifier.getUniqueTableSegmentIdentifier();
segmentTaskIndexWrapper = (SegmentTaskIndexWrapper) lruCache.get(lruCacheKey);
if (segmentTaskIndexWrapper == null || tableSegmentUniqueIdentifier.isSegmentUpdated()) {
// get the segment loader lock object this is to avoid
// same segment is getting loaded multiple times
// in case of concurrent query
Object segmentLoderLockObject = segmentLockMap.get(lruCacheKey);
if (null == segmentLoderLockObject) {
segmentLoderLockObject = addAndGetSegmentLock(lruCacheKey);
}
// acquire lock to lod the segment
synchronized (segmentLoderLockObject) {
segmentTaskIndexWrapper = (SegmentTaskIndexWrapper) lruCache.get(lruCacheKey);
if (null == segmentTaskIndexWrapper || tableSegmentUniqueIdentifier.isSegmentUpdated()) {
// so that the same can be updated after loading the btree.
if (tableSegmentUniqueIdentifier.isSegmentUpdated() && null != segmentTaskIndexWrapper) {
taskIdToSegmentIndexMap = segmentTaskIndexWrapper.getTaskIdToTableSegmentMap();
} else {
// creating a map of take if to table segment
taskIdToSegmentIndexMap = new HashMap<TaskBucketHolder, AbstractIndex>();
segmentTaskIndexWrapper = new SegmentTaskIndexWrapper(taskIdToSegmentIndexMap);
segmentTaskIndexWrapper.incrementAccessCount();
}
Iterator<Map.Entry<TaskBucketHolder, List<TableBlockInfo>>> iterator = taskIdToTableBlockInfoMap.entrySet().iterator();
long requiredSize = calculateRequiredSize(taskIdToTableBlockInfoMap, absoluteTableIdentifier);
segmentTaskIndexWrapper.setMemorySize(requiredSize + segmentTaskIndexWrapper.getMemorySize());
boolean isAddedToLruCache = lruCache.put(lruCacheKey, segmentTaskIndexWrapper, requiredSize);
if (isAddedToLruCache) {
while (iterator.hasNext()) {
Map.Entry<TaskBucketHolder, List<TableBlockInfo>> taskToBlockInfoList = iterator.next();
taskBucketHolder = taskToBlockInfoList.getKey();
taskIdToSegmentIndexMap.put(taskBucketHolder, loadBlocks(taskBucketHolder, taskToBlockInfoList.getValue(), absoluteTableIdentifier));
}
} else {
throw new IndexBuilderException("Can not load the segment. No Enough space available.");
}
// set the latest timestamp.
segmentTaskIndexWrapper.setRefreshedTimeStamp(updateVO.getCreatedOrUpdatedTimeStamp());
// tableSegmentMapTemp.put(next.getKey(), taskIdToSegmentIndexMap);
// removing from segment lock map as once segment is loaded
// if concurrent query is coming for same segment
// it will wait on the lock so after this segment will be already
// loaded so lock is not required, that is why removing the
// the lock object as it wont be useful
segmentLockMap.remove(lruCacheKey);
} else {
segmentTaskIndexWrapper.incrementAccessCount();
}
}
} else {
segmentTaskIndexWrapper.incrementAccessCount();
}
}
} catch (IndexBuilderException e) {
LOGGER.error("Problem while loading the segment");
throw e;
}
return segmentTaskIndexWrapper;
}
use of org.apache.carbondata.core.datastore.block.SegmentTaskIndexWrapper in project carbondata by apache.
the class BlockIndexStore method clearAccessCount.
@Override
public void clearAccessCount(List<TableBlockUniqueIdentifier> keys) {
for (TableBlockUniqueIdentifier tableBlockUniqueIdentifier : keys) {
SegmentTaskIndexWrapper cacheable = (SegmentTaskIndexWrapper) lruCache.get(tableBlockUniqueIdentifier.getUniqueTableBlockName());
cacheable.clear();
}
}
use of org.apache.carbondata.core.datastore.block.SegmentTaskIndexWrapper in project carbondata by apache.
the class InMemoryBTreeIndex method getSegmentAbstractIndexs.
private Map<SegmentTaskIndexStore.TaskBucketHolder, AbstractIndex> getSegmentAbstractIndexs(JobContext job, AbsoluteTableIdentifier identifier) throws IOException {
Map<SegmentTaskIndexStore.TaskBucketHolder, AbstractIndex> segmentIndexMap = null;
CacheClient cacheClient = new CacheClient(identifier.getStorePath());
TableSegmentUniqueIdentifier segmentUniqueIdentifier = new TableSegmentUniqueIdentifier(identifier, segment.getId());
try {
SegmentTaskIndexWrapper segmentTaskIndexWrapper = cacheClient.getSegmentAccessClient().getIfPresent(segmentUniqueIdentifier);
if (null != segmentTaskIndexWrapper) {
segmentIndexMap = segmentTaskIndexWrapper.getTaskIdToTableSegmentMap();
}
// if segment tree is not loaded, load the segment tree
if (segmentIndexMap == null) {
List<TableBlockInfo> tableBlockInfoList = getTableBlockInfo(job);
Map<String, List<TableBlockInfo>> segmentToTableBlocksInfos = new HashMap<>();
segmentToTableBlocksInfos.put(segment.getId(), tableBlockInfoList);
segmentUniqueIdentifier.setSegmentToTableBlocksInfos(segmentToTableBlocksInfos);
// TODO: loadAndGetTaskIdToSegmentsMap can be optimized, use tableBlockInfoList as input
// get Btree blocks for given segment
segmentTaskIndexWrapper = cacheClient.getSegmentAccessClient().get(segmentUniqueIdentifier);
segmentIndexMap = segmentTaskIndexWrapper.getTaskIdToTableSegmentMap();
}
} finally {
cacheClient.close();
}
return segmentIndexMap;
}
use of org.apache.carbondata.core.datastore.block.SegmentTaskIndexWrapper in project carbondata by apache.
the class SegmentTaskIndexStore method clearAccessCount.
/**
* The method clears the access count of table segments
*
* @param tableSegmentUniqueIdentifiers
*/
@Override
public void clearAccessCount(List<TableSegmentUniqueIdentifier> tableSegmentUniqueIdentifiers) {
for (TableSegmentUniqueIdentifier segmentUniqueIdentifier : tableSegmentUniqueIdentifiers) {
SegmentTaskIndexWrapper cacheable = (SegmentTaskIndexWrapper) lruCache.get(segmentUniqueIdentifier.getUniqueTableSegmentIdentifier());
cacheable.clear();
}
}
use of org.apache.carbondata.core.datastore.block.SegmentTaskIndexWrapper in project carbondata by apache.
the class SegmentTaskIndexStoreTest method checkExistenceOfSegmentBTree.
@Test
public void checkExistenceOfSegmentBTree() {
TableSegmentUniqueIdentifier tableSegmentUniqueIdentifier = new TableSegmentUniqueIdentifier(absoluteTableIdentifier, "SG100");
SegmentTaskIndexWrapper segmentTaskIndexWrapper = taskIndexStore.getIfPresent(tableSegmentUniqueIdentifier);
Map<SegmentTaskIndexStore.TaskBucketHolder, AbstractIndex> result = segmentTaskIndexWrapper != null ? segmentTaskIndexWrapper.getTaskIdToTableSegmentMap() : null;
assertNull(result);
}
Aggregations