Skip to content

Commit a36d6be

Browse files
author
Shlomi Noach
authored
Merge branch 'logging-interface-contrib' into master
2 parents 3ca5f89 + 7c9c2b3 commit a36d6be

File tree

5 files changed

+28
-5
lines changed

5 files changed

+28
-5
lines changed

doc/command-line-flags.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ If, for some reason, you do not wish `gh-ost` to connect to a replica, you may c
1818

1919
### approve-renamed-columns
2020

21-
When your migration issues a column rename (`change column old_name new_name ...`) `gh-ost` analyzes the statement to try an associate the old column name with new column name. Otherwise the new structure may also look like some column was dropped and another was added.
21+
When your migration issues a column rename (`change column old_name new_name ...`) `gh-ost` analyzes the statement to try and associate the old column name with new column name. Otherwise the new structure may also look like some column was dropped and another was added.
2222

2323
`gh-ost` will print out what it thinks the _rename_ implied, but will not issue the migration unless you provide with `--approve-renamed-columns`.
2424

@@ -161,7 +161,7 @@ List of metrics and threshold values; topping the threshold of any will cause th
161161

162162
### migrate-on-replica
163163

164-
Typically `gh-ost` is used to migrate tables on a master. If you wish to only perform the migration in full on a replica, connect `gh-ost` to said replica and pass `--migrate-on-replica`. `gh-ost` will briefly connect to the master but other issue no changes on the master. Migration will be fully executed on the replica, while making sure to maintain a small replication lag.
164+
Typically `gh-ost` is used to migrate tables on a master. If you wish to only perform the migration in full on a replica, connect `gh-ost` to said replica and pass `--migrate-on-replica`. `gh-ost` will briefly connect to the master but otherwise will make no changes on the master. Migration will be fully executed on the replica, while making sure to maintain a small replication lag.
165165

166166
### postpone-cut-over-flag-file
167167

doc/hooks.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ The following variables are available on all hooks:
6565
- `GH_OST_ELAPSED_COPY_SECONDS` - row-copy time (excluding startup, row-count and postpone time)
6666
- `GH_OST_ESTIMATED_ROWS` - estimated total rows in table
6767
- `GH_OST_COPIED_ROWS` - number of rows copied by `gh-ost`
68+
- `GH_OST_INSPECTED_LAG` - lag in seconds (floating point) of inspected server
69+
- `GH_OST_PROGRESS` - progress pct ([0..100], floating point) of migration
6870
- `GH_OST_MIGRATED_HOST`
6971
- `GH_OST_INSPECTED_HOST`
7072
- `GH_OST_EXECUTING_HOST`

go/base/context.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ package base
77

