github.com/Hnampk/fabric@v2.1.1+incompatible/core/ledger/pvtdatastorage/store.go (about)

     1  /*
     2  Copyright IBM Corp. All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package pvtdatastorage
     8  
     9  import (
    10  	"github.com/hyperledger/fabric/core/ledger"
    11  	"github.com/hyperledger/fabric/core/ledger/pvtdatapolicy"
    12  )
    13  
    14  // Provider provides handle to specific 'Store' that in turn manages
    15  // private write sets for a ledger
    16  type Provider interface {
    17  	OpenStore(id string) (Store, error)
    18  	Close()
    19  }
    20  
    21  // Store manages the permanent storage of private write sets for a ledger
    22  // Because the pvt data is supposed to be in sync with the blocks in the
    23  // ledger, both should logically happen in an atomic operation. In order
    24  // to accomplish this, an implementation of this store should provide
    25  // support for a two-phase like commit/rollback capability.
    26  // The expected use is such that - first the private data will be given to
    27  // this store (via `Prepare` function) and then the block is appended to the block storage.
    28  // Finally, one of the functions `Commit` or `Rollback` is invoked on this store based
    29  // on whether the block was written successfully or not. The store implementation
    30  // is expected to survive a server crash between the call to `Prepare` and `Commit`/`Rollback`
    31  type Store interface {
    32  	// Init initializes the store. This function is expected to be invoked before using the store
    33  	Init(btlPolicy pvtdatapolicy.BTLPolicy)
    34  	// GetPvtDataByBlockNum returns only the pvt data  corresponding to the given block number
    35  	// The pvt data is filtered by the list of 'ns/collections' supplied in the filter
    36  	// A nil filter does not filter any results
    37  	GetPvtDataByBlockNum(blockNum uint64, filter ledger.PvtNsCollFilter) ([]*ledger.TxPvtData, error)
    38  	// GetMissingPvtDataInfoForMostRecentBlocks returns the missing private data information for the
    39  	// most recent `maxBlock` blocks which miss at least a private data of a eligible collection.
    40  	GetMissingPvtDataInfoForMostRecentBlocks(maxBlock int) (ledger.MissingPvtDataInfo, error)
    41  	// Commit commits the pvt data as well as both the eligible and ineligible
    42  	// missing private data --- `eligible` denotes that the missing private data belongs to a collection
    43  	// for which this peer is a member; `ineligible` denotes that the missing private data belong to a
    44  	// collection for which this peer is not a member.
    45  	Commit(blockNum uint64, pvtData []*ledger.TxPvtData, missingPvtData ledger.TxMissingPvtDataMap) error
    46  	// ProcessCollsEligibilityEnabled notifies the store when the peer becomes eligible to receive data for an
    47  	// existing collection. Parameter 'committingBlk' refers to the block number that contains the corresponding
    48  	// collection upgrade transaction and the parameter 'nsCollMap' contains the collections for which the peer
    49  	// is now eligible to receive pvt data
    50  	ProcessCollsEligibilityEnabled(committingBlk uint64, nsCollMap map[string][]string) error
    51  	// CommitPvtDataOfOldBlocks commits the pvtData (i.e., previously missing data) of old blocks.
    52  	// The parameter `blocksPvtData` refers a list of old block's pvtdata which are missing in the pvtstore.
    53  	// This call stores an additional entry called `lastUpdatedOldBlocksList` which keeps the exact list
    54  	// of updated blocks. This list would be used during recovery process. Once the stateDB is updated with
    55  	// these pvtData, the `lastUpdatedOldBlocksList` must be removed. During the peer startup,
    56  	// if the `lastUpdatedOldBlocksList` exists, stateDB needs to be updated with the appropriate pvtData.
    57  	CommitPvtDataOfOldBlocks(blocksPvtData map[uint64][]*ledger.TxPvtData) error
    58  	// GetLastUpdatedOldBlocksPvtData returns the pvtdata of blocks listed in `lastUpdatedOldBlocksList`
    59  	GetLastUpdatedOldBlocksPvtData() (map[uint64][]*ledger.TxPvtData, error)
    60  	// ResetLastUpdatedOldBlocksList removes the `lastUpdatedOldBlocksList` entry from the store
    61  	ResetLastUpdatedOldBlocksList() error
    62  	// LastCommittedBlockHeight returns the height of the last committed block
    63  	LastCommittedBlockHeight() (uint64, error)
    64  	// Shutdown stops the store
    65  	Shutdown()
    66  }
    67  
    68  // PrivateDataConfig encapsulates the configuration for private data storage on the ledger
    69  type PrivateDataConfig struct {
    70  	// PrivateDataConfig is used to configure a private data storage provider
    71  	*ledger.PrivateDataConfig
    72  	// StorePath is the filesystem path for private data storage.
    73  	// It is internally computed by the ledger component,
    74  	// so it is not in ledger.PrivateDataConfig and not exposed to other components.
    75  	StorePath string
    76  }
    77  
    78  // ErrIllegalCall is to be thrown by a store impl if the store does not expect a call to Prepare/Commit/Rollback/InitLastCommittedBlock
    79  type ErrIllegalCall struct {
    80  	msg string
    81  }
    82  
    83  func (err *ErrIllegalCall) Error() string {
    84  	return err.msg
    85  }
    86  
    87  // ErrIllegalArgs is to be thrown by a store impl if the args passed are not allowed
    88  type ErrIllegalArgs struct {
    89  	msg string
    90  }
    91  
    92  func (err *ErrIllegalArgs) Error() string {
    93  	return err.msg
    94  }
    95  
    96  // ErrOutOfRange is to be thrown for the request for the data that is not yet committed
    97  type ErrOutOfRange struct {
    98  	msg string
    99  }
   100  
   101  func (err *ErrOutOfRange) Error() string {
   102  	return err.msg
   103  }