Skip to content

Commit

Permalink
[LEDGER] merge queryHelper with the queryExecutor (hyperledger#1097)
Browse files Browse the repository at this point in the history
In lockbasedtxmgr, we have a lockBasedQueryExecutor and a
lockBasedTxSimulator struct. The lockBasedTxSimulator implements
mainly SetXXX() APIs while lockBasedQueryExecutor implements GetXXX()
APIs. As the transaction simulation also involves query, the
lockBasedTxSimulator encapsulate lockBasedQueryExecutor. Only in
the lockBasedTxSimulator, we collect readSet while using GetXXX()
and writeSet while using SetXXX(). However, when we use
lockBasedQueryExecutor alone, we don't collect readSet.

Currently, we have an unnecessary indirection with QueryHelper
and it makes code readability a bit hard. Hence, we merge
the QueryHelper with the lockBasedQueryExecutor itself
and do some renaming of files/structs too.

Signed-off-by: senthil <cendhu@gmail.com>
  • Loading branch information
cendhu authored Apr 18, 2020
1 parent 179dc42 commit 9ccf752
Show file tree
Hide file tree
Showing 7 changed files with 249 additions and 306 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ import (
type collNameValidator struct {
ledgerID string
ccInfoProvider ledger.DeployedChaincodeInfoProvider
queryExecutor *lockBasedQueryExecutor
queryExecutor *queryExecutor
cache collConfigCache
noop bool
}

func newCollNameValidator(ledgerID string, ccInfoProvider ledger.DeployedChaincodeInfoProvider, qe *lockBasedQueryExecutor, noop bool) *collNameValidator {
func newCollNameValidator(ledgerID string, ccInfoProvider ledger.DeployedChaincodeInfoProvider, qe *queryExecutor, noop bool) *collNameValidator {
return &collNameValidator{ledgerID, ccInfoProvider, qe, make(collConfigCache), noop}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ func TestPvtGetNoCollection(t *testing.T) {
txMgr := testEnv.getTxMgr().(*LockBasedTxMgr)
cryptoProvider, err := sw.NewDefaultSecurityLevelWithKeystore(sw.NewDummyKeyStore())
assert.NoError(t, err)
queryHelper := newQueryHelper(txMgr, nil, true, cryptoProvider)
valueHash, metadataBytes, err := queryHelper.getPrivateDataValueHash("cc", "coll", "key")
qe := newQueryExecutor(txMgr, "", nil, true, cryptoProvider)
valueHash, metadataBytes, err := qe.getPrivateDataValueHash("cc", "coll", "key")
assert.Nil(t, valueHash)
assert.Nil(t, metadataBytes)
assert.Error(t, err)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (txmgr *LockBasedTxMgr) GetLastSavepoint() (*version.Height, error) {

// NewQueryExecutor implements method in interface `txmgmt.TxMgr`
func (txmgr *LockBasedTxMgr) NewQueryExecutor(txid string) (ledger.QueryExecutor, error) {
qe := newQueryExecutor(txmgr, txid, true, txmgr.hasher)
qe := newQueryExecutor(txmgr, txid, nil, true, txmgr.hasher)
txmgr.commitRWLock.RLock()
return qe, nil
}
Expand All @@ -117,15 +117,15 @@ func (txmgr *LockBasedTxMgr) NewQueryExecutor(txid string) (ledger.QueryExecutor
// querying the ledger state so that the sequence of initialization is explicitly controlled.
// However that needs a bigger refactoring of code.
func (txmgr *LockBasedTxMgr) NewQueryExecutorNoCollChecks() (ledger.QueryExecutor, error) {
qe := newQueryExecutor(txmgr, "", false, txmgr.hasher)
qe := newQueryExecutor(txmgr, "", nil, false, txmgr.hasher)
txmgr.commitRWLock.RLock()
return qe, nil
}

// NewTxSimulator implements method in interface `txmgmt.TxMgr`
func (txmgr *LockBasedTxMgr) NewTxSimulator(txid string) (ledger.TxSimulator, error) {
logger.Debugf("constructing new tx simulator")
s, err := newLockBasedTxSimulator(txmgr, txid, txmgr.hasher)
s, err := newTxSimulator(txmgr, txid, txmgr.hasher)
if err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit 9ccf752

Please sign in to comment.