@@ -2,39 +2,26 @@ package ctlstore
22
33import (
44 "database/sql"
5- "sync"
6- "sync/atomic"
7- "time"
85
9- "github.com/segmentio/stats/v4"
10-
11- "github.com/segmentio/ctlstore/pkg/globalstats"
126 "github.com/segmentio/ctlstore/pkg/scanfunc"
137 "github.com/segmentio/ctlstore/pkg/schema"
148)
159
1610// Rows composes an *sql.Rows and allows scanning ctlstore table rows into
1711// structs or maps, similar to how the GetRowByKey reader method works.
18- // It also keeps track of number of rows read and emits as a metric on Close
1912//
2013// The contract around Next/Err/Close is the same was it is for
2114// *sql.Rows.
2215type Rows struct {
23- rows * sql.Rows
24- cols []schema.DBColumnMeta
25- familyName string
26- tableName string
27- count uint32
28- once sync.Once
29- start time.Time
16+ rows * sql.Rows
17+ cols []schema.DBColumnMeta
3018}
3119
3220// Next returns true if there's another row available.
3321func (r * Rows ) Next () bool {
3422 if r .rows == nil {
3523 return false
3624 }
37- atomic .AddUint32 (& r .count , 1 )
3825 return r .rows .Next ()
3926}
4027
@@ -54,16 +41,6 @@ func (r *Rows) Close() error {
5441 if r .rows == nil {
5542 return nil
5643 }
57- r .once .Do (func () {
58- globalstats .Observe ("get_rows_by_key_prefix_row_count" , atomic .LoadUint32 (& r .count ),
59- stats .T ("family" , r .familyName ),
60- stats .T ("table" , r .tableName ))
61- if ! r .start .IsZero () {
62- globalstats .Observe ("get_rows_by_prefix_scan_time" , time .Now ().Sub (r .start ),
63- stats .T ("family" , r .familyName ),
64- stats .T ("table" , r .tableName ))
65- }
66- })
6744 return r .rows .Close ()
6845}
6946
0 commit comments