forked from cockroachdb/cockroach
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rditer: add functions to compute the MVCC stats for user-only and non…
…-user spans ComputeStatsForRange iterates over an entire range and computes its MVCC stats. This patch adds ComputeStatsForRangeUserOnly and ComputeStatsForRangeExcludingUser, which compute the MVCC stats corresponding to the user-only and non-user spans in the range, respectively. These functions are useful for computing the estimated stats proposed in cockroachdb#119499 by allowing to quickly iterate only over the non-user key spans in the range, and separately iterate over the user-only key spans. Part of: cockroachdb#119499 Release note: None
- Loading branch information
1 parent
8ad5029
commit 4b963ea
Showing
5 changed files
with
141 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright 2024 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package rditer | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/roachpb" | ||
"github.com/cockroachdb/cockroach/pkg/storage" | ||
"github.com/cockroachdb/cockroach/pkg/util/leaktest" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
// TestComputeStats verifies that the sum of the stats returned by | ||
// ComputeStatsForRangeUserOnly and ComputeStatsForRangeExcludingUser equals the | ||
// total range stats returned by ComputeStatsForRange. | ||
func TestComputeStats(t *testing.T) { | ||
defer leaktest.AfterTest(t)() | ||
|
||
storage.DisableMetamorphicSimpleValueEncoding(t) | ||
|
||
eng := storage.NewDefaultInMemForTesting() | ||
defer eng.Close() | ||
|
||
desc := roachpb.RangeDescriptor{ | ||
RangeID: 1, | ||
StartKey: roachpb.RKey("a"), | ||
EndKey: roachpb.RKey("b"), | ||
} | ||
|
||
createRangeData(t, eng, desc) | ||
nowNanos := time.Now().UnixNano() | ||
|
||
userOnly, err := ComputeStatsForRangeUserOnly(context.Background(), &desc, eng, nowNanos) | ||
require.NoError(t, err) | ||
nonUserOnly, err := ComputeStatsForRangeExcludingUser(context.Background(), &desc, eng, nowNanos) | ||
require.NoError(t, err) | ||
all, err := ComputeStatsForRange(context.Background(), &desc, eng, nowNanos) | ||
require.NoError(t, err) | ||
|
||
userPlusNonUser := userOnly | ||
userPlusNonUser.Add(nonUserOnly) | ||
require.Equal(t, all, userPlusNonUser) | ||
} |