github.com/zuoyebang/bitalosdb@v1.1.1-0.20240516111551-79a8c4d8ce20/internal/consts/options.go (about) 1 // Copyright 2021 The Bitalosdb author(hustxrb@163.com) and other contributors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package consts 16 17 const ( 18 DefaultBytesPerSync int = 1 << 20 19 DefaultMemTableSize int = 512 << 20 20 DefaultMemTableStopWritesThreshold int = 8 21 DefaultCacheSize int64 = 128 << 20 22 DefaultLruCacheShards int = 128 23 DefaultLruCacheHashSize int = 8 * 1024 * DefaultLruCacheShards 24 DefaultLfuCacheShards int = 256 25 DefaultBitowerNum int = 8 26 DefaultBitowerNumMask int = DefaultBitowerNum - 1 27 ) 28 29 const ( 30 MaxKeySize int = 62 << 10 31 KvSeparateSize int = 256 32 BithashTableMaxSize int = 512 << 20 33 CompactToBitableCiMaxSize int = 512 << 20 34 UseBitableBitreeMaxSize int64 = 24 << 30 35 UseBitableForceCompactMaxSize int64 = 16 << 30 36 BufioWriterBufSize int = 256 << 10 37 ) 38 39 const ( 40 IterSlowCountThreshold = 1280 41 IterReadAmplificationThreshold = 1280 42 DefaultDeletePercent = 0.4 43 MinCompactInterval = 360 44 DefaultCompactInterval = 720 45 DeletionFileInterval = 4 46 ) 47 48 const ( 49 CacheTypeLru int = 1 + iota 50 CacheTypeLfu 51 ) 52 53 const ( 54 FlushDelPercentL1 float64 = 0.3 55 FlushDelPercentL2 float64 = 0.5 56 FlushDelPercentL3 float64 = 0.7 57 FlushDelPercentL4 float64 = 0.9 58 59 FlushItemCountL1 int = 1 << 20 60 FlushItemCountL2 int = 2 << 20 61 FlushItemCountL3 int = 3 << 20 62 ) 63 64 const ( 65 BdbInitialSize int = 64 << 20 66 BdbPageSize int = 4 << 10 67 BdbAllocSize int = 16 << 20 68 69 BdbFreelistArrayType = "array" 70 BdbFreelistMapType = "hashmap" 71 ) 72 73 const ( 74 BitpageBlockCacheShards int = 16 75 BitpageDefaultBlockCacheSize int64 = 1 << 30 76 BitpageBlockSize uint32 = 32 << 10 77 BitpageBlockCacheHashSize int = 24 << 10 78 BitpageBlockMinItemCount int = 40 79 BitpageFlushSize uint64 = 256 << 20 80 BitpageSplitSize uint64 = 592 << 20 81 BitpageSplitNum int = 3 82 BitpageInitMmapSize int = 4 << 30 83 ) 84 85 const ( 86 BitableCacheSize int64 = 1 << 30 87 BitableMemTableSize int = 64 << 20 88 BitableMemTableStopWritesThreshold int = 8 89 BitableL0FileSize int64 = 256 << 20 90 BitableL0CompactionFileThreshold int = 2 91 BitableL0CompactionThreshold int = 2 92 BitableL0StopWritesThreshold int = 128 93 BitableLBaseMaxBytes int64 = 1 << 30 94 BitableMaxOpenFiles int = 5000 95 ) 96 97 const FileMode = 0600 98 99 var ( 100 BdbBucketName = []byte("brt") 101 BdbMaxKey = []byte{0xff, 0xff, 0xff, 0xff} 102 ) 103 104 func CheckFlushDelPercent(delPercent float64, inuse, size uint64) bool { 105 if (delPercent > FlushDelPercentL1 && inuse > size/2) || 106 (delPercent > FlushDelPercentL2 && inuse > size/3) || 107 (delPercent > FlushDelPercentL3 && inuse > size/4) || 108 (delPercent > FlushDelPercentL4 && inuse > size/5) { 109 return true 110 } 111 return false 112 } 113 114 func CheckFlushItemCount(itemCount int, inuse, size uint64) bool { 115 if (itemCount > FlushItemCountL1 && inuse > (size*3/5)) || 116 (itemCount > FlushItemCountL2 && inuse > (size/2)) || 117 (itemCount > FlushItemCountL3 && inuse > (size*2/5)) { 118 return true 119 } 120 return false 121 }