Skip to content

Commit 8638813

Browse files
committed
[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 <[email protected]>
1 parent d39dee5 commit 8638813

File tree

1 file changed

+13
-10
lines changed
  • core/ledger/kvledger/txmgmt/txmgr/lockbasedtxmgr

1 file changed

+13
-10
lines changed

core/ledger/kvledger/txmgmt/txmgr/lockbasedtxmgr/helper.go

+13-10
Original file line numberDiff line numberDiff line change
@@ -87,25 +87,28 @@ func (h *queryHelper) done() {
8787
if h.doneInvoked {
8888
return
8989
}
90-
defer h.txmgr.commitRWLock.RUnlock()
91-
h.doneInvoked = true
90+
91+
defer func() {
92+
h.txmgr.commitRWLock.RUnlock()
93+
h.doneInvoked = true
94+
for _, itr := range h.itrs {
95+
itr.Close()
96+
}
97+
}()
98+
9299
for _, itr := range h.itrs {
93-
itr.Close()
94100
if h.rwsetBuilder != nil {
95101
results, hash, err := itr.rangeQueryResultsHelper.Done()
102+
if err != nil {
103+
h.err = err
104+
return
105+
}
96106
if results != nil {
97107
itr.rangeQueryInfo.SetRawReads(results)
98108
}
99109
if hash != nil {
100110
itr.rangeQueryInfo.SetMerkelSummary(hash)
101111
}
102-
// TODO Change the method signature of done() to return error. However, this will have
103-
// repercurssions in the chaincode package, so deferring to a separate changeset.
104-
// For now, capture the first error that is encountered
105-
// during final processing and return the error when the caller retrieves the simulation results.
106-
if h.err == nil {
107-
h.err = err
108-
}
109112
h.rwsetBuilder.AddToRangeQuerySet(itr.ns, itr.rangeQueryInfo)
110113
}
111114
}

0 commit comments

Comments
 (0)