Skip to content

Commit

Permalink
Merge pull request vitessio#2089 from michael-berlin/vtctl_migrate_se…
Browse files Browse the repository at this point in the history
…rved_types_sleep

vtctl: MigrateServedTypes: Wait for several seconds for the old table…
  • Loading branch information
michael-berlin authored Sep 27, 2016
2 parents 4269441 + 76c269e commit ca52128
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
23 changes: 23 additions & 0 deletions go/vt/wrangler/keyspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package wrangler

import (
"flag"
"fmt"
"strings"
"sync"
Expand All @@ -23,6 +24,12 @@ import (
topodatapb "github.com/youtube/vitess/go/vt/proto/topodata"
)

// TODO(b/26388813): Remove these flags once vtctl WaitForDrain is integrated in the vtctl MigrateServed* commands.
var (
waitForDrainSleepRdonly = flag.Duration("wait_for_drain_sleep_rdonly", 5*time.Second, "time to wait before shutting the query service on old RDONLY tablets during MigrateServedTypes")
waitForDrainSleepReplica = flag.Duration("wait_for_drain_sleep_replica", 15*time.Second, "time to wait before shutting the query service on old REPLICA tablets during MigrateServedTypes")
)

// keyspace related methods for Wrangler

// SetKeyspaceShardingInfo locks a keyspace and sets its ShardingColumnName
Expand Down Expand Up @@ -151,6 +158,22 @@ func (wr *Wrangler) MigrateServedTypes(ctx context.Context, keyspace, shard stri
// For a forwards migration, we just disabled query service on the source shards
refreshShards = sourceShards
}

// TODO(b/26388813): Integrate vtctl WaitForDrain here instead of just sleeping.
var waitForDrainSleep time.Duration
switch servedType {
case topodatapb.TabletType_RDONLY:
waitForDrainSleep = *waitForDrainSleepRdonly
case topodatapb.TabletType_REPLICA:
waitForDrainSleep = *waitForDrainSleepReplica
default:
wr.Logger().Warningf("invalid TabletType: %v for MigrateServedTypes command", servedType)
}

wr.Logger().Infof("WaitForDrain: Sleeping for %.0f seconds before shutting down query service on old tablets...", waitForDrainSleep.Seconds())
time.Sleep(waitForDrainSleep)
wr.Logger().Infof("WaitForDrain: Sleeping finished. Shutting down queryservice on old tablets now.")

for _, si := range refreshShards {
rec.RecordError(wr.RefreshTabletsByShard(ctx, si, servedType, cells))
}
Expand Down
5 changes: 5 additions & 0 deletions go/vt/wrangler/testlib/migrate_served_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package testlib

import (
"flag"
"testing"

"github.com/youtube/vitess/go/sqltypes"
Expand Down Expand Up @@ -43,6 +44,10 @@ func checkShardSourceShards(t *testing.T, ts topo.Server, shard string, expected
}

func TestMigrateServedTypes(t *testing.T) {
// TODO(b/26388813): Remove the next two lines once vtctl WaitForDrain is integrated in the vtctl MigrateServed* commands.
flag.Set("wait_for_drain_sleep_rdonly", "0s")
flag.Set("wait_for_drain_sleep_replica", "0s")

db := fakesqldb.Register()
ts := zktestserver.New(t, []string{"cell1", "cell2"})
wr := wrangler.New(logutil.NewConsoleLogger(), ts, tmclient.NewTabletManagerClient())
Expand Down
8 changes: 8 additions & 0 deletions test/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,10 @@ def run_vtctl_vtctl(clargs, auto_log=False, expect_fail=False,
args.extend(['-throttler_client_protocol',
protocols_flavor().throttler_client_protocol()])
args.extend(['-vtgate_protocol', protocols_flavor().vtgate_protocol()])
# TODO(b/26388813): Remove the next two lines once vtctl WaitForDrain is
# integrated in the vtctl MigrateServed* commands.
args.extend(['--wait_for_drain_sleep_rdonly', '0s'])
args.extend(['--wait_for_drain_sleep_replica', '0s'])

if auto_log:
args.append('--stderrthreshold=%s' % get_log_level())
Expand Down Expand Up @@ -1235,6 +1239,10 @@ def start(self, enable_schema_change_dir=False):
protocols_flavor().throttler_client_protocol(),
'-vtgate_protocol', protocols_flavor().vtgate_protocol(),
] + environment.topo_server().flags()
# TODO(b/26388813): Remove the next two lines once vtctl WaitForDrain is
# integrated in the vtctl MigrateServed* commands.
args.extend(['--wait_for_drain_sleep_rdonly', '0s'])
args.extend(['--wait_for_drain_sleep_replica', '0s'])
if enable_schema_change_dir:
args += [
'--schema_change_dir', self.schema_change_dir,
Expand Down

0 comments on commit ca52128

Please sign in to comment.