Skip to content

Commit f6fb384

Browse files
authored
Merge pull request #1 from ThienLK1/v.2.2-mongodb
V.2.2 mongodb
2 parents b026fd4 + 092bac7 commit f6fb384

File tree

14 files changed

+276
-141
lines changed

14 files changed

+276
-141
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ tags
2424
TESTS*.xml
2525
.tox/
2626
.vagrant/
27-
.vscode
27+
.vscode

Makefile

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -222,16 +222,16 @@ $(BUILD_DIR)/images/peer/$(DUMMY): BUILD_ARGS=--build-arg GO_TAGS=${GO_TAGS}
222222
$(BUILD_DIR)/images/orderer/$(DUMMY): BUILD_ARGS=--build-arg GO_TAGS=${GO_TAGS}
223223

224224
$(BUILD_DIR)/images/%/$(DUMMY):
225-
@echo "Building Docker image $(DOCKER_NS)/fabric-$*"
225+
@echo "Building Docker image $(DOCKER_NS_CUSTOM)/fabric-$*"
226226
@mkdir -p $(@D)
227227
$(DBUILD) -f images/$*/Dockerfile \
228228
--build-arg GO_VER=$(GO_VER) \
229229
--build-arg ALPINE_VER=$(ALPINE_VER) \
230230
$(BUILD_ARGS) \
231-
-t $(DOCKER_NS)/fabric-$* ./$(BUILD_CONTEXT)
232-
docker tag $(DOCKER_NS)/fabric-$* $(DOCKER_NS)/fabric-$*:$(BASE_VERSION)
233-
docker tag $(DOCKER_NS)/fabric-$* $(DOCKER_NS)/fabric-$*:$(TWO_DIGIT_VERSION)
234-
docker tag $(DOCKER_NS)/fabric-$* $(DOCKER_NS)/fabric-$*:$(DOCKER_TAG)
231+
-t $(DOCKER_NS_CUSTOM)/fabric-$* ./$(BUILD_CONTEXT)
232+
docker tag $(DOCKER_NS_CUSTOM)/fabric-$* $(DOCKER_NS_CUSTOM)/fabric-$*:$(BASE_VERSION)
233+
docker tag $(DOCKER_NS_CUSTOM)/fabric-$* $(DOCKER_NS_CUSTOM)/fabric-$*:$(TWO_DIGIT_VERSION)
234+
docker tag $(DOCKER_NS_CUSTOM)/fabric-$* $(DOCKER_NS_CUSTOM)/fabric-$*:$(DOCKER_TAG)
235235
@touch $@
236236

237237
# builds release packages for the host platform
@@ -268,31 +268,31 @@ dist/%: release/%
268268
.PHONY: docker-list
269269
docker-list: $(RELEASE_IMAGES:%=%-docker-list)
270270
%-docker-list:
271-
@echo $(DOCKER_NS)/fabric-$*:$(DOCKER_TAG)
271+
@echo $(DOCKER_NS_CUSTOM)/fabric-$*:$(DOCKER_TAG)
272272

273273
.PHONY: docker-clean
274274
docker-clean: $(RELEASE_IMAGES:%=%-docker-clean)
275275
%-docker-clean:
276-
-@for image in "$$(docker images --quiet --filter=reference='$(DOCKER_NS)/fabric-$*:$(DOCKER_TAG)')"; do \
276+
-@for image in "$$(docker images --quiet --filter=reference='$(DOCKER_NS_CUSTOM)/fabric-$*:$(DOCKER_TAG)')"; do \
277277
[ -z "$$image" ] || docker rmi -f $$image; \
278278
done
279279
-@rm -rf $(BUILD_DIR)/images/$* || true
280280

281281
.PHONY: docker-tag-latest
282282
docker-tag-latest: $(RELEASE_IMAGES:%=%-docker-tag-latest)
283283
%-docker-tag-latest:
284-
docker tag $(DOCKER_NS)/fabric-$*:$(DOCKER_TAG) $(DOCKER_NS)/fabric-$*:latest
284+
docker tag $(DOCKER_NS_CUSTOM)/fabric-$*:$(DOCKER_TAG) $(DOCKER_NS_CUSTOM)/fabric-$*:latest
285285

