1 package org.rocksdb; 2 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved. 3 // This source code is licensed under both the GPLv2 (found in the 4 // COPYING file in the root directory) and Apache 2.0 License 5 // (found in the LICENSE.Apache file in the root directory). 6 7 import java.util.List; 8 9 /** 10 * IngestExternalFileOptions is used by 11 * {@link RocksDB#ingestExternalFile(ColumnFamilyHandle, List, IngestExternalFileOptions)}. 12 */ 13 public class IngestExternalFileOptions extends RocksObject { 14 IngestExternalFileOptions()15 public IngestExternalFileOptions() { 16 super(newIngestExternalFileOptions()); 17 } 18 19 /** 20 * @param moveFiles {@link #setMoveFiles(boolean)} 21 * @param snapshotConsistency {@link #setSnapshotConsistency(boolean)} 22 * @param allowGlobalSeqNo {@link #setAllowGlobalSeqNo(boolean)} 23 * @param allowBlockingFlush {@link #setAllowBlockingFlush(boolean)} 24 */ IngestExternalFileOptions(final boolean moveFiles, final boolean snapshotConsistency, final boolean allowGlobalSeqNo, final boolean allowBlockingFlush)25 public IngestExternalFileOptions(final boolean moveFiles, 26 final boolean snapshotConsistency, final boolean allowGlobalSeqNo, 27 final boolean allowBlockingFlush) { 28 super(newIngestExternalFileOptions(moveFiles, snapshotConsistency, 29 allowGlobalSeqNo, allowBlockingFlush)); 30 } 31 32 /** 33 * Can be set to true to move the files instead of copying them. 34 * 35 * @return true if files will be moved 36 */ moveFiles()37 public boolean moveFiles() { 38 return moveFiles(nativeHandle_); 39 } 40 41 /** 42 * Can be set to true to move the files instead of copying them. 43 * 44 * @param moveFiles true if files should be moved instead of copied 45 * 46 * @return the reference to the current IngestExternalFileOptions. 47 */ setMoveFiles(final boolean moveFiles)48 public IngestExternalFileOptions setMoveFiles(final boolean moveFiles) { 49 setMoveFiles(nativeHandle_, moveFiles); 50 return this; 51 } 52 53 /** 54 * If set to false, an ingested file keys could appear in existing snapshots 55 * that where created before the file was ingested. 56 * 57 * @return true if snapshot consistency is assured 58 */ snapshotConsistency()59 public boolean snapshotConsistency() { 60 return snapshotConsistency(nativeHandle_); 61 } 62 63 /** 64 * If set to false, an ingested file keys could appear in existing snapshots 65 * that where created before the file was ingested. 66 * 67 * @param snapshotConsistency true if snapshot consistency is required 68 * 69 * @return the reference to the current IngestExternalFileOptions. 70 */ setSnapshotConsistency( final boolean snapshotConsistency)71 public IngestExternalFileOptions setSnapshotConsistency( 72 final boolean snapshotConsistency) { 73 setSnapshotConsistency(nativeHandle_, snapshotConsistency); 74 return this; 75 } 76 77 /** 78 * If set to false, {@link RocksDB#ingestExternalFile(ColumnFamilyHandle, List, IngestExternalFileOptions)} 79 * will fail if the file key range overlaps with existing keys or tombstones in the DB. 80 * 81 * @return true if global seq numbers are assured 82 */ allowGlobalSeqNo()83 public boolean allowGlobalSeqNo() { 84 return allowGlobalSeqNo(nativeHandle_); 85 } 86 87 /** 88 * If set to false, {@link RocksDB#ingestExternalFile(ColumnFamilyHandle, List, IngestExternalFileOptions)} 89 * will fail if the file key range overlaps with existing keys or tombstones in the DB. 90 * 91 * @param allowGlobalSeqNo true if global seq numbers are required 92 * 93 * @return the reference to the current IngestExternalFileOptions. 94 */ setAllowGlobalSeqNo( final boolean allowGlobalSeqNo)95 public IngestExternalFileOptions setAllowGlobalSeqNo( 96 final boolean allowGlobalSeqNo) { 97 setAllowGlobalSeqNo(nativeHandle_, allowGlobalSeqNo); 98 return this; 99 } 100 101 /** 102 * If set to false and the file key range overlaps with the memtable key range 103 * (memtable flush required), IngestExternalFile will fail. 104 * 105 * @return true if blocking flushes may occur 106 */ allowBlockingFlush()107 public boolean allowBlockingFlush() { 108 return allowBlockingFlush(nativeHandle_); 109 } 110 111 /** 112 * If set to false and the file key range overlaps with the memtable key range 113 * (memtable flush required), IngestExternalFile will fail. 114 * 115 * @param allowBlockingFlush true if blocking flushes are allowed 116 * 117 * @return the reference to the current IngestExternalFileOptions. 118 */ setAllowBlockingFlush( final boolean allowBlockingFlush)119 public IngestExternalFileOptions setAllowBlockingFlush( 120 final boolean allowBlockingFlush) { 121 setAllowBlockingFlush(nativeHandle_, allowBlockingFlush); 122 return this; 123 } 124 125 /** 126 * Returns true if duplicate keys in the file being ingested are 127 * to be skipped rather than overwriting existing data under that key. 128 * 129 * @return true if duplicate keys in the file being ingested are to be 130 * skipped, false otherwise. 131 */ ingestBehind()132 public boolean ingestBehind() { 133 return ingestBehind(nativeHandle_); 134 } 135 136 /** 137 * Set to true if you would like duplicate keys in the file being ingested 138 * to be skipped rather than overwriting existing data under that key. 139 * 140 * Usecase: back-fill of some historical data in the database without 141 * over-writing existing newer version of data. 142 * 143 * This option could only be used if the DB has been running 144 * with DBOptions#allowIngestBehind() == true since the dawn of time. 145 * 146 * All files will be ingested at the bottommost level with seqno=0. 147 * 148 * Default: false 149 * 150 * @param ingestBehind true if you would like duplicate keys in the file being 151 * ingested to be skipped. 152 * 153 * @return the reference to the current IngestExternalFileOptions. 154 */ setIngestBehind(final boolean ingestBehind)155 public IngestExternalFileOptions setIngestBehind(final boolean ingestBehind) { 156 setIngestBehind(nativeHandle_, ingestBehind); 157 return this; 158 } 159 160 /** 161 * Returns true write if the global_seqno is written to a given offset 162 * in the external SST file for backward compatibility. 163 * 164 * See {@link #setWriteGlobalSeqno(boolean)}. 165 * 166 * @return true if the global_seqno is written to a given offset, 167 * false otherwise. 168 */ writeGlobalSeqno()169 public boolean writeGlobalSeqno() { 170 return writeGlobalSeqno(nativeHandle_); 171 } 172 173 /** 174 * Set to true if you would like to write the global_seqno to a given offset 175 * in the external SST file for backward compatibility. 176 * 177 * Older versions of RocksDB write the global_seqno to a given offset within 178 * the ingested SST files, and new versions of RocksDB do not. 179 * 180 * If you ingest an external SST using new version of RocksDB and would like 181 * to be able to downgrade to an older version of RocksDB, you should set 182 * {@link #writeGlobalSeqno()} to true. 183 * 184 * If your service is just starting to use the new RocksDB, we recommend that 185 * you set this option to false, which brings two benefits: 186 * 1. No extra random write for global_seqno during ingestion. 187 * 2. Without writing external SST file, it's possible to do checksum. 188 * 189 * We have a plan to set this option to false by default in the future. 190 * 191 * Default: true 192 * 193 * @param writeGlobalSeqno true to write the gloal_seqno to a given offset, 194 * false otherwise 195 * 196 * @return the reference to the current IngestExternalFileOptions. 197 */ setWriteGlobalSeqno( final boolean writeGlobalSeqno)198 public IngestExternalFileOptions setWriteGlobalSeqno( 199 final boolean writeGlobalSeqno) { 200 setWriteGlobalSeqno(nativeHandle_, writeGlobalSeqno); 201 return this; 202 } 203 newIngestExternalFileOptions()204 private native static long newIngestExternalFileOptions(); newIngestExternalFileOptions( final boolean moveFiles, final boolean snapshotConsistency, final boolean allowGlobalSeqNo, final boolean allowBlockingFlush)205 private native static long newIngestExternalFileOptions( 206 final boolean moveFiles, final boolean snapshotConsistency, 207 final boolean allowGlobalSeqNo, final boolean allowBlockingFlush); disposeInternal(final long handle)208 @Override protected final native void disposeInternal(final long handle); 209 moveFiles(final long handle)210 private native boolean moveFiles(final long handle); setMoveFiles(final long handle, final boolean move_files)211 private native void setMoveFiles(final long handle, final boolean move_files); snapshotConsistency(final long handle)212 private native boolean snapshotConsistency(final long handle); setSnapshotConsistency(final long handle, final boolean snapshotConsistency)213 private native void setSnapshotConsistency(final long handle, 214 final boolean snapshotConsistency); allowGlobalSeqNo(final long handle)215 private native boolean allowGlobalSeqNo(final long handle); setAllowGlobalSeqNo(final long handle, final boolean allowGloablSeqNo)216 private native void setAllowGlobalSeqNo(final long handle, 217 final boolean allowGloablSeqNo); allowBlockingFlush(final long handle)218 private native boolean allowBlockingFlush(final long handle); setAllowBlockingFlush(final long handle, final boolean allowBlockingFlush)219 private native void setAllowBlockingFlush(final long handle, 220 final boolean allowBlockingFlush); ingestBehind(final long handle)221 private native boolean ingestBehind(final long handle); setIngestBehind(final long handle, final boolean ingestBehind)222 private native void setIngestBehind(final long handle, 223 final boolean ingestBehind); writeGlobalSeqno(final long handle)224 private native boolean writeGlobalSeqno(final long handle); setWriteGlobalSeqno(final long handle, final boolean writeGlobalSeqNo)225 private native void setWriteGlobalSeqno(final long handle, 226 final boolean writeGlobalSeqNo); 227 } 228