Skip to content

Commit

Permalink
row: track KV bytes read for GetRequests
Browse files Browse the repository at this point in the history
After cockroachdb#61583, we emit GetRequests from SQL when possible. We forgot to
update the stats collection code that tracks the number of bytes read
from KV when GetRequests were emitted; this is now corrected.

Release note: None
  • Loading branch information
jordanlewis committed Sep 10, 2021
1 parent fd070d5 commit 562d860
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
1 change: 0 additions & 1 deletion pkg/sql/row/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ go_library(
"//pkg/util/log/eventpb",
"//pkg/util/metric",
"//pkg/util/mon",
"//pkg/util/syncutil",
"//pkg/util/timeutil",
"//pkg/util/unique",
"//pkg/util/uuid",
Expand Down
19 changes: 10 additions & 9 deletions pkg/sql/row/kv_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ package row
import (
"context"
"time"
"sync/atomic"

"github.com/cockroachdb/cockroach/pkg/kv"
"github.com/cockroachdb/cockroach/pkg/roachpb"
Expand All @@ -22,7 +23,6 @@ import (
"github.com/cockroachdb/cockroach/pkg/storage/enginepb"
"github.com/cockroachdb/cockroach/pkg/util/hlc"
"github.com/cockroachdb/cockroach/pkg/util/mon"
"github.com/cockroachdb/cockroach/pkg/util/syncutil"
"github.com/cockroachdb/errors"
)

Expand All @@ -37,8 +37,8 @@ type KVFetcher struct {
newSpan bool

// Observability fields.
mu struct {
syncutil.Mutex
// Note: these need to be read via an atomic op.
atomics struct {
bytesRead int64
}
}
Expand Down Expand Up @@ -114,9 +114,7 @@ func (f *KVFetcher) GetBytesRead() int64 {
if f == nil {
return 0
}
f.mu.Lock()
defer f.mu.Unlock()
return f.mu.bytesRead
return atomic.LoadInt64(&f.atomics.bytesRead)
}

// MVCCDecodingStrategy controls if and how the fetcher should decode MVCC
Expand Down Expand Up @@ -192,9 +190,12 @@ func (f *KVFetcher) NextKV(
return false, kv, false, nil
}
f.newSpan = true
f.mu.Lock()
f.mu.bytesRead += int64(len(f.batchResponse))
f.mu.Unlock()
nBytes := len(f.batchResponse)
for i := range f.kvs {
nBytes += len(f.kvs[i].Key)
nBytes += len(f.kvs[i].Value.RawBytes)
}
atomic.AddInt64(&f.atomics.bytesRead, int64(nBytes))
}
}

Expand Down

0 comments on commit 562d860

Please sign in to comment.