Skip to content

Commit

Permalink
Merge pull request #34 from github/rename-gh-ost
Browse files Browse the repository at this point in the history
Rename to gh-ost
  • Loading branch information
Shlomi Noach committed May 16, 2016
2 parents 92d09db + 21f6ae9 commit c6a371e
Show file tree
Hide file tree
Showing 26 changed files with 101 additions and 101 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# gh-osc
# gh-ost
GitHub's Online Schema Change for MySQL
12 changes: 6 additions & 6 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
#
#

buildpath=/tmp/gh-osc
target=gh-osc
buildpath=/tmp/gh-ost
target=gh-ost
timestamp=$(date "+%Y%m%d%H%M%S")
mkdir -p ${buildpath}
gobuild="go build -o $buildpath/$target go/cmd/gh-osc/main.go"
gobuild="go build -o $buildpath/$target go/cmd/gh-ost/main.go"

echo "Building OS/X binary"
echo "GO15VENDOREXPERIMENT=1 GOOS=darwin GOARCH=amd64 $gobuild" | bash
(cd $buildpath && tar cfz ./gh-osc-binary-osx-${timestamp}.tar.gz $target)
(cd $buildpath && tar cfz ./gh-ost-binary-osx-${timestamp}.tar.gz $target)

echo "Building linux binary"
echo "GO15VENDOREXPERIMENT=1 GOOS=linux GOARCH=amd64 $gobuild" | bash
(cd $buildpath && tar cfz ./gh-osc-binary-linux-${timestamp}.tar.gz $target)
(cd $buildpath && tar cfz ./gh-ost-binary-linux-${timestamp}.tar.gz $target)

echo "Binaries found in:"
ls -1 $buildpath/gh-osc-binary*${timestamp}.tar.gz
ls -1 $buildpath/gh-ost-binary*${timestamp}.tar.gz
6 changes: 3 additions & 3 deletions go/base/context.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Copyright 2016 GitHub Inc.
See https://github.com/github/gh-osc/blob/master/LICENSE
See https://github.com/github/gh-ost/blob/master/LICENSE
*/

package base
Expand All @@ -13,8 +13,8 @@ import (
"sync/atomic"
"time"

"github.com/github/gh-osc/go/mysql"
"github.com/github/gh-osc/go/sql"
"github.com/github/gh-ost/go/mysql"
"github.com/github/gh-ost/go/sql"

"gopkg.in/gcfg.v1"
)
Expand Down
2 changes: 1 addition & 1 deletion go/base/utils.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Copyright 2016 GitHub Inc.
See https://github.com/github/gh-osc/blob/master/LICENSE
See https://github.com/github/gh-ost/blob/master/LICENSE
*/

package base
Expand Down
4 changes: 2 additions & 2 deletions go/binlog/binlog_dml_event.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/*
Copyright 2016 GitHub Inc.
See https://github.com/github/gh-osc/blob/master/LICENSE
See https://github.com/github/gh-ost/blob/master/LICENSE
*/

package binlog

import (
"fmt"
"github.com/github/gh-osc/go/sql"
"github.com/github/gh-ost/go/sql"
"strings"
)

Expand Down
4 changes: 2 additions & 2 deletions go/binlog/binlog_entry.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/*
Copyright 2016 GitHub Inc.
See https://github.com/github/gh-osc/blob/master/LICENSE
See https://github.com/github/gh-ost/blob/master/LICENSE
*/

package binlog

import (
"fmt"
"github.com/github/gh-osc/go/mysql"
"github.com/github/gh-ost/go/mysql"
)

// BinlogEntry describes an entry in the binary log
Expand Down
2 changes: 1 addition & 1 deletion go/binlog/binlog_reader.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Copyright 2016 GitHub Inc.
See https://github.com/github/gh-osc/blob/master/LICENSE
See https://github.com/github/gh-ost/blob/master/LICENSE
*/

