Class

com.twitter.finatra.kafkastreams.transformer.stores.internal

CachingFinatraKeyValueStoreImpl

Related Doc: package internal

Permalink

class CachingFinatraKeyValueStoreImpl[K, V] extends FinatraKeyValueStore[K, V] with Logging

A write-behind caching layer around the FinatraKeyValueStore.

We cache Java objects here and then periodically flush entries into RocksDB which involves serializing the objects into byte arrays. As such this cache: 1) Reduces the number of reads/writes to RocksDB 2) Reduces the number of serialization/deserialization operations which can be expensive for some classes 3) Reduces the number of publishes to the Kafka changelog topic backing this key value store

This caching does introduce a few odd corner cases :-( 1. Items in the cache have pass-by-reference semantics but items in rocksdb have pass-by-value semantics. Modifying items after a put is a bad idea! Ideally, only immutable objects would be stored in a CachingFinatraKeyValueStore 2. Range queries currently only work against the uncached RocksDB data. This is because sorted Java maps are much less performant than their unsorted counterparts. We typically only use range queries for queryable state where it is ok to read stale data If fresher data is required for range queries, decrease your commit interval, or disable caching on your key value store

This class is inspired by: https://github.com/apache/samza/blob/1.0.0/samza-kv/src/main/scala/org/apache/samza/storage/kv/CachedStore.scala

Linear Supertypes
Logging, Logging, FinatraKeyValueStore[K, V], FinatraReadOnlyKeyValueStore[K, V], KeyValueStore[K, V], ReadOnlyKeyValueStore[K, V], StateStore, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. CachingFinatraKeyValueStoreImpl
  2. Logging
  3. Logging
  4. FinatraKeyValueStore
  5. FinatraReadOnlyKeyValueStore
  6. KeyValueStore
  7. ReadOnlyKeyValueStore
  8. StateStore
  9. AnyRef
  10. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new CachingFinatraKeyValueStoreImpl(keyValueStore: FinatraKeyValueStore[K, V], statsReceiver: StatsReceiver)

    Permalink

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. def all(): KeyValueIterator[K, V]

    Permalink
    Definition Classes
    CachingFinatraKeyValueStoreImpl → ReadOnlyKeyValueStore
  5. def approximateNumEntries(): Long

    Permalink
    Definition Classes
    CachingFinatraKeyValueStoreImpl → ReadOnlyKeyValueStore
  6. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  7. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  8. def close(): Unit

    Permalink
    Definition Classes
    CachingFinatraKeyValueStoreImpl → StateStore
  9. def debug(marker: Marker, message: ⇒ Any, cause: Throwable): Unit

    Permalink
    Attributes
    protected[this]
    Definition Classes
    Logging
  10. def debug(message: ⇒ Any, cause: Throwable): Unit

    Permalink
    Attributes
    protected[this]
    Definition Classes
    Logging
  11. def debug(marker: Marker, message: ⇒ Any): Unit

    Permalink
    Attributes
    protected[this]
    Definition Classes
    Logging
  12. def debug(message: ⇒ Any): Unit

    Permalink
    Attributes
    protected[this]
    Definition Classes
    Logging
  13. def debugFutureResult[T](msg: String)(func: ⇒ Future[T]): Future[T]

    Permalink
    Attributes
    protected
    Definition Classes
    Logging
  14. def debugResult[T](message: ⇒ String)(fn: ⇒ T): T

    Permalink
    Attributes
    protected[this]
    Definition Classes
    Logging
  15. def delete(k: K): V

    Permalink
    Definition Classes
    CachingFinatraKeyValueStoreImpl → KeyValueStore
  16. def deleteRange(from: K, to: K): Unit

    Permalink

    Removes the database entries in the range ["from", "to"), i.e., including "from" and excluding "to".

    Removes the database entries in the range ["from", "to"), i.e., including "from" and excluding "to". It is not an error if no keys exist in the range ["from", "to").

    Definition Classes
    CachingFinatraKeyValueStoreImplFinatraKeyValueStore
    Exceptions thrown

    InvalidStateStoreException if the store is not initialized

  17. def deleteRangeExperimentalWithNoChangelogUpdates(beginKeyInclusive: Array[Byte], endKeyExclusive: Array[Byte]): Unit

    Permalink

    Removes the database entries in the range ["begin_key", "end_key"), i.e., including "begin_key" and excluding "end_key".

    Removes the database entries in the range ["begin_key", "end_key"), i.e., including "begin_key" and excluding "end_key". Returns OK on success, and a non-OK status on error. It is not an error if no keys exist in the range ["begin_key", "end_key").

    This feature is currently an experimental performance optimization for deleting very large ranges of contiguous keys. Invoking it many times or on small ranges may severely degrade read performance; in particular, the resulting performance can be worse than calling Delete() for each key in the range. Note also the degraded read performance affects keys outside the deleted ranges, and affects database operations involving scans, like flush and compaction.

    Consider setting ReadOptions::ignore_range_deletions = true to speed up reads for key(s) that are known to be unaffected by range deletions.

    Note: Changelog entries will not be deleted, so this method is best used when relying on retention.ms to delete entries from the changelog

    Definition Classes
    CachingFinatraKeyValueStoreImplFinatraKeyValueStore
  18. def deleteWithoutGettingPriorValue(key: K): Unit

    Permalink

    Delete the value from the store (if there is one) Note: This version of delete avoids getting the prior value which keyValueStore.delete does

    Delete the value from the store (if there is one) Note: This version of delete avoids getting the prior value which keyValueStore.delete does

    key

    The key

    returns

    The old value or null if there is no such key.

    Definition Classes
    CachingFinatraKeyValueStoreImplFinatraKeyValueStore
    Exceptions thrown

    NullPointerException If null is used for key.

  19. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  20. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  21. def error(marker: Marker, message: ⇒ Any, cause: Throwable): Unit

    Permalink
    Attributes
    protected[this]
    Definition Classes
    Logging
  22. def error(message: ⇒ Any, cause: Throwable): Unit

    Permalink
    Attributes
    protected[this]
    Definition Classes
    Logging
  23. def error(marker: Marker, message: ⇒ Any): Unit

    Permalink
    Attributes
    protected[this]
    Definition Classes
    Logging
  24. def error(message: ⇒ Any): Unit

    Permalink
    Attributes
    protected[this]
    Definition Classes
    Logging
  25. def errorResult[T](message: ⇒ String)(fn: ⇒ T): T

    Permalink
    Attributes
    protected[this]
    Definition Classes
    Logging
  26. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  27. def flush(): Unit

    Permalink
    Definition Classes
    CachingFinatraKeyValueStoreImpl → StateStore
  28. def get(k: K): V

    Permalink
    Definition Classes
    CachingFinatraKeyValueStoreImpl → ReadOnlyKeyValueStore
  29. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  30. def getOrDefault(k: K, default: ⇒ V): V

    Permalink

    Get the value corresponding to this key or return the specified default value if no key is found

    Get the value corresponding to this key or return the specified default value if no key is found

    default

    The default value to return if key is not found in the store

    returns

    The value associated with the key or the default value if the key is not found

    Definition Classes
    CachingFinatraKeyValueStoreImplFinatraKeyValueStore
    Exceptions thrown

    InvalidStateStoreException if the store is not initialized

    NullPointerException If null is used for key.

  31. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  32. def info(marker: Marker, message: ⇒ Any, cause: Throwable): Unit

    Permalink
    Attributes
    protected[this]
    Definition Classes
    Logging
  33. def info(message: ⇒ Any, cause: Throwable): Unit

    Permalink
    Attributes
    protected[this]
    Definition Classes
    Logging
  34. def info(marker: Marker, message: ⇒ Any): Unit

    Permalink
    Attributes
    protected[this]
    Definition Classes
    Logging
  35. def info(message: ⇒ Any): Unit

    Permalink
    Attributes
    protected[this]
    Definition Classes
    Logging
  36. def infoResult[T](message: ⇒ String)(fn: ⇒ T): T

    Permalink
    Attributes
    protected[this]
    Definition Classes
    Logging
  37. def init(processorContext: ProcessorContext, stateStore: StateStore): Unit

    Permalink
    Definition Classes
    CachingFinatraKeyValueStoreImpl → StateStore
  38. def isDebugEnabled(marker: Marker): Boolean

    Permalink
    Attributes
    protected[this]
    Definition Classes
    Logging
  39. def isDebugEnabled: Boolean

    Permalink
    Attributes
    protected[this]
    Definition Classes
    Logging
  40. def isErrorEnabled(marker: Marker): Boolean

    Permalink
    Attributes
    protected[this]
    Definition Classes
    Logging
  41. def isErrorEnabled: Boolean

    Permalink
    Attributes
    protected[this]
    Definition Classes
    Logging
  42. def isInfoEnabled(marker: Marker): Boolean

    Permalink
    Attributes
    protected[this]
    Definition Classes
    Logging
  43. def isInfoEnabled: Boolean

    Permalink
    Attributes
    protected[this]
    Definition Classes
    Logging
  44. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  45. def isOpen(): Boolean

    Permalink
    Definition Classes
    CachingFinatraKeyValueStoreImpl → StateStore
  46. def isTraceEnabled(marker: Marker): Boolean

    Permalink
    Attributes
    protected[this]
    Definition Classes
    Logging
  47. def isTraceEnabled: Boolean

    Permalink
    Attributes
    protected[this]
    Definition Classes
    Logging
  48. def isWarnEnabled(marker: Marker): Boolean

    Permalink
    Attributes
    protected[this]
    Definition Classes
    Logging
  49. def isWarnEnabled: Boolean

    Permalink
    Attributes
    protected[this]
    Definition Classes
    Logging
  50. final def logger: Logger

    Permalink
    Attributes
    protected[this]
    Definition Classes
    Logging
  51. final def loggerName: String

    Permalink
    Attributes
    protected[this]
    Definition Classes
    Logging
  52. def name(): String

    Permalink
    Definition Classes
    CachingFinatraKeyValueStoreImpl → StateStore
  53. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  54. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  55. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  56. def persistent(): Boolean

    Permalink
    Definition Classes
    CachingFinatraKeyValueStoreImpl → StateStore
  57. def put(key: K, value: V): Unit

    Permalink
    Definition Classes
    CachingFinatraKeyValueStoreImpl → KeyValueStore
  58. def putAll(list: List[KeyValue[K, V]]): Unit

    Permalink
    Definition Classes
    CachingFinatraKeyValueStoreImpl → KeyValueStore
  59. def putIfAbsent(k: K, v: V): V

    Permalink
    Definition Classes
    CachingFinatraKeyValueStoreImpl → KeyValueStore
  60. def range(fromBytesInclusive: Array[Byte]): KeyValueIterator[K, V]

    Permalink

    A range scan starting from bytes.

    A range scan starting from bytes.

    Note 1: This is an API for Advanced users only

    Note 2: If this RocksDB instance is configured in "prefix seek mode", than fromBytes will be used as a "prefix" and the iteration will end when the prefix is no longer part of the next element. Enabling "prefix seek mode" can be done by calling options.useFixedLengthPrefixExtractor. When enabled, prefix scans can take advantage of a prefix based bloom filter for better seek performance See: https://github.com/facebook/rocksdb/wiki/Prefix-Seek-API-Changes

    Definition Classes
    CachingFinatraKeyValueStoreImplFinatraKeyValueStore
    Exceptions thrown

    InvalidStateStoreException if the store is not initialized

  61. def range(fromBytesInclusive: Array[Byte], toBytesExclusive: Array[Byte]): KeyValueIterator[K, V]

    Permalink

    Get an iterator over a given range of keys.

    Get an iterator over a given range of keys. This iterator must be closed after use. The returned iterator must be safe from java.util.ConcurrentModificationExceptions and must not return null values. No ordering guarantees are provided.

    fromBytesInclusive

    Inclusive bytes to start the range scan

    toBytesExclusive

    Exclusive bytes to end the range scan

    returns

    The iterator for this range.

    Definition Classes
    CachingFinatraKeyValueStoreImplFinatraKeyValueStore
    Exceptions thrown

    InvalidStateStoreException if the store is not initialized

    NullPointerException If null is used for from or to.

  62. def range(fromInclusive: K, toInclusive: K): KeyValueIterator[K, V]

    Permalink
    Definition Classes
    CachingFinatraKeyValueStoreImpl → ReadOnlyKeyValueStore
  63. def range(fromInclusive: K, toInclusive: K, allowStaleReads: Boolean): KeyValueIterator[K, V]

    Permalink

    Get an iterator over a given range of keys.

    Get an iterator over a given range of keys. This iterator must be closed after use. The returned iterator must be safe from java.util.ConcurrentModificationExceptions and must not return null values. No ordering guarantees are provided.

    allowStaleReads

    Allow stale reads when querying (Stale reads can occur when querying key value stores with caching enabled).

    returns

    The iterator for this range.

    Definition Classes
    CachingFinatraKeyValueStoreImplFinatraReadOnlyKeyValueStore
    Exceptions thrown

    InvalidStateStoreException if the store is not initialized

    NullPointerException If null is used for from or to.

  64. def registerFlushListener(flushListener: (K, V) ⇒ Unit): Unit

    Permalink

    Register a flush listener callback that will be called every time a cached key value store entry is flushed into the underlying RocksDB store

    Register a flush listener callback that will be called every time a cached key value store entry is flushed into the underlying RocksDB store

    flushListener

    Flush callback for cached entries

  65. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  66. def taskId: TaskId

    Permalink

    Returns the task id of this tore

    Returns the task id of this tore

    returns

    the task id of this store

    Definition Classes
    CachingFinatraKeyValueStoreImplFinatraReadOnlyKeyValueStore
  67. def time[T](formatStr: String)(func: ⇒ T): T

    Permalink
    Attributes
    protected
    Definition Classes
    Logging
  68. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  69. def trace(marker: Marker, message: ⇒ Any, cause: Throwable): Unit

    Permalink
    Attributes
    protected[this]
    Definition Classes
    Logging
  70. def trace(message: ⇒ Any, cause: Throwable): Unit

    Permalink
    Attributes
    protected[this]
    Definition Classes
    Logging
  71. def trace(marker: Marker, message: ⇒ Any): Unit

    Permalink
    Attributes
    protected[this]
    Definition Classes
    Logging
  72. def trace(message: ⇒ Any): Unit

    Permalink
    Attributes
    protected[this]
    Definition Classes
    Logging
  73. def traceResult[T](message: ⇒ String)(fn: ⇒ T): T

    Permalink
    Attributes
    protected[this]
    Definition Classes
    Logging
  74. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  75. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  76. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  77. def warn(marker: Marker, message: ⇒ Any, cause: Throwable): Unit

    Permalink
    Attributes
    protected[this]
    Definition Classes
    Logging
  78. def warn(message: ⇒ Any, cause: Throwable): Unit

    Permalink
    Attributes
    protected[this]
    Definition Classes
    Logging
  79. def warn(marker: Marker, message: ⇒ Any): Unit

    Permalink
    Attributes
    protected[this]
    Definition Classes
    Logging
  80. def warn(message: ⇒ Any): Unit

    Permalink
    Attributes
    protected[this]
    Definition Classes
    Logging
  81. def warnResult[T](message: ⇒ String)(fn: ⇒ T): T

    Permalink
    Attributes
    protected[this]
    Definition Classes
    Logging

Inherited from Logging

Inherited from Logging

Inherited from FinatraKeyValueStore[K, V]

Inherited from FinatraReadOnlyKeyValueStore[K, V]

Inherited from KeyValueStore[K, V]

Inherited from ReadOnlyKeyValueStore[K, V]

Inherited from StateStore

Inherited from AnyRef

Inherited from Any

Ungrouped