public static Dictionary getDictionary(DictionaryColumnUniqueIdentifier columnIdentifier) throws IOException { Cache<DictionaryColumnUniqueIdentifier, Dictionary> dictCache = CacheProvider.getInstance().createCache(CacheType.REVERSE_DICTIONARY); return dictCache.get(columnIdentifier); }
/** * This method will remove the cache for a given key * * @param keys */ public void invalidateAll(List<K> keys) { for (K key : keys) { cache.invalidate(key); } }
/** * @param cacheInfo * @return */ private boolean canBeRemoved(Cacheable cacheInfo) { if (cacheInfo.getAccessCount() > 0) { return false; } return true; }
/** * This method will remove dictionary cache from driver for both reverse and forward dictionary * * @param carbonTableIdentifier * @param columnId */ public static void removeDictionaryColumnFromCache(AbsoluteTableIdentifier carbonTableIdentifier, String columnId) { Cache<DictionaryColumnUniqueIdentifier, Dictionary> dictCache = CacheProvider.getInstance().createCache(CacheType.REVERSE_DICTIONARY); DictionaryColumnUniqueIdentifier dictionaryColumnUniqueIdentifier = new DictionaryColumnUniqueIdentifier(carbonTableIdentifier, new ColumnIdentifier(columnId, null, null)); dictCache.invalidate(dictionaryColumnUniqueIdentifier); dictCache = CacheProvider.getInstance().createCache(CacheType.FORWARD_DICTIONARY); dictCache.invalidate(dictionaryColumnUniqueIdentifier); } }
public BlockletDataMapFactory(CarbonTable carbonTable, DataMapSchema dataMapSchema) { super(carbonTable, dataMapSchema); this.identifier = carbonTable.getAbsoluteTableIdentifier(); cache = CacheProvider.getInstance() .createCache(CacheType.DRIVER_BLOCKLET_DATAMAP); }
/** * This method will get the value for the given key. If value does not exist * for the given key, it will check and load the value. * * @param key * @return * @throws IOException in case memory is not sufficient to load data into memory */ public V get(K key) throws IOException { V value = cache.get(key); if (value != null) { segmentSet.add(key); } return value; }
/** * This method will remove the cache for a given key * * @param dictionaryColumnUniqueIdentifier unique identifier which contains dbName, * tableName and columnIdentifier */ @Override public void invalidate( DictionaryColumnUniqueIdentifier dictionaryColumnUniqueIdentifier) { carbonLRUCache.remove( getLruCacheKey(dictionaryColumnUniqueIdentifier.getColumnIdentifier().getColumnId(), CacheType.REVERSE_DICTIONARY)); }
/** * This method will remove the cache for a given key * * @param dictionaryColumnUniqueIdentifier unique identifier which contains dbName, * tableName and columnIdentifier */ @Override public void invalidate( DictionaryColumnUniqueIdentifier dictionaryColumnUniqueIdentifier) { carbonLRUCache.remove( getLruCacheKey(dictionaryColumnUniqueIdentifier.getColumnIdentifier().getColumnId(), CacheType.FORWARD_DICTIONARY)); }
/** * This method will check a required column can be loaded into memory or not. If required * this method will call for eviction of existing data from memory * * @param requiredSize * @return */ private boolean freeMemorySizeForAddingCache(long requiredSize) { boolean memoryAvailable = false; if (isSizeAvailableToLoadColumnDictionary(requiredSize)) { memoryAvailable = true; } else { // get the keys that can be removed from memory List<String> keysToBeRemoved = getKeysToBeRemoved(requiredSize); for (String cacheKey : keysToBeRemoved) { removeKey(cacheKey); } // after removing the keys check again if required size is available if (isSizeAvailableToLoadColumnDictionary(requiredSize)) { memoryAvailable = true; } } return memoryAvailable; }
/** * This method will check if a cache already exists for given cache type and create in case * it is not present in the map * * @param cacheType type of cache * @param <K> * @param <V> * @return */ public <K, V> Cache<K, V> createCache(CacheType cacheType) { //check if lru cache is null, if null create one //check if cache is null for given cache type, if null create one if (!dictionaryCacheAlreadyExists(cacheType)) { synchronized (lock) { if (!dictionaryCacheAlreadyExists(cacheType)) { if (null == carbonLRUCache) { createLRULevelCacheInstance(); } createDictionaryCacheForGivenType(cacheType); } } } return cacheTypeToCacheMap.get(cacheType); }
@Override public BloomCacheKeyValue.CacheValue getIfPresent(BloomCacheKeyValue.CacheKey key) { return (BloomCacheKeyValue.CacheValue) lruCache.get(key.toString()); }
/** * This method will return the value for the given key. It will not check and load * the data for the given key * * @param key * @return */ public V getIfPresent(K key) { V value = cache.getIfPresent(key); if (value != null) { segmentSet.add(key); } return value; }
/** * This method will remove the key from lru cache * * @param key */ private void removeKey(String key) { Cacheable cacheable = lruCacheMap.get(key); if (null != cacheable) { long memorySize = cacheable.getMemorySize(); cacheable.invalidate(); lruCacheMap.remove(key); currentSize = currentSize - memorySize; LOGGER.info("Removed entry from InMemory lru cache :: " + key); } }
@Override public void invalidate(BloomCacheKeyValue.CacheKey key) { lruCache.remove(key.toString()); }
/** * @param key */ public void remove(String key) { synchronized (lruCacheMap) { removeKey(key); } }
@Override public void cache(TableBlockIndexUniqueIdentifierWrapper tableBlockIndexUniqueIdentifierWrapper, BlockletDataMapIndexWrapper blockletDataMapIndexWrapper) throws IOException, MemoryException { cache.put(tableBlockIndexUniqueIdentifierWrapper, blockletDataMapIndexWrapper); }
/** * This method will prepare the lru cache key and return the same * * @param columnIdentifier * @return */ protected String getLruCacheKey(String columnIdentifier, CacheType cacheType) { return columnIdentifier + CarbonCommonConstants.UNDERSCORE + cacheType.getCacheName(); }
/** * This method will clear the access count for a given list of segments * * @param segmentList */ public void clearAccessCount(List<K> segmentList) { cache.clearAccessCount(segmentList); // remove from segment set so that access count is not decremented again during close operation segmentSet.removeAll(segmentList); }
/** * Below method will be used to clear the cache */ public void dropAllCache() { if (null != carbonLRUCache) { carbonLRUCache.clear(); carbonLRUCache = null; } cacheTypeToCacheMap.clear(); } }
/** * returns the SegmentTaskIndexWrapper * * @param tableSegmentUniqueIdentifierWrapper * @return */ @Override public BlockletDataMapIndexWrapper getIfPresent( TableBlockIndexUniqueIdentifierWrapper tableSegmentUniqueIdentifierWrapper) { return (BlockletDataMapIndexWrapper) lruCache.get( tableSegmentUniqueIdentifierWrapper.getTableBlockIndexUniqueIdentifier() .getUniqueTableSegmentIdentifier()); }