Skip to content

Commit 75fceeb

Browse files
committed
fixes concurrent iterate and write with current height iterator
This situation came up in a busy node, staked for chains 0001,0003,0004,0005,0009,0010,0021,0022,0023,0024,0025,0026,0027,0028 simultaneously. We need to observe the effects of this change in the CPU and general performance: if it's too big a dip in performance, we may have to consider the more complex alternative of more closely mimicking the iavl's iterator generation technique.
1 parent 30ef159 commit 75fceeb

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

store/rootmulti/heightcache/memorycache.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,19 +72,14 @@ func (m MemoryCache) Remove(key []byte) error {
7272
}
7373

7474
func (m MemoryCache) Iterator(height int64, start, end []byte) (types.Iterator, error) {
75-
if !m.isValid(height) {
76-
return nil, errors.New("invalid height for iterator")
77-
}
78-
if height == m.current.height {
79-
return NewMemoryHeightIterator(m.current.data, string(start), string(end), []string{}, true), nil
80-
} else {
75+
if height != m.current.height && m.isValid(height) {
8176
for _, v := range m.pastHeights {
8277
if v.height == height {
8378
return NewMemoryHeightIterator(v.data, string(start), string(end), v.orderedKeys, true), nil
8479
}
8580
}
8681
}
87-
return NewMemoryHeightIterator(map[string]string{}, string(start), string(end), []string{}, true), nil
82+
return nil, errors.New("invalid height for iterator")
8883
}
8984

9085
func (m MemoryCache) ReverseIterator(height int64, start, end []byte) (types.Iterator, error) {

0 commit comments

Comments
 (0)