1 // Copyright (c) Meta Platforms, Inc. and affiliates.
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).
9 * Enum PrepopulateBlobCache
11 * <p>Prepopulate warm/hot blobs which are already in memory into blob
12 * cache at the time of flush. On a flush, the blob that is in memory
13 * (in memtables) get flushed to the device. If using Direct IO,
14 * additional IO is incurred to read this blob back into memory again,
15 * which is avoided by enabling this option. This further helps if the
16 * workload exhibits high temporal locality, where most of the reads go
17 * to recently written data. This also helps in case of the remote file
18 * system since it involves network traffic and higher latencies.</p>
20 public enum PrepopulateBlobCache
{
21 PREPOPULATE_BLOB_DISABLE((byte) 0x0, "prepopulate_blob_disable", "kDisable"),
22 PREPOPULATE_BLOB_FLUSH_ONLY((byte) 0x1, "prepopulate_blob_flush_only", "kFlushOnly");
25 * <p>Get the PrepopulateBlobCache enumeration value by
26 * passing the library name to this method.</p>
28 * <p>If library cannot be found the enumeration
29 * value {@code PREPOPULATE_BLOB_DISABLE} will be returned.</p>
31 * @param libraryName prepopulate blob cache library name.
33 * @return PrepopulateBlobCache instance.
35 public static PrepopulateBlobCache
getPrepopulateBlobCache(String libraryName
) {
36 if (libraryName
!= null) {
37 for (PrepopulateBlobCache prepopulateBlobCache
: PrepopulateBlobCache
.values()) {
38 if (prepopulateBlobCache
.getLibraryName() != null
39 && prepopulateBlobCache
.getLibraryName().equals(libraryName
)) {
40 return prepopulateBlobCache
;
44 return PrepopulateBlobCache
.PREPOPULATE_BLOB_DISABLE
;
48 * <p>Get the PrepopulateBlobCache enumeration value by
49 * passing the byte identifier to this method.</p>
51 * @param byteIdentifier of PrepopulateBlobCache.
53 * @return PrepopulateBlobCache instance.
55 * @throws IllegalArgumentException If PrepopulateBlobCache cannot be found for the
56 * provided byteIdentifier
58 public static PrepopulateBlobCache
getPrepopulateBlobCache(byte byteIdentifier
) {
59 for (final PrepopulateBlobCache prepopulateBlobCache
: PrepopulateBlobCache
.values()) {
60 if (prepopulateBlobCache
.getValue() == byteIdentifier
) {
61 return prepopulateBlobCache
;
65 throw new IllegalArgumentException("Illegal value provided for PrepopulateBlobCache.");
69 * <p>Get a PrepopulateBlobCache value based on the string key in the C++ options output.
70 * This gets used in support of getting options into Java from an options string,
71 * which is generated at the C++ level.
74 * @param internalName the internal (C++) name by which the option is known.
76 * @return PrepopulateBlobCache instance (optional)
78 static PrepopulateBlobCache
getFromInternal(final String internalName
) {
79 for (final PrepopulateBlobCache prepopulateBlobCache
: PrepopulateBlobCache
.values()) {
80 if (prepopulateBlobCache
.internalName_
.equals(internalName
)) {
81 return prepopulateBlobCache
;
85 throw new IllegalArgumentException(
86 "Illegal internalName '" + internalName
+ " ' provided for PrepopulateBlobCache.");
90 * <p>Returns the byte value of the enumerations value.</p>
92 * @return byte representation
94 public byte getValue() {
99 * <p>Returns the library name of the prepopulate blob cache mode
100 * identified by the enumeration value.</p>
102 * @return library name
104 public String
getLibraryName() {
108 PrepopulateBlobCache(final byte value
, final String libraryName
, final String internalName
) {
110 libraryName_
= libraryName
;
111 internalName_
= internalName
;
114 private final byte value_
;
115 private final String libraryName_
;
116 private final String internalName_
;