Search in sources :

Example 1 with BlockletDataMap

use of org.apache.carbondata.core.indexstore.blockletindex.BlockletDataMap in project carbondata by apache.

the class BlockletDataMapIndexStore method loadAndGetDataMap.

/**
 * 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
 *
 * @return map of taks id to segment mapping
 * @throws IOException
 */
private BlockletDataMap loadAndGetDataMap(TableBlockIndexUniqueIdentifier identifier, SegmentIndexFileStore indexFileStore, Map<String, BlockMetaInfo> blockMetaInfoMap) throws IOException, MemoryException {
    String uniqueTableSegmentIdentifier = identifier.getUniqueTableSegmentIdentifier();
    Object lock = segmentLockMap.get(uniqueTableSegmentIdentifier);
    if (lock == null) {
        lock = addAndGetSegmentLock(uniqueTableSegmentIdentifier);
    }
    BlockletDataMap dataMap;
    synchronized (lock) {
        dataMap = new BlockletDataMap();
        dataMap.init(new BlockletDataMapModel(identifier.getIndexFilePath() + CarbonCommonConstants.FILE_SEPARATOR + identifier.getIndexFileName(), indexFileStore.getFileData(identifier.getIndexFileName()), blockMetaInfoMap, identifier.getSegmentId()));
        lruCache.put(identifier.getUniqueTableSegmentIdentifier(), dataMap, dataMap.getMemorySize());
    }
    return dataMap;
}
Also used : BlockletDataMap(org.apache.carbondata.core.indexstore.blockletindex.BlockletDataMap) BlockletDataMapModel(org.apache.carbondata.core.indexstore.blockletindex.BlockletDataMapModel)

Example 2 with BlockletDataMap

use of org.apache.carbondata.core.indexstore.blockletindex.BlockletDataMap in project carbondata by apache.

the class BlockletDataMapIndexStore method getAll.

@Override
public List<BlockletDataMap> getAll(List<TableBlockIndexUniqueIdentifier> tableSegmentUniqueIdentifiers) throws IOException {
    List<BlockletDataMap> blockletDataMaps = new ArrayList<>(tableSegmentUniqueIdentifiers.size());
    List<TableBlockIndexUniqueIdentifier> missedIdentifiers = new ArrayList<>();
    // Get the datamaps for each indexfile from cache.
    try {
        for (TableBlockIndexUniqueIdentifier identifier : tableSegmentUniqueIdentifiers) {
            BlockletDataMap ifPresent = getIfPresent(identifier);
            if (ifPresent != null) {
                blockletDataMaps.add(ifPresent);
            } else {
                missedIdentifiers.add(identifier);
            }
        }
        if (missedIdentifiers.size() > 0) {
            SegmentIndexFileStore indexFileStore = new SegmentIndexFileStore();
            Set<String> filesRead = new HashSet<>();
            for (TableBlockIndexUniqueIdentifier identifier : missedIdentifiers) {
                Map<String, BlockMetaInfo> blockMetaInfoMap = getBlockMetaInfoMap(identifier, indexFileStore, filesRead);
                blockletDataMaps.add(loadAndGetDataMap(identifier, indexFileStore, blockMetaInfoMap));
            }
        }
    } catch (Throwable e) {
        for (BlockletDataMap dataMap : blockletDataMaps) {
            dataMap.clear();
        }
        throw new IOException("Problem in loading segment blocks.", e);
    }
    return blockletDataMaps;
}
Also used : SegmentIndexFileStore(org.apache.carbondata.core.indexstore.blockletindex.SegmentIndexFileStore) ArrayList(java.util.ArrayList) IOException(java.io.IOException) BlockletDataMap(org.apache.carbondata.core.indexstore.blockletindex.BlockletDataMap) HashSet(java.util.HashSet)

Example 3 with BlockletDataMap

use of org.apache.carbondata.core.indexstore.blockletindex.BlockletDataMap in project carbondata by apache.

the class BlockletDataMapIndexStore method get.

@Override
public BlockletDataMap get(TableBlockIndexUniqueIdentifier identifier) throws IOException {
    String lruCacheKey = identifier.getUniqueTableSegmentIdentifier();
    BlockletDataMap dataMap = (BlockletDataMap) lruCache.get(lruCacheKey);
    if (dataMap == null) {
        try {
            SegmentIndexFileStore indexFileStore = new SegmentIndexFileStore();
            Set<String> filesRead = new HashSet<>();
            Map<String, BlockMetaInfo> blockMetaInfoMap = getBlockMetaInfoMap(identifier, indexFileStore, filesRead);
            dataMap = loadAndGetDataMap(identifier, indexFileStore, blockMetaInfoMap);
        } catch (MemoryException e) {
            LOGGER.error("memory exception when loading datamap: " + e.getMessage());
            throw new RuntimeException(e.getMessage(), e);
        }
    }
    return dataMap;
}
Also used : MemoryException(org.apache.carbondata.core.memory.MemoryException) SegmentIndexFileStore(org.apache.carbondata.core.indexstore.blockletindex.SegmentIndexFileStore) BlockletDataMap(org.apache.carbondata.core.indexstore.blockletindex.BlockletDataMap) HashSet(java.util.HashSet)

Example 4 with BlockletDataMap

use of org.apache.carbondata.core.indexstore.blockletindex.BlockletDataMap in project carbondata by apache.

the class BlockletDataMapIndexStore method clearAccessCount.

/**
 * The method clears the access count of table segments
 *
 * @param tableSegmentUniqueIdentifiers
 */
@Override
public void clearAccessCount(List<TableBlockIndexUniqueIdentifier> tableSegmentUniqueIdentifiers) {
    for (TableBlockIndexUniqueIdentifier identifier : tableSegmentUniqueIdentifiers) {
        BlockletDataMap cacheable = (BlockletDataMap) lruCache.get(identifier.getUniqueTableSegmentIdentifier());
        cacheable.clear();
    }
}
Also used : BlockletDataMap(org.apache.carbondata.core.indexstore.blockletindex.BlockletDataMap)

Aggregations

BlockletDataMap (org.apache.carbondata.core.indexstore.blockletindex.BlockletDataMap)4 HashSet (java.util.HashSet)2 SegmentIndexFileStore (org.apache.carbondata.core.indexstore.blockletindex.SegmentIndexFileStore)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 BlockletDataMapModel (org.apache.carbondata.core.indexstore.blockletindex.BlockletDataMapModel)1 MemoryException (org.apache.carbondata.core.memory.MemoryException)1