public class RocksDBStore extends java.lang.Object implements KeyValueStore<org.apache.kafka.common.utils.Bytes,byte[]>
Bytes
class,
i.e. use RocksDBStore<Bytes, ...>
rather than RocksDBStore<byte[], ...>
.Modifier and Type | Field and Description |
---|---|
protected boolean |
open |
Modifier and Type | Method and Description |
---|---|
KeyValueIterator<org.apache.kafka.common.utils.Bytes,byte[]> |
all()
Return an iterator over all keys in this store.
|
long |
approximateNumEntries()
Return an approximate count of key-value mappings in this store.
|
void |
close()
Close the storage engine.
|
byte[] |
delete(org.apache.kafka.common.utils.Bytes key)
Delete the value from the store (if there is one).
|
void |
flush()
Flush any cached data
|
byte[] |
get(org.apache.kafka.common.utils.Bytes key)
Get the value corresponding to this key.
|
org.rocksdb.Options |
getOptions() |
void |
init(ProcessorContext context,
StateStore root)
Initializes this state store.
|
boolean |
isOpen()
Is this store open for reading and writing
|
java.lang.String |
name()
The name of this store.
|
void |
openDB(ProcessorContext context) |
boolean |
persistent()
Return if the storage is persistent or not.
|
void |
put(org.apache.kafka.common.utils.Bytes key,
byte[] value)
Update the value associated with this key.
|
void |
putAll(java.util.List<KeyValue<org.apache.kafka.common.utils.Bytes,byte[]>> entries)
Update all the given key/value pairs.
|
byte[] |
putIfAbsent(org.apache.kafka.common.utils.Bytes key,
byte[] value)
Update the value associated with this key, unless a value is already associated with the key.
|
KeyValueIterator<org.apache.kafka.common.utils.Bytes,byte[]> |
range(org.apache.kafka.common.utils.Bytes from,
org.apache.kafka.common.utils.Bytes to)
Get an iterator over a given range of keys.
|
public void openDB(ProcessorContext context)
public void init(ProcessorContext context, StateStore root)
StateStore
The implementation of this function must register the root store in the context via the
ProcessorContext.register(StateStore, StateRestoreCallback)
function, where the
first StateStore
parameter should always be the passed-in root
object, and
the second parameter should be an object of user's implementation
of the StateRestoreCallback
interface used for restoring the state store from the changelog.
Note that if the state store engine itself supports bulk writes, users can implement another
interface BatchingStateRestoreCallback
which extends StateRestoreCallback
to
let users implement bulk-load restoration logic instead of restoring one record at a time.
init
in interface StateStore
public java.lang.String name()
StateStore
name
in interface StateStore
public boolean persistent()
StateStore
persistent
in interface StateStore
true
if the storage is persistent—false
otherwisepublic boolean isOpen()
StateStore
isOpen
in interface StateStore
true
if the store is openpublic byte[] get(org.apache.kafka.common.utils.Bytes key)
ReadOnlyKeyValueStore
get
in interface ReadOnlyKeyValueStore<org.apache.kafka.common.utils.Bytes,byte[]>
key
- The key to fetchpublic void put(org.apache.kafka.common.utils.Bytes key, byte[] value)
KeyValueStore
put
in interface KeyValueStore<org.apache.kafka.common.utils.Bytes,byte[]>
key
- The key to associate the value tovalue
- The value to update, it can be null
;
if the serialized bytes are also null
it is interpreted as deletespublic byte[] putIfAbsent(org.apache.kafka.common.utils.Bytes key, byte[] value)
KeyValueStore
putIfAbsent
in interface KeyValueStore<org.apache.kafka.common.utils.Bytes,byte[]>
key
- The key to associate the value tovalue
- The value to update, it can be null
;
if the serialized bytes are also null
it is interpreted as deletesnull
if there is no such key.public void putAll(java.util.List<KeyValue<org.apache.kafka.common.utils.Bytes,byte[]>> entries)
KeyValueStore
putAll
in interface KeyValueStore<org.apache.kafka.common.utils.Bytes,byte[]>
entries
- A list of entries to put into the store;
if the serialized bytes are also null
it is interpreted as deletespublic byte[] delete(org.apache.kafka.common.utils.Bytes key)
KeyValueStore
delete
in interface KeyValueStore<org.apache.kafka.common.utils.Bytes,byte[]>
key
- The keynull
if there is no such key.public KeyValueIterator<org.apache.kafka.common.utils.Bytes,byte[]> range(org.apache.kafka.common.utils.Bytes from, org.apache.kafka.common.utils.Bytes to)
ReadOnlyKeyValueStore
ConcurrentModificationException
s
and must not return null values. No ordering guarantees are provided.range
in interface ReadOnlyKeyValueStore<org.apache.kafka.common.utils.Bytes,byte[]>
from
- The first key that could be in the rangeto
- The last key that could be in the rangepublic KeyValueIterator<org.apache.kafka.common.utils.Bytes,byte[]> all()
ReadOnlyKeyValueStore
ConcurrentModificationException
s
and must not return null values. No ordering guarantees are provided.all
in interface ReadOnlyKeyValueStore<org.apache.kafka.common.utils.Bytes,byte[]>
public long approximateNumEntries()
RocksDB
cannot return an exact entry count without doing a
full scan, so this method relies on the rocksdb.estimate-num-keys
property to get an approximate count. The returned size also includes
a count of dirty keys in the store's in-memory cache, which may lead to some
double-counting of entries and inflate the estimate.approximateNumEntries
in interface ReadOnlyKeyValueStore<org.apache.kafka.common.utils.Bytes,byte[]>
public void flush()
StateStore
flush
in interface StateStore
public void close()
StateStore
Users only need to implement this function but should NEVER need to call this api explicitly as it will be called by the library automatically when necessary
close
in interface StateStore
public org.rocksdb.Options getOptions()