1 // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. 2 package org.rocksdb; 3 4 /** 5 * The config for hash skip-list mem-table representation. 6 * Such mem-table representation contains a fix-sized array of 7 * buckets, where each bucket points to a skiplist (or null if the 8 * bucket is empty). 9 * 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. 16 */ 17 public class HashSkipListMemTableConfig extends MemTableConfig { 18 public static final int DEFAULT_BUCKET_COUNT = 1000000; 19 public static final int DEFAULT_BRANCHING_FACTOR = 4; 20 public static final int DEFAULT_HEIGHT = 4; 21 22 /** 23 * HashSkipListMemTableConfig constructor 24 */ HashSkipListMemTableConfig()25 public HashSkipListMemTableConfig() { 26 bucketCount_ = DEFAULT_BUCKET_COUNT; 27 branchingFactor_ = DEFAULT_BRANCHING_FACTOR; 28 height_ = DEFAULT_HEIGHT; 29 } 30 31 /** 32 * Set the number of hash buckets used in the hash skiplist memtable. 33 * Default = 1000000. 34 * 35 * @param count the number of hash buckets used in the hash 36 * skiplist memtable. 37 * @return the reference to the current HashSkipListMemTableConfig. 38 */ setBucketCount( final long count)39 public HashSkipListMemTableConfig setBucketCount( 40 final long count) { 41 bucketCount_ = count; 42 return this; 43 } 44 45 /** 46 * @return the number of hash buckets 47 */ bucketCount()48 public long bucketCount() { 49 return bucketCount_; 50 } 51 52 /** 53 * Set the height of the skip list. Default = 4. 54 * 55 * @param height height to set. 56 * 57 * @return the reference to the current HashSkipListMemTableConfig. 58 */ setHeight(final int height)59 public HashSkipListMemTableConfig setHeight(final int height) { 60 height_ = height; 61 return this; 62 } 63 64 /** 65 * @return the height of the skip list. 66 */ height()67 public int height() { 68 return height_; 69 } 70 71 /** 72 * Set the branching factor used in the hash skip-list memtable. 73 * This factor controls the probabilistic size ratio between adjacent 74 * links in the skip list. 75 * 76 * @param bf the probabilistic size ratio between adjacent link 77 * lists in the skip list. 78 * @return the reference to the current HashSkipListMemTableConfig. 79 */ setBranchingFactor( final int bf)80 public HashSkipListMemTableConfig setBranchingFactor( 81 final int bf) { 82 branchingFactor_ = bf; 83 return this; 84 } 85 86 /** 87 * @return branching factor, the probabilistic size ratio between 88 * adjacent links in the skip list. 89 */ branchingFactor()90 public int branchingFactor() { 91 return branchingFactor_; 92 } 93 newMemTableFactoryHandle()94 @Override protected long newMemTableFactoryHandle() { 95 return newMemTableFactoryHandle( 96 bucketCount_, height_, branchingFactor_); 97 } 98 newMemTableFactoryHandle( long bucketCount, int height, int branchingFactor)99 private native long newMemTableFactoryHandle( 100 long bucketCount, int height, int branchingFactor) 101 throws IllegalArgumentException; 102 103 private long bucketCount_; 104 private int branchingFactor_; 105 private int height_; 106 } 107