org.apache.storm.metricstore.rocksdb

## 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

    All Methods Instance Methods Concrete Methods
    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.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### get

          public org.apache.storm.metricstore.rocksdb.StringMetadata get(String s)

      Get the string metadata from the cache.

      Specified by:
        `get` in interface `ReadOnlyStringMetadataCache`
      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 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

    - #### evictionCallback

          public 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.

      Specified by:
        `evictionCallback` in 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

    - #### contains

          public boolean contains(Integer stringId)

      Determines if a string Id is contained in the cache.

      Specified by:
        `contains` in interface `ReadOnlyStringMetadataCache`
      Parameters:
        `stringId` - The string Id to check
      Returns:
        true if the Id is in the cache, false otherwise

    - #### getMetadataString

          public String getMetadataString(Integer stringId)

      Returns the string matching the string Id if in the cache.

      Specified by:
        `getMetadataString` in interface `ReadOnlyStringMetadataCache`
      Parameters:
        `stringId` - The string Id to check
      Returns:
        the associated string if the Id is in the cache, null otherwise

    - #### entrySet

          public 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.

      Specified by:
        `entrySet` in interface `WritableStringMetadataCache`
      Returns:
        the string metadata map entrySet

Copyright © 2021 The Apache Software Foundation. All rights reserved.