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.
Modifier and Type | Method and Description |
---|---|
boolean |
contains(Integer stringId)
Determines if a string Id is contained in the cache.
|
Set<Map.Entry<String,org.apache.storm.metricstore.rocksdb.StringMetadata>> |
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(String s)
Get the string metadata from the cache.
|
String |
getMetadataString(Integer stringId)
Returns the string matching the string Id if in the cache.
|
void |
put(String s,
org.apache.storm.metricstore.rocksdb.StringMetadata stringMetadata,
boolean newEntry)
Add the string metadata to the cache.
|
public org.apache.storm.metricstore.rocksdb.StringMetadata get(String s)
Get the string metadata from the cache.
get
in interface ReadOnlyStringMetadataCache
s
- The string to look forpublic 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.
put
in interface WritableStringMetadataCache
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 immediatelyMetricException
- when evicted data fails to save to the database or when the database is shutdownpublic void evictionCallback(String key, org.apache.storm.metricstore.rocksdb.StringMetadata val)
Callback when data is about to be removed from the cache. This method then immediately writes the metadata to RocksDB.
evictionCallback
in interface LruMap.CacheEvictionCallback<String,org.apache.storm.metricstore.rocksdb.StringMetadata>
key
- The evicted stringval
- The evicted string’s metadataRuntimeException
- when evicted data fails to save to the databasepublic boolean contains(Integer stringId)
Determines if a string Id is contained in the cache.
contains
in interface ReadOnlyStringMetadataCache
stringId
- The string Id to checkpublic String getMetadataString(Integer stringId)
Returns the string matching the string Id if in the cache.
getMetadataString
in interface ReadOnlyStringMetadataCache
stringId
- The string Id to checkpublic Set<Map.Entry<String,org.apache.storm.metricstore.rocksdb.StringMetadata>> entrySet()
Get the map of the cache contents. Provided to allow writing the data to RocksDB on shutdown.
entrySet
in interface WritableStringMetadataCache
Copyright © 2019 The Apache Software Foundation. All rights reserved.