@@ -16,6 +16,7 @@ import (
1616 "github.com/cockroachdb/pebble/internal/base"
1717 "github.com/cockroachdb/pebble/internal/bytealloc"
1818 "github.com/cockroachdb/pebble/internal/humanize"
19+ "github.com/cockroachdb/pebble/internal/inflight"
1920 "github.com/cockroachdb/pebble/internal/invariants"
2021 "github.com/cockroachdb/pebble/internal/keyspan"
2122 "github.com/cockroachdb/pebble/internal/keyspan/keyspanimpl"
@@ -209,12 +210,14 @@ type Iterator struct {
209210 // short-lived (since they pin memtables and sstables), (b) plumbing a
210211 // context into every method is very painful, (c) they do not (yet) respect
211212 // context cancellation and are only used for tracing.
212- ctx context.Context
213- opts IterOptions
214- merge Merge
215- comparer * base.Comparer
216- iter internalIterator
217- pointIter topLevelIterator
213+ ctx context.Context
214+ tracker * inflight.Tracker
215+ trackerHandle inflight.Handle
216+ opts IterOptions
217+ merge Merge
218+ comparer * base.Comparer
219+ iter internalIterator
220+ pointIter topLevelIterator
218221 // Either readState or version is set, but not both.
219222 readState * readState
220223 version * manifest.Version
@@ -2362,6 +2365,9 @@ const maxKeyBufCacheSize = 4 << 10 // 4 KB
23622365// It is not valid to call any method, including Close, after the iterator
23632366// has been closed.
23642367func (i * Iterator ) Close () error {
2368+ if i .tracker != nil {
2369+ i .tracker .Stop (i .trackerHandle )
2370+ }
23652371 // Close the child iterator before releasing the readState because when the
23662372 // readState is released sstables referenced by the readState may be deleted
23672373 // which will fail on Windows if the sstables are still open by the child
@@ -2895,6 +2901,10 @@ func (i *Iterator) CloneWithContext(ctx context.Context, opts CloneOptions) (*It
28952901 newIterRangeKey : i .newIterRangeKey ,
28962902 seqNum : i .seqNum ,
28972903 }
2904+ if i .tracker != nil {
2905+ dbi .tracker = i .tracker
2906+ dbi .trackerHandle = i .tracker .Start ()
2907+ }
28982908 if i .batch != nil {
28992909 dbi .batch = & buf .batchState
29002910 dbi .batch .batch = i .batch .batch
0 commit comments