-
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.
Fixes #54971 This commit introduces a new ALTER RANGE RELOCATE command, which will allow an admin to move a lease or replica for a specific range. Unlike ALTER TABLE RELOCATE this command works on a range_id, which makes it a lot easier to use since the user does not have to worry about range keys, which are difficult to deal with in an emergncy situation. Release note (sql change): Introduce new SQL syntax ALTER RANGE RELOCATE to move a lease or replica between stores. This is helpful in an emergency situation to relocate data in the cluster.
- Loading branch information
Showing
33 changed files
with
761 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
alter_range_relocate_lease_stmt ::= | ||
'ALTER' 'RANGE' relocate_kw 'LEASE' 'TO' iconst64 'FOR' select_stmt | ||
| 'ALTER' 'RANGE' iconst64 relocate_kw 'LEASE' 'TO' iconst64 |
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,5 @@ | ||
alter_range_relocate_stmt ::= | ||
'ALTER' 'RANGE' relocate_kw voters_kw 'FROM' iconst64 'TO' iconst64 'FOR' select_stmt | ||
| 'ALTER' 'RANGE' iconst64 relocate_kw voters_kw 'FROM' iconst64 'TO' iconst64 | ||
| 'ALTER' 'RANGE' relocate_kw 'NON_VOTERS' 'FROM' iconst64 'TO' iconst64 'FOR' select_stmt | ||
| 'ALTER' 'RANGE' iconst64 relocate_kw 'NON_VOTERS' 'FROM' iconst64 'TO' iconst64 |
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 |
---|---|---|
@@ -1,2 +1,4 @@ | ||
alter_range_stmt ::= | ||
alter_zone_range_stmt | ||
| alter_range_relocate_lease_stmt | ||
| alter_range_relocate_stmt |
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
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
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,62 @@ | ||
// Copyright 2018 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 optbuilder | ||
|
||
import ( | ||
"github.com/cockroachdb/cockroach/pkg/sql/catalog/colinfo" | ||
"github.com/cockroachdb/cockroach/pkg/sql/opt/memo" | ||
"github.com/cockroachdb/cockroach/pkg/sql/opt/props/physical" | ||
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree" | ||
"github.com/cockroachdb/cockroach/pkg/sql/types" | ||
) | ||
|
||
// buildAlterTableRelocate builds an ALTER RANGE RELOCATE (LEASE). | ||
func (b *Builder) buildAlterRangeRelocate( | ||
relocate *tree.RelocateRange, inScope *scope, | ||
) (outScope *scope) { | ||
|
||
if err := b.catalog.RequireAdminRole(b.ctx, "ALTER RANGE RELOCATE"); err != nil { | ||
panic(err) | ||
} | ||
|
||
b.DisableMemoReuse = true | ||
|
||
outScope = inScope.push() | ||
b.synthesizeResultColumns(outScope, colinfo.AlterTableRelocateColumns) | ||
|
||
cmdName := "RELOCATE" | ||
if relocate.RelocateLease { | ||
cmdName += " LEASE" | ||
} | ||
colNames := []string{"range ids"} | ||
colTypes := []*types.T{types.Int} | ||
|
||
outScope = inScope.push() | ||
b.synthesizeResultColumns(outScope, colinfo.AlterRangeRelocateColumns) | ||
|
||
// We don't allow the input statement to reference outer columns, so we | ||
// pass a "blank" scope rather than inScope. | ||
inputScope := b.buildStmt(relocate.Rows, colTypes, b.allocScope()) | ||
checkInputColumns(cmdName, inputScope, colNames, colTypes, 1) | ||
|
||
outScope.expr = b.factory.ConstructAlterRangeRelocate( | ||
inputScope.expr.(memo.RelExpr), | ||
&memo.AlterRangeRelocatePrivate{ | ||
RelocateLease: relocate.RelocateLease, | ||
RelocateNonVoters: relocate.RelocateNonVoters, | ||
ToStoreID: relocate.ToStoreID, | ||
FromStoreID: relocate.FromStoreID, | ||
Columns: colsToColList(outScope.cols), | ||
Props: physical.MinRequired, | ||
}, | ||
) | ||
return outScope | ||
} |
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.