286286
.PHONY: docker-tag-stable
287287
docker-tag-stable: $(RELEASE_IMAGES:%=%-docker-tag-stable)
288288
%-docker-tag-stable:
289-
docker tag $(DOCKER_NS)/fabric-$*:$(DOCKER_TAG) $(DOCKER_NS)/fabric-$*:stable
289+
docker tag $(DOCKER_NS_CUSTOM)/fabric-$*:$(DOCKER_TAG) $(DOCKER_NS_CUSTOM)/fabric-$*:stable
290290

291291
.PHONY: publish-images
292292
publish-images: $(RELEASE_IMAGES:%=%-publish-images)
293293
%-publish-images:
294294
@docker login $(DOCKER_HUB_USERNAME) $(DOCKER_HUB_PASSWORD)
295-
@docker push $(DOCKER_NS)/fabric-$*:$(PROJECT_VERSION)
295+
@docker push $(DOCKER_NS_CUSTOM)/fabric-$*:$(PROJECT_VERSION)
296296

297297
.PHONY: clean
298298
clean: docker-clean unit-test-clean release-clean

core/chaincode/chaincodetest.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ chaincode:
304304

305305
golang:
306306
# golang will never need more than baseos
307-
runtime: $(DOCKER_NS)/fabric-baseos:$(TWO_DIGIT_VERSION)
307+
runtime: hyperledger/fabric-baseos:$(TWO_DIGIT_VERSION)
308308

309309
# whether or not golang chaincode should be linked dynamically
310310
dynamicLink: false

