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 package org.rocksdb;
6 
7 /**
8  * A CompactionFilter allows an application to modify/delete a key-value at
9  * the time of compaction.
10  *
11  * At present we just permit an overriding Java class to wrap a C++
12  * implementation
13  */
14 public abstract class AbstractCompactionFilter<T extends AbstractSlice<?>>
15     extends RocksObject {
16 
17   public static class Context {
18     private final boolean fullCompaction;
19     private final boolean manualCompaction;
20 
Context(final boolean fullCompaction, final boolean manualCompaction)21     public Context(final boolean fullCompaction, final boolean manualCompaction) {
22       this.fullCompaction = fullCompaction;
23       this.manualCompaction = manualCompaction;
24     }
25 
26     /**
27      * Does this compaction run include all data files
28      *
29      * @return true if this is a full compaction run
30      */
isFullCompaction()31     public boolean isFullCompaction() {
32       return fullCompaction;
33     }
34 
35     /**
36      * Is this compaction requested by the client,
37      * or is it occurring as an automatic compaction process
38      *
39      * @return true if the compaction was initiated by the client
40      */
isManualCompaction()41     public boolean isManualCompaction() {
42       return manualCompaction;
43     }
44   }
45 
AbstractCompactionFilter(final long nativeHandle)46   protected AbstractCompactionFilter(final long nativeHandle) {
47     super(nativeHandle);
48   }
49 
50   /**
51    * Deletes underlying C++ compaction pointer.
52    *
53    * Note that this function should be called only after all
54    * RocksDB instances referencing the compaction filter are closed.
55    * Otherwise an undefined behavior will occur.
56    */
57   @Override
disposeInternal(final long handle)58   protected final native void disposeInternal(final long handle);
59 }
60