github.com/osdi23p228/fabric@v0.0.0-20221218062954-77808885f5db/internal/peer/node/config.go (about)

     1  /*
     2  Copyright IBM Corp. 2016 All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package node
     8  
     9  import (
    10  	"path/filepath"
    11  	"time"
    12  
    13  	coreconfig "github.com/osdi23p228/fabric/core/config"
    14  	"github.com/osdi23p228/fabric/core/ledger"
    15  	"github.com/spf13/viper"
    16  )
    17  
    18  func ledgerConfig() *ledger.Config {
    19  	// set defaults
    20  	warmAfterNBlocks := 1
    21  	if viper.IsSet("ledger.state.couchDBConfig.warmIndexesAfterNBlocks") {
    22  		warmAfterNBlocks = viper.GetInt("ledger.state.couchDBConfig.warmIndexesAfterNBlocks")
    23  	}
    24  	internalQueryLimit := 1000
    25  	if viper.IsSet("ledger.state.couchDBConfig.internalQueryLimit") {
    26  		internalQueryLimit = viper.GetInt("ledger.state.couchDBConfig.internalQueryLimit")
    27  	}
    28  	maxBatchUpdateSize := 500
    29  	if viper.IsSet("ledger.state.couchDBConfig.maxBatchUpdateSize") {
    30  		maxBatchUpdateSize = viper.GetInt("ledger.state.couchDBConfig.maxBatchUpdateSize")
    31  	}
    32  	collElgProcMaxDbBatchSize := 5000
    33  	if viper.IsSet("ledger.pvtdataStore.collElgProcMaxDbBatchSize") {
    34  		collElgProcMaxDbBatchSize = viper.GetInt("ledger.pvtdataStore.collElgProcMaxDbBatchSize")
    35  	}
    36  	collElgProcDbBatchesInterval := 1000
    37  	if viper.IsSet("ledger.pvtdataStore.collElgProcDbBatchesInterval") {
    38  		collElgProcDbBatchesInterval = viper.GetInt("ledger.pvtdataStore.collElgProcDbBatchesInterval")
    39  	}
    40  	purgeInterval := 100
    41  	if viper.IsSet("ledger.pvtdataStore.purgeInterval") {
    42  		purgeInterval = viper.GetInt("ledger.pvtdataStore.purgeInterval")
    43  	}
    44  	deprioritizedDataReconcilerInterval := 60 * time.Minute
    45  	if viper.IsSet("ledger.pvtdataStore.deprioritizedDataReconcilerInterval") {
    46  		deprioritizedDataReconcilerInterval = viper.GetDuration("ledger.pvtdataStore.deprioritizedDataReconcilerInterval")
    47  	}
    48  
    49  	rootFSPath := filepath.Join(coreconfig.GetPath("peer.fileSystemPath"), "ledgersData")
    50  	snapshotsRootDir := viper.GetString("ledger.snapshots.rootDir")
    51  	if snapshotsRootDir == "" {
    52  		snapshotsRootDir = filepath.Join(rootFSPath, "snapshots")
    53  	}
    54  	conf := &ledger.Config{
    55  		RootFSPath: rootFSPath,
    56  		StateDBConfig: &ledger.StateDBConfig{
    57  			StateDatabase: viper.GetString("ledger.state.stateDatabase"),
    58  			CouchDB:       &ledger.CouchDBConfig{},
    59  		},
    60  		PrivateDataConfig: &ledger.PrivateDataConfig{
    61  			MaxBatchSize:                        collElgProcMaxDbBatchSize,
    62  			BatchesInterval:                     collElgProcDbBatchesInterval,
    63  			PurgeInterval:                       purgeInterval,
    64  			DeprioritizedDataReconcilerInterval: deprioritizedDataReconcilerInterval,
    65  		},
    66  		HistoryDBConfig: &ledger.HistoryDBConfig{
    67  			Enabled: viper.GetBool("ledger.history.enableHistoryDatabase"),
    68  		},
    69  		SnapshotsConfig: &ledger.SnapshotsConfig{
    70  			RootDir: snapshotsRootDir,
    71  		},
    72  	}
    73  
    74  	if conf.StateDBConfig.StateDatabase == "CouchDB" {
    75  		conf.StateDBConfig.CouchDB = &ledger.CouchDBConfig{
    76  			Address:                 viper.GetString("ledger.state.couchDBConfig.couchDBAddress"),
    77  			Username:                viper.GetString("ledger.state.couchDBConfig.username"),
    78  			Password:                viper.GetString("ledger.state.couchDBConfig.password"),
    79  			MaxRetries:              viper.GetInt("ledger.state.couchDBConfig.maxRetries"),
    80  			MaxRetriesOnStartup:     viper.GetInt("ledger.state.couchDBConfig.maxRetriesOnStartup"),
    81  			RequestTimeout:          viper.GetDuration("ledger.state.couchDBConfig.requestTimeout"),
    82  			InternalQueryLimit:      internalQueryLimit,
    83  			MaxBatchUpdateSize:      maxBatchUpdateSize,
    84  			WarmIndexesAfterNBlocks: warmAfterNBlocks,
    85  			CreateGlobalChangesDB:   viper.GetBool("ledger.state.couchDBConfig.createGlobalChangesDB"),
    86  			RedoLogPath:             filepath.Join(rootFSPath, "couchdbRedoLogs"),
    87  			UserCacheSizeMBs:        viper.GetInt("ledger.state.couchDBConfig.cacheSize"),
    88  		}
    89  	}
    90  	return conf
    91  }