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  * CompactionOptions are used in
12  * {@link RocksDB#compactFiles(CompactionOptions, ColumnFamilyHandle, List, int, int, CompactionJobInfo)}
13  * calls.
14  */
15 public class CompactionOptions extends RocksObject {
16 
CompactionOptions()17   public CompactionOptions() {
18     super(newCompactionOptions());
19   }
20 
21   /**
22    * Get the compaction output compression type.
23    *
24    * See {@link #setCompression(CompressionType)}.
25    *
26    * @return the compression type.
27    */
compression()28   public CompressionType compression() {
29     return CompressionType.getCompressionType(
30         compression(nativeHandle_));
31   }
32 
33   /**
34    * Set the compaction output compression type.
35    *
36    * Default: snappy
37    *
38    * If set to {@link CompressionType#DISABLE_COMPRESSION_OPTION},
39    * RocksDB will choose compression type according to the
40    * {@link ColumnFamilyOptions#compressionType()}, taking into account
41    * the output level if {@link ColumnFamilyOptions#compressionPerLevel()}
42    * is specified.
43    *
44    * @param compression the compression type to use for compaction output.
45    *
46    * @return the instance of the current Options.
47    */
setCompression(final CompressionType compression)48   public CompactionOptions setCompression(final CompressionType compression) {
49     setCompression(nativeHandle_, compression.getValue());
50     return this;
51   }
52 
53   /**
54    * Get the compaction output file size limit.
55    *
56    * See {@link #setOutputFileSizeLimit(long)}.
57    *
58    * @return the file size limit.
59    */
outputFileSizeLimit()60   public long outputFileSizeLimit() {
61     return outputFileSizeLimit(nativeHandle_);
62   }
63 
64   /**
65    * Compaction will create files of size {@link #outputFileSizeLimit()}.
66    *
67    * Default: 2^64-1, which means that compaction will create a single file
68    *
69    * @param outputFileSizeLimit the size limit
70    *
71    * @return the instance of the current Options.
72    */
setOutputFileSizeLimit( final long outputFileSizeLimit)73   public CompactionOptions setOutputFileSizeLimit(
74       final long outputFileSizeLimit) {
75     setOutputFileSizeLimit(nativeHandle_, outputFileSizeLimit);
76     return this;
77   }
78 
79   /**
80    * Get the maximum number of threads that will concurrently perform a
81    * compaction job.
82    *
83    * @return the maximum number of threads.
84    */
maxSubcompactions()85   public int maxSubcompactions() {
86     return maxSubcompactions(nativeHandle_);
87   }
88 
89   /**
90    * This value represents the maximum number of threads that will
91    * concurrently perform a compaction job by breaking it into multiple,
92    * smaller ones that are run simultaneously.
93    *
94    * Default: 0 (i.e. no subcompactions)
95    *
96    * If > 0, it will replace the option in
97    * {@link DBOptions#maxSubcompactions()} for this compaction.
98    *
99    * @param maxSubcompactions The maximum number of threads that will
100    *     concurrently perform a compaction job
101    *
102    * @return the instance of the current Options.
103    */
setMaxSubcompactions(final int maxSubcompactions)104   public CompactionOptions setMaxSubcompactions(final int maxSubcompactions) {
105     setMaxSubcompactions(nativeHandle_, maxSubcompactions);
106     return this;
107   }
108 
newCompactionOptions()109   private static native long newCompactionOptions();
disposeInternal(final long handle)110   @Override protected final native void disposeInternal(final long handle);
111 
compression(final long handle)112   private static native byte compression(final long handle);
setCompression(final long handle, final byte compressionTypeValue)113   private static native void setCompression(final long handle,
114       final byte compressionTypeValue);
outputFileSizeLimit(final long handle)115   private static native long outputFileSizeLimit(final long handle);
setOutputFileSizeLimit(final long handle, final long outputFileSizeLimit)116   private static native void setOutputFileSizeLimit(final long handle,
117       final long outputFileSizeLimit);
maxSubcompactions(final long handle)118   private static native int maxSubcompactions(final long handle);
setMaxSubcompactions(final long handle, final int maxSubcompactions)119   private static native void setMaxSubcompactions(final long handle,
120       final int maxSubcompactions);
121 }
122