MCPcopy Create free account
hub / github.com/e2wugui/zeze / RocksDatabase

Class RocksDatabase

ZezeJava/ZezeJava/src/main/java/Zeze/Util/RocksDatabase.java:25–896  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23import org.rocksdb.*;
24
25public class RocksDatabase extends ReentrantLock implements Closeable {
26 static {
27 RocksDB.loadLibrary();
28 }
29
30 private static final @NotNull Logger logger = LogManager.getLogger(RocksDatabase.class);
31 private static final LRUCache dbCache = new LRUCache(Str.parseLongSize(System.getProperty("rocksdbCache"), 64 << 20));
32 private static final TableFormatConfig tableCfg = new BlockBasedTableConfig().setBlockCache(dbCache);
33 private static final long dbBuffer = Str.parseLongSize(System.getProperty("rocksdbBuffer"), 64 << 20);
34 private static final Options commonOptions = new Options()
35 .setCreateIfMissing(true)
36 .setTableFormatConfig(tableCfg)
37 .setDbWriteBufferSize(dbBuffer) // total write buffer bytes, include all the columns
38 .setKeepLogFileNum(5); // reserve "LOG.old.*" file count
39 private static final DBOptions commonDbOptions = new DBOptions()
40 .setCreateIfMissing(true)
41 .setDbWriteBufferSize(dbBuffer) // total write buffer bytes, include all the columns
42 .setKeepLogFileNum(5) // reserve "LOG.old.*" file count
43 // .setAtomicFlush(true); // atomic batch 独立于这个选项?
44 .setMaxWriteBatchGroupSizeBytes(100 * 1024 * 1024);
45 private static final ColumnFamilyOptions commonCfOptions = new ColumnFamilyOptions()
46 .setTableFormatConfig(tableCfg);
47 private static final ReadOptions defaultReadOptions = new ReadOptions();
48 private static final WriteOptions defaultWriteOptions = new WriteOptions();
49 private static final WriteOptions syncWriteOptions = new WriteOptions().setSync(true);
50 private static final TransactionDBOptions transactionDbOptions = new TransactionDBOptions();
51 private static final @NotNull MethodHandle mhWriteBatchPutCf;
52 private static final @NotNull MethodHandle mhWriteBatchDeleteCf;
53 private static final @NotNull MethodHandle mhWriteBatchNativeNew;
54 private static final @NotNull MethodHandle mhWriteBatchNew;
55 private static final @Nullable ZezeCounter.LongObserver rocksDbGetObserver;
56 private static final @Nullable ZezeCounter.LongObserver rocksDbPutObserver;
57 private static final @Nullable ZezeCounter.LongObserver rocksDbDeleteObserver;
58 private static final @Nullable ZezeCounter.LongObserver rocksDbDeleteRangeObserver;
59 private static final @Nullable ZezeCounter.LongObserver rocksDbWriteObserver;
60 private static final @Nullable ZezeCounter.LongObserver rocksDbTxnPutObserver;
61 private static final @Nullable ZezeCounter.LongObserver rocksDbTxnDeleteObserver;
62 private static final @Nullable ZezeCounter.LongObserver rocksDbCompactObserver;
63
64 static {
65 try {
66 var lookup = MethodHandles.lookup();
67 var clsWriteBatch = WriteBatch.class;
68 // native void put(long handle, byte[] key, int keyLen, byte[] value, int valueLen, long cfHandle);
69 var m = clsWriteBatch.getDeclaredMethod("put",
70 long.class, byte[].class, int.class, byte[].class, int.class, long.class);
71 m.setAccessible(true);
72 mhWriteBatchPutCf = lookup.unreflect(m);
73 // native void delete(long handle, byte[] key, int keyLen, long cfHandle);
74 m = clsWriteBatch.getDeclaredMethod("delete", long.class, byte[].class, int.class, long.class);
75 m.setAccessible(true);
76 mhWriteBatchDeleteCf = lookup.unreflect(m);
77 // native static long newWriteBatch(byte[] serialized, int serializedLength)
78 m = clsWriteBatch.getDeclaredMethod("newWriteBatch", byte[].class, int.class);
79 m.setAccessible(true);
80 mhWriteBatchNativeNew = lookup.unreflect(m);
81 // WriteBatch(long nativeHandle, boolean owningNativeHandle)
82 var c = clsWriteBatch.getDeclaredConstructor(long.class, boolean.class);

Callers

nothing calls this directly

Calls 6

parseLongSizeMethod · 0.95
getPropertyMethod · 0.80
setAccessibleMethod · 0.80
labelValuesMethod · 0.65
setSyncMethod · 0.45

Tested by

no test coverage detected