Skip to content

Commit

Permalink
*: suport alter table set flash replica syntax (#564)
Browse files Browse the repository at this point in the history
  • Loading branch information
crazycs520 authored and lzmhhh123 committed Oct 21, 2019
1 parent 646d641 commit 488522f
Show file tree
Hide file tree
Showing 7 changed files with 7,851 additions and 7,738 deletions.
21 changes: 21 additions & 0 deletions ast/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -1966,6 +1966,8 @@ const (
AlterTableIndexInvisible
// TODO: Add more actions
AlterTableOrderByColumns
// AlterTableSetTiFlashReplica uses to set the table TiFlash replica.
AlterTableSetTiFlashReplica
)

// LockType is the type for AlterTableSpec.
Expand Down Expand Up @@ -2060,6 +2062,12 @@ type AlterTableSpec struct {
WithValidation bool
Num uint64
Visibility IndexVisibility
TiFlashReplica *TiFlashReplicaSpec
}

type TiFlashReplicaSpec struct {
Count uint64
Labels []string
}

// AlterOrderItem represents an item in order by at alter table stmt.
Expand All @@ -2083,6 +2091,19 @@ func (n *AlterOrderItem) Restore(ctx *RestoreCtx) error {
// Restore implements Node interface.
func (n *AlterTableSpec) Restore(ctx *RestoreCtx) error {
switch n.Tp {
case AlterTableSetTiFlashReplica:
ctx.WriteKeyWord("SET TIFLASH REPLICA ")
ctx.WritePlainf("%d", n.TiFlashReplica.Count)
if len(n.TiFlashReplica.Labels) == 0 {
break
}
ctx.WriteKeyWord(" LOCATION LABELS ")
for i, v := range n.TiFlashReplica.Labels {
if i > 0 {
ctx.WritePlain(", ")
}
ctx.WriteString(v)
}
case AlterTableOption:
switch {
case len(n.Options) == 2 &&
Expand Down
3 changes: 3 additions & 0 deletions misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,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 @@ -365,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 @@ -479,6 +481,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 @@ -59,6 +59,8 @@ const (
ActionLockTable ActionType = 27
ActionUnlockTable ActionType = 28
ActionRepairTable ActionType = 29
ActionSetTiFlashReplica ActionType = 30
ActionUpdateTiFlashReplicaStatus ActionType = 31
)

// AddIndexStr is a string related to the operation of "add index".
Expand Down Expand Up @@ -94,6 +96,8 @@ var actionMap = map[ActionType]string{
ActionLockTable: "lock table",
ActionUnlockTable: "unlock table",
ActionRepairTable: "repair table",
ActionSetTiFlashReplica: "set tiflash replica",
ActionUpdateTiFlashReplicaStatus: "update tiflash replica status",
}

// String return current ddl action in string
Expand Down
10 changes: 10 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"`

// TiFlashReplica means the TiFlash replica info.
TiFlashReplica *TiFlashReplicaInfo `json:"tiflash_replica"`
}

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

// TiFlashReplicaInfo means the flash replica info.
type TiFlashReplicaInfo struct {
Count uint64
LocationLabels []string
Available bool
}

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

0 comments on commit 488522f

Please sign in to comment.