github.com/anjalikarhana/fabric@v2.1.1+incompatible/common/ledger/blkstorage/fsblkstorage/config.go (about)

     1  /*
     2  Copyright IBM Corp. 2016 All Rights Reserved.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8  		 http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package fsblkstorage
    18  
    19  import "path/filepath"
    20  
    21  const (
    22  	// ChainsDir is the name of the directory containing the channel ledgers.
    23  	ChainsDir = "chains"
    24  	// IndexDir is the name of the directory containing all block indexes across ledgers.
    25  	IndexDir                = "index"
    26  	defaultMaxBlockfileSize = 64 * 1024 * 1024 // bytes
    27  )
    28  
    29  // Conf encapsulates all the configurations for `FsBlockStore`
    30  type Conf struct {
    31  	blockStorageDir  string
    32  	maxBlockfileSize int
    33  }
    34  
    35  // NewConf constructs new `Conf`.
    36  // blockStorageDir is the top level folder under which `FsBlockStore` manages its data
    37  func NewConf(blockStorageDir string, maxBlockfileSize int) *Conf {
    38  	if maxBlockfileSize <= 0 {
    39  		maxBlockfileSize = defaultMaxBlockfileSize
    40  	}
    41  	return &Conf{blockStorageDir, maxBlockfileSize}
    42  }
    43  
    44  func (conf *Conf) getIndexDir() string {
    45  	return filepath.Join(conf.blockStorageDir, IndexDir)
    46  }
    47  
    48  func (conf *Conf) getChainsDir() string {
    49  	return filepath.Join(conf.blockStorageDir, ChainsDir)
    50  }
    51  
    52  func (conf *Conf) getLedgerBlockDir(ledgerid string) string {
    53  	return filepath.Join(conf.getChainsDir(), ledgerid)
    54  }