| 141 | } |
| 142 | |
| 143 | func newOptions(cfg *config.LevelDBConfig) *opt.Options { |
| 144 | opts := &opt.Options{} |
| 145 | opts.ErrorIfMissing = false |
| 146 | |
| 147 | opts.BlockCacheCapacity = cfg.CacheSize |
| 148 | |
| 149 | // we must use bloomfilter |
| 150 | opts.Filter = filter.NewBloomFilter(defaultFilterBits) |
| 151 | |
| 152 | if !cfg.Compression { |
| 153 | opts.Compression = opt.NoCompression |
| 154 | } else { |
| 155 | opts.Compression = opt.SnappyCompression |
| 156 | } |
| 157 | |
| 158 | opts.BlockSize = cfg.BlockSize |
| 159 | opts.WriteBuffer = cfg.WriteBufferSize |
| 160 | opts.OpenFilesCacheCapacity = cfg.MaxOpenFiles |
| 161 | |
| 162 | // here we use default value, later add config support |
| 163 | opts.CompactionTableSize = 32 * 1024 * 1024 |
| 164 | opts.WriteL0SlowdownTrigger = 16 |
| 165 | opts.WriteL0PauseTrigger = 64 |
| 166 | |
| 167 | return opts |
| 168 | } |
| 169 | |
| 170 | func (db *DB) Close() error { |
| 171 | db.cache.Close() |