Skip to content

Commit 9010525

Browse files
committed
Add SecondaryCache Java API
1 parent a9906f0 commit 9010525

1 file changed

Lines changed: 76 additions & 0 deletions

File tree

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2+
// This source code is licensed under both the GPLv2 (found in the
3+
// COPYING file in the root directory) and Apache 2.0 License
4+
// (found in the LICENSE.Apache file in the root directory).
5+
6+
package org.rocksdb;
7+
8+
/**
9+
* Second-tier cache below the primary block cache.
10+
* Stores blocks in compressed form or on non-volatile storage.
11+
*/
12+
public abstract class SecondaryCache extends RocksObject {
13+
14+
protected SecondaryCache(final long nativeHandle) {
15+
super(nativeHandle);
16+
}
17+
18+
@Override
19+
protected final void disposeInternal(final long handle) {
20+
disposeInternalJni(handle);
21+
}
22+
23+
/**
24+
* Creates a CompressedSecondaryCache with default settings.
25+
*
26+
* @param capacity cache size in bytes
27+
* @return a new CompressedSecondaryCache
28+
*/
29+
public static SecondaryCache newCompressedSecondaryCache(final long capacity) {
30+
return new CompressedSecondaryCache(capacity);
31+
}
32+
33+
/**
34+
* Creates a CompressedSecondaryCache with custom options.
35+
*
36+
* @param capacity cache size in bytes
37+
* @param numShardBits shard bits (2^n shards), -1 for auto
38+
* @param strictCapacityLimit if true, reject inserts when full
39+
* @param highPriPoolRatio fraction reserved for high-priority entries (0.0-1.0)
40+
* @return a new CompressedSecondaryCache
41+
*/
42+
public static SecondaryCache newCompressedSecondaryCache(
43+
final long capacity,
44+
final int numShardBits,
45+
final boolean strictCapacityLimit,
46+
final double highPriPoolRatio) {
47+
return new CompressedSecondaryCache(
48+
capacity, numShardBits, strictCapacityLimit, highPriPoolRatio);
49+
}
50+
51+
/**
52+
* Compressed cache using LZ4 compression.
53+
*/
54+
private static class CompressedSecondaryCache extends SecondaryCache {
55+
56+
private CompressedSecondaryCache(final long capacity) {
57+
super(newCompressedSecondaryCacheInstance(capacity));
58+
}
59+
60+
private CompressedSecondaryCache(
61+
final long capacity,
62+
final int numShardBits,
63+
final boolean strictCapacityLimit,
64+
final double highPriPoolRatio) {
65+
super(newCompressedSecondaryCacheInstance(
66+
capacity, numShardBits, strictCapacityLimit, highPriPoolRatio));
67+
}
68+
69+
private static native long newCompressedSecondaryCacheInstance(long capacity);
70+
71+
private static native long newCompressedSecondaryCacheInstance(
72+
long capacity, int numShardBits, boolean strictCapacityLimit, double highPriPoolRatio);
73+
}
74+
75+
private static native void disposeInternalJni(final long handle);
76+
}

0 commit comments

Comments
 (0)