Skip to content

Commit 7dccf7e

Browse files
author
Shlomi Noach
committed
Merge pull request #46 from github/operational-perks
operational perks
2 parents 25fd74b + b73eb5a commit 7dccf7e

File tree

4 files changed

+40
-3
lines changed

4 files changed

+40
-3
lines changed

build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22
#
33
#
4-
RELEASE_VERSION="0.7.17"
4+
RELEASE_VERSION="0.8.2"
55

66
buildpath=/tmp/gh-ost
77
target=gh-ost

go/cmd/gh-ost/main.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
"flag"
1010
"fmt"
1111
"os"
12+
"os/signal"
13+
"syscall"
1214

1315
"github.com/github/gh-ost/go/base"
1416
"github.com/github/gh-ost/go/logic"
@@ -17,6 +19,26 @@ import (
1719

1820
var AppVersion string
1921

22+
// acceptSignals registers for OS signals
23+
func acceptSignals(migrationContext *base.MigrationContext) {
24+
c := make(chan os.Signal, 1)
25+
26+
signal.Notify(c, syscall.SIGHUP)
27+
go func() {
28+
for sig := range c {
29+
switch sig {
30+
case syscall.SIGHUP:
31+
log.Infof("Received SIGHUP. Reloading configuration")
32+
if err := migrationContext.ReadConfigFile(); err != nil {
33+
log.Errore(err)
34+
} else {
35+
migrationContext.MarkPointOfInterest()
36+
}
37+
}
38+
}
39+
}()
40+
}
41+
2042
// main is the application's entry point. It will either spawn a CLI or HTTP itnerfaces.
2143
func main() {
2244
migrationContext := base.GetMigrationContext()
@@ -122,6 +144,7 @@ func main() {
122144
migrationContext.ApplyCredentials()
123145

124146
log.Infof("starting gh-ost %+v", AppVersion)
147+
acceptSignals(migrationContext)
125148

126149
migrator := logic.NewMigrator()
127150
err := migrator.Migrate()

go/logic/migrator.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -578,8 +578,21 @@ func (this *Migrator) printStatus() {
578578
if rowsEstimate > 0 {
579579
progressPct = 100.0 * float64(totalRowsCopied) / float64(rowsEstimate)
580580
}
581-
var etaSeconds float64 = math.MaxFloat64
582581

582+
// Before status, let's see if we should print a nice reminder for what exactly we're doing here.
583+
shouldPrintCourtesyReminder := (elapsedSeconds%600 == 0)
584+
if shouldPrintCourtesyReminder {
585+
courtesyReminder := fmt.Sprintf("# Migrating %s.%s; Ghost table is %s.%s; migration started at %+v",
586+
sql.EscapeName(this.migrationContext.DatabaseName),
587+
sql.EscapeName(this.migrationContext.OriginalTableName),
588+
sql.EscapeName(this.migrationContext.DatabaseName),
589+
sql.EscapeName(this.migrationContext.GetGhostTableName()),
590+
this.migrationContext.StartTime.Format(time.RubyDate),
591+
)
592+
fmt.Println(courtesyReminder)
593+
}
594+
595+
var etaSeconds float64 = math.MaxFloat64
583596
eta := "N/A"
584597
if isThrottled, throttleReason := this.migrationContext.IsThrottled(); isThrottled {
585598
eta = fmt.Sprintf("throttled, %s", throttleReason)
@@ -606,7 +619,7 @@ func (this *Migrator) printStatus() {
606619
shouldPrintStatus = (elapsedSeconds%5 == 0)
607620
} else if elapsedSeconds <= 180 {
608621
shouldPrintStatus = (elapsedSeconds%5 == 0)
609-
} else if this.migrationContext.TimeSincePointOfInterest() <= 60 {
622+
} else if this.migrationContext.TimeSincePointOfInterest().Seconds() <= 60 {
610623
shouldPrintStatus = (elapsedSeconds%5 == 0)
611624
} else {
612625
shouldPrintStatus = (elapsedSeconds%30 == 0)

go/logic/streamer.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ func (this *EventsStreamer) StreamEvents(canStopStreaming func() bool) error {
189189
for {
190190
if err := this.binlogReader.StreamEvents(canStopStreaming, this.eventsChannel); err != nil {
191191
log.Infof("StreamEvents encountered unexpected error: %+v", err)
192+
this.migrationContext.MarkPointOfInterest()
192193
time.Sleep(ReconnectStreamerSleepSeconds * time.Second)
193194

194195
// Reposition at same binlog file. Single attempt (TODO: make multiple attempts?)

0 commit comments

Comments
 (0)