Skip to content

Commit 6cd5915

Browse files
author
Shlomi Noach
authored
Merge pull request #119 from github/row-copy-start-mark
ETA counting rows, fixed copy time on count
2 parents f11a39f + bae4af8 commit 6cd5915

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-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="1.0.6"
4+
RELEASE_VERSION="1.0.7"
55

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

go/base/context.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ type MigrationContext struct {
111111
throttleReason string
112112
throttleMutex *sync.Mutex
113113
IsPostponingCutOver int64
114+
CountingRowsFlag int64
114115

115116
OriginalTableColumns *sql.ColumnList
116117
OriginalTableUniqueKeys [](*sql.UniqueKey)
@@ -261,11 +262,23 @@ func (this *MigrationContext) ElapsedTime() time.Duration {
261262
return time.Now().Sub(this.StartTime)
262263
}
263264

265+
// MarkRowCopyStartTime
266+
func (this *MigrationContext) MarkRowCopyStartTime() {
267+
this.throttleMutex.Lock()
268+
defer this.throttleMutex.Unlock()
269+
this.RowCopyStartTime = time.Now()
270+
}
271+
264272
// ElapsedRowCopyTime returns time since starting to copy chunks of rows
265273
func (this *MigrationContext) ElapsedRowCopyTime() time.Duration {
266274
this.throttleMutex.Lock()
267275
defer this.throttleMutex.Unlock()
268276

277+
if this.RowCopyStartTime.IsZero() {
278+
// Row copy hasn't started yet
279+
return 0
280+
}
281+
269282
if this.RowCopyEndTime.IsZero() {
270283
return time.Now().Sub(this.RowCopyStartTime)
271284
}

go/logic/inspect.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
gosql "database/sql"
1010
"fmt"
1111
"strings"
12+
"sync/atomic"
1213

1314
"github.com/github/gh-ost/go/base"
1415
"github.com/github/gh-ost/go/mysql"
@@ -364,13 +365,19 @@ func (this *Inspector) estimateTableRowsViaExplain() error {
364365

365366
// CountTableRows counts exact number of rows on the original table
366367
func (this *Inspector) CountTableRows() error {
368+
atomic.StoreInt64(&this.migrationContext.CountingRowsFlag, 1)
369+
defer atomic.StoreInt64(&this.migrationContext.CountingRowsFlag, 0)
370+
367371
log.Infof("As instructed, I'm issuing a SELECT COUNT(*) on the table. This may take a while")
372+
368373
query := fmt.Sprintf(`select /* gh-ost */ count(*) as rows from %s.%s`, sql.EscapeName(this.migrationContext.DatabaseName), sql.EscapeName(this.migrationContext.OriginalTableName))
369374
if err := this.db.QueryRow(query).Scan(&this.migrationContext.RowsEstimate); err != nil {
370375
return err
371376
}
372377
this.migrationContext.UsedRowsEstimateMethod = base.CountRowsEstimate
378+
373379
log.Infof("Exact number of rows via COUNT: %d", this.migrationContext.RowsEstimate)
380+
374381
return nil
375382
}
376383

go/logic/migrator.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ func (this *Migrator) Migrate() (err error) {
418418
go this.initiateThrottler()
419419
go this.executeWriteFuncs()
420420
go this.iterateChunks()
421-
this.migrationContext.RowCopyStartTime = time.Now()
421+
this.migrationContext.MarkRowCopyStartTime()
422422
go this.initiateStatus()
423423

424424
log.Debugf("Operating until row copy is complete")
@@ -951,7 +951,9 @@ func (this *Migrator) printStatus(rule PrintStatusRule, writers ...io.Writer) {
951951

952952
var etaSeconds float64 = math.MaxFloat64
953953
eta := "N/A"
954-
if atomic.LoadInt64(&this.migrationContext.IsPostponingCutOver) > 0 {
954+
if atomic.LoadInt64(&this.migrationContext.CountingRowsFlag) > 0 {
955+
eta = "counting rows"
956+
} else if atomic.LoadInt64(&this.migrationContext.IsPostponingCutOver) > 0 {
955957
eta = "postponing cut-over"
956958
} else if isThrottled, throttleReason := this.migrationContext.IsThrottled(); isThrottled {
957959
eta = fmt.Sprintf("throttled, %s", throttleReason)

0 commit comments

Comments
 (0)