@@ -16,6 +16,7 @@ import (
16
16
"github.com/cockroachdb/pebble/internal/base"
17
17
"github.com/cockroachdb/pebble/internal/bytealloc"
18
18
"github.com/cockroachdb/pebble/internal/humanize"
19
+ "github.com/cockroachdb/pebble/internal/inflight"
19
20
"github.com/cockroachdb/pebble/internal/invariants"
20
21
"github.com/cockroachdb/pebble/internal/keyspan"
21
22
"github.com/cockroachdb/pebble/internal/keyspan/keyspanimpl"
@@ -209,12 +210,14 @@ type Iterator struct {
209
210
// short-lived (since they pin memtables and sstables), (b) plumbing a
210
211
// context into every method is very painful, (c) they do not (yet) respect
211
212
// 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
218
221
// Either readState or version is set, but not both.
219
222
readState * readState
220
223
version * manifest.Version
@@ -2362,6 +2365,9 @@ const maxKeyBufCacheSize = 4 << 10 // 4 KB
2362
2365
// It is not valid to call any method, including Close, after the iterator
2363
2366
// has been closed.
2364
2367
func (i * Iterator ) Close () error {
2368
+ if i .tracker != nil {
2369
+ i .tracker .Stop (i .trackerHandle )
2370
+ }
2365
2371
// Close the child iterator before releasing the readState because when the
2366
2372
// readState is released sstables referenced by the readState may be deleted
2367
2373
// 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
2895
2901
newIterRangeKey : i .newIterRangeKey ,
2896
2902
seqNum : i .seqNum ,
2897
2903
}
2904
+ if i .tracker != nil {
2905
+ dbi .tracker = i .tracker
2906
+ dbi .trackerHandle = i .tracker .Start ()
2907
+ }
2898
2908
if i .batch != nil {
2899
2909
dbi .batch = & buf .batchState
2900
2910
dbi .batch .batch = i .batch .batch
0 commit comments