@Override public BloomCacheKeyValue.CacheValue get(BloomCacheKeyValue.CacheKey key) throws IOException { BloomCacheKeyValue.CacheValue cacheValue = getIfPresent(key); if (cacheValue == null) { List<CarbonBloomFilter> bloomFilters = BloomIndexFileStore.loadBloomFilterFromFile(key.getShardPath(), key.getIndexColumn()); cacheValue = new BloomCacheKeyValue.CacheValue(bloomFilters); lruCache.put(key.toString(), cacheValue, cacheValue.getMemorySize()); } return cacheValue; }
@Override public void put(TableBlockIndexUniqueIdentifierWrapper tableBlockIndexUniqueIdentifierWrapper, BlockletDataMapIndexWrapper wrapper) throws IOException, MemoryException { // As dataMap will use unsafe memory, it is not recommended to overwrite an existing entry // as in that case clearing unsafe memory need to be taken card. If at all datamap entry // in the cache need to be overwritten then use the invalidate interface // and then use the put interface if (null == getIfPresent(tableBlockIndexUniqueIdentifierWrapper)) { List<BlockDataMap> dataMaps = wrapper.getDataMaps(); try { for (BlockDataMap blockletDataMap : dataMaps) { blockletDataMap.convertToUnsafeDMStore(); } // Locking is not required here because in LRU cache map add method is synchronized to add // only one entry at a time and if a key already exists it will not overwrite the entry lruCache.put(tableBlockIndexUniqueIdentifierWrapper.getTableBlockIndexUniqueIdentifier() .getUniqueTableSegmentIdentifier(), wrapper, wrapper.getMemorySize()); } catch (Throwable e) { // clear all the memory acquired by data map in case of any failure for (DataMap blockletDataMap : dataMaps) { blockletDataMap.clear(); } throw new IOException("Problem in adding datamap to cache.", e); } } }
lruCache.put(identifier.getUniqueTableSegmentIdentifier(), blockletDataMapIndexWrapper, blockletDataMapIndexWrapper.getMemorySize());
long updateRequiredSize = ObjectSizeCalculator.estimate(dictionaryInfo, requiredSize); dictionaryInfo.setMemorySize(updateRequiredSize); if (!carbonLRUCache.put(lruCacheKey, dictionaryInfo, updateRequiredSize)) { throw new DictionaryBuilderException( "Cannot load dictionary into memory. Not enough memory available");