Skip to content

Commit

Permalink
[FAB-3270] Cleanup a TODO in Ledger queryHelper done()
Browse files Browse the repository at this point in the history
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 <manish.sethi@gmail.com>
  • Loading branch information
manish-sethi committed Apr 22, 2017
1 parent d39dee5 commit 8638813
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions core/ledger/kvledger/txmgmt/txmgr/lockbasedtxmgr/helper.go
Expand Up @@ -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)
}
}
Expand Down

0 comments on commit 8638813

Please sign in to comment.