Modifier and Type | Class and Description |
---|---|
class |
RocksMap.RocksMapEntry<K,V> |
class |
RocksMap.RocksMapIterator<K,V> |
static class |
RocksMap.RocksWalReader
按批次读取Wal, wal 读取器
|
static class |
RocksMap.RocksWalRecord |
Modifier and Type | Field and Description |
---|---|
org.rocksdb.ColumnFamilyOptions |
columnFamilyOptions |
org.rocksdb.DBOptions |
dbOptions |
static String |
DEFAULT_COLUMN_FAMILY_NAME |
org.rocksdb.ReadOptions |
readOptions |
static ThreadLocal<org.rocksdb.WriteBatch> |
THREAD_LOCAL_WRITE_BATCH |
org.rocksdb.WriteOptions |
writeOptions |
Constructor and Description |
---|
RocksMap()
构造方法
|
RocksMap(boolean readOnly)
构造方法
|
RocksMap(String columnFamilyName)
构造方法
|
RocksMap(String columnFamilyName,
boolean readOnly)
构造方法
|
RocksMap(String dbname,
String columnFamilyName)
构造方法
|
RocksMap(String dbname,
String columnFamilyName,
boolean readOnly)
构造方法
|
RocksMap(String dbname,
String columnFamilyName,
org.rocksdb.ColumnFamilyOptions columnFamilyOptions,
org.rocksdb.DBOptions dbOptions,
org.rocksdb.ReadOptions readOptions,
org.rocksdb.WriteOptions writeOptions,
Boolean readOnly)
构造方法
|
Modifier and Type | Method and Description |
---|---|
void |
beginTransaction()
开启事务
同一个线程共线给一个事务
默认: 锁提交等待时间-1, 死锁检测:true, 是否启用快照事务: false
|
void |
beginTransaction(long expire,
boolean deadlockDetect,
boolean withSnapShot)
开启事务
同一个线程共线给一个事务
事务都是读事务,无论操作的记录间是否有交集,都不会锁定。
事务包含读、写事务:
所有的读事务不会锁定,读到的数据取决于snapshot设置。
写事务之间如果不存在记录交集,不会锁定。
写事务之间如果存在记录交集,此时如果未设置snapshot,则交集部分的记录是可以串行提交的。如果设置了snapshot,则第一个写事务(写锁队列的head)会成功,其他写事务会失败(之前的事务修改了该记录的情况下)。
|
RocksMap<K,V> |
choseColumnFamily(String cfName)
在多个 Columnt 之间切换
|
void |
clear() |
void |
close() |
void |
commit()
事务提交
|
void |
compact() |
void |
compactRange(K start,
K end) |
Comparator<? super K> |
comparator() |
boolean |
containsKey(Object key) |
boolean |
containsValue(Object value) |
String |
createBackup() |
String |
createBackup(org.rocksdb.BackupableDBOptions backupableDBOptions) |
String |
createBackup(org.rocksdb.BackupableDBOptions backupableDBOptions,
boolean beforeFlush)
创建一个备份
|
static org.rocksdb.BackupableDBOptions |
createBackupableOption(RocksMap rocksMap) |
static org.rocksdb.BackupableDBOptions |
createBackupableOption(String dbName) |
static org.rocksdb.BackupableDBOptions |
createBackupableOption(String dbName,
String backupPath)
创建一个备份选项
|
void |
drop()
删除这个列族
|
RocksMap<K,V> |
duplicate(String cfName)
复制出一个列族不同,但事务共享的 RocksMap
|
RocksMap<K,V> |
duplicate(String cfName,
boolean shareTransaction)
复制出一个列族不同的 RocksMAp
|
void |
empty(Object key) |
Set<Map.Entry<K,V>> |
entrySet()
数据拷贝到内存中, 所以对这个 Set 的修改不会在 Rocksdb 中生效
|
K |
firstKey() |
void |
flush()
刷新数据到文件
|
void |
flush(boolean sync)
刷新数据到文件
|
void |
flush(boolean sync,
boolean allowStall)
刷新数据到文件
|
void |
flushWal() |
void |
flushWal(boolean sync)
刷新WAL数据到文件
|
V |
get(Object key) |
List<V> |
getAll(Collection<K> keys) |
List<org.rocksdb.BackupInfo> |
getBackupInfo() |
List<org.rocksdb.BackupInfo> |
getBackupInfo(org.rocksdb.BackupableDBOptions backupableDBOptions)
获取备份信息
|
int |
getColumnFamilyId() |
int |
getColumnFamilyId(String columnFamilyName) |
String |
getColumnFamilyName() |
String |
getDataPath() |
String |
getDbname() |
static String |
getDefaultDbPath()
获取默认数据存储路径
|
static String |
getDefaultWalPath()
默认WAL数存储据路径
|
Long |
getLastSequence()
获取最后的序号
|
String |
getProperty(String name) |
String |
getProperty(String columnFamilyName,
String name) |
Boolean |
getReadOnly() |
org.rocksdb.RocksDB |
getRocksDB() |
org.rocksdb.Transaction |
getTransaction() |
int |
getTransactionLockTimeout()
获取事务锁超时时间
|
List<RocksMap.RocksWalRecord> |
getWalBetween(Long startSequence,
Long endSequence,
BiFunction<Integer,Integer,Boolean> filter,
boolean withSerial)
获取某个序号以后的更新操作记录
|
String |
getWalPath() |
List<RocksMap.RocksWalRecord> |
getWalSince(Long startSequence,
BiFunction<Integer,Integer,Boolean> filter,
boolean withSerial)
获取某个序号以后的更新操作记录
|
List<RocksMap.RocksWalRecord> |
getWalSince(Long sequenceNumber,
boolean withSerial)
获取某个序号以后的更新操作记录
|
List<RocksMap.RocksWalRecord> |
getWalSince(Long startSequence,
Long endSequence,
boolean withSerial)
获取某个序号以后的更新操作记录
|
SortedMap<K,V> |
headMap(K toKey) |
boolean |
isEmpty() |
RocksMap.RocksMapIterator<K,V> |
iterator()
构造一个迭代器
|
RocksMap.RocksMapIterator<K,V> |
iterator(int size)
构造一个有范围的迭代器
|
RocksMap.RocksMapIterator<K,V> |
iterator(int skipSize,
int size)
构造一个有范围的迭代器
|
RocksMap.RocksMapIterator<K,V> |
iterator(K fromKey,
K toKey)
构造一个有范围的迭代器
|
RocksMap.RocksMapIterator<K,V> |
iterator(K fromKey,
K toKey,
int skipSize,
int size)
构造一个有范围的迭代器
|
boolean |
keyMayExists(K key)
判断 key 是否不存在
|
Set |
keySet()
数据拷贝到内存中, 所以对这个 Set 的修改不会在 Rocksdb 中生效
|
K |
lastKey() |
V |
lock(Object key)
获取并锁定, 默认独占模式
|
V |
lock(Object key,
boolean exclusive)
获取并加锁
|
Object |
put(Object key,
Object value) |
Object |
put(Object key,
Object value,
boolean isRetVal) |
void |
putAll(Map m) |
V |
putIfAbsent(K key,
V value) |
V |
remove(Object key) |
V |
remove(Object key,
boolean isRetVal)
删除某个 key
|
void |
removeAll(Collection<K> keys) |
void |
removeRange(K fromKey,
K toKey)
Removes the database entries in the range ["beginKey", "endKey"), i.e.,
including "beginKey" and excluding "endKey".
|
void |
removeRange(K fromKey,
K toKey,
boolean useTransaction)
Removes the database entries in the range ["beginKey", "endKey"), i.e.,
including "beginKey" and excluding "endKey".
|
boolean |
replace(K key,
V oldValue,
V newValue) |
static void |
restore(int backupId) |
static void |
restore(int backupId,
String dbName,
org.rocksdb.BackupableDBOptions backupableDBOptions,
Boolean keepLogfile)
从指定备份恢复数据
|
static void |
restoreFromLatestBackup() |
static void |
restoreFromLatestBackup(String dbName,
org.rocksdb.BackupableDBOptions backupableDBOptions,
Boolean keepLogfile)
从最后一次备份恢复数据
|
void |
rollback()
事务回滚
|
void |
rollback(boolean all)
事务回滚
|
void |
rollbackSavePoint() |
void |
savePoint() |
int |
savePointCount() |
void |
scan(Function<RocksMap.RocksMapEntry<K,V>,Boolean> checker)
数据清理执行器
|
void |
scan(Function<RocksMap.RocksMapEntry<K,V>,Boolean> checker,
boolean disableWal)
数据清理执行器
|
void |
scan(K fromKey,
K toKey,
Function<RocksMap.RocksMapEntry<K,V>,Boolean> checker)
数据清理执行器
|
void |
scan(K fromKey,
K toKey,
Function<RocksMap.RocksMapEntry<K,V>,Boolean> checker,
boolean disableWal)
数据清理执行器
|
static byte[] |
serialize(Object obj) |
static void |
setDefaultDbPath(String defaultDbPath)
设置默认数存储据路径
|
static void |
setDefaultWalPath(String defaultWalPath)
设置WAL数存储据路径
|
void |
setTransactionLockTimeout(int transactionLockTimeout)
设置事务锁超时时间
|
int |
size() |
Map<K,V> |
startWith(K key)
按前缀查找关联的 key
|
Map<K,V> |
startWith(K key,
int skipSize,
int size)
按前缀查找关联的 key
|
SortedMap<K,V> |
subMap(K fromKey,
K toKey) |
SortedMap<K,V> |
tailMap(K fromKey) |
void |
unlock(Object key)
释放锁
|
static Object |
unserialize(byte[] obj) |
Collection |
values() |
<T> T |
withTransaction(Function<RocksMap<K,V>,T> transFunction)
开启式事务模式 (立即失败, 死锁检测,无快照)
同一个线程共线给一个事务
使用内置公共事务通过 savepoint 来失败回滚, 但统一提交, 性能会好很多, 但是由于很多层嵌套的 savepont 在高并发时使用这种方式时回导致提交会慢很多
|
<T> T |
withTransaction(long expire,
boolean deadlockDetect,
boolean withSnapShot,
Function<RocksMap<K,V>,T> transFunction)
开启式事务模式
同一个线程共线给一个事务
使用内置公共事务通过 savepoint 来失败回滚, 但统一提交, 性能会好很多, 但是由于很多层嵌套的 savepont 在高并发时使用这种方式时回导致提交会慢很多
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, remove, replace, replaceAll
public static final String DEFAULT_COLUMN_FAMILY_NAME
public transient org.rocksdb.DBOptions dbOptions
public transient org.rocksdb.ReadOptions readOptions
public transient org.rocksdb.WriteOptions writeOptions
public transient org.rocksdb.ColumnFamilyOptions columnFamilyOptions
public static ThreadLocal<org.rocksdb.WriteBatch> THREAD_LOCAL_WRITE_BATCH
public RocksMap()
public RocksMap(String columnFamilyName)
columnFamilyName
- 列族名称public RocksMap(String dbname, String columnFamilyName)
dbname
- 数据库的名称, 基于数据保存目录的相对路径columnFamilyName
- 列族名称public RocksMap(boolean readOnly)
readOnly
- 是否以只读模式打开public RocksMap(String columnFamilyName, boolean readOnly)
columnFamilyName
- 列族名称readOnly
- 是否以只读模式打开public RocksMap(String dbname, String columnFamilyName, boolean readOnly)
dbname
- 数据库的名称, 基于数据保存目录的相对路径columnFamilyName
- 列族名称readOnly
- 是否以只读模式打开public RocksMap(String dbname, String columnFamilyName, org.rocksdb.ColumnFamilyOptions columnFamilyOptions, org.rocksdb.DBOptions dbOptions, org.rocksdb.ReadOptions readOptions, org.rocksdb.WriteOptions writeOptions, Boolean readOnly)
dbname
- 数据库的名称, 基于数据保存目录的相对路径columnFamilyName
- 列族名称dbOptions
- DBOptions 配置对象readOptions
- ReadOptions 配置对象writeOptions
- WriteOptions 配置对象columnFamilyOptions
- 列族配置对象readOnly
- 是否以只读模式打开public static String getDefaultDbPath()
public static void setDefaultDbPath(String defaultDbPath)
defaultDbPath
- 默认数存储据路径public static String getDefaultWalPath()
public static void setDefaultWalPath(String defaultWalPath)
defaultWalPath
- WAL数存储据路径public static byte[] serialize(Object obj)
public static Object unserialize(byte[] obj)
public RocksMap<K,V> duplicate(String cfName)
cfName
- 列族名称public RocksMap<K,V> duplicate(String cfName, boolean shareTransaction)
cfName
- 列族名称shareTransaction
- true: 共享事务, false: 不共享事务public String getDbname()
public String getDataPath()
public String getWalPath()
public String getColumnFamilyName()
public Boolean getReadOnly()
public int savePointCount()
public org.rocksdb.RocksDB getRocksDB()
public static org.rocksdb.BackupableDBOptions createBackupableOption(String dbName, String backupPath)
dbName
- db 名称backupPath
- 备份路径, null 使用默认路径public static org.rocksdb.BackupableDBOptions createBackupableOption(String dbName)
public static org.rocksdb.BackupableDBOptions createBackupableOption(RocksMap rocksMap)
public String createBackup(org.rocksdb.BackupableDBOptions backupableDBOptions, boolean beforeFlush) throws org.rocksdb.RocksDBException
backupableDBOptions
- 备份选项beforeFlush
- 是否在备份前执行 flushorg.rocksdb.RocksDBException
- 异常public String createBackup(org.rocksdb.BackupableDBOptions backupableDBOptions) throws org.rocksdb.RocksDBException
org.rocksdb.RocksDBException
public String createBackup() throws org.rocksdb.RocksDBException
org.rocksdb.RocksDBException
public List<org.rocksdb.BackupInfo> getBackupInfo(org.rocksdb.BackupableDBOptions backupableDBOptions) throws org.rocksdb.RocksDBException
backupableDBOptions
- 备份选线org.rocksdb.RocksDBException
- 异常public List<org.rocksdb.BackupInfo> getBackupInfo() throws org.rocksdb.RocksDBException
org.rocksdb.RocksDBException
public static void restoreFromLatestBackup(String dbName, org.rocksdb.BackupableDBOptions backupableDBOptions, Boolean keepLogfile) throws org.rocksdb.RocksDBException
dbName
- 数据库名, 用以确定恢复路径backupableDBOptions
- 备份选项keepLogfile
- 是否覆盖原有 wal 日志org.rocksdb.RocksDBException
- 异常public static void restoreFromLatestBackup() throws org.rocksdb.RocksDBException
org.rocksdb.RocksDBException
public static void restore(int backupId, String dbName, org.rocksdb.BackupableDBOptions backupableDBOptions, Boolean keepLogfile) throws org.rocksdb.RocksDBException
backupId
- 备份 id 标识dbName
- 数据库名, 用以确定恢复路径backupableDBOptions
- 备份选项keepLogfile
- 是否覆盖原有 wal 日志org.rocksdb.RocksDBException
- 异常public static void restore(int backupId) throws org.rocksdb.RocksDBException
org.rocksdb.RocksDBException
public int getColumnFamilyId()
public void compact()
public Long getLastSequence()
public List<RocksMap.RocksWalRecord> getWalSince(Long sequenceNumber, boolean withSerial)
sequenceNumber
- 序号withSerial
- 是否进行序列化行为public List<RocksMap.RocksWalRecord> getWalSince(Long startSequence, BiFunction<Integer,Integer,Boolean> filter, boolean withSerial)
startSequence
- 起始序号filter
- 过滤器,用来过滤可用的操作类型和列族withSerial
- 是否进行反序列化public List<RocksMap.RocksWalRecord> getWalSince(Long startSequence, Long endSequence, boolean withSerial)
startSequence
- 起始序号endSequence
- 结束序号withSerial
- 是否进行反序列化public List<RocksMap.RocksWalRecord> getWalBetween(Long startSequence, Long endSequence, BiFunction<Integer,Integer,Boolean> filter, boolean withSerial)
startSequence
- 起始序号endSequence
- 结束序号filter
- 过滤器,用来过滤可用的操作类型和列族withSerial
- 是否进行反序列化public int getColumnFamilyId(String columnFamilyName)
public RocksMap<K,V> choseColumnFamily(String cfName)
cfName
- columnFamily 的名称public int getTransactionLockTimeout()
public void setTransactionLockTimeout(int transactionLockTimeout)
transactionLockTimeout
- 事务锁超时时间public <T> T withTransaction(Function<RocksMap<K,V>,T> transFunction)
T
- 范型transFunction
- 事务执行器, 返回 Null 则事务回滚, 其他则事务提交public <T> T withTransaction(long expire, boolean deadlockDetect, boolean withSnapShot, Function<RocksMap<K,V>,T> transFunction)
T
- 范型expire
- 提交时锁超时时间deadlockDetect
- 死锁检测是否打开withSnapShot
- 是否启用快照事务transFunction
- 事务执行器, 返回 Null 则事务回滚, 其他则事务提交public void beginTransaction()
public void beginTransaction(long expire, boolean deadlockDetect, boolean withSnapShot)
expire
- 提交时锁超时时间deadlockDetect
- 死锁检测是否打开withSnapShot
- 是否启用快照事务public org.rocksdb.Transaction getTransaction()
public void savePoint()
public void rollbackSavePoint()
public void commit()
public void rollback()
public void rollback(boolean all)
all
- true: 直接彻底回滚当前事务, false: 回滚到上一个 savepointpublic Comparator<? super K> comparator()
comparator
in interface SortedMap<K,V>
public boolean containsKey(Object key)
containsKey
in interface Map<K,V>
public boolean containsValue(Object value)
containsValue
in interface Map<K,V>
public void unlock(Object key)
key
- 将被释放锁的 keypublic V lock(Object key, boolean exclusive)
key
- 将被加锁的 keyexclusive
- 是否独占模式public List<V> getAll(Collection<K> keys)
public void empty(Object key)
public boolean keyMayExists(K key)
key
- key对象public V remove(Object key, boolean isRetVal)
key
- key 对象isRetVal
- 是否返回被移除的 valuepublic void removeAll(Collection<K> keys)
public void removeRange(K fromKey, K toKey)
fromKey
- 其实 keytoKey
- 结束 keypublic void removeRange(K fromKey, K toKey, boolean useTransaction)
fromKey
- 其实 keytoKey
- 结束 keyuseTransaction
- 是否嵌套至已有事务public void flush(boolean sync, boolean allowStall)
sync
- 同步刷新allowStall
- 是否允许写入暂停public void flush(boolean sync)
sync
- 同步刷新public void flush()
public void flushWal(boolean sync)
sync
- 同步刷新public void flushWal()
public void drop()
public Set keySet()
public Collection values()
public Map<K,V> startWith(K key)
key
- key 的前缀public Map<K,V> startWith(K key, int skipSize, int size)
key
- key 的前缀skipSize
- 跳过记录数size
- 返回记录数public void close()
close
in interface Closeable
close
in interface AutoCloseable
public RocksMap.RocksMapIterator<K,V> iterator(K fromKey, K toKey, int skipSize, int size)
fromKey
- 起始 keytoKey
- 结束 keysize
- 迭代的记录数skipSize
- 跳过记录数size
- 返回记录数public RocksMap.RocksMapIterator<K,V> iterator(K fromKey, K toKey)
fromKey
- 起始 keytoKey
- 结束 keypublic RocksMap.RocksMapIterator<K,V> iterator(int skipSize, int size)
skipSize
- 跳过记录数size
- 返回记录数public RocksMap.RocksMapIterator<K,V> iterator(int size)
size
- 迭代的记录数public RocksMap.RocksMapIterator<K,V> iterator()
public void scan(Function<RocksMap.RocksMapEntry<K,V>,Boolean> checker)
checker
- 数据清理逻辑, true: 继续扫描, false: 停止扫描public void scan(Function<RocksMap.RocksMapEntry<K,V>,Boolean> checker, boolean disableWal)
checker
- 数据清理逻辑, true: 继续扫描, false: 停止扫描disableWal
- 是否屏蔽 walpublic void scan(K fromKey, K toKey, Function<RocksMap.RocksMapEntry<K,V>,Boolean> checker)
fromKey
- 起始 keytoKey
- 结束 keychecker
- 数据清理逻辑, true: 继续扫描, false: 停止扫描Copyright © 2020 Voovan. All rights reserved.