public final class RocksUtils extends Object
Modifier and Type | Class and Description |
---|---|
static interface |
RocksUtils.RocksIteratorParser<T>
Used to parse current
RocksIterator element. |
Modifier and Type | Method and Description |
---|---|
static <T> CloseableIterator<T> |
createCloseableIterator(org.rocksdb.RocksIterator rocksIterator,
RocksUtils.RocksIteratorParser<T> parser,
java.util.function.Supplier<Void> abortCheck,
RocksSharedLockHandle rocksDbSharedLock)
Used to wrap an
CloseableIterator over RocksIterator . |
static long |
readLong(byte[] bytes,
int start) |
static byte[] |
toByteArray(long long1,
long long2) |
static byte[] |
toByteArray(long n,
String str) |
public static byte[] toByteArray(long long1, long long2)
long1
- a long valuelong2
- a long valuepublic static byte[] toByteArray(long n, String str)
n
- a long valuestr
- a string valuepublic static long readLong(byte[] bytes, int start)
bytes
- an array of bytesstart
- the place in the array to read the long frompublic static <T> CloseableIterator<T> createCloseableIterator(org.rocksdb.RocksIterator rocksIterator, RocksUtils.RocksIteratorParser<T> parser, java.util.function.Supplier<Void> abortCheck, RocksSharedLockHandle rocksDbSharedLock)
CloseableIterator
over RocksIterator
.
It seeks given iterator to first entry before returning the iterator.
The Iterator is associated with a shared lock to the RocksStore. The lock should be acquired
by the caller (See java doc on RocksStore.checkAndAcquireSharedLock()) for how.
And the lock is held throughout the lifecycle of this iterator until it is closed
either on completion or on exception. This shared lock guarantees thread safety when
accessing the RocksDB. In other words, when this shared lock is held, the underlying
RocksDB will not be stopped/restarted.
The abortCheck defines a way to voluntarily abort the iteration. This typically happens
when the underlying RocksDB will be closed/restart/checkpointed, where all accesses should
be stopped.
With the thread safety baked into hasNext() and next(), users of this Iterator do not need
to worry about safety and can use this Iterator normally.
See examples in how this iterator is used in RocksBlockMetaStore and RocksInodeStore.T
- iterator value typerocksIterator
- the rocks iteratorparser
- parser to produce iterated values from rocks key-valueabortCheck
- if true, abort the iterationrocksDbSharedLock
- the shared lock acquired by the iteratorCopyright © 2023. All Rights Reserved.