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 Summary
Modifier and TypeMethodDescriptionboolean
Determines if a string Id is contained in the cache.entrySet()
Get the map of the cache contents.void
evictionCallback
(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.StringMetadata
Get the string metadata from the cache.getMetadataString
(Integer stringId) Returns the string matching the string Id if in the cache.void
Add the string metadata to the cache.
-
Method Details
-
get
Get the string metadata from the cache.- Specified by:
get
in interfaceReadOnlyStringMetadataCache
- Parameters:
s
- The string to look for- Returns:
- the metadata associated with the string or null if not found
-
put
public 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:
put
in interfaceWritableStringMetadataCache
- Parameters:
s
- The string to addstringMetadata
- The string's metadatanewEntry
- 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
-
evictionCallback
Callback when data is about to be removed from the cache. This method then immediately writes the metadata to RocksDB.- Specified by:
evictionCallback
in interfaceLruMap.CacheEvictionCallback<String,
org.apache.storm.metricstore.rocksdb.StringMetadata> - Parameters:
key
- The evicted stringval
- The evicted string's metadata- Throws:
RuntimeException
- when evicted data fails to save to the database
-
contains
Determines if a string Id is contained in the cache.- Specified by:
contains
in interfaceReadOnlyStringMetadataCache
- Parameters:
stringId
- The string Id to check- Returns:
- true if the Id is in the cache, false otherwise
-
getMetadataString
Returns the string matching the string Id if in the cache.- Specified by:
getMetadataString
in interfaceReadOnlyStringMetadataCache
- Parameters:
stringId
- The string Id to check- Returns:
- the associated string if the Id is in the cache, null otherwise
-
entrySet
Get the map of the cache contents. Provided to allow writing the data to RocksDB on shutdown.- Specified by:
entrySet
in interfaceWritableStringMetadataCache
- Returns:
- the string metadata map entrySet
-