-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #134988 from angles-n-daemons/backport24.3-133190-…
…133840-134106 release-24.3: ui, apiutil, server: surface multiple indexes within a range in the hot ranges page
- Loading branch information
Showing
24 changed files
with
1,610 additions
and
121 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,127 @@ | ||
// Copyright 2024 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the CockroachDB Software License | ||
// included in the /LICENSE file. | ||
|
||
package roachpb_test | ||
|
||
import ( | ||
"math" | ||
"testing" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/keys" | ||
"github.com/cockroachdb/cockroach/pkg/roachpb" | ||
"github.com/cockroachdb/cockroach/pkg/testutils" | ||
"github.com/cockroachdb/cockroach/pkg/util/encoding" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestKeyClampTenants(t *testing.T) { | ||
// tp = TablePrefix | ||
tp := keys.MakeSQLCodec(roachpb.MustMakeTenantID(3)).TablePrefix | ||
lowTp := keys.MakeSQLCodec(roachpb.MustMakeTenantID(1)).TablePrefix | ||
highTp := keys.MakeSQLCodec(roachpb.MustMakeTenantID(5)).TablePrefix | ||
sysTp := keys.SystemSQLCodec.TablePrefix | ||
tests := []struct { | ||
name string | ||
k, a, b roachpb.Key | ||
expected roachpb.Key | ||
}{ | ||
{"key within main tenant is unchanged", tp(5), tp(1), tp(10), tp(5)}, | ||
{"low tenant codec gets clamped to lower bound", lowTp(5), tp(1), tp(10), tp(1)}, | ||
{"high tenant codec gets clamped to upper bound", highTp(5), tp(1), tp(10), tp(10)}, | ||
{"system codec occurs below the tenant table boundaries", sysTp(5), tp(1), tp(10), tp(1)}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
result, err := tt.k.Clamp(tt.a, tt.b) | ||
require.NoError(t, err) | ||
if !result.Equal(tt.expected) { | ||
t.Errorf("Clamp(%v, %v, %v) = %v; want %v", tt.k, tt.a, tt.b, result, tt.expected) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestKeyClampTables(t *testing.T) { | ||
// tp = TablePrefix | ||
tp := keys.MakeSQLCodec(roachpb.MustMakeTenantID(3)).TablePrefix | ||
tests := []struct { | ||
name string | ||
k, a, b roachpb.Key | ||
expected roachpb.Key | ||
}{ | ||
{"table within prefix is unchanged", tp(5), tp(1), tp(10), tp(5)}, | ||
{"low table gets clamped to lower bound", tp(0), tp(1), tp(10), tp(1)}, | ||
{"high table gets clamped to upper bound", tp(11), tp(1), tp(10), tp(10)}, | ||
{"low table on lower bound is unchanged", tp(1), tp(1), tp(10), tp(1)}, | ||
{"high table on upper bound is unchanged", tp(10), tp(1), tp(10), tp(10)}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
result, err := tt.k.Clamp(tt.a, tt.b) | ||
require.NoError(t, err) | ||
if !result.Equal(tt.expected) { | ||
t.Errorf("Clamp(%v, %v, %v) = %v; want %v", tt.k, tt.a, tt.b, result, tt.expected) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestKeyClampTenantTablespace(t *testing.T) { | ||
timeseriesKeyPrefix := encoding.EncodeVarintAscending( | ||
encoding.EncodeBytesAscending( | ||
append(roachpb.Key(nil), keys.TimeseriesPrefix...), | ||
[]byte("my.fake.metric"), | ||
), | ||
int64(10), | ||
) | ||
tsKey := func(source string, timestamp int64) roachpb.Key { | ||
return append(encoding.EncodeVarintAscending(timeseriesKeyPrefix, timestamp), source...) | ||
} | ||
|
||
tp := keys.MakeSQLCodec(roachpb.MustMakeTenantID(3)).TablePrefix | ||
lower := tp(0) | ||
upper := tp(math.MaxUint32) | ||
tests := []struct { | ||
name string | ||
k, a, b roachpb.Key | ||
expected roachpb.Key | ||
}{ | ||
{"KeyMin gets clamped to lower", roachpb.KeyMin, lower, upper, lower}, | ||
{"KeyMax gets clamped to upper", roachpb.KeyMax, lower, upper, upper}, | ||
{"Meta1Prefix gets clamped to lower", keys.Meta1Prefix, lower, upper, lower}, | ||
{"Meta2Prefix gets clamped to lower", keys.Meta2Prefix, lower, upper, lower}, | ||
{"TableDataMin gets clamped to lower", keys.TableDataMin, lower, upper, lower}, | ||
// below is an unexpected test case for a tenant codec | ||
{"TableDataMax also gets clamped to lower", keys.TableDataMax, lower, upper, lower}, | ||
{"SystemPrefix gets clamped to lower", keys.SystemPrefix, lower, upper, lower}, | ||
{"TimeseriesKey gets clamped to lower", tsKey("5", 123), lower, upper, lower}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
result, err := tt.k.Clamp(tt.a, tt.b) | ||
require.NoError(t, err) | ||
if !result.Equal(tt.expected) { | ||
t.Errorf("Clamp(%v, %v, %v) = %v; want %v", tt.k, tt.a, tt.b, result, tt.expected) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestKeyClampError(t *testing.T) { | ||
// verify that max < min throws error | ||
a, b := roachpb.Key([]byte{'a'}), roachpb.Key([]byte{'b'}) | ||
expected := `cannot clamp when min '"b"' is larger than max '"a"'` | ||
_, err := a.Clamp(b, a) | ||
if !testutils.IsError(err, expected) { | ||
t.Fatalf("expected error to be '%s', got '%s'", expected, err) | ||
} | ||
|
||
// verify that max = min throws no error | ||
_, err = a.Clamp(a, a) | ||
require.NoError(t, err) | ||
} |
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,88 @@ | ||
// Copyright 2024 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the CockroachDB Software License | ||
// included in the /LICENSE file. | ||
|
||
package roachpb_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/keys" | ||
"github.com/cockroachdb/cockroach/pkg/roachpb" | ||
"github.com/cockroachdb/cockroach/pkg/testutils" | ||
) | ||
|
||
func TestSpanZeroLength(t *testing.T) { | ||
// create two separate references here. | ||
shouldBeEmpty := roachpb.Span{ | ||
Key: keys.SystemSQLCodec.TablePrefix(1), | ||
EndKey: keys.SystemSQLCodec.TablePrefix(1), | ||
} | ||
if !shouldBeEmpty.ZeroLength() { | ||
t.Fatalf("expected span %s to be empty.", shouldBeEmpty) | ||
} | ||
|
||
shouldNotBeEmpty := roachpb.Span{ | ||
Key: keys.SystemSQLCodec.TablePrefix(1), | ||
EndKey: keys.SystemSQLCodec.TablePrefix(1).Next(), | ||
} | ||
if shouldNotBeEmpty.ZeroLength() { | ||
t.Fatalf("expected span %s to not be empty.", shouldNotBeEmpty) | ||
} | ||
} | ||
|
||
func TestSpanClamp(t *testing.T) { | ||
tp := keys.SystemSQLCodec.TablePrefix | ||
tests := []struct { | ||
name string | ||
span roachpb.Span | ||
bounds roachpb.Span | ||
want roachpb.Span | ||
error string | ||
}{ | ||
{ | ||
name: "within bounds", | ||
span: roachpb.Span{tp(5), tp(10)}, | ||
bounds: roachpb.Span{tp(0), tp(15)}, | ||
want: roachpb.Span{tp(5), tp(10)}, | ||
}, | ||
{ | ||
name: "clamp lower bound", | ||
span: roachpb.Span{tp(0), tp(10)}, | ||
bounds: roachpb.Span{tp(5), tp(15)}, | ||
want: roachpb.Span{tp(5), tp(10)}, | ||
}, | ||
{ | ||
name: "clamp upper bound", | ||
span: roachpb.Span{tp(5), tp(20)}, | ||
bounds: roachpb.Span{tp(0), tp(15)}, | ||
want: roachpb.Span{tp(5), tp(15)}, | ||
}, | ||
{ | ||
name: "clamp both bounds", | ||
span: roachpb.Span{tp(0), tp(20)}, | ||
bounds: roachpb.Span{tp(5), tp(15)}, | ||
want: roachpb.Span{tp(5), tp(15)}, | ||
}, | ||
{ | ||
name: "clamp start error", | ||
span: roachpb.Span{}, | ||
bounds: roachpb.Span{tp(2), tp(1)}, | ||
want: roachpb.Span{}, | ||
error: "cannot clamp when min '/Table/2' is larger than max '/Table/1'", | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
span, err := tt.span.Clamp(tt.bounds) | ||
if !testutils.IsError(err, tt.error) { | ||
t.Fatalf("expected error to be '%s', got '%s'", tt.error, err) | ||
} | ||
if !span.Equal(tt.want) { | ||
t.Errorf("Clamp() = %v, want %v", span, tt.want) | ||
} | ||
}) | ||
} | ||
} |
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
Oops, something went wrong.