Skip to content

Commit 65e5866

Browse files
committed
Add Temperature and CacheTier enums for Java bindings
1 parent a9906f0 commit 65e5866

2 files changed

Lines changed: 123 additions & 0 deletions

File tree

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package org.rocksdb;
2+
3+
/**
4+
* The control option of how the cache tiers will be used.
5+
* Currently RocksDB supports block cache (volatile tier) and
6+
* secondary cache (non-volatile tier).
7+
*/
8+
public enum CacheTier {
9+
/**
10+
* Volatile tier only (traditional block cache)
11+
*/
12+
VOLATILE_TIER((byte) 0x00),
13+
14+
/**
15+
* Volatile compressed tier
16+
*/
17+
VOLATILE_COMPRESSED_TIER((byte) 0x01),
18+
19+
/**
20+
* Non-volatile block tier (secondary cache)
21+
*/
22+
NON_VOLATILE_BLOCK_TIER((byte) 0x02);
23+
24+
private final byte value;
25+
26+
CacheTier(final byte value) {
27+
this.value = value;
28+
}
29+
30+
/**
31+
* Get the internal byte value.
32+
*
33+
* @return the internal byte value
34+
*/
35+
public byte getValue() {
36+
return value;
37+
}
38+
39+
/**
40+
* Get CacheTier by byte value.
41+
*
42+
* @param value the byte value representing CacheTier
43+
* @return {@link CacheTier} instance or null
44+
* @throws IllegalArgumentException if an invalid value is provided
45+
*/
46+
public static CacheTier getCacheTier(final byte value) {
47+
for (final CacheTier cacheTier : CacheTier.values()) {
48+
if (cacheTier.getValue() == value) {
49+
return cacheTier;
50+
}
51+
}
52+
throw new IllegalArgumentException("Illegal value provided for CacheTier: " + value);
53+
}
54+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package org.rocksdb;
2+
3+
/**
4+
* Temperature of a file. Used to pass to FileSystem for a different
5+
* placement and/or coding.
6+
* Reserve some numbers in the middle for potential future use.
7+
*/
8+
public enum Temperature {
9+
/**
10+
* Unknown temperature, default value
11+
*/
12+
UNKNOWN((byte) 0),
13+
14+
/**
15+
* Hot data, accessed frequently
16+
*/
17+
HOT((byte) 0x04),
18+
19+
/**
20+
* Warm data, accessed occasionally
21+
*/
22+
WARM((byte) 0x08),
23+
24+
/**
25+
* Cool data, less frequently accessed
26+
*/
27+
COOL((byte) 0x0A),
28+
29+
/**
30+
* Cold data, rarely accessed
31+
*/
32+
COLD((byte) 0x0C),
33+
34+
/**
35+
* Ice data, very rarely accessed (archive tier)
36+
*/
37+
ICE((byte) 0x10);
38+
39+
private final byte value;
40+
41+
Temperature(final byte value) {
42+
this.value = value;
43+
}
44+
45+
/**
46+
* Get the internal byte value.
47+
*
48+
* @return the internal byte value
49+
*/
50+
public byte getValue() {
51+
return value;
52+
}
53+
54+
/**
55+
* Get Temperature by byte value.
56+
*
57+
* @param value the byte value representing Temperature
58+
* @return {@link Temperature} instance
59+
* @throws IllegalArgumentException if an invalid value is provided
60+
*/
61+
public static Temperature getTemperature(final byte value) {
62+
for (final Temperature temperature : Temperature.values()) {
63+
if (temperature.getValue() == value) {
64+
return temperature;
65+
}
66+
}
67+
throw new IllegalArgumentException("Illegal value provided for Temperature: " + value);
68+
}
69+
}

0 commit comments

Comments
 (0)