package binlog
Expand Down
2 changes: 1 addition & 1 deletion go/binlog/binlog_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Copyright 2016 GitHub Inc.
See https://github.com/github/gh-osc/blob/master/LICENSE
See https://github.com/github/gh-ost/blob/master/LICENSE
*/

package binlog
Expand Down
6 changes: 3 additions & 3 deletions go/binlog/gomysql_reader.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/*
Copyright 2016 GitHub Inc.
See https://github.com/github/gh-osc/blob/master/LICENSE
See https://github.com/github/gh-ost/blob/master/LICENSE
*/

package binlog

import (
"fmt"

"github.com/github/gh-osc/go/mysql"
"github.com/github/gh-osc/go/sql"
"github.com/github/gh-ost/go/mysql"
"github.com/github/gh-ost/go/sql"

"github.com/outbrain/golib/log"
gomysql "github.com/siddontang/go-mysql/mysql"
Expand Down
4 changes: 2 additions & 2 deletions go/binlog/mysqlbinlog_reader.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Copyright 2016 GitHub Inc.
See https://github.com/github/gh-osc/blob/master/LICENSE
See https://github.com/github/gh-ost/blob/master/LICENSE
*/

package binlog
Expand All @@ -14,7 +14,7 @@ import (
"strconv"
// "strings"

"github.com/github/gh-osc/go/os"
"github.com/github/gh-ost/go/os"
"github.com/outbrain/golib/log"
)

Expand Down
2 changes: 1 addition & 1 deletion go/binlog/mysqlbinlog_reader_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Copyright 2016 GitHub Inc.
See https://github.com/github/gh-osc/blob/master/LICENSE
See https://github.com/github/gh-ost/blob/master/LICENSE
*/

package binlog
Expand Down
16 changes: 8 additions & 8 deletions go/cmd/gh-osc/main.go → go/cmd/gh-ost/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Copyright 2016 GitHub Inc.
See https://github.com/github/gh-osc/blob/master/LICENSE
See https://github.com/github/gh-ost/blob/master/LICENSE
*/

package main
Expand All @@ -10,8 +10,8 @@ import (
"fmt"
"os"

"github.com/github/gh-osc/go/base"
"github.com/github/gh-osc/go/logic"
"github.com/github/gh-ost/go/base"
"github.com/github/gh-ost/go/logic"
"github.com/outbrain/golib/log"
)

Expand All @@ -32,7 +32,7 @@ func main() {
flag.BoolVar(&migrationContext.AllowedRunningOnMaster, "allow-on-master", false, "allow this migration to run directly on master. Preferably it would run on a replica")

executeFlag := flag.Bool("execute", false, "actually execute the alter & migrate the table. Default is noop: do some tests and exit")
flag.BoolVar(&migrationContext.TestOnReplica, "test-on-replica", false, "Have the migration run on a replica, not on the master. At the end of migration tables are not swapped; gh-osc issues `STOP SLAVE` and you can compare the two tables for building trust")
flag.BoolVar(&migrationContext.TestOnReplica, "test-on-replica", false, "Have the migration run on a replica, not on the master. At the end of migration tables are not swapped; gh-ost issues `STOP SLAVE` and you can compare the two tables for building trust")
flag.BoolVar(&migrationContext.OkToDropTable, "ok-to-drop-table", false, "Shall the tool drop the old table at end of operation. DROPping tables can be a long locking operation, which is why I'm not doing it by default. I'm an online tool, yes?")
flag.BoolVar(&migrationContext.QuickAndBumpySwapTables, "quick-and-bumpy-swap-tables", false, "Shall the tool issue a faster swapping of tables at end of operation, at the cost of causing a brief period of time when the table does not exist? This will cause queries on table to fail with error (as opposed to being locked for a longer duration of a swap)")
flag.BoolVar(&migrationContext.InitiallyDropOldTable, "initially-drop-old-table", false, "Drop a possibly existing OLD table (remains from a previous run?) before beginning operation. Default is to panic and abort if such table exists")
Expand All @@ -47,10 +47,10 @@ func main() {
migrationContext.ChunkSize = 100000
}
flag.Int64Var(&migrationContext.MaxLagMillisecondsThrottleThreshold, "max-lag-millis", 1500, "replication lag at which to throttle operation")
flag.StringVar(&migrationContext.ReplictionLagQuery, "replication-lag-query", "", "Query that detects replication lag in seconds. Result can be a floating point (by default gh-osc issues SHOW SLAVE STATUS and reads Seconds_behind_master). If you're using pt-heartbeat, query would be something like: SELECT ROUND(UNIX_TIMESTAMP() - MAX(UNIX_TIMESTAMP(ts))) AS delay FROM my_schema.heartbeat")
flag.StringVar(&migrationContext.ReplictionLagQuery, "replication-lag-query", "", "Query that detects replication lag in seconds. Result can be a floating point (by default gh-ost issues SHOW SLAVE STATUS and reads Seconds_behind_master). If you're using pt-heartbeat, query would be something like: SELECT ROUND(UNIX_TIMESTAMP() - MAX(UNIX_TIMESTAMP(ts))) AS delay FROM my_schema.heartbeat")
throttleControlReplicas := flag.String("throttle-control-replicas", "", "List of replicas on which to check for lag; comma delimited. Example: myhost1.com:3306,myhost2.com,myhost3.com:3307")
flag.StringVar(&migrationContext.ThrottleFlagFile, "throttle-flag-file", "", "operation pauses when this file exists; hint: use a file that is specific to the table being altered")
flag.StringVar(&migrationContext.ThrottleAdditionalFlagFile, "throttle-additional-flag-file", "/tmp/gh-osc.throttle", "operation pauses when this file exists; hint: keep default, use for throttling multiple gh-osc operations")
flag.StringVar(&migrationContext.ThrottleAdditionalFlagFile, "throttle-additional-flag-file", "/tmp/gh-ost.throttle", "operation pauses when this file exists; hint: keep default, use for throttling multiple gh-ost operations")
maxLoad := flag.String("max-load", "", "Comma delimited status-name=threshold. e.g: 'Threads_running=100,Threads_connected=500'")
quiet := flag.Bool("quiet", false, "quiet")
verbose := flag.Bool("verbose", false, "verbose")
Expand All @@ -60,7 +60,7 @@ func main() {
flag.Parse()

if *help {
fmt.Fprintf(os.Stderr, "Usage of gh-osc:\n")
fmt.Fprintf(os.Stderr, "Usage of gh-ost:\n")
flag.PrintDefaults()
return
}
Expand Down Expand Up @@ -106,7 +106,7 @@ func main() {
log.Fatale(err)
}

log.Info("starting gh-osc")
log.Info("starting gh-ost")

migrator := logic.NewMigrator()
err := migrator.Migrate()
Expand Down
40 changes: 20 additions & 20 deletions go/logic/applier.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Copyright 2016 GitHub Inc.
See https://github.com/github/gh-osc/blob/master/LICENSE
See https://github.com/github/gh-ost/blob/master/LICENSE
*/

package logic
Expand All @@ -11,10 +11,10 @@ import (
"sync/atomic"
"time"

"github.com/github/gh-osc/go/base"
"github.com/github/gh-osc/go/binlog"
"github.com/github/gh-osc/go/mysql"
"github.com/github/gh-osc/go/sql"
"github.com/github/gh-ost/go/base"
"github.com/github/gh-ost/go/binlog"
"github.com/github/gh-ost/go/mysql"
"github.com/github/gh-ost/go/sql"

"github.com/outbrain/golib/log"
"github.com/outbrain/golib/sqlutils"
Expand Down Expand Up @@ -70,7 +70,7 @@ func (this *Applier) validateConnection(db *gosql.DB) error {
}

func (this *Applier) tableExists(tableName string) (tableFound bool) {
query := fmt.Sprintf(`show /* gh-osc */ table status from %s like '%s'`, sql.EscapeName(this.migrationContext.DatabaseName), tableName)
query := fmt.Sprintf(`show /* gh-ost */ table status from %s like '%s'`, sql.EscapeName(this.migrationContext.DatabaseName), tableName)

sqlutils.QueryRowsMap(this.db, query, func(m sqlutils.RowMap) error {
tableFound = true
Expand Down Expand Up @@ -102,7 +102,7 @@ func (this *Applier) ValidateOrDropExistingTables() error {

// CreateGhostTable creates the ghost table on the applier host
func (this *Applier) CreateGhostTable() error {
query := fmt.Sprintf(`create /* gh-osc */ table %s.%s like %s.%s`,
query := fmt.Sprintf(`create /* gh-ost */ table %s.%s like %s.%s`,
sql.EscapeName(this.migrationContext.DatabaseName),
sql.EscapeName(this.migrationContext.GetGhostTableName()),
sql.EscapeName(this.migrationContext.DatabaseName),
Expand All @@ -121,7 +121,7 @@ func (this *Applier) CreateGhostTable() error {

// AlterGhost applies `alter` statement on ghost table
func (this *Applier) AlterGhost() error {
query := fmt.Sprintf(`alter /* gh-osc */ table %s.%s %s`,
query := fmt.Sprintf(`alter /* gh-ost */ table %s.%s %s`,
sql.EscapeName(this.migrationContext.DatabaseName),
sql.EscapeName(this.migrationContext.GetGhostTableName()),
this.migrationContext.AlterStatement,
Expand All @@ -143,7 +143,7 @@ func (this *Applier) CreateChangelogTable() error {
if err := this.DropChangelogTable(); err != nil {
return err
}
query := fmt.Sprintf(`create /* gh-osc */ table %s.%s (
query := fmt.Sprintf(`create /* gh-ost */ table %s.%s (
id bigint auto_increment,
last_update timestamp not null DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
hint varchar(64) charset ascii not null,
Expand All @@ -168,7 +168,7 @@ func (this *Applier) CreateChangelogTable() error {

// dropTable drops a given table on the applied host
func (this *Applier) dropTable(tableName string) error {
query := fmt.Sprintf(`drop /* gh-osc */ table if exists %s.%s`,
query := fmt.Sprintf(`drop /* gh-ost */ table if exists %s.%s`,
sql.EscapeName(this.migrationContext.DatabaseName),
sql.EscapeName(tableName),
)
Expand Down Expand Up @@ -211,7 +211,7 @@ func (this *Applier) WriteChangelog(hint, value string) (string, error) {
explicitId = 3
}
query := fmt.Sprintf(`
insert /* gh-osc */ into %s.%s
insert /* gh-ost */ into %s.%s
(id, hint, value)
values
(NULLIF(?, 0), ?, ?)
Expand Down Expand Up @@ -336,7 +336,7 @@ func (this *Applier) __unused_IterationIsComplete() (bool, error) {
}
args = append(args, explodedArgs...)
query := fmt.Sprintf(`
select /* gh-osc IterationIsComplete */ 1
select /* gh-ost IterationIsComplete */ 1
from %s.%s
where (%s) and (%s)
limit 1
Expand Down Expand Up @@ -434,15 +434,15 @@ func (this *Applier) ApplyIterationInsertQuery() (chunkSize int64, rowsAffected

// LockTables
func (this *Applier) LockTables() error {
// query := fmt.Sprintf(`lock /* gh-osc */ tables %s.%s write, %s.%s write, %s.%s write`,
// query := fmt.Sprintf(`lock /* gh-ost */ tables %s.%s write, %s.%s write, %s.%s write`,
// sql.EscapeName(this.migrationContext.DatabaseName),
// sql.EscapeName(this.migrationContext.OriginalTableName),
// sql.EscapeName(this.migrationContext.DatabaseName),
// sql.EscapeName(this.migrationContext.GetGhostTableName()),
// sql.EscapeName(this.migrationContext.DatabaseName),
// sql.EscapeName(this.migrationContext.GetChangelogTableName()),
// )
query := fmt.Sprintf(`lock /* gh-osc */ tables %s.%s write`,
query := fmt.Sprintf(`lock /* gh-ost */ tables %s.%s write`,
sql.EscapeName(this.migrationContext.DatabaseName),
sql.EscapeName(this.migrationContext.OriginalTableName),
)
Expand All @@ -457,7 +457,7 @@ func (this *Applier) LockTables() error {

// UnlockTables
func (this *Applier) UnlockTables() error {
query := `unlock /* gh-osc */ tables`
query := `unlock /* gh-ost */ tables`
log.Infof("Unlocking tables")
if _, err := sqlutils.ExecNoPrepare(this.singletonDB, query); err != nil {
return err
Expand All @@ -468,7 +468,7 @@ func (this *Applier) UnlockTables() error {

// SwapTablesQuickAndBumpy
func (this *Applier) SwapTablesQuickAndBumpy() error {
query := fmt.Sprintf(`alter /* gh-osc */ table %s.%s rename %s`,
query := fmt.Sprintf(`alter /* gh-ost */ table %s.%s rename %s`,
sql.EscapeName(this.migrationContext.DatabaseName),
sql.EscapeName(this.migrationContext.OriginalTableName),
sql.EscapeName(this.migrationContext.GetOldTableName()),
Expand All @@ -478,7 +478,7 @@ func (this *Applier) SwapTablesQuickAndBumpy() error {
if _, err := sqlutils.ExecNoPrepare(this.singletonDB, query); err != nil {
return err
}
query = fmt.Sprintf(`alter /* gh-osc */ table %s.%s rename %s`,
query = fmt.Sprintf(`alter /* gh-ost */ table %s.%s rename %s`,
sql.EscapeName(this.migrationContext.DatabaseName),
sql.EscapeName(this.migrationContext.GetGhostTableName()),
sql.EscapeName(this.migrationContext.OriginalTableName),
Expand Down Expand Up @@ -513,7 +513,7 @@ func (this *Applier) SwapTablesAtomic(sessionIdChan chan int64) error {
}
sessionIdChan <- sessionId

query = fmt.Sprintf(`rename /* gh-osc */ table %s.%s to %s.%s, %s.%s to %s.%s`,
query = fmt.Sprintf(`rename /* gh-ost */ table %s.%s to %s.%s, %s.%s to %s.%s`,
sql.EscapeName(this.migrationContext.DatabaseName),
sql.EscapeName(this.migrationContext.OriginalTableName),
sql.EscapeName(this.migrationContext.DatabaseName),
Expand All @@ -539,7 +539,7 @@ func (this *Applier) SwapTablesAtomic(sessionIdChan chan int64) error {
// We need to keep the SQL thread active so as to complete processing received events,
// and have them written to the binary log, so that we can then read them via streamer
func (this *Applier) StopSlaveIOThread() error {
query := `stop /* gh-osc */ slave io_thread`
query := `stop /* gh-ost */ slave io_thread`
log.Infof("Stopping replication")
if _, err := sqlutils.ExecNoPrepare(this.db, query); err != nil {
return err
Expand Down Expand Up @@ -646,7 +646,7 @@ func (this *Applier) IssueBlockingQueryOnVoluntaryLock(sessionIdChan chan int64)

// Grab
query := fmt.Sprintf(`
select /* gh-osc blocking-query-%s */
select /* gh-ost blocking-query-%s */
release_lock(?)
from %s.%s
where
Expand Down
Loading

0 comments on commit c6a371e

Please sign in to comment.