-
Notifications
You must be signed in to change notification settings - Fork 8.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FAB-5874] Support for queries over pvtdata
This CR allows queries over pvt data in addition to the key based (Get/Set) operations. The queries over pvt data is allowed in read-only transactions. Because, for the peers that do not have pvt data, there is no easy way to detect phantom items during commit time and hence guaranteeing the serializability of trans. If a tran performs both 'queries over pvt data' and update operations an error is raised during simulation. Change-Id: Ia607c13d16a20e939bbe978476757086866fa84a Signed-off-by: manish <manish.sethi@gmail.com>
- Loading branch information
1 parent
590dce1
commit a0ad3d0
Showing
8 changed files
with
432 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
core/ledger/kvledger/txmgmt/txmgr/lockbasedtxmgr/helper_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
Copyright IBM Corp. 2016 All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package lockbasedtxmgr | ||
|
||
import ( | ||
"testing" | ||
|
||
commonledger "github.com/hyperledger/fabric/common/ledger" | ||
"github.com/hyperledger/fabric/common/ledger/testutil" | ||
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/privacyenabledstate" | ||
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/version" | ||
"github.com/hyperledger/fabric/core/ledger/util" | ||
"github.com/hyperledger/fabric/protos/ledger/queryresult" | ||
) | ||
|
||
func TestPvtdataResultsItr(t *testing.T) { | ||
testEnv := testEnvs[0] | ||
testEnv.init(t, "test-pvtdata-range-queries") | ||
defer testEnv.cleanup() | ||
|
||
txMgr := testEnv.getTxMgr().(*LockBasedTxMgr) | ||
|
||
updates := privacyenabledstate.NewUpdateBatch() | ||
putPvtUpdates(t, updates, "ns1", "coll1", "key1", []byte("pvt_value1"), version.NewHeight(1, 1)) | ||
putPvtUpdates(t, updates, "ns1", "coll1", "key2", []byte("pvt_value2"), version.NewHeight(1, 2)) | ||
putPvtUpdates(t, updates, "ns1", "coll1", "key3", []byte("pvt_value3"), version.NewHeight(1, 3)) | ||
putPvtUpdates(t, updates, "ns1", "coll1", "key4", []byte("pvt_value4"), version.NewHeight(1, 4)) | ||
putPvtUpdates(t, updates, "ns2", "coll1", "key5", []byte("pvt_value5"), version.NewHeight(1, 5)) | ||
putPvtUpdates(t, updates, "ns2", "coll1", "key6", []byte("pvt_value6"), version.NewHeight(1, 6)) | ||
putPvtUpdates(t, updates, "ns3", "coll1", "key7", []byte("pvt_value7"), version.NewHeight(1, 7)) | ||
txMgr.db.ApplyPrivacyAwareUpdates(updates, version.NewHeight(2, 7)) | ||
queryHelper := &queryHelper{txmgr: txMgr} | ||
|
||
resItr, err := queryHelper.getPrivateDataRangeScanIterator("ns1", "coll1", "key1", "key3") | ||
testutil.AssertNoError(t, err, "") | ||
testItr(t, resItr, "ns1", "coll1", []string{"key1", "key2"}) | ||
|
||
resItr, err = queryHelper.getPrivateDataRangeScanIterator("ns4", "coll1", "key1", "key3") | ||
testutil.AssertNoError(t, err, "") | ||
testItr(t, resItr, "ns4", "coll1", []string{}) | ||
} | ||
|
||
func putPvtUpdates(t *testing.T, updates *privacyenabledstate.UpdateBatch, ns, coll, key string, value []byte, ver *version.Height) { | ||
updates.PvtUpdates.Put(ns, coll, key, value, ver) | ||
updates.HashUpdates.Put(ns, coll, util.ComputeStringHash(key), util.ComputeHash(value), ver) | ||
} | ||
|
||
func testItr(t *testing.T, itr commonledger.ResultsIterator, expectedNs string, expectedColl string, expectedKeys []string) { | ||
t.Logf("Testing itr for [%d] keys", len(expectedKeys)) | ||
defer itr.Close() | ||
for _, expectedKey := range expectedKeys { | ||
queryResult, _ := itr.Next() | ||
pvtdataKV := queryResult.(*queryresult.KV) | ||
ns := pvtdataKV.Namespace | ||
key := pvtdataKV.Key | ||
testutil.AssertEquals(t, ns, expectedNs) | ||
testutil.AssertEquals(t, key, expectedKey) | ||
} | ||
last, err := itr.Next() | ||
testutil.AssertNoError(t, err, "") | ||
testutil.AssertNil(t, last) | ||
} |
Oops, something went wrong.