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 public enum CompactionReason {
9   kUnknown((byte)0x0),
10 
11   /**
12    * [Level] number of L0 files > level0_file_num_compaction_trigger
13    */
14   kLevelL0FilesNum((byte)0x1),
15 
16   /**
17    * [Level] total size of level > MaxBytesForLevel()
18    */
19   kLevelMaxLevelSize((byte)0x2),
20 
21   /**
22    * [Universal] Compacting for size amplification
23    */
24   kUniversalSizeAmplification((byte)0x3),
25 
26   /**
27    * [Universal] Compacting for size ratio
28    */
29   kUniversalSizeRatio((byte)0x4),
30 
31   /**
32    * [Universal] number of sorted runs > level0_file_num_compaction_trigger
33    */
34   kUniversalSortedRunNum((byte)0x5),
35 
36   /**
37    * [FIFO] total size > max_table_files_size
38    */
39   kFIFOMaxSize((byte)0x6),
40 
41   /**
42    * [FIFO] reduce number of files.
43    */
44   kFIFOReduceNumFiles((byte)0x7),
45 
46   /**
47    * [FIFO] files with creation time < (current_time - interval)
48    */
49   kFIFOTtl((byte)0x8),
50 
51   /**
52    * Manual compaction
53    */
54   kManualCompaction((byte)0x9),
55 
56   /**
57    * DB::SuggestCompactRange() marked files for compaction
58    */
59   kFilesMarkedForCompaction((byte)0x10),
60 
61   /**
62    * [Level] Automatic compaction within bottommost level to cleanup duplicate
63    * versions of same user key, usually due to a released snapshot.
64    */
65   kBottommostFiles((byte)0x0A),
66 
67   /**
68    * Compaction based on TTL
69    */
70   kTtl((byte)0x0B),
71 
72   /**
73    * According to the comments in flush_job.cc, RocksDB treats flush as
74    * a level 0 compaction in internal stats.
75    */
76   kFlush((byte)0x0C),
77 
78   /**
79    * Compaction caused by external sst file ingestion
80    */
81   kExternalSstIngestion((byte)0x0D);
82 
83   private final byte value;
84 
CompactionReason(final byte value)85   CompactionReason(final byte value) {
86     this.value = value;
87   }
88 
89   /**
90    * Get the internal representation value.
91    *
92    * @return the internal representation value
93    */
getValue()94   byte getValue() {
95     return value;
96   }
97 
98   /**
99    * Get the CompactionReason from the internal representation value.
100    *
101    * @return the compaction reason.
102    *
103    * @throws IllegalArgumentException if the value is unknown.
104    */
fromValue(final byte value)105   static CompactionReason fromValue(final byte value) {
106     for (final CompactionReason compactionReason : CompactionReason.values()) {
107       if(compactionReason.value == value) {
108         return compactionReason;
109       }
110     }
111 
112     throw new IllegalArgumentException(
113         "Illegal value provided for CompactionReason: " + value);
114   }
115 }
116