Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions deploy/crds/planetscale.com_vitessclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2140,6 +2140,12 @@ spec:
type: object
equal:
properties:
hexWidth:
default: 0
format: int32
maximum: 65536
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reasonable maximum for this that isn't int32 max?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i have based it on the maximum size we support in vitess:

	default:
		return nil, errors.New("this function does not support more than 65536 shards in a single keyspace")

minimum: 0
type: integer
parts:
format: int32
maximum: 65536
Expand Down
6 changes: 6 additions & 0 deletions deploy/crds/planetscale.com_vitesskeyspaces.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,12 @@ spec:
type: object
equal:
properties:
hexWidth:
default: 0
format: int32
maximum: 65536
minimum: 0
type: integer
parts:
format: int32
maximum: 65536
Expand Down
12 changes: 12 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -5806,6 +5806,18 @@ migration, and then remove the old partitioning.</p>
</tr>
<tr>
<td>
<code>hexWidth</code><br>
<em>
int32
</em>
</td>
<td>
<p>HexWidth is the number of hex characters to use for the shard range start and end.
If not set or set to 0, it will be automatically computed based on the number of requested shards.</p>
</td>
</tr>
<tr>
<td>
<code>shardTemplate</code><br>
<em>
<a href="#planetscale.com/v2.VitessShardTemplate">
Expand Down
12 changes: 12 additions & 0 deletions docs/api/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5808,6 +5808,18 @@ <h3 id="planetscale.com/v2.VitessKeyspaceEqualPartitioning">VitessKeyspaceEqualP
</tr>
<tr>
<td>
<code>hexWidth</code><br>
<em>
int32
</em>
</td>
<td>
<p>HexWidth is the number of hex characters to use for the shard range start and end.
If not set or set to 0, it will be automatically computed based on the number of requested shards.</p>
</td>
</tr>
<tr>
<td>
<code>shardTemplate</code><br>
<em>
<a href="#planetscale.com/v2.VitessShardTemplate">
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/planetscale/v2/vitesskeyspace_methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
func (p *VitessKeyspaceEqualPartitioning) KeyRanges() []VitessKeyRange {
// Invariant: number of parts must be between 1-65536. This is enforced via
// the CRD.
ranges, err := key.GenerateShardRanges(int(p.Parts), 0)
ranges, err := key.GenerateShardRanges(int(p.Parts), int(p.HexWidth))
if err != nil {
panic(fmt.Sprintf("could not generate shard range with %d parts: %v", p.Parts, err))
}
Expand Down
37 changes: 34 additions & 3 deletions pkg/apis/planetscale/v2/vitesskeyspace_methods_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ import (

func TestTranslationToVitessKeyRange(t *testing.T) {
table := []struct {
parts int32
want []VitessKeyRange
hexWidth int32
parts int32
want []VitessKeyRange
}{
{
parts: 1,
Expand Down Expand Up @@ -62,10 +63,40 @@ func TestTranslationToVitessKeyRange(t *testing.T) {
{"e0", ""},
},
},
{
hexWidth: 4,
parts: 7,
want: []VitessKeyRange{
{"", "2492"},
{"2492", "4924"},
{"4924", "6db6"},
{"6db6", "9249"},
{"9249", "b6db"},
{"b6db", "db6d"},
{"db6d", ""},
},
},
{
hexWidth: 4,
parts: 8,
want: []VitessKeyRange{
{"", "2000"},
{"2000", "4000"},
{"4000", "6000"},
{"6000", "8000"},
{"8000", "a000"},
{"a000", "c000"},
{"c000", "e000"},
{"e000", ""},
},
},
}

for _, test := range table {
p := VitessKeyspaceEqualPartitioning{Parts: test.parts}
p := VitessKeyspaceEqualPartitioning{
HexWidth: test.hexWidth,
Parts: test.parts,
}
if got, want := p.KeyRanges(), test.want; !reflect.DeepEqual(got, want) {
t.Errorf("KeyRanges(%v) = %#v; want %#v", test.parts, got, want)
}
Expand Down
7 changes: 7 additions & 0 deletions pkg/apis/planetscale/v2/vitesskeyspace_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,13 @@ type VitessKeyspaceEqualPartitioning struct {
// +kubebuilder:validation:Maximum=65536
Parts int32 `json:"parts"`

// HexWidth is the number of hex characters to use for the shard range start and end.
// If not set or set to 0, it will be automatically computed based on the number of requested shards.
// +kubebuilder:default=0
// +kubebuilder:validation:Minimum=0
// +kubebuilder:validation:Maximum=65536
HexWidth int32 `json:"hexWidth,omitempty"`

// ShardTemplate is the configuration used for each equal-sized shard.
// If you need shards that don't all share the same configuration,
// use custom partitioning instead.
Expand Down
1 change: 1 addition & 0 deletions test/endtoend/operator/302_new_shards.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ spec:
storage: 10Gi
- equal:
parts: 2
hexWidth: 4
shardTemplate:
databaseInitScriptSecret:
name: example-cluster-config
Expand Down
1 change: 1 addition & 0 deletions test/endtoend/operator/306_down_shard_0.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ spec:
partitionings:
- equal:
parts: 2
hexWidth: 4
shardTemplate:
databaseInitScriptSecret:
name: example-cluster-config
Expand Down
5 changes: 3 additions & 2 deletions test/endtoend/operator/401_scheduled_backups.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ spec:
strategies:
- name: customer_80-x
keyspace: "customer"
shard: "80-"
shard: "8000-"
- name: customer_x-80
keyspace: "customer"
shard: "-80"
shard: "-8000"
images:
vtctld: vitess/lite:mysql80
vtgate: vitess/lite:mysql80
Expand Down Expand Up @@ -139,6 +139,7 @@ spec:
partitionings:
- equal:
parts: 2
hexWidth: 4
shardTemplate:
databaseInitScriptSecret:
name: example-cluster-config
Expand Down
14 changes: 14 additions & 0 deletions test/endtoend/operator/operator-latest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4022,6 +4022,12 @@ spec:
type: object
equal:
properties:
hexWidth:
default: 0
format: int32
maximum: 65536
minimum: 0
type: integer
parts:
format: int32
maximum: 65536
Expand Down Expand Up @@ -4459,6 +4465,7 @@ spec:
- databaseInitScriptSecret
type: object
required:
- hexWidth
- parts
type: object
type: object
Expand Down Expand Up @@ -5847,6 +5854,12 @@ spec:
type: object
equal:
properties:
hexWidth:
default: 0
format: int32
maximum: 65536
minimum: 0
type: integer
parts:
format: int32
maximum: 65536
Expand Down Expand Up @@ -6284,6 +6297,7 @@ spec:
- databaseInitScriptSecret
type: object
required:
- hexWidth
- parts
type: object
type: object
Expand Down
34 changes: 17 additions & 17 deletions test/endtoend/upgrade_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,16 @@ function resharding() {

echo "Apply 302_new_shards.yaml"
kubectl apply -f 302_new_shards.yaml
checkPodStatusWithTimeout "example-customer-80-x-zone1-vtorc(.*)1/1(.*)Running(.*)"
checkPodStatusWithTimeout "example-customer-x-80-zone1-vtorc(.*)1/1(.*)Running(.*)"
checkPodStatusWithTimeout "example-customer-8000-x-zone1-vtorc(.*)1/1(.*)Running(.*)"
checkPodStatusWithTimeout "example-customer-x-8000-zone1-vtorc(.*)1/1(.*)Running(.*)"
checkPodStatusWithTimeout "example-vttablet-zone1(.*)3/3(.*)Running(.*)" 12

setupPortForwarding
waitForKeyspaceToBeServing customer -80 2
waitForKeyspaceToBeServing customer 80- 2
waitForKeyspaceToBeServing customer -8000 2
waitForKeyspaceToBeServing customer 8000- 2

echo "Ready to reshard ..."
vtctldclient LegacyVtctlCommand -- Reshard --source_shards '-' --target_shards '-80,80-' Create customer.cust2cust
vtctldclient LegacyVtctlCommand -- Reshard --source_shards '-' --target_shards '-8000,8000-' Create customer.cust2cust
if [ $? -ne 0 ]; then
echo "Reshard Create failed"
printMysqlErrorFiles
Expand Down Expand Up @@ -120,8 +120,8 @@ function resharding() {

sleep 10

assertSelect ../common/select_customer-80_data.sql "customer/-80" << EOF
Using customer/-80
assertSelect ../common/select_customer-80_data.sql "customer/-8000" << EOF
Using customer/-8000
Customer
+-------------+--------------------+
| customer_id | email |
Expand All @@ -142,8 +142,8 @@ COrder
+----------+-------------+----------+-------+
EOF

assertSelect ../common/select_customer80-_data.sql "customer/80-" << EOF
Using customer/80-
assertSelect ../common/select_customer80-_data.sql "customer/8000-" << EOF
Using customer/8000-
Customer
+-------------+----------------+
| customer_id | email |
Expand All @@ -168,8 +168,8 @@ EOF

kubectl apply -f 306_down_shard_0.yaml
checkPodStatusWithTimeout "example-vttablet-zone1(.*)3/3(.*)Running(.*)" 9
waitForKeyspaceToBeServing customer -80 2
waitForKeyspaceToBeServing customer 80- 2
waitForKeyspaceToBeServing customer -8000 2
waitForKeyspaceToBeServing customer 8000- 2
}

function scheduledBackups() {
Expand All @@ -180,20 +180,20 @@ function scheduledBackups() {
checkVitessBackupScheduleStatusWithTimeout "example-vbsc-customer(.*)"

initialCommerceBackups=$(kubectl get vtb -n example --no-headers | grep "commerce-x-x" | wc -l)
initialCustomerFirstShardBackups=$(kubectl get vtb -n example --no-headers | grep "customer-x-80" | wc -l)
initialCustomerSecondShardBackups=$(kubectl get vtb -n example --no-headers | grep "customer-80-x" | wc -l)
initialCustomerFirstShardBackups=$(kubectl get vtb -n example --no-headers | grep "customer-x-8000" | wc -l)
initialCustomerSecondShardBackups=$(kubectl get vtb -n example --no-headers | grep "customer-8000-x" | wc -l)

for i in {1..60} ; do
commerceBackups=$(kubectl get vtb -n example --no-headers | grep "commerce-x-x" | wc -l)
customerFirstShardBackups=$(kubectl get vtb -n example --no-headers | grep "customer-x-80" | wc -l)
customerSecondShardBackups=$(kubectl get vtb -n example --no-headers | grep "customer-80-x" | wc -l)
customerFirstShardBackups=$(kubectl get vtb -n example --no-headers | grep "customer-x-8000" | wc -l)
customerSecondShardBackups=$(kubectl get vtb -n example --no-headers | grep "customer-8000-x" | wc -l)

if [[ "${customerFirstShardBackups}" -ge $(( initialCustomerFirstShardBackups + 2 )) && "${customerSecondShardBackups}" -ge $(( initialCustomerSecondShardBackups + 2 )) && "${commerceBackups}" -ge $(( initialCommerceBackups + 2 )) ]]; then
echo "Found all backups"
return
else
echo "Got: ${customerFirstShardBackups} customer-x-80 backups but want: $(( initialCustomerFirstShardBackups + 2 ))"
echo "Got: ${customerSecondShardBackups} customer-80-x backups but want: $(( initialCustomerSecondShardBackups + 2 ))"
echo "Got: ${customerFirstShardBackups} customer-x-8000 backups but want: $(( initialCustomerFirstShardBackups + 2 ))"
echo "Got: ${customerSecondShardBackups} customer-8000-x backups but want: $(( initialCustomerSecondShardBackups + 2 ))"
echo "Got: ${commerceBackups} commerce-x-x backups but want: $(( initialCommerceBackups + 2 ))"
echo ""
fi
Expand Down