Class StringMetadataCache
java.lang.Object
org.apache.storm.metricstore.rocksdb.StringMetadataCache
- All Implemented Interfaces:
- ReadOnlyStringMetadataCache,- WritableStringMetadataCache,- LruMap.CacheEvictionCallback<String,- org.apache.storm.metricstore.rocksdb.StringMetadata> 
public class StringMetadataCache
extends Object
implements LruMap.CacheEvictionCallback<String,org.apache.storm.metricstore.rocksdb.StringMetadata>, WritableStringMetadataCache, ReadOnlyStringMetadataCache 
Class to create a use a cache that stores Metadata string information in memory.  It allows searching for a
 Metadata string's unique id, or looking up the string by the unique id.  The StringMetadata is stored in an
 LRU map.  When an entry is added to the cache, an older entry may be evicted, which then needs to be
 immediately stored to the database to provide a consistent view of all the metadata strings.
 
All write operations adding metadata to RocksDB are done by a single thread (a RocksDbMetricsWriter), but multiple threads can read values from the cache. To clarify which permissions are accessible by various threads, the ReadOnlyStringMetadataCache and WritableStringMetadataCache are provided to be used.
- 
Method SummaryModifier and TypeMethodDescriptionbooleanDetermines if a string Id is contained in the cache.entrySet()Get the map of the cache contents.voidevictionCallback(String key, org.apache.storm.metricstore.rocksdb.StringMetadata val) Callback when data is about to be removed from the cache.org.apache.storm.metricstore.rocksdb.StringMetadataGet the string metadata from the cache.getMetadataString(Integer stringId) Returns the string matching the string Id if in the cache.voidAdd the string metadata to the cache.
- 
Method Details- 
getGet the string metadata from the cache.- Specified by:
- getin interface- ReadOnlyStringMetadataCache
- Parameters:
- s- The string to look for
- Returns:
- the metadata associated with the string or null if not found
 
- 
putpublic void put(String s, org.apache.storm.metricstore.rocksdb.StringMetadata stringMetadata, boolean newEntry) throws MetricException Add the string metadata to the cache.NOTE: this can cause data to be evicted from the cache when full. When this occurs, the evictionCallback() method is called to store the metadata back into the RocksDB database. This method is only exposed to the WritableStringMetadataCache interface. - Specified by:
- putin interface- WritableStringMetadataCache
- Parameters:
- s- The string to add
- stringMetadata- The string's metadata
- newEntry- Indicates the metadata is being used for the first time and should be written to RocksDB immediately
- Throws:
- MetricException- when evicted data fails to save to the database or when the database is shutdown
 
- 
evictionCallbackCallback when data is about to be removed from the cache. This method then immediately writes the metadata to RocksDB.- Specified by:
- evictionCallbackin interface- LruMap.CacheEvictionCallback<String,- org.apache.storm.metricstore.rocksdb.StringMetadata> 
- Parameters:
- key- The evicted string
- val- The evicted string's metadata
- Throws:
- RuntimeException- when evicted data fails to save to the database
 
- 
containsDetermines if a string Id is contained in the cache.- Specified by:
- containsin interface- ReadOnlyStringMetadataCache
- Parameters:
- stringId- The string Id to check
- Returns:
- true if the Id is in the cache, false otherwise
 
- 
getMetadataStringReturns the string matching the string Id if in the cache.- Specified by:
- getMetadataStringin interface- ReadOnlyStringMetadataCache
- Parameters:
- stringId- The string Id to check
- Returns:
- the associated string if the Id is in the cache, null otherwise
 
- 
entrySetGet the map of the cache contents. Provided to allow writing the data to RocksDB on shutdown.- Specified by:
- entrySetin interface- WritableStringMetadataCache
- Returns:
- the string metadata map entrySet
 
 
-