-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Problem: memiavl db in CacheMultiStoreWithVersion not closed (#1151)
* Problem: memiavl db in CacheMultiStoreWithVersion not closed Solution: - add a wrapper that supports io.Closer Impact: - this PR only adds a Closer method to it, but not call it, for example, sdk grpc query service will not call it, unless patched. - versiondb nodes handle grpc queries without memiavl, so no problem there. - for other use cases that use memiavl's `CacheMultiStoreWithVersion` method should call the `Close()` method explicitly. * Update CHANGELOG.md Signed-off-by: yihuang <[email protected]> --------- Signed-off-by: yihuang <[email protected]>
- Loading branch information
Showing
3 changed files
with
41 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package cachemulti | ||
|
||
import ( | ||
"io" | ||
|
||
"github.com/cosmos/cosmos-sdk/store/cachemulti" | ||
"github.com/cosmos/cosmos-sdk/store/types" | ||
dbm "github.com/tendermint/tm-db" | ||
) | ||
|
||
var NoopCloser io.Closer = CloserFunc(func() error { return nil }) | ||
|
||
type CloserFunc func() error | ||
|
||
func (fn CloserFunc) Close() error { | ||
return fn() | ||
} | ||
|
||
// Store wraps sdk's cachemulti.Store to add io.Closer interface | ||
type Store struct { | ||
cachemulti.Store | ||
io.Closer | ||
} | ||
|
||
func NewStore( | ||
db dbm.DB, stores map[types.StoreKey]types.CacheWrapper, keys map[string]types.StoreKey, | ||
traceWriter io.Writer, traceContext types.TraceContext, | ||
closer io.Closer, | ||
) Store { | ||
if closer == nil { | ||
closer = NoopCloser | ||
} | ||
return Store{ | ||
Store: cachemulti.NewStore(db, stores, keys, traceWriter, traceContext), | ||
Closer: closer, | ||
} | ||
} |
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