Skip to content

Commit

Permalink
Merge pull request cockroachdb#66790 from Azhng/backport21.1-66787
Browse files Browse the repository at this point in the history
release-21.1: roachpb: fix incorrect addition of roachpb.ExecStats Count field
  • Loading branch information
Azhng committed Jun 23, 2021
2 parents a0c9050 + 2d36097 commit 46ce2fb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pkg/roachpb/app_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,5 +182,5 @@ func (s *ExecStats) Add(other ExecStats) {
s.NetworkMessages.Add(other.NetworkMessages, execStatCollectionCount, other.Count)
s.MaxDiskUsage.Add(other.MaxDiskUsage, execStatCollectionCount, other.Count)

s.Count += s.Count
s.Count += other.Count
}
11 changes: 6 additions & 5 deletions pkg/roachpb/app_stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,13 @@ func TestAddNumericStats(t *testing.T) {
}

func TestAddExecStats(t *testing.T) {
numericStatA := NumericStat{Mean: 1, SquaredDiffs: 1}
numericStatB := NumericStat{Mean: 1, SquaredDiffs: 1}
a := ExecStats{Count: 1, NetworkBytes: numericStatA}
numericStatA := NumericStat{Mean: 354.123, SquaredDiffs: 34.34123}
numericStatB := NumericStat{Mean: 9.34354, SquaredDiffs: 75.321}
a := ExecStats{Count: 3, NetworkBytes: numericStatA}
b := ExecStats{Count: 1, NetworkBytes: numericStatB}
expectedNumericStat := AddNumericStats(a.NetworkBytes, b.NetworkBytes, a.Count, b.Count)
a.Add(b)
require.Equal(t, int64(2), a.Count)
require.Equal(t, expectedNumericStat, a.NetworkBytes)
require.Equal(t, int64(4), a.Count)
epsilon := 0.00000001
require.True(t, expectedNumericStat.AlmostEqual(a.NetworkBytes, epsilon), "expected %+v, but found %+v", expectedNumericStat, a.NetworkMessages)
}

0 comments on commit 46ce2fb

Please sign in to comment.