github.com/iotexproject/iotex-core@v1.14.1-rc1/db/config.go (about)

     1  // Copyright (c) 2021 IoTeX Foundation
     2  // This source code is provided 'as is' and no warranties are given as to title or non-infringement, merchantability
     3  // or fitness for purpose and, to the extent permitted by law, all liability for your use of the code is disclaimed.
     4  // This source code is governed by Apache License 2.0 that can be found in the LICENSE file.
     5  
     6  package db
     7  
     8  // Config is the config for database
     9  type Config struct {
    10  	DbPath string `yaml:"dbPath"`
    11  	// NumRetries is the number of retries
    12  	NumRetries uint8 `yaml:"numRetries"`
    13  	// MaxCacheSize is the max number of blocks that will be put into an LRU cache. 0 means disabled
    14  	MaxCacheSize int `yaml:"maxCacheSize"`
    15  	// BlockStoreBatchSize is the number of blocks to be stored together as a unit (to get better compression)
    16  	BlockStoreBatchSize int `yaml:"blockStoreBatchSize"`
    17  	// V2BlocksToSplitDB is the accumulated number of blocks to split a new file after v1.1.2
    18  	V2BlocksToSplitDB uint64 `yaml:"v2BlocksToSplitDB"`
    19  	// Compressor is the compression used on block data, used by new DB file after v1.1.2
    20  	Compressor string `yaml:"compressor"`
    21  	// CompressLegacy enables gzip compression on block data, used by legacy DB file before v1.1.2
    22  	CompressLegacy bool `yaml:"compressLegacy"`
    23  	// SplitDBSize is the config for DB's split file size
    24  	SplitDBSizeMB uint64 `yaml:"splitDBSizeMB"`
    25  	// SplitDBHeight is the config for DB's split start height
    26  	SplitDBHeight uint64 `yaml:"splitDBHeight"`
    27  	// HistoryStateRetention is the number of blocks account/contract state will be retained
    28  	HistoryStateRetention uint64 `yaml:"historyStateRetention"`
    29  	// ReadOnly is set db to be opened in read only mode
    30  	ReadOnly bool `yaml:"readOnly"`
    31  }
    32  
    33  // SplitDBSize returns the configured SplitDBSizeMB
    34  func (cfg Config) SplitDBSize() uint64 {
    35  	return cfg.SplitDBSizeMB * 1024 * 1024
    36  }
    37  
    38  // DefaultConfig returns the default config
    39  var DefaultConfig = Config{
    40  	NumRetries:            3,
    41  	MaxCacheSize:          64,
    42  	BlockStoreBatchSize:   16,
    43  	V2BlocksToSplitDB:     1000000,
    44  	Compressor:            "Snappy",
    45  	CompressLegacy:        false,
    46  	SplitDBSizeMB:         0,
    47  	SplitDBHeight:         900000,
    48  	HistoryStateRetention: 2000,
    49  }