1 // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
5 * The config for hash linked list memtable representation
6 * Such memtable contains a fix-sized array of buckets, where
7 * each bucket points to a sorted singly-linked
8 * list (or null if the bucket is empty).
10 * Note that since this mem-table representation relies on the
11 * key prefix, it is required to invoke one of the usePrefixExtractor
12 * functions to specify how to extract key prefix given a key.
13 * If proper prefix-extractor is not set, then RocksDB will
14 * use the default memtable representation (SkipList) instead
15 * and post a warning in the LOG.
17 public class HashLinkedListMemTableConfig
extends MemTableConfig
{
18 public static final long DEFAULT_BUCKET_COUNT
= 50000;
19 public static final long DEFAULT_HUGE_PAGE_TLB_SIZE
= 0;
20 public static final int DEFAULT_BUCKET_ENTRIES_LOG_THRES
= 4096;
21 public static final boolean
22 DEFAULT_IF_LOG_BUCKET_DIST_WHEN_FLUSH
= true;
23 public static final int DEFAUL_THRESHOLD_USE_SKIPLIST
= 256;
26 * HashLinkedListMemTableConfig constructor
28 public HashLinkedListMemTableConfig() {
29 bucketCount_
= DEFAULT_BUCKET_COUNT
;
30 hugePageTlbSize_
= DEFAULT_HUGE_PAGE_TLB_SIZE
;
31 bucketEntriesLoggingThreshold_
= DEFAULT_BUCKET_ENTRIES_LOG_THRES
;
32 ifLogBucketDistWhenFlush_
= DEFAULT_IF_LOG_BUCKET_DIST_WHEN_FLUSH
;
33 thresholdUseSkiplist_
= DEFAUL_THRESHOLD_USE_SKIPLIST
;
37 * Set the number of buckets in the fixed-size array used
38 * in the hash linked-list mem-table.
40 * @param count the number of hash buckets.
41 * @return the reference to the current HashLinkedListMemTableConfig.
43 public HashLinkedListMemTableConfig
setBucketCount(
50 * Returns the number of buckets that will be used in the memtable
51 * created based on this config.
53 * @return the number of buckets
55 public long bucketCount() {
60 * <p>Set the size of huge tlb or allocate the hashtable bytes from
61 * malloc if {@code size <= 0}.</p>
63 * <p>The user needs to reserve huge pages for it to be allocated,
64 * like: {@code sysctl -w vm.nr_hugepages=20}</p>
66 * <p>See linux documentation/vm/hugetlbpage.txt</p>
68 * @param size if set to {@code <= 0} hashtable bytes from malloc
69 * @return the reference to the current HashLinkedListMemTableConfig.
71 public HashLinkedListMemTableConfig
setHugePageTlbSize(
73 hugePageTlbSize_
= size
;
78 * Returns the size value of hugePageTlbSize.
80 * @return the hugePageTlbSize.
82 public long hugePageTlbSize() {
83 return hugePageTlbSize_
;
87 * If number of entries in one bucket exceeds that setting, log
90 * @param threshold - number of entries in a single bucket before
92 * @return the reference to the current HashLinkedListMemTableConfig.
94 public HashLinkedListMemTableConfig
95 setBucketEntriesLoggingThreshold(final int threshold
) {
96 bucketEntriesLoggingThreshold_
= threshold
;
101 * Returns the maximum number of entries in one bucket before
104 * @return maximum number of entries in one bucket before logging
107 public int bucketEntriesLoggingThreshold() {
108 return bucketEntriesLoggingThreshold_
;
112 * If true the distrubition of number of entries will be logged.
114 * @param logDistribution - boolean parameter indicating if number
115 * of entry distribution shall be logged.
116 * @return the reference to the current HashLinkedListMemTableConfig.
118 public HashLinkedListMemTableConfig
119 setIfLogBucketDistWhenFlush(final boolean logDistribution
) {
120 ifLogBucketDistWhenFlush_
= logDistribution
;
125 * Returns information about logging the distribution of
126 * number of entries on flush.
128 * @return if distribution of number of entries shall be logged.
130 public boolean ifLogBucketDistWhenFlush() {
131 return ifLogBucketDistWhenFlush_
;
135 * Set maximum number of entries in one bucket. Exceeding this val
136 * leads to a switch from LinkedList to SkipList.
138 * @param threshold maximum number of entries before SkipList is
140 * @return the reference to the current HashLinkedListMemTableConfig.
142 public HashLinkedListMemTableConfig
143 setThresholdUseSkiplist(final int threshold
) {
144 thresholdUseSkiplist_
= threshold
;
149 * Returns entries per bucket threshold before LinkedList is
150 * replaced by SkipList usage for that bucket.
152 * @return entries per bucket threshold before SkipList is used.
154 public int thresholdUseSkiplist() {
155 return thresholdUseSkiplist_
;
158 @Override protected long newMemTableFactoryHandle() {
159 return newMemTableFactoryHandle(bucketCount_
, hugePageTlbSize_
,
160 bucketEntriesLoggingThreshold_
, ifLogBucketDistWhenFlush_
,
161 thresholdUseSkiplist_
);
164 private native long newMemTableFactoryHandle(long bucketCount
,
165 long hugePageTlbSize
, int bucketEntriesLoggingThreshold
,
166 boolean ifLogBucketDistWhenFlush
, int thresholdUseSkiplist
)
167 throws IllegalArgumentException
;
169 private long bucketCount_
;
170 private long hugePageTlbSize_
;
171 private int bucketEntriesLoggingThreshold_
;
172 private boolean ifLogBucketDistWhenFlush_
;
173 private int thresholdUseSkiplist_
;