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 import java.util.List; 9 10 /** 11 * Enum CompactionStyle 12 * 13 * RocksDB supports different styles of compaction. Available 14 * compaction styles can be chosen using this enumeration. 15 * 16 * <ol> 17 * <li><strong>LEVEL</strong> - Level based Compaction style</li> 18 * <li><strong>UNIVERSAL</strong> - Universal Compaction Style is a 19 * compaction style, targeting the use cases requiring lower write 20 * amplification, trading off read amplification and space 21 * amplification.</li> 22 * <li><strong>FIFO</strong> - FIFO compaction style is the simplest 23 * compaction strategy. It is suited for keeping event log data with 24 * very low overhead (query log for example). It periodically deletes 25 * the old data, so it's basically a TTL compaction style.</li> 26 * <li><strong>NONE</strong> - Disable background compaction. 27 * Compaction jobs are submitted 28 * {@link RocksDB#compactFiles(CompactionOptions, ColumnFamilyHandle, List, int, int, CompactionJobInfo)} ()}.</li> 29 * </ol> 30 * 31 * @see <a 32 * href="https://github.com/facebook/rocksdb/wiki/Universal-Compaction"> 33 * Universal Compaction</a> 34 * @see <a 35 * href="https://github.com/facebook/rocksdb/wiki/FIFO-compaction-style"> 36 * FIFO Compaction</a> 37 */ 38 public enum CompactionStyle { 39 LEVEL((byte) 0x0), 40 UNIVERSAL((byte) 0x1), 41 FIFO((byte) 0x2), 42 NONE((byte) 0x3); 43 44 private final byte value; 45 CompactionStyle(final byte value)46 CompactionStyle(final byte value) { 47 this.value = value; 48 } 49 50 /** 51 * Get the internal representation value. 52 * 53 * @return the internal representation value. 54 */ 55 //TODO(AR) should be made package-private getValue()56 public byte getValue() { 57 return value; 58 } 59 60 /** 61 * Get the Compaction style from the internal representation value. 62 * 63 * @param value the internal representation value. 64 * 65 * @return the Compaction style 66 * 67 * @throws IllegalArgumentException if the value does not match a 68 * CompactionStyle 69 */ fromValue(final byte value)70 static CompactionStyle fromValue(final byte value) 71 throws IllegalArgumentException { 72 for (final CompactionStyle compactionStyle : CompactionStyle.values()) { 73 if (compactionStyle.value == value) { 74 return compactionStyle; 75 } 76 } 77 throw new IllegalArgumentException("Unknown value for CompactionStyle: " 78 + value); 79 } 80 } 81