|
|
|
@ -7,28 +7,43 @@ package org.rocksdb; |
|
|
|
|
/** |
|
|
|
|
* The config for plain table sst format. |
|
|
|
|
* |
|
|
|
|
* PlainTable is a RocksDB's SST file format optimized for low query latency |
|
|
|
|
* on pure-memory or really low-latency media. It also support prefix |
|
|
|
|
* hash feature. |
|
|
|
|
* <p>PlainTable is a RocksDB's SST file format optimized for low query |
|
|
|
|
* latency on pure-memory or really low-latency media.</p> |
|
|
|
|
* |
|
|
|
|
* <p>It also support prefix hash feature.</p> |
|
|
|
|
*/ |
|
|
|
|
public class PlainTableConfig extends TableFormatConfig { |
|
|
|
|
public static final int VARIABLE_LENGTH = 0; |
|
|
|
|
public static final int DEFAULT_BLOOM_BITS_PER_KEY = 10; |
|
|
|
|
public static final double DEFAULT_HASH_TABLE_RATIO = 0.75; |
|
|
|
|
public static final int DEFAULT_INDEX_SPARSENESS = 16; |
|
|
|
|
public static final int DEFAULT_HUGE_TLB_SIZE = 0; |
|
|
|
|
public static final EncodingType DEFAULT_ENCODING_TYPE = |
|
|
|
|
EncodingType.kPlain; |
|
|
|
|
public static final boolean DEFAULT_FULL_SCAN_MODE = false; |
|
|
|
|
public static final boolean DEFAULT_STORE_INDEX_IN_FILE |
|
|
|
|
= false; |
|
|
|
|
|
|
|
|
|
public PlainTableConfig() { |
|
|
|
|
keySize_ = VARIABLE_LENGTH; |
|
|
|
|
bloomBitsPerKey_ = DEFAULT_BLOOM_BITS_PER_KEY; |
|
|
|
|
hashTableRatio_ = DEFAULT_HASH_TABLE_RATIO; |
|
|
|
|
indexSparseness_ = DEFAULT_INDEX_SPARSENESS; |
|
|
|
|
hugePageTlbSize_ = DEFAULT_HUGE_TLB_SIZE; |
|
|
|
|
encodingType_ = DEFAULT_ENCODING_TYPE; |
|
|
|
|
fullScanMode_ = DEFAULT_FULL_SCAN_MODE; |
|
|
|
|
storeIndexInFile_ = DEFAULT_STORE_INDEX_IN_FILE; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Set the length of the user key. If it is set to be VARIABLE_LENGTH, |
|
|
|
|
* then it indicates the user keys are variable-lengthed. Otherwise, |
|
|
|
|
* all the keys need to have the same length in byte. |
|
|
|
|
* DEFAULT: VARIABLE_LENGTH |
|
|
|
|
* <p>Set the length of the user key. If it is set to be |
|
|
|
|
* VARIABLE_LENGTH, then it indicates the user keys are |
|
|
|
|
* of variable length.</p> |
|
|
|
|
* |
|
|
|
|
* <p>Otherwise,all the keys need to have the same length |
|
|
|
|
* in byte.</p> |
|
|
|
|
* |
|
|
|
|
* <p>DEFAULT: VARIABLE_LENGTH</p> |
|
|
|
|
* |
|
|
|
|
* @param keySize the length of the user key. |
|
|
|
|
* @return the reference to the current config. |
|
|
|
@ -103,21 +118,134 @@ public class PlainTableConfig extends TableFormatConfig { |
|
|
|
|
/** |
|
|
|
|
* @return the index sparseness. |
|
|
|
|
*/ |
|
|
|
|
public int indexSparseness() { |
|
|
|
|
public long indexSparseness() { |
|
|
|
|
return indexSparseness_; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* <p>huge_page_tlb_size: if <=0, allocate hash indexes and blooms |
|
|
|
|
* from malloc otherwise from huge page TLB.</p> |
|
|
|
|
* |
|
|
|
|
* <p>The user needs to reserve huge pages for it to be allocated, |
|
|
|
|
* like: {@code sysctl -w vm.nr_hugepages=20}</p> |
|
|
|
|
* |
|
|
|
|
* <p>See linux doc Documentation/vm/hugetlbpage.txt</p> |
|
|
|
|
* |
|
|
|
|
* @param hugePageTlbSize |
|
|
|
|
* @return the reference to the current config. |
|
|
|
|
*/ |
|
|
|
|
public PlainTableConfig setHugePageTlbSize(int hugePageTlbSize) { |
|
|
|
|
this.hugePageTlbSize_ = hugePageTlbSize; |
|
|
|
|
return this; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Returns the value for huge page tlb size |
|
|
|
|
* |
|
|
|
|
* @return hugePageTlbSize |
|
|
|
|
*/ |
|
|
|
|
public int hugePageTlbSize() { |
|
|
|
|
return hugePageTlbSize_; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Sets the encoding type. |
|
|
|
|
* |
|
|
|
|
* <p>This setting determines how to encode |
|
|
|
|
* the keys. See enum {@link EncodingType} for |
|
|
|
|
* the choices.</p> |
|
|
|
|
* |
|
|
|
|
* <p>The value will determine how to encode keys |
|
|
|
|
* when writing to a new SST file. This value will be stored |
|
|
|
|
* inside the SST file which will be used when reading from |
|
|
|
|
* the file, which makes it possible for users to choose |
|
|
|
|
* different encoding type when reopening a DB. Files with |
|
|
|
|
* different encoding types can co-exist in the same DB and |
|
|
|
|
* can be read.</p> |
|
|
|
|
* |
|
|
|
|
* @param encodingType {@link org.rocksdb.EncodingType} value. |
|
|
|
|
* @return the reference to the current config. |
|
|
|
|
*/ |
|
|
|
|
public PlainTableConfig setEncodingType(EncodingType encodingType) { |
|
|
|
|
this.encodingType_ = encodingType; |
|
|
|
|
return this; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Returns the active EncodingType |
|
|
|
|
* |
|
|
|
|
* @return currently set encoding type |
|
|
|
|
*/ |
|
|
|
|
public EncodingType encodingType() { |
|
|
|
|
return encodingType_; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Set full scan mode, if true the whole file will be read |
|
|
|
|
* one record by one without using the index. |
|
|
|
|
* |
|
|
|
|
* @param fullScanMode boolean value indicating if full |
|
|
|
|
* scan mode shall be enabled. |
|
|
|
|
* @return the reference to the current config. |
|
|
|
|
*/ |
|
|
|
|
public PlainTableConfig setFullScanMode(boolean fullScanMode) { |
|
|
|
|
this.fullScanMode_ = fullScanMode; |
|
|
|
|
return this; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Return if full scan mode is active |
|
|
|
|
* @return boolean value indicating if the full scan mode is |
|
|
|
|
* enabled. |
|
|
|
|
*/ |
|
|
|
|
public boolean fullScanMode() { |
|
|
|
|
return fullScanMode_; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* <p>If set to true: compute plain table index and bloom |
|
|
|
|
* filter during file building and store it in file. |
|
|
|
|
* When reading file, index will be mmaped instead |
|
|
|
|
* of doing recomputation.</p> |
|
|
|
|
* |
|
|
|
|
* @param storeIndexInFile value indicating if index shall |
|
|
|
|
* be stored in a file |
|
|
|
|
* @return the reference to the current config. |
|
|
|
|
*/ |
|
|
|
|
public PlainTableConfig setStoreIndexInFile(boolean storeIndexInFile) { |
|
|
|
|
this.storeIndexInFile_ = storeIndexInFile; |
|
|
|
|
return this; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Return a boolean value indicating if index shall be stored |
|
|
|
|
* in a file. |
|
|
|
|
* |
|
|
|
|
* @return currently set value for store index in file. |
|
|
|
|
*/ |
|
|
|
|
public boolean storeIndexInFile() { |
|
|
|
|
return storeIndexInFile_; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override protected long newTableFactoryHandle() { |
|
|
|
|
return newTableFactoryHandle(keySize_, bloomBitsPerKey_, |
|
|
|
|
hashTableRatio_, indexSparseness_); |
|
|
|
|
hashTableRatio_, indexSparseness_, hugePageTlbSize_, |
|
|
|
|
encodingType_.getValue(), fullScanMode_, |
|
|
|
|
storeIndexInFile_); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private native long newTableFactoryHandle( |
|
|
|
|
int keySize, int bloomBitsPerKey, |
|
|
|
|
double hashTableRatio, int indexSparseness); |
|
|
|
|
double hashTableRatio, int indexSparseness, |
|
|
|
|
int hugePageTlbSize, byte encodingType, |
|
|
|
|
boolean fullScanMode, boolean storeIndexInFile); |
|
|
|
|
|
|
|
|
|
private int keySize_; |
|
|
|
|
private int bloomBitsPerKey_; |
|
|
|
|
private double hashTableRatio_; |
|
|
|
|
private int indexSparseness_; |
|
|
|
|
private int hugePageTlbSize_; |
|
|
|
|
private EncodingType encodingType_; |
|
|
|
|
private boolean fullScanMode_; |
|
|
|
|
private boolean storeIndexInFile_; |
|
|
|
|
} |
|
|
|
|