88
import (
99
"fmt"
10-
"github.com/outbrain/golib/log"
10+
"math"
1111
"os"
1212
"regexp"
1313
"strings"
@@ -19,6 +19,7 @@ import (
1919

2020
"github.com/github/gh-ost/go/mysql"
2121
"github.com/github/gh-ost/go/sql"
22+
"github.com/outbrain/golib/log"
2223

2324
"gopkg.in/gcfg.v1"
2425
gcfgscanner "gopkg.in/gcfg.v1/scanner"
@@ -175,6 +176,7 @@ type MigrationContext struct {
175176
pointOfInterestTime time.Time
176177
pointOfInterestTimeMutex *sync.Mutex
177178
CurrentLag int64
179+
currentProgress uint64
178180
ThrottleHTTPStatusCode int64
179181
controlReplicasLagResult mysql.ReplicationLagResult
180182
TotalRowsCopied int64
@@ -449,6 +451,20 @@ func (this *MigrationContext) MarkRowCopyEndTime() {
449451
this.RowCopyEndTime = time.Now()
450452
}
451453

454+
func (this *MigrationContext) GetCurrentLagDuration() time.Duration {
455+
return time.Duration(atomic.LoadInt64(&this.CurrentLag))
456+
}
457+
458+
func (this *MigrationContext) GetProgressPct() float64 {
459+
return math.Float64frombits(atomic.LoadUint64(&this.currentProgress))
460+
}
461+
462+
func (this *MigrationContext) SetProgressPct(progressPct float64) {
463+
atomic.StoreUint64(&this.currentProgress, math.Float64bits(progressPct))
464+
}
465+
466+
// math.Float64bits([f=0..100])
467+
452468
// GetTotalRowsCopied returns the accurate number of rows being copied (affected)
453469
// This is not exactly the same as the rows being iterated via chunks, but potentially close enough
454470
func (this *MigrationContext) GetTotalRowsCopied() int64 {

go/logic/hooks.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ func (this *HooksExecutor) applyEnvironmentVariables(extraVariables ...string) [
6363
env = append(env, fmt.Sprintf("GH_OST_MIGRATED_HOST=%s", this.migrationContext.GetApplierHostname()))
6464
env = append(env, fmt.Sprintf("GH_OST_INSPECTED_HOST=%s", this.migrationContext.GetInspectorHostname()))
6565
env = append(env, fmt.Sprintf("GH_OST_EXECUTING_HOST=%s", this.migrationContext.Hostname))
66+
env = append(env, fmt.Sprintf("GH_OST_INSPECTED_LAG=%f", this.migrationContext.GetCurrentLagDuration().Seconds()))
67+
env = append(env, fmt.Sprintf("GH_OST_PROGRESS=%f", this.migrationContext.GetProgressPct()))
6668
env = append(env, fmt.Sprintf("GH_OST_HOOKS_HINT=%s", this.migrationContext.HooksHintMessage))
6769
env = append(env, fmt.Sprintf("GH_OST_HOOKS_HINT_OWNER=%s", this.migrationContext.HooksHintOwner))
6870
env = append(env, fmt.Sprintf("GH_OST_HOOKS_HINT_TOKEN=%s", this.migrationContext.HooksHintToken))

go/logic/migrator.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,8 @@ func (this *Migrator) printStatus(rule PrintStatusRule, writers ...io.Writer) {
893893
} else {
894894
progressPct = 100.0 * float64(totalRowsCopied) / float64(rowsEstimate)
895895
}
896+
// we take the opportunity to update migration context with progressPct
897+
this.migrationContext.SetProgressPct(progressPct)
896898
// Before status, let's see if we should print a nice reminder for what exactly we're doing here.
897899
shouldPrintMigrationStatusHint := (elapsedSeconds%600 == 0)
898900
if rule == ForcePrintStatusAndHintRule {
@@ -909,7 +911,7 @@ func (this *Migrator) printStatus(rule PrintStatusRule, writers ...io.Writer) {
909911
eta := "N/A"
910912
if progressPct >= 100.0 {
911913
eta = "due"
912-
} else if progressPct >= 1.0 {
914+
} else if progressPct >= 0.1 {
913915
elapsedRowCopySeconds := this.migrationContext.ElapsedRowCopyTime().Seconds()
914916
totalExpectedSeconds := elapsedRowCopySeconds * float64(rowsEstimate) / float64(totalRowsCopied)
915917
etaSeconds = totalExpectedSeconds - elapsedRowCopySeconds
@@ -956,12 +958,13 @@ func (this *Migrator) printStatus(rule PrintStatusRule, writers ...io.Writer) {
956958

957959
currentBinlogCoordinates := *this.eventsStreamer.GetCurrentBinlogCoordinates()
958960

959-
status := fmt.Sprintf("Copy: %d/%d %.1f%%; Applied: %d; Backlog: %d/%d; Time: %+v(total), %+v(copy); streamer: %+v; State: %s; ETA: %s",
961+
status := fmt.Sprintf("Copy: %d/%d %.1f%%; Applied: %d; Backlog: %d/%d; Time: %+v(total), %+v(copy); streamer: %+v; Lag: %.2fs, State: %s; ETA: %s",
960962
totalRowsCopied, rowsEstimate, progressPct,
961963
atomic.LoadInt64(&this.migrationContext.TotalDMLEventsApplied),
962964
len(this.applyEventsQueue), cap(this.applyEventsQueue),
963965
base.PrettifyDurationOutput(elapsedTime), base.PrettifyDurationOutput(this.migrationContext.ElapsedRowCopyTime()),
964966
currentBinlogCoordinates,
967+
this.migrationContext.GetCurrentLagDuration().Seconds(),
965968
state,
966969
eta,
967970
)

0 commit comments

Comments
 (0)