github.com/klaytn/klaytn@v1.12.1/storage/database/rocksdb_database_config.go (about)

     1  // Copyright 2023 The klaytn Authors
     2  // This file is part of the klaytn library.
     3  //
     4  // The klaytn library is free software: you can redistribute it and/or modify
     5  // it under the terms of the GNU Lesser General Public License as published by
     6  // the Free Software Foundation, either version 3 of the License, or
     7  // (at your option) any later version.
     8  //
     9  // The klaytn library is distributed in the hope that it will be useful,
    10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    12  // GNU Lesser General Public License for more details.
    13  //
    14  // You should have received a copy of the GNU Lesser General Public License
    15  // along with the klaytn library. If not, see <http://www.gnu.org/licenses/>.
    16  
    17  package database
    18  
    19  const (
    20  	defaultRocksDBCacheSize    = 2 // 2MB
    21  	defaultBitsPerKey          = 10
    22  	minCacheSizeForRocksDB     = 16
    23  	defaultOpenFilesForRocksDB = 1024
    24  	minOpenFilesForRocksDB     = 16
    25  )
    26  
    27  var properties = []string{
    28  	"rocksdb.num-immutable-mem-table",         // returns number of immutable memtables that have not yet been flushed.
    29  	"rocksdb.mem-table-flush-pending",         // returns 1 if a memtable flush is pending; otherwise, returns 0.
    30  	"rocksdb.compaction-pending",              // returns 1 if at least one compaction is pending; otherwise, returns 0
    31  	"rocksdb.background-errors",               // returns accumulated number of background errors.
    32  	"rocksdb.cur-size-active-mem-table",       // returns approximate size of active memtable (bytes).
    33  	"rocksdb.cur-size-all-mem-tables",         // returns approximate size of active and unflushed immutable memtables (bytes)
    34  	"rocksdb.size-all-mem-tables",             // returns approximate size of active, unflushed immutable, and pinned immutable memtables (bytes)
    35  	"rocksdb.num-entries-active-mem-table",    // returns total number of entries in the active memtable.
    36  	"rocksdb.num-entries-imm-mem-tables",      // returns total number of entries in the unflushed immutable memtables.
    37  	"rocksdb.num-deletes-active-mem-table",    // returns total number of delete entries in the active memtable.
    38  	"rocksdb.num-deletes-imm-mem-tables",      // returns total number of delete entries in the unflushed immutable memtables.
    39  	"rocksdb.estimate-num-keys",               // returns estimated number of total keys in the active and unflushed immutable memtables and storage.
    40  	"rocksdb.estimate-table-readers-mem",      // returns estimated memory used for reading SST tables, excluding memory used in block cache (e.g.filter and index blocks).
    41  	"rocksdb.is-file-deletions-enabled",       // returns 0 if deletion of obsolete files is enabled; otherwise, returns a non-zero number. This name may be misleading because true(non-zero) means disable, but we keep the name for backward compatibility.
    42  	"rocksdb.num-snapshots",                   // returns number of unreleased snapshots of the database.
    43  	"rocksdb.oldest-snapshot-time",            // returns number representing unix timestamp of oldest unreleased snapshot.
    44  	"rocksdb.num-live-versions",               // returns number of live versions. `Version` is an internal data structure. See version_set.h for details. More live versions often mean more SST files are held from being deleted, by iterators or unfinished compactions.
    45  	"rocksdb.current-super-version-number",    // returns number of current LSM version. It is a uint64_t integer number, incremented after there is any change to the LSM tree. The number is not preserved after restarting the DB. After DB restart, it will start from 0 again.
    46  	"rocksdb.estimate-live-data-size",         // returns an estimate of the amount of live data in bytes. For BlobDB, it also includes the exact value of live bytes in the blob files of the version.
    47  	"rocksdb.min-log-number-to-keep",          // return the minimum log number of the log files that should be kept.
    48  	"rocksdb.min-obsolete-sst-number-to-keep", // return the minimum file number for an obsolete SST to be kept. The max value of `uint64_t` will be returned if all obsolete files can be deleted.
    49  	//"rocksdb.total-sst-files-size", // returns total size (bytes) of all SST files belonging to any of the CF's versions. WARNING: may slow down online queries if there are too many files.
    50  	"rocksdb.live-sst-files-size",               // returns total size (bytes) of all SST files belong to the CF's current version.
    51  	"rocksdb.obsolete-sst-files-size",           // returns total size (bytes) of all SST files that became obsolete but have not yet been deleted or scheduled for deletion. SST files can end up in this state when using `DisableFileDeletions()`, for example. N.B. Unlike the other "*SstFilesSize" properties, this property includes SST files that originated in any of the DB's CFs.
    52  	"rocksdb.base-level",                        // returns number of level to which L0 data will be compacted.
    53  	"rocksdb.estimate-pending-compaction-bytes", // returns estimated total number of bytes compaction needs to rewrite to get all levels down to under target size. Not valid for other compactions than level-based.
    54  	"rocksdb.num-running-compactions",           // returns the number of currently running compactions.
    55  	"rocksdb.num-running-flushes",               // returns the number of currently running flushes.
    56  	"rocksdb.actual-delayed-write-rate",         // returns the current actual delayed write rate. 0 means no delay.
    57  	"rocksdb.is-write-stopped",                  // return 1 if write has been stopped.
    58  	"rocksdb.estimate-oldest-key-time",          // returns an estimation of oldest key timestamp in the DB. Currently only available for FIFO compaction with compaction_options_fifo.allow_compaction = false.
    59  
    60  	// Properties dedicated for BlobDB
    61  	"rocksdb.num-blob-files",          // returns number of blob files in the current version.
    62  	"rocksdb.total-blob-file-size",    // returns the total size of all blob files over all versions.
    63  	"rocksdb.live-blob-file-size",     // returns the total size of all blob files in the current version.
    64  	"rocksdb.blob-cache-capacity",     // returns blob cache capacity.
    65  	"rocksdb.blob-cache-usage",        // returns the memory size for the entries residing in blob cache.
    66  	"rocksdb.blob-cache-pinned-usage", // returns the memory size for the entries being pinned in blob cache.
    67  }
    68  
    69  type RocksDBConfig struct {
    70  	Secondary                 bool
    71  	DumpMallocStat            bool
    72  	DisableMetrics            bool
    73  	CacheSize                 uint64
    74  	CompressionType           string
    75  	BottommostCompressionType string
    76  	FilterPolicy              string
    77  	MaxOpenFiles              int
    78  	CacheIndexAndFilter       bool
    79  }
    80  
    81  func GetDefaultRocksDBConfig() *RocksDBConfig {
    82  	return &RocksDBConfig{
    83  		Secondary:                 false,
    84  		CacheSize:                 defaultRocksDBCacheSize,
    85  		DumpMallocStat:            false,
    86  		CompressionType:           "lz4",
    87  		BottommostCompressionType: "zstd",
    88  		FilterPolicy:              "ribbon",
    89  		DisableMetrics:            false,
    90  		MaxOpenFiles:              defaultOpenFilesForRocksDB,
    91  		CacheIndexAndFilter:       true,
    92  	}
    93  }