@@ -207,6 +207,13 @@ type IterOptions struct {
207207 // changed by calling SetOptions.
208208 Category block.Category
209209
210+ // ExemptFromTracking indicates that we should not track the lifetime of the
211+ // iterator (used to log information about long-lived iterators). Useful for
212+ // hot paths where we know the iterator will be short-lived.
213+ ExemptFromTracking bool
214+
215+ // DebugRangeKeyStack enables additional logging of the range key stack
216+ // iterator, via keyspan.InjectLogging. Only used for debugging.
210217 DebugRangeKeyStack bool
211218
212219 // Internal options.
@@ -792,6 +799,22 @@ type Options struct {
792799 // virtual table rewrite compactions entirely. The default value is 0.30
793800 // (rewrite when >= 30% of backing data is unreferenced).
794801 VirtualTableRewriteUnreferencedFraction func () float64
802+
803+ // IteratorTracking configures periodic logging of iterators held open for
804+ // too long.
805+ IteratorTracking struct {
806+ // PollInterval is the interval at which to log a report of long-lived
807+ // iterators. If zero, disables iterator tracking.
808+ //
809+ // The default value is 0 (disabled).
810+ PollInterval time.Duration
811+
812+ // MaxAge is the age above which iterators are considered long-lived. If
813+ // zero, disables iterator tracking.
814+ //
815+ // The default value is 0 (disabled).
816+ MaxAge time.Duration
817+ }
795818 }
796819
797820 // Filters is a map from filter policy name to filter policy. It is used for
@@ -1790,6 +1813,13 @@ func (o *Options) String() string {
17901813 fmt .Fprintf (& buf , " secondary_cache_size_bytes=%d\n " , o .Experimental .SecondaryCacheSizeBytes )
17911814 fmt .Fprintf (& buf , " create_on_shared=%d\n " , o .Experimental .CreateOnShared )
17921815
1816+ if o .Experimental .IteratorTracking .PollInterval != 0 {
1817+ fmt .Fprintf (& buf , " iterator_tracking_poll_interval=%s\n " , o .Experimental .IteratorTracking .PollInterval )
1818+ }
1819+ if o .Experimental .IteratorTracking .MaxAge != 0 {
1820+ fmt .Fprintf (& buf , " iterator_tracking_max_age=%s\n " , o .Experimental .IteratorTracking .MaxAge )
1821+ }
1822+
17931823 // Private options.
17941824 //
17951825 // These options are only encoded if true, because we do not want them to
@@ -2232,6 +2262,10 @@ func (o *Options) Parse(s string, hooks *ParseHooks) error {
22322262 var createOnSharedInt int64
22332263 createOnSharedInt , err = strconv .ParseInt (value , 10 , 64 )
22342264 o .Experimental .CreateOnShared = remote .CreateOnSharedStrategy (createOnSharedInt )
2265+ case "iterator_tracking_poll_interval" :
2266+ o .Experimental .IteratorTracking .PollInterval , err = time .ParseDuration (value )
2267+ case "iterator_tracking_max_age" :
2268+ o .Experimental .IteratorTracking .MaxAge , err = time .ParseDuration (value )
22352269 default :
22362270 if hooks != nil && hooks .SkipUnknown != nil && hooks .SkipUnknown (section + "." + key , value ) {
22372271 return nil
0 commit comments