Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*: suport alter table set flash replica syntax #564

Merged
merged 11 commits into from
Oct 21, 2019
21 changes: 21 additions & 0 deletions ast/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -1921,6 +1921,8 @@ const (
AlterTableIndexInvisible
// TODO: Add more actions
AlterTableOrderByColumns
// AlterTableSetFlashReplica uses to set the table TiFlash replica.
AlterTableSetFlashReplica
)

// LockType is the type for AlterTableSpec.
Expand Down Expand Up @@ -2015,6 +2017,12 @@ type AlterTableSpec struct {
WithValidation bool
Num uint64
Visibility IndexVisibility
FlashReplica *FlashReplicaSpec
}

type FlashReplicaSpec struct {
Count uint64
Labels []string
}

// AlterOrderItem represents an item in order by at alter table stmt.
Expand All @@ -2038,6 +2046,19 @@ func (n *AlterOrderItem) Restore(ctx *RestoreCtx) error {
// Restore implements Node interface.
func (n *AlterTableSpec) Restore(ctx *RestoreCtx) error {
switch n.Tp {
case AlterTableSetFlashReplica:
ctx.WriteKeyWord("SET FLASH REPLICA ")
ctx.WritePlainf("%d", n.FlashReplica.Count)
if len(n.FlashReplica.Labels) == 0 {
break
}
ctx.WriteKeyWord(" LOCATION LABELS ")
for i, v := range n.FlashReplica.Labels {
if i > 0 {
ctx.WritePlain(", ")
}
ctx.WriteString(v)
}
case AlterTableOption:
switch {
case len(n.Options) == 2 &&
Expand Down
4 changes: 4 additions & 0 deletions misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ var tokenMap = map[string]int{
"FIRST": first,
"FIXED": fixed,
"FLOAT": floatType,
"FLASH": flash,
"FLUSH": flush,
"FOLLOWING": following,
"FOR": forKwd,
Expand Down Expand Up @@ -350,6 +351,7 @@ var tokenMap = map[string]int{
"KEY_BLOCK_SIZE": keyBlockSize,
"KEYS": keys,
"KILL": kill,
"LABELS": labels,
"LAST": last,
"LEADING": leading,
"LEFT": left,
Expand All @@ -364,6 +366,7 @@ var tokenMap = map[string]int{
"LOCAL": local,
"LOCALTIME": localTime,
"LOCALTIMESTAMP": localTs,
"LOCATION": location,
"LOCK": lock,
"LONG": long,
"LONGBLOB": longblobType,
Expand Down Expand Up @@ -477,6 +480,7 @@ var tokenMap = map[string]int{
"REPEATABLE": repeatable,
"REPLACE": replace,
"RESPECT": respect,
"REPLICA": replica,
"REPLICATION": replication,
"REQUIRE": require,
"RESTRICT": restrict,
Expand Down
4 changes: 4 additions & 0 deletions model/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ const (
ActionModifySchemaCharsetAndCollate ActionType = 26
ActionLockTable ActionType = 27
ActionUnlockTable ActionType = 28
ActionSetFlashReplica ActionType = 29
ActionUpdateFlashReplicaStatus ActionType = 30
)

// AddIndexStr is a string related to the operation of "add index".
Expand Down Expand Up @@ -92,6 +94,8 @@ var actionMap = map[ActionType]string{
ActionModifySchemaCharsetAndCollate: "modify schema charset and collate",
ActionLockTable: "lock table",
ActionUnlockTable: "unlock table",
ActionSetFlashReplica: "set flash replica",
ActionUpdateFlashReplicaStatus: "update flash replica status",
}

// String return current ddl action in string
Expand Down
11 changes: 11 additions & 0 deletions model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,9 @@ type TableInfo struct {

// Version means the version of the table info.
Version uint16 `json:"version"`

// FlashReplica means the flash replica info.
FlashReplica *FlashReplicaInfo `json:"flash_replica"`
}

// TableLockInfo provides meta data describing a table lock.
Expand Down Expand Up @@ -323,6 +326,14 @@ func (t TableLockType) String() string {
return ""
}

// FlashReplicaInfo means the flash replica info.
type FlashReplicaInfo struct {
Count uint64
LocationLabels []string
RegionCount uint64
FlashRegionCount uint64
}

// GetPartitionInfo returns the partition information.
func (t *TableInfo) GetPartitionInfo() *PartitionInfo {
if t.Partition != nil && t.Partition.Enable {
Expand Down
Loading