Skip to content

Commit 46bead0

Browse files
author
Shlomi Noach
authored
Merge branch 'master' into fClose-Fix
2 parents c6a6a53 + a79109b commit 46bead0

File tree

12 files changed

+104
-24
lines changed

12 files changed

+104
-24
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ Please see [Coding gh-ost](doc/coding-ghost.md) for a guide to getting started d
9494

9595
[Download latest release here](https://github.com/github/gh-ost/releases/latest)
9696

97-
`gh-ost` is a Go project; it is built with Go `1.8` (though `1.7` should work as well). To build on your own, use either:
97+
`gh-ost` is a Go project; it is built with Go `1.9` and above. To build on your own, use either:
9898
- [script/build](https://github.com/github/gh-ost/blob/master/script/build) - this is the same build script used by CI hence the authoritative; artifact is `./bin/gh-ost` binary.
9999
- [build.sh](https://github.com/github/gh-ost/blob/master/build.sh) for building `tar.gz` artifacts in `/tmp/gh-ost`
100100

build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function build {
1010
GOOS=$3
1111
GOARCH=$4
1212

13-
if [[ $(go version | egrep "go1[.][012345678]") ]]; then
13+
if ! go version | egrep -q 'go(1[.]9|1[.]1[0-9])' ; then
1414
echo "go version is too low. Must use 1.9 or above"
1515
exit 1
1616
fi

go/base/context.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,23 @@ type RowsEstimateMethod string
2828

2929
const (
3030
TableStatusRowsEstimate RowsEstimateMethod = "TableStatusRowsEstimate"
31-
ExplainRowsEstimate = "ExplainRowsEstimate"
32-
CountRowsEstimate = "CountRowsEstimate"
31+
ExplainRowsEstimate RowsEstimateMethod = "ExplainRowsEstimate"
32+
CountRowsEstimate RowsEstimateMethod = "CountRowsEstimate"
3333
)
3434

3535
type CutOver int
3636

3737
const (
38-
CutOverAtomic CutOver = iota
39-
CutOverTwoStep = iota
38+
CutOverAtomic CutOver = iota
39+
CutOverTwoStep
4040
)
4141

4242
type ThrottleReasonHint string
4343

4444
const (
4545
NoThrottleReasonHint ThrottleReasonHint = "NoThrottleReasonHint"
46-
UserCommandThrottleReasonHint = "UserCommandThrottleReasonHint"
47-
LeavingHibernationThrottleReasonHint = "LeavingHibernationThrottleReasonHint"
46+
UserCommandThrottleReasonHint ThrottleReasonHint = "UserCommandThrottleReasonHint"
47+
LeavingHibernationThrottleReasonHint ThrottleReasonHint = "LeavingHibernationThrottleReasonHint"
4848
)
4949

5050
const (

go/binlog/binlog_dml_event.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,18 @@ package binlog
77

88
import (
99
"fmt"
10-
"github.com/github/gh-ost/go/sql"
1110
"strings"
11+
12+
"github.com/github/gh-ost/go/sql"
1213
)
1314

1415
type EventDML string
1516

1617
const (
1718
NotDML EventDML = "NoDML"
18-
InsertDML = "Insert"
19-
UpdateDML = "Update"
20-
DeleteDML = "Delete"
19+
InsertDML EventDML = "Insert"
20+
UpdateDML EventDML = "Update"
21+
DeleteDML EventDML = "Delete"
2122
)
2223

2324
func ToEventDML(description string) EventDML {

go/logic/migrator.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,11 @@ func (this *Migrator) listenOnPanicAbort() {
255255
// validateStatement validates the `alter` statement meets criteria.
256256
// At this time this means:
257257
// - column renames are approved
258+
// - no table rename allowed
258259
func (this *Migrator) validateStatement() (err error) {
260+
if this.parser.IsRenameTable() {
261+
return fmt.Errorf("ALTER statement seems to RENAME the table. This is not supported, and you should run your RENAME outside gh-ost.")
262+
}
259263
if this.parser.HasNonTrivialRenames() && !this.migrationContext.SkipRenamedColumns {
260264
this.migrationContext.ColumnRenameMap = this.parser.GetNonTrivialRenames()
261265
if !this.migrationContext.ApproveRenamedColumns {

go/sql/builder.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ type ValueComparisonSign string
1515

1616
const (
1717
LessThanComparisonSign ValueComparisonSign = "<"
18-
LessThanOrEqualsComparisonSign = "<="
19-
EqualsComparisonSign = "="
20-
GreaterThanOrEqualsComparisonSign = ">="
21-
GreaterThanComparisonSign = ">"
22-
NotEqualsComparisonSign = "!="
18+
LessThanOrEqualsComparisonSign ValueComparisonSign = "<="
19+
EqualsComparisonSign ValueComparisonSign = "="
20+
GreaterThanOrEqualsComparisonSign ValueComparisonSign = ">="
21+
GreaterThanComparisonSign ValueComparisonSign = ">"
22+
NotEqualsComparisonSign ValueComparisonSign = "!="
2323
)
2424

2525
// EscapeName will escape a db/table/column/... name by wrapping with backticks.

go/sql/parser.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@ var (
1515
sanitizeQuotesRegexp = regexp.MustCompile("('[^']*')")
1616
renameColumnRegexp = regexp.MustCompile(`(?i)\bchange\s+(column\s+|)([\S]+)\s+([\S]+)\s+`)
1717
dropColumnRegexp = regexp.MustCompile(`(?i)\bdrop\s+(column\s+|)([\S]+)$`)
18+
renameTableRegexp = regexp.MustCompile(`(?i)\brename\s+(to|as)\s+`)
1819
)
1920

2021
type Parser struct {
2122
columnRenameMap map[string]string
2223
droppedColumns map[string]bool
24+
isRenameTable bool
2325
}
2426

2527
func NewParser() *Parser {
@@ -86,6 +88,12 @@ func (this *Parser) parseAlterToken(alterToken string) (err error) {
8688
this.droppedColumns[submatch[2]] = true
8789
}
8890
}
91+
{
92+
// rename table
93+
if renameTableRegexp.MatchString(alterToken) {
94+
this.isRenameTable = true
95+
}
96+
}
8997
return nil
9098
}
9199

@@ -115,3 +123,7 @@ func (this *Parser) HasNonTrivialRenames() bool {
115123
func (this *Parser) DroppedColumnsMap() map[string]bool {
116124
return this.droppedColumns
117125
}
126+
127+
func (this *Parser) IsRenameTable() bool {
128+
return this.isRenameTable
129+
}

go/sql/parser_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,42 @@ func TestParseAlterStatementDroppedColumns(t *testing.T) {
159159
test.S(t).ExpectTrue(parser.droppedColumns["b"])
160160
}
161161
}
162+
163+
func TestParseAlterStatementRenameTable(t *testing.T) {
164+
165+
{
166+
parser := NewParser()
167+
statement := "drop column b"
168+
err := parser.ParseAlterStatement(statement)
169+
test.S(t).ExpectNil(err)
170+
test.S(t).ExpectFalse(parser.isRenameTable)
171+
}
172+
{
173+
parser := NewParser()
174+
statement := "rename as something_else"
175+
err := parser.ParseAlterStatement(statement)
176+
test.S(t).ExpectNil(err)
177+
test.S(t).ExpectTrue(parser.isRenameTable)
178+
}
179+
{
180+
parser := NewParser()
181+
statement := "drop column b, rename as something_else"
182+
err := parser.ParseAlterStatement(statement)
183+
test.S(t).ExpectNil(err)
184+
test.S(t).ExpectTrue(parser.isRenameTable)
185+
}
186+
{
187+
parser := NewParser()
188+
statement := "engine=innodb rename as something_else"
189+
err := parser.ParseAlterStatement(statement)
190+
test.S(t).ExpectNil(err)
191+
test.S(t).ExpectTrue(parser.isRenameTable)
192+
}
193+
{
194+
parser := NewParser()
195+
statement := "rename as something_else, engine=innodb"
196+
err := parser.ParseAlterStatement(statement)
197+
test.S(t).ExpectNil(err)
198+
test.S(t).ExpectTrue(parser.isRenameTable)
199+
}
200+
}

go/sql/types.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ import (
1515
type ColumnType int
1616

1717
const (
18-
UnknownColumnType ColumnType = iota
19-
TimestampColumnType = iota
20-
DateTimeColumnType = iota
21-
EnumColumnType = iota
22-
MediumIntColumnType = iota
23-
JSONColumnType = iota
24-
FloatColumnType = iota
18+
UnknownColumnType ColumnType = iota
19+
TimestampColumnType
20+
DateTimeColumnType
21+
EnumColumnType
22+
MediumIntColumnType
23+
JSONColumnType
24+
FloatColumnType
2525
)
2626

2727
const maxMediumintUnsigned int32 = 16777215
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
drop table if exists gh_ost_test;
2+
create table gh_ost_test (
3+
id int auto_increment,
4+
i int not null,
5+
ts timestamp,
6+
primary key(id)
7+
) auto_increment=1;
8+
9+
drop event if exists gh_ost_test;
10+
delimiter ;;
11+
create event gh_ost_test
12+
on schedule every 1 second
13+
starts current_timestamp
14+
ends current_timestamp + interval 60 second
15+
on completion not preserve
16+
enable
17+
do
18+
begin
19+
insert into gh_ost_test values (null, 11, now());
20+
insert into gh_ost_test values (null, 13, now());
21+
insert into gh_ost_test values (null, 17, now());
22+
end ;;

0 commit comments

Comments
 (0)