From 8638813c19bc36a2c110d0de02f29c0f9fca680c Mon Sep 17 00:00:00 2001 From: manish Date: Fri, 21 Apr 2017 15:10:52 +0530 Subject: [PATCH] [FAB-3270] Cleanup a TODO in Ledger queryHelper done() In this cleanup done() exits on first error and closes all the open iterators in a defer function Change-Id: Ifdc0771f13efc0d5b968429a2f207bf0fdf2ad54 Signed-off-by: manish --- .../txmgmt/txmgr/lockbasedtxmgr/helper.go | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/core/ledger/kvledger/txmgmt/txmgr/lockbasedtxmgr/helper.go b/core/ledger/kvledger/txmgmt/txmgr/lockbasedtxmgr/helper.go index 3eba9c88411..dea624f9715 100644 --- a/core/ledger/kvledger/txmgmt/txmgr/lockbasedtxmgr/helper.go +++ b/core/ledger/kvledger/txmgmt/txmgr/lockbasedtxmgr/helper.go @@ -87,25 +87,28 @@ func (h *queryHelper) done() { if h.doneInvoked { return } - defer h.txmgr.commitRWLock.RUnlock() - h.doneInvoked = true + + defer func() { + h.txmgr.commitRWLock.RUnlock() + h.doneInvoked = true + for _, itr := range h.itrs { + itr.Close() + } + }() + for _, itr := range h.itrs { - itr.Close() if h.rwsetBuilder != nil { results, hash, err := itr.rangeQueryResultsHelper.Done() + if err != nil { + h.err = err + return + } if results != nil { itr.rangeQueryInfo.SetRawReads(results) } if hash != nil { itr.rangeQueryInfo.SetMerkelSummary(hash) } - // TODO Change the method signature of done() to return error. However, this will have - // repercurssions in the chaincode package, so deferring to a separate changeset. - // For now, capture the first error that is encountered - // during final processing and return the error when the caller retrieves the simulation results. - if h.err == nil { - h.err = err - } h.rwsetBuilder.AddToRangeQuerySet(itr.ns, itr.rangeQueryInfo) } }