core/ledger/kvledger/txmgmt/privacyenabledstate/db.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ import (
2020
"github.com/hyperledger/fabric/core/ledger/kvledger/bookkeeping"
2121
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/statedb"
2222
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/statedb/statecouchdb"
23-
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/statedb/statemongodb"
2423
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/statedb/stateleveldb"
24+
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/statedb/statemongodb"
2525
"github.com/hyperledger/fabric/core/ledger/util"
2626
"github.com/pkg/errors"
2727
)
@@ -65,7 +65,8 @@ func NewDBProvider(
6565

6666
var vdbProvider statedb.VersionedDBProvider
6767
var err error
68-
logger.Debugf("constructing NewDBProvider stateDBConf %s",stateDBConf.MongoDB)
68+
logger.Debugf("****StateDB****: %s", stateDBConf.StateDatabase)
69+
//logger.Debugf("constructing NewDBProvider stateDBConf %s",stateDBConf.MongoDB)
6970

7071
if stateDBConf != nil && stateDBConf.StateDatabase == couchDB {
7172
if vdbProvider, err = statecouchdb.NewVersionedDBProvider(stateDBConf.CouchDB, metricsProvider, sysNamespaces); err != nil {
@@ -204,6 +205,7 @@ func (s *DB) GetPrivateDataHash(namespace, collection, key string) (*statedb.Ver
204205

205206
// GetPrivateDataHash gets the value hash of a private data item identified by a tuple <namespace, collection, keyHash>
206207
func (s *DB) GetValueHash(namespace, collection string, keyHash []byte) (*statedb.VersionedValue, error) {
208+
logger.Debugf("GetValueHash")
207209
keyHashStr := string(keyHash)
208210
if !s.BytesKeySupported() {
209211
keyHashStr = base64.StdEncoding.EncodeToString(keyHash)
@@ -263,7 +265,7 @@ func (s *DB) ApplyPrivacyAwareUpdates(updates *UpdateBatch, height *version.Heig
263265
addPvtUpdates(combinedUpdates, updates.PvtUpdates)
264266
addHashedUpdates(combinedUpdates, updates.HashUpdates, !s.BytesKeySupported())
265267
s.metadataHint.setMetadataUsedFlag(updates)
266-
logger.Debugf("ApplyPrivacyAwareUpdates %s",s.VersionedDB)
268+
logger.Debugf("ApplyPrivacyAwareUpdates %s", s.VersionedDB)
267269
return s.VersionedDB.ApplyUpdates(combinedUpdates.UpdateBatch, height)
268270
}
269271

core/ledger/kvledger/txmgmt/statedb/statecouchdb/couchdb.go

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ func (dbclient *couchDatabase) dropDatabase() (*dbOperationResponse, error) {
517517
func (dbclient *couchDatabase) saveDoc(id string, rev string, couchDoc *couchDoc) (string, error) {
518518
dbName := dbclient.dbName
519519

520-
couchdbLogger.Debugf("[%s] Entering SaveDoc() id=[%s]", dbName, id)
520+
couchdbLogger.Debugf("[%s] Entering SaveDoc() id=[%s] couchDoc: %+v", dbName, id, couchDoc)
521521

522522
if !utf8.ValidString(id) {
523523
return "", errors.Errorf("doc id [%x] not a valid utf8 string", id)
@@ -540,16 +540,17 @@ func (dbclient *couchDatabase) saveDoc(id string, rev string, couchDoc *couchDoc
540540

541541
//check to see if attachments is nil, if so, then this is a JSON only
542542
if couchDoc.attachments == nil {
543-
543+
logger.Debugf("saveDoc() id: %s couchDoc.attachments == nil", id)
544544
//Test to see if this is a valid JSON
545545
if !isJSON(string(couchDoc.jsonValue)) {
546546
return "", errors.New("JSON format is not valid")
547547
}
548548

549549
// if there are no attachments, then use the bytes passed in as the JSON
550550
data = couchDoc.jsonValue
551-
551+
logger.Debugf("saveDoc() data: %+v", data)
552552
} else { // there are attachments
553+
logger.Debugf("saveDoc() id: %s couchDoc.attachments != nil", id)
553554

554555
//attachments are included, create the multipart definition
555556
multipartData, multipartBoundary, err3 := createAttachmentPart(couchDoc)
@@ -566,15 +567,15 @@ func (dbclient *couchDatabase) saveDoc(id string, rev string, couchDoc *couchDoc
566567

567568
//Set the data buffer to the data from the create multi-part data
568569
data = multipartData.Bytes()
569-
570+
logger.Debugf("saveDoc() data: %+v", data)
570571
//Set the default boundary to the value generated in the multipart creation
571572
defaultBoundary = multipartBoundary
572573

573574
}
574575

575576
//get the number of retries
576577
maxRetries := dbclient.couchInstance.conf.MaxRetries
577-
578+
//couchdbLogger.Debugf("[SaveDoc() id:[%s] rev=[%s]",id, rev)
578579
//handle the request for saving document with a retry if there is a revision conflict
579580
resp, _, err := dbclient.handleRequestWithRevisionRetry(id, http.MethodPut, dbName, "SaveDoc", saveURL, data, rev, defaultBoundary, maxRetries, keepConnectionOpen, nil)
580581

@@ -589,8 +590,8 @@ func (dbclient *couchDatabase) saveDoc(id string, rev string, couchDoc *couchDoc
589590
return "", err
590591
}
591592

592-
couchdbLogger.Debugf("[%s] Exiting SaveDoc()", dbclient.dbName)
593-
593+
//couchdbLogger.Debugf("SaveDoc() %+v",revision)
594+
couchdbLogger.Debugf("Database Name : [%s] Revision: [%s] Exiting saveDoc()", dbclient.dbName, revision)
594595
return revision, nil
595596

596597
}
@@ -599,13 +600,14 @@ func (dbclient *couchDatabase) saveDoc(id string, rev string, couchDoc *couchDoc
599600
func (dbclient *couchDatabase) getDocumentRevision(id string) string {
600601

601602
var rev = ""
602-
603+
logger.Debugf("getDocumentRevision")
603604
//See if the document already exists, we need the rev for saves and deletes
604605
_, revdoc, err := dbclient.readDoc(id)
605606
if err == nil {
606607
//set the revision to the rev returned from the document read
607608
rev = revdoc
608609
}
610+
logger.Debugf("getDocumentRevision rev: %v", rev)
609611
return rev
610612
}
611613

@@ -825,7 +827,7 @@ func (dbclient *couchDatabase) readDoc(id string) (*couchDoc, string, error) {
825827
} // for all multiparts
826828

827829
couchDoc.attachments = attachments
828-
830+
couchdbLogger.Debugf("return readDoc couchDoc: %+v, revision: %s, nil", couchDoc, revision)
829831
return &couchDoc, revision, nil
830832
}
831833

@@ -835,7 +837,7 @@ func (dbclient *couchDatabase) readDoc(id string) (*couchDoc, string, error) {
835837
return nil, "", errors.Wrap(err, "error reading response body")
836838
}
837839

838-
couchdbLogger.Debugf("[%s] Exiting ReadDoc()", dbclient.dbName)
840+
couchdbLogger.Debugf("[%s] Exiting ReadDoc() id: %v revision: %v", dbclient.dbName, id, revision)
839841
return &couchDoc, revision, nil
840842
}
841843

@@ -1456,11 +1458,12 @@ func (dbclient *couchDatabase) batchRetrieveDocumentMetadata(keys []string) ([]*
14561458
if err2 != nil {
14571459
return nil, errors.Wrap(err2, "error unmarshalling json data")
14581460
}
1459-
1461+
couchdbLogger.Debugf("BatchRetrieveDocumentMetadata() jsonResponse:%+v", jsonResponse)
14601462
docMetadataArray := []*docMetadata{}
14611463

14621464
for _, row := range jsonResponse.Rows {
14631465
docMetadata := &docMetadata{ID: row.ID, Rev: row.DocMetadata.Rev, Version: row.DocMetadata.Version}
1466+
couchdbLogger.Debugf("BatchRetrieveDocumentMetadata() docMetadata:%+v", docMetadata)
14641467
docMetadataArray = append(docMetadataArray, docMetadata)
14651468
}
14661469

@@ -1473,7 +1476,7 @@ func (dbclient *couchDatabase) batchRetrieveDocumentMetadata(keys []string) ([]*
14731476
//batchUpdateDocuments - batch method to batch update documents
14741477
func (dbclient *couchDatabase) batchUpdateDocuments(documents []*couchDoc) ([]*batchUpdateResponse, error) {
14751478
dbName := dbclient.dbName
1476-
1479+
logger.Debugf("batchUpdateDocuments =[%v]", documents)
14771480
if couchdbLogger.IsEnabledFor(zapcore.DebugLevel) {
14781481
documentIdsString, err := printDocumentIds(documents)
14791482
if err == nil {
@@ -1494,7 +1497,7 @@ func (dbclient *couchDatabase) batchUpdateDocuments(documents []*couchDoc) ([]*b
14941497
var jsonDocumentMap []interface{}
14951498

14961499
for _, jsonDocument := range documents {
1497-
1500+
couchdbLogger.Debugf("BatchUpdateDocuments() jsonDocument=[%+v]", jsonDocument)
14981501
//create a document map
14991502
var document = make(map[string]interface{})
15001503

@@ -1503,9 +1506,10 @@ func (dbclient *couchDatabase) batchUpdateDocuments(documents []*couchDoc) ([]*b
15031506
if err != nil {
15041507
return nil, errors.Wrap(err, "error unmarshalling json data")
15051508
}
1506-
1509+
couchdbLogger.Debugf("BatchUpdateDocuments() Unmarshal document: %+v", document)
15071510
//iterate through any attachments
15081511
if len(jsonDocument.attachments) > 0 {
1512+
couchdbLogger.Debugf("BatchUpdateDocuments() len(jsonDocument.attachments) > 0")
15091513

15101514
//create a file attachment map
15111515
fileAttachment := make(map[string]interface{})
@@ -1526,7 +1530,7 @@ func (dbclient *couchDatabase) batchUpdateDocuments(documents []*couchDoc) ([]*b
15261530
jsonDocumentMap = append(jsonDocumentMap, document)
15271531

15281532
}
1529-
1533+
couchdbLogger.Debugf("BatchUpdateDocuments() jsonDocumentMap=[%+v]", jsonDocumentMap)
15301534
//Add the documents to the "docs" item
15311535
documentMap["docs"] = jsonDocumentMap
15321536

core/ledger/kvledger/txmgmt/statedb/statemongodb/commit_handling.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ func (c *committer) commitUpdates() error {
186186
// IF INDIVIDUAL DOCUMENTS IN THE BULK UPDATE DID NOT SUCCEED, TRY THEM INDIVIDUALLY
187187
// iterate through the response from MongoDB by document
188188
for _, resp := range responses {
189-
logger.Debugf("commitUpdates resp.Error :%s", resp.Error)
190189
// If the document returned an error, retry the individual document
191190
if resp.Error != "" || resp.ID == "" {
192191
rev := string(resp.Rev)

0 commit comments

Comments
 (0)