本文整理汇总了Golang中github.com/youtube/vitess/go/vt/mysqlctl/replication.EncodePosition函数的典型用法代码示例。如果您正苦于以下问题:Golang EncodePosition函数的具体用法?Golang EncodePosition怎么用?Golang EncodePosition使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了EncodePosition函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: PromoteSlaveWhenCaughtUp
// PromoteSlaveWhenCaughtUp waits for this slave to be caught up on
// replication up to the provided point, and then makes the slave the
// shard master.
func (agent *ActionAgent) PromoteSlaveWhenCaughtUp(ctx context.Context, position string) (string, error) {
pos, err := replication.DecodePosition(position)
if err != nil {
return "", err
}
// TODO(alainjobart) change the flavor API to take the context directly
// For now, extract the timeout from the context, or wait forever
var waitTimeout time.Duration
if deadline, ok := ctx.Deadline(); ok {
waitTimeout = deadline.Sub(time.Now())
if waitTimeout <= 0 {
waitTimeout = time.Millisecond
}
}
if err := agent.MysqlDaemon.WaitMasterPos(pos, waitTimeout); err != nil {
return "", err
}
pos, err = agent.MysqlDaemon.PromoteSlave(agent.hookExtraEnv())
if err != nil {
return "", err
}
if err := agent.MysqlDaemon.SetReadOnly(false); err != nil {
return "", err
}
if _, err := topotools.ChangeType(ctx, agent.TopoServer, agent.TabletAlias, topodatapb.TabletType_MASTER, topotools.ClearHealthMap); err != nil {
return "", err
}
return replication.EncodePosition(pos), nil
}
开发者ID:littleyang,项目名称:vitess,代码行数:37,代码来源:agent_rpc_actions.go
示例2: TestStreamerParseEventsDMLWithoutBegin
func TestStreamerParseEventsDMLWithoutBegin(t *testing.T) {
input := []replication.BinlogEvent{
rotateEvent{},
formatEvent{},
queryEvent{query: replication.Query{
Database: "vt_test_keyspace",
SQL: "insert into vt_a(eid, id) values (1, 1) /* _stream vt_a (eid id ) (1 1 ); */"}},
xidEvent{},
}
events := make(chan replication.BinlogEvent)
want := []binlogdatapb.BinlogTransaction{
{
Statements: []*binlogdatapb.BinlogTransaction_Statement{
{Category: binlogdatapb.BinlogTransaction_Statement_BL_SET, Sql: []byte("SET TIMESTAMP=1407805592")},
{Category: binlogdatapb.BinlogTransaction_Statement_BL_DML, Sql: []byte("insert into vt_a(eid, id) values (1, 1) /* _stream vt_a (eid id ) (1 1 ); */")},
},
EventToken: &querypb.EventToken{
Timestamp: 1407805592,
Position: replication.EncodePosition(replication.Position{
GTIDSet: replication.MariadbGTID{
Domain: 0,
Server: 62344,
Sequence: 0x0d,
},
}),
},
},
{
Statements: nil,
EventToken: &querypb.EventToken{
Timestamp: 1407805592,
Position: replication.EncodePosition(replication.Position{
GTIDSet: replication.MariadbGTID{
Domain: 0,
Server: 62344,
Sequence: 0x0d,
},
}),
},
},
}
var got []binlogdatapb.BinlogTransaction
sendTransaction := func(trans *binlogdatapb.BinlogTransaction) error {
got = append(got, *trans)
return nil
}
bls := NewStreamer("vt_test_keyspace", nil, nil, replication.Position{}, 0, sendTransaction)
go sendTestEvents(events, input)
if _, err := bls.parseEvents(context.Background(), events); err != ErrServerEOF {
t.Errorf("unexpected error: %v", err)
}
if !reflect.DeepEqual(got, want) {
t.Errorf("binlogConnStreamer.parseEvents(): got %v, want %v", got, want)
}
}
开发者ID:erzel,项目名称:vitess,代码行数:59,代码来源:binlog_streamer_test.go
示例3: updateBlpCheckpoint
// updateBlpCheckpoint returns a statement to update a value in the
// _vt.blp_checkpoint table.
func updateBlpCheckpoint(uid uint32, pos replication.Position, timeUpdated int64, txTimestamp int64) string {
if txTimestamp != 0 {
return fmt.Sprintf(
"UPDATE _vt.blp_checkpoint "+
"SET pos='%v', time_updated=%v, transaction_timestamp=%v "+
"WHERE source_shard_uid=%v",
replication.EncodePosition(pos), timeUpdated, txTimestamp, uid)
}
return fmt.Sprintf(
"UPDATE _vt.blp_checkpoint "+
"SET pos='%v', time_updated=%v "+
"WHERE source_shard_uid=%v",
replication.EncodePosition(pos), timeUpdated, uid)
}
开发者ID:c3p0hz,项目名称:vitess,代码行数:17,代码来源:binlog_player.go
示例4: PromoteSlave
// PromoteSlave makes the current tablet the master
func (agent *ActionAgent) PromoteSlave(ctx context.Context) (string, error) {
if err := agent.lock(ctx); err != nil {
return "", err
}
defer agent.unlock()
pos, err := agent.MysqlDaemon.PromoteSlave(agent.hookExtraEnv())
if err != nil {
return "", err
}
// If using semi-sync, we need to enable it before going read-write.
if *enableSemiSync {
if err := agent.enableSemiSync(true); err != nil {
return "", err
}
}
// Set the server read-write
if err := agent.MysqlDaemon.SetReadOnly(false); err != nil {
return "", err
}
if _, err := topotools.ChangeType(ctx, agent.TopoServer, agent.TabletAlias, topodatapb.TabletType_MASTER); err != nil {
return "", err
}
if err := agent.refreshTablet(ctx, "PromoteSlave"); err != nil {
return "", err
}
return replication.EncodePosition(pos), nil
}
开发者ID:erzel,项目名称:vitess,代码行数:34,代码来源:rpc_replication.go
示例5: MasterPosition
// MasterPosition returns the master position
// Should be called under RPCWrap.
func (agent *ActionAgent) MasterPosition(ctx context.Context) (string, error) {
pos, err := agent.MysqlDaemon.MasterPosition()
if err != nil {
return "", err
}
return replication.EncodePosition(pos), nil
}
开发者ID:littleyang,项目名称:vitess,代码行数:9,代码来源:agent_rpc_actions.go
示例6: PromoteSlaveWhenCaughtUp
// PromoteSlaveWhenCaughtUp waits for this slave to be caught up on
// replication up to the provided point, and then makes the slave the
// shard master.
func (agent *ActionAgent) PromoteSlaveWhenCaughtUp(ctx context.Context, position string) (string, error) {
pos, err := replication.DecodePosition(position)
if err != nil {
return "", err
}
if err := agent.MysqlDaemon.WaitMasterPos(ctx, pos); err != nil {
return "", err
}
pos, err = agent.MysqlDaemon.PromoteSlave(agent.hookExtraEnv())
if err != nil {
return "", err
}
// If using semi-sync, we need to enable it before going read-write.
if *enableSemiSync {
if err := agent.enableSemiSync(true); err != nil {
return "", err
}
}
if err := agent.MysqlDaemon.SetReadOnly(false); err != nil {
return "", err
}
if _, err := topotools.ChangeType(ctx, agent.TopoServer, agent.TabletAlias, topodatapb.TabletType_MASTER); err != nil {
return "", err
}
return replication.EncodePosition(pos), nil
}
开发者ID:jmptrader,项目名称:vitess,代码行数:35,代码来源:rpc_replication.go
示例7: InitMaster
// InitMaster breaks slaves replication, get the current MySQL replication
// position, insert a row in the reparent_journal table, and returns
// the replication position
func (agent *ActionAgent) InitMaster(ctx context.Context) (string, error) {
// we need to insert something in the binlogs, so we can get the
// current position. Let's just use the mysqlctl.CreateReparentJournal commands.
cmds := mysqlctl.CreateReparentJournal()
if err := agent.MysqlDaemon.ExecuteSuperQueryList(cmds); err != nil {
return "", err
}
// get the current replication position
pos, err := agent.MysqlDaemon.MasterPosition()
if err != nil {
return "", err
}
// Set the server read-write, from now on we can accept real
// client writes. Note that if semi-sync replication is enabled,
// we'll still need some slaves to be able to commit
// transactions.
if err := agent.MysqlDaemon.SetReadOnly(false); err != nil {
return "", err
}
// Change our type to master if not already
if _, err := agent.TopoServer.UpdateTabletFields(ctx, agent.TabletAlias, func(tablet *topodatapb.Tablet) error {
tablet.Type = topodatapb.TabletType_MASTER
tablet.HealthMap = nil
return nil
}); err != nil {
return "", err
}
agent.initReplication = true
return replication.EncodePosition(pos), nil
}
开发者ID:littleyang,项目名称:vitess,代码行数:37,代码来源:agent_rpc_actions.go
示例8: DemoteMaster
// DemoteMaster marks the server read-only, wait until it is done with
// its current transactions, and returns its master position.
// Should be called under RPCWrapLockAction.
func (agent *ActionAgent) DemoteMaster(ctx context.Context) (string, error) {
// Set the server read-only. Note all active connections are not
// affected.
if err := agent.MysqlDaemon.SetReadOnly(true); err != nil {
return "", err
}
// Now disallow queries, to make sure nobody is writing to the
// database.
tablet := agent.Tablet()
// We don't care if the QueryService state actually changed because we'll
// let vtgate keep serving read traffic from this master (see comment below).
if _ /* state changed */, err := agent.disallowQueries(tablet.Type, "DemoteMaster marks server rdonly"); err != nil {
return "", fmt.Errorf("disallowQueries failed: %v", err)
}
// If using semi-sync, we need to disable master-side.
if *enableSemiSync {
if err := agent.enableSemiSync(false); err != nil {
return "", err
}
}
pos, err := agent.MysqlDaemon.DemoteMaster()
if err != nil {
return "", err
}
return replication.EncodePosition(pos), nil
// There is no serving graph update - the master tablet will
// be replaced. Even though writes may fail, reads will
// succeed. It will be less noisy to simply leave the entry
// until we'll promote the master.
}
开发者ID:aaijazi,项目名称:vitess,代码行数:36,代码来源:rpc_replication.go
示例9: RunBlpUntil
// RunBlpUntil runs the binlog player server until the position is reached,
// and returns the current mysql master replication position.
func (agent *ActionAgent) RunBlpUntil(ctx context.Context, bpl []*tabletmanagerdatapb.BlpPosition, waitTime time.Duration) (string, error) {
if agent.BinlogPlayerMap == nil {
return "", fmt.Errorf("No BinlogPlayerMap configured")
}
if err := agent.BinlogPlayerMap.RunUntil(ctx, bpl, waitTime); err != nil {
return "", err
}
pos, err := agent.MysqlDaemon.MasterPosition()
if err != nil {
return "", err
}
return replication.EncodePosition(pos), nil
}
开发者ID:littleyang,项目名称:vitess,代码行数:15,代码来源:agent_rpc_actions.go
示例10: InitMaster
// InitMaster enables writes and returns the replication position.
func (agent *ActionAgent) InitMaster(ctx context.Context) (string, error) {
if err := agent.lock(ctx); err != nil {
return "", err
}
defer agent.unlock()
// Initializing as master implies undoing any previous "do not replicate".
agent.setSlaveStopped(false)
// we need to insert something in the binlogs, so we can get the
// current position. Let's just use the mysqlctl.CreateReparentJournal commands.
cmds := mysqlctl.CreateReparentJournal()
if err := agent.MysqlDaemon.ExecuteSuperQueryList(ctx, cmds); err != nil {
return "", err
}
// get the current replication position
pos, err := agent.MysqlDaemon.MasterPosition()
if err != nil {
return "", err
}
// If using semi-sync, we need to enable it before going read-write.
if *enableSemiSync {
if err := agent.enableSemiSync(true); err != nil {
return "", err
}
}
// Set the server read-write, from now on we can accept real
// client writes. Note that if semi-sync replication is enabled,
// we'll still need some slaves to be able to commit transactions.
if err := agent.MysqlDaemon.SetReadOnly(false); err != nil {
return "", err
}
// Change our type to master if not already
if _, err := agent.TopoServer.UpdateTabletFields(ctx, agent.TabletAlias, func(tablet *topodatapb.Tablet) error {
tablet.Type = topodatapb.TabletType_MASTER
return nil
}); err != nil {
return "", err
}
// and refresh our state
agent.initReplication = true
if err := agent.refreshTablet(ctx, "InitMaster"); err != nil {
return "", err
}
return replication.EncodePosition(pos), nil
}
开发者ID:dumbunny,项目名称:vitess,代码行数:52,代码来源:rpc_replication.go
示例11: StopSlaveMinimum
// StopSlaveMinimum will stop the slave after it reaches at least the
// provided position. Works both when Vitess manages
// replication or not (using hook if not).
func (agent *ActionAgent) StopSlaveMinimum(ctx context.Context, position string, waitTime time.Duration) (string, error) {
pos, err := replication.DecodePosition(position)
if err != nil {
return "", err
}
if err := agent.MysqlDaemon.WaitMasterPos(pos, waitTime); err != nil {
return "", err
}
if err := mysqlctl.StopSlave(agent.MysqlDaemon, agent.hookExtraEnv()); err != nil {
return "", err
}
pos, err = agent.MysqlDaemon.MasterPosition()
if err != nil {
return "", err
}
return replication.EncodePosition(pos), nil
}
开发者ID:littleyang,项目名称:vitess,代码行数:20,代码来源:agent_rpc_actions.go
示例12: PromoteSlave
// PromoteSlave makes the current tablet the master
func (agent *ActionAgent) PromoteSlave(ctx context.Context) (string, error) {
pos, err := agent.MysqlDaemon.PromoteSlave(agent.hookExtraEnv())
if err != nil {
return "", err
}
// Set the server read-write
if err := agent.MysqlDaemon.SetReadOnly(false); err != nil {
return "", err
}
if _, err := topotools.ChangeType(ctx, agent.TopoServer, agent.TabletAlias, topodatapb.TabletType_MASTER, topotools.ClearHealthMap); err != nil {
return "", err
}
return replication.EncodePosition(pos), nil
}
开发者ID:littleyang,项目名称:vitess,代码行数:18,代码来源:agent_rpc_actions.go
示例13: TestStreamerParseEventsMariadbBeginGTID
func TestStreamerParseEventsMariadbBeginGTID(t *testing.T) {
input := []replication.BinlogEvent{
mariadbRotateEvent,
mariadbFormatEvent,
mariadbBeginGTIDEvent,
mariadbInsertEvent,
mariadbXidEvent,
}
events := make(chan replication.BinlogEvent)
want := []binlogdatapb.BinlogTransaction{
{
Statements: []*binlogdatapb.BinlogTransaction_Statement{
{Category: binlogdatapb.BinlogTransaction_Statement_BL_SET, Charset: charset, Sql: []byte("SET TIMESTAMP=1409892744")},
{Category: binlogdatapb.BinlogTransaction_Statement_BL_DML, Charset: charset, Sql: []byte("insert into vt_insert_test(msg) values ('test 0') /* _stream vt_insert_test (id ) (null ); */")},
},
EventToken: &querypb.EventToken{
Timestamp: 1409892744,
Position: replication.EncodePosition(replication.Position{
GTIDSet: replication.MariadbGTID{
Domain: 0,
Server: 62344,
Sequence: 10,
},
}),
},
},
}
var got []binlogdatapb.BinlogTransaction
sendTransaction := func(trans *binlogdatapb.BinlogTransaction) error {
got = append(got, *trans)
return nil
}
bls := NewStreamer("vt_test_keyspace", nil, nil, replication.Position{}, 0, sendTransaction)
go sendTestEvents(events, input)
if _, err := bls.parseEvents(context.Background(), events); err != ErrServerEOF {
t.Errorf("unexpected error: %v", err)
}
if !reflect.DeepEqual(got, want) {
t.Errorf("binlogConnStreamer.parseEvents(): got %v, want %v", got, want)
}
}
开发者ID:erzel,项目名称:vitess,代码行数:45,代码来源:binlog_streamer_test.go
示例14: PromoteSlave
// PromoteSlave makes the current tablet the master
func (agent *ActionAgent) PromoteSlave(ctx context.Context) (string, error) {
tablet, err := agent.TopoServer.GetTablet(ctx, agent.TabletAlias)
if err != nil {
return "", err
}
pos, err := agent.MysqlDaemon.PromoteSlave(agent.hookExtraEnv())
if err != nil {
return "", err
}
// Set the server read-write
if err := agent.MysqlDaemon.SetReadOnly(false); err != nil {
return "", err
}
return replication.EncodePosition(pos), agent.updateReplicationGraphForPromotedSlave(ctx, tablet)
}
开发者ID:c3p0hz,项目名称:vitess,代码行数:19,代码来源:agent_rpc_actions.go
示例15: TestStreamerParseEventsMariadbStandaloneGTID
func TestStreamerParseEventsMariadbStandaloneGTID(t *testing.T) {
input := []replication.BinlogEvent{
mariadbRotateEvent,
mariadbFormatEvent,
mariadbStandaloneGTIDEvent,
mariadbCreateEvent,
}
events := make(chan replication.BinlogEvent)
want := []binlogdatapb.BinlogTransaction{
{
Statements: []*binlogdatapb.BinlogTransaction_Statement{
{Category: binlogdatapb.BinlogTransaction_Statement_BL_SET, Charset: &binlogdatapb.Charset{Client: 8, Conn: 8, Server: 33}, Sql: []byte("SET TIMESTAMP=1409892744")},
{Category: binlogdatapb.BinlogTransaction_Statement_BL_DDL, Charset: &binlogdatapb.Charset{Client: 8, Conn: 8, Server: 33}, Sql: []byte("create table if not exists vt_insert_test (\nid bigint auto_increment,\nmsg varchar(64),\nprimary key (id)\n) Engine=InnoDB")},
},
EventToken: &querypb.EventToken{
Timestamp: 1409892744,
Position: replication.EncodePosition(replication.Position{
GTIDSet: replication.MariadbGTID{
Domain: 0,
Server: 62344,
Sequence: 9,
},
}),
},
},
}
var got []binlogdatapb.BinlogTransaction
sendTransaction := func(trans *binlogdatapb.BinlogTransaction) error {
got = append(got, *trans)
return nil
}
bls := NewStreamer("vt_test_keyspace", nil, nil, replication.Position{}, 0, sendTransaction)
go sendTestEvents(events, input)
if _, err := bls.parseEvents(context.Background(), events); err != ErrServerEOF {
t.Errorf("unexpected error: %v", err)
}
if !reflect.DeepEqual(got, want) {
t.Errorf("binlogConnStreamer.parseEvents(): got %v, want %v", got, want)
}
}
开发者ID:erzel,项目名称:vitess,代码行数:44,代码来源:binlog_streamer_test.go
示例16: StopSlaveMinimum
// StopSlaveMinimum will stop the slave after it reaches at least the
// provided position. Works both when Vitess manages
// replication or not (using hook if not).
func (agent *ActionAgent) StopSlaveMinimum(ctx context.Context, position string, waitTime time.Duration) (string, error) {
pos, err := replication.DecodePosition(position)
if err != nil {
return "", err
}
waitCtx, cancel := context.WithTimeout(ctx, waitTime)
defer cancel()
if err := agent.MysqlDaemon.WaitMasterPos(waitCtx, pos); err != nil {
return "", err
}
if err := agent.StopSlave(ctx); err != nil {
return "", err
}
pos, err = agent.MysqlDaemon.MasterPosition()
if err != nil {
return "", err
}
return replication.EncodePosition(pos), nil
}
开发者ID:jmptrader,项目名称:vitess,代码行数:22,代码来源:rpc_replication.go
示例17: DemoteMaster
// DemoteMaster marks the server read-only, wait until it is done with
// its current transactions, and returns its master position.
// Should be called under RPCWrapLockAction.
func (agent *ActionAgent) DemoteMaster(ctx context.Context) (string, error) {
// Set the server read-only. Note all active connections are not
// affected.
if err := agent.MysqlDaemon.SetReadOnly(true); err != nil {
return "", err
}
// Now stop the query service, to make sure nobody is writing to the
// database. This will in effect close the connection pools to the
// database.
tablet := agent.Tablet()
agent.disallowQueries(tablet.Tablet.Type, "DemoteMaster marks server rdonly")
pos, err := agent.MysqlDaemon.DemoteMaster()
if err != nil {
return "", err
}
return replication.EncodePosition(pos), nil
// There is no serving graph update - the master tablet will
// be replaced. Even though writes may fail, reads will
// succeed. It will be less noisy to simply leave the entry
// until well promote the master.
}
开发者ID:c3p0hz,项目名称:vitess,代码行数:26,代码来源:agent_rpc_actions.go
示例18: TestMigrateServedTypes
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())
vp := NewVtctlPipe(t, ts)
defer vp.Close()
// create keyspace
if err := ts.CreateKeyspace(context.Background(), "ks", &topodatapb.Keyspace{
ShardingColumnName: "keyspace_id",
ShardingColumnType: topodatapb.KeyspaceIdType_UINT64,
}); err != nil {
t.Fatalf("CreateKeyspace failed: %v", err)
}
// create the source shard
sourceMaster := NewFakeTablet(t, wr, "cell1", 10, topodatapb.TabletType_MASTER, db,
TabletKeyspaceShard(t, "ks", "0"))
sourceReplica := NewFakeTablet(t, wr, "cell1", 11, topodatapb.TabletType_REPLICA, db,
TabletKeyspaceShard(t, "ks", "0"))
sourceRdonly := NewFakeTablet(t, wr, "cell1", 12, topodatapb.TabletType_RDONLY, db,
TabletKeyspaceShard(t, "ks", "0"))
// create the first destination shard
dest1Master := NewFakeTablet(t, wr, "cell1", 20, topodatapb.TabletType_MASTER, db,
TabletKeyspaceShard(t, "ks", "-80"))
dest1Replica := NewFakeTablet(t, wr, "cell1", 21, topodatapb.TabletType_REPLICA, db,
TabletKeyspaceShard(t, "ks", "-80"))
dest1Rdonly := NewFakeTablet(t, wr, "cell1", 22, topodatapb.TabletType_RDONLY, db,
TabletKeyspaceShard(t, "ks", "-80"))
// create the second destination shard
dest2Master := NewFakeTablet(t, wr, "cell1", 30, topodatapb.TabletType_MASTER, db,
TabletKeyspaceShard(t, "ks", "80-"))
dest2Replica := NewFakeTablet(t, wr, "cell1", 31, topodatapb.TabletType_REPLICA, db,
TabletKeyspaceShard(t, "ks", "80-"))
dest2Rdonly := NewFakeTablet(t, wr, "cell1", 32, topodatapb.TabletType_RDONLY, db,
TabletKeyspaceShard(t, "ks", "80-"))
// double check the shards have the right served types
checkShardServedTypes(t, ts, "0", 3)
checkShardServedTypes(t, ts, "-80", 0)
checkShardServedTypes(t, ts, "80-", 0)
// sourceRdonly will see the refresh
sourceRdonly.StartActionLoop(t, wr)
defer sourceRdonly.StopActionLoop(t)
// sourceReplica will see the refresh
sourceReplica.StartActionLoop(t, wr)
defer sourceReplica.StopActionLoop(t)
// sourceMaster will see the refresh, and has to respond to it
// also will be asked about its replication position.
sourceMaster.FakeMysqlDaemon.CurrentMasterPosition = replication.Position{
GTIDSet: replication.MariadbGTID{
Domain: 5,
Server: 456,
Sequence: 892,
},
}
sourceMaster.StartActionLoop(t, wr)
defer sourceMaster.StopActionLoop(t)
// dest1Rdonly will see the refresh
dest1Rdonly.StartActionLoop(t, wr)
defer dest1Rdonly.StopActionLoop(t)
// dest1Replica will see the refresh
dest1Replica.StartActionLoop(t, wr)
defer dest1Replica.StopActionLoop(t)
// dest1Master will see the refresh, and has to respond to it.
// It will also need to respond to WaitBlpPosition, saying it's already caught up.
dest1Master.FakeMysqlDaemon.FetchSuperQueryMap = map[string]*sqltypes.Result{
"SELECT pos, flags FROM _vt.blp_checkpoint WHERE source_shard_uid=0": {
Rows: [][]sqltypes.Value{
{
sqltypes.MakeString([]byte(replication.EncodePosition(sourceMaster.FakeMysqlDaemon.CurrentMasterPosition))),
sqltypes.MakeString([]byte("")),
},
},
},
}
dest1Master.StartActionLoop(t, wr)
defer dest1Master.StopActionLoop(t)
// dest2Rdonly will see the refresh
dest2Rdonly.StartActionLoop(t, wr)
defer dest2Rdonly.StopActionLoop(t)
// dest2Replica will see the refresh
dest2Replica.StartActionLoop(t, wr)
defer dest2Replica.StopActionLoop(t)
// dest2Master will see the refresh, and has to respond to it.
//.........这里部分代码省略.........
开发者ID:dumbunny,项目名称:vitess,代码行数:101,代码来源:migrate_served_types_test.go
示例19: TestMigrateServedTypes
func TestMigrateServedTypes(t *testing.T) {
db := fakesqldb.Register()
ts := zktopo.NewTestServer(t, []string{"cell1", "cell2"})
wr := wrangler.New(logutil.NewConsoleLogger(), ts, tmclient.NewTabletManagerClient())
vp := NewVtctlPipe(t, ts)
defer vp.Close()
// create keyspace
if err := ts.CreateKeyspace(context.Background(), "ks", &topodatapb.Keyspace{
ShardingColumnName: "keyspace_id",
ShardingColumnType: topodatapb.KeyspaceIdType_UINT64,
}); err != nil {
t.Fatalf("CreateKeyspace failed: %v", err)
}
// create the source shard
sourceMaster := NewFakeTablet(t, wr, "cell1", 10, topodatapb.TabletType_MASTER, db,
TabletKeyspaceShard(t, "ks", "0"))
sourceReplica := NewFakeTablet(t, wr, "cell1", 11, topodatapb.TabletType_REPLICA, db,
TabletKeyspaceShard(t, "ks", "0"))
sourceRdonly := NewFakeTablet(t, wr, "cell1", 12, topodatapb.TabletType_RDONLY, db,
TabletKeyspaceShard(t, "ks", "0"))
// create the first destination shard
dest1Master := NewFakeTablet(t, wr, "cell1", 20, topodatapb.TabletType_MASTER, db,
TabletKeyspaceShard(t, "ks", "-80"))
dest1Replica := NewFakeTablet(t, wr, "cell1", 21, topodatapb.TabletType_REPLICA, db,
TabletKeyspaceShard(t, "ks", "-80"))
dest1Rdonly := NewFakeTablet(t, wr, "cell1", 22, topodatapb.TabletType_RDONLY, db,
TabletKeyspaceShard(t, "ks", "-80"))
// create the second destination shard
dest2Master := NewFakeTablet(t, wr, "cell1", 30, topodatapb.TabletType_MASTER, db,
TabletKeyspaceShard(t, "ks", "80-"))
dest2Replica := NewFakeTablet(t, wr, "cell1", 31, topodatapb.TabletType_REPLICA, db,
TabletKeyspaceShard(t, "ks", "80-"))
dest2Rdonly := NewFakeTablet(t, wr, "cell1", 32, topodatapb.TabletType_RDONLY, db,
TabletKeyspaceShard(t, "ks", "80-"))
// double check the shards have the right served types
checkShardServedTypes(t, ts, "0", 3)
checkShardServedTypes(t, ts, "-80", 0)
checkShardServedTypes(t, ts, "80-", 0)
// sourceRdonly will see the refresh
sourceRdonly.StartActionLoop(t, wr)
defer sourceRdonly.StopActionLoop(t)
// sourceReplica will see the refresh
sourceReplica.StartActionLoop(t, wr)
defer sourceReplica.StopActionLoop(t)
// sourceMaster will see the refresh, and has to respond to it
// also will be asked about its replication position.
sourceMaster.FakeMysqlDaemon.CurrentMasterPosition = replication.Position{
GTIDSet: replication.MariadbGTID{
Domain: 5,
Server: 456,
Sequence: 892,
},
}
sourceMaster.StartActionLoop(t, wr)
defer sourceMaster.StopActionLoop(t)
// dest1Rdonly will see the refresh
dest1Rdonly.StartActionLoop(t, wr)
defer dest1Rdonly.StopActionLoop(t)
// dest1Replica will see the refresh
dest1Replica.StartActionLoop(t, wr)
defer dest1Replica.StopActionLoop(t)
// dest1Master will see the refresh, and has to respond to it.
// It will also need to respond to WaitBlpPosition, saying it's already caught up.
dest1Master.FakeMysqlDaemon.FetchSuperQueryMap = map[string]*sqltypes.Result{
"SELECT pos, flags FROM _vt.blp_checkpoint WHERE source_shard_uid=0": {
Rows: [][]sqltypes.Value{
{
sqltypes.MakeString([]byte(replication.EncodePosition(sourceMaster.FakeMysqlDaemon.CurrentMasterPosition))),
sqltypes.MakeString([]byte("")),
},
},
},
}
dest1Master.StartActionLoop(t, wr)
defer dest1Master.StopActionLoop(t)
// dest2Rdonly will see the refresh
dest2Rdonly.StartActionLoop(t, wr)
defer dest2Rdonly.StopActionLoop(t)
// dest2Replica will see the refresh
dest2Replica.StartActionLoop(t, wr)
defer dest2Replica.StopActionLoop(t)
// dest2Master will see the refresh, and has to respond to it.
// It will also need to respond to WaitBlpPosition, saying it's already caught up.
dest2Master.FakeMysqlDaemon.FetchSuperQueryMap = map[string]*sqltypes.Result{
"SELECT pos, flags FROM _vt.blp_checkpoint WHERE source_shard_uid=0": {
Rows: [][]sqltypes.Value{
//.........这里部分代码省略.........
开发者ID:ChrisYangLiu,项目名称:vitess,代码行数:101,代码来源:migrate_served_types_test.go
示例20: ApplyBinlogEvents
// ApplyBinlogEvents makes an RPC request to BinlogServer
// and processes the events. It will return nil if the provided context
// was canceled, or if we reached the stopping point.
// It will return io.EOF if the server stops sending us updates.
// It may return any other error it encounters.
func (blp *BinlogPlayer) ApplyBinlogEvents(ctx context.Context) error {
// Instantiate the throttler based on the configuration stored in the db.
maxTPS, maxReplicationLag, err := blp.readThrottlerSettings()
if err != nil {
log.Error(err)
return err
}
t, err := throttler.NewThrottler(
fmt.Sprintf("BinlogPlayer/%d", blp.uid), "transactions", 1 /* threadCount */, maxTPS, maxReplicationLag)
if err != nil {
err := fmt.Errorf("failed to instantiate throttler: %v", err)
log.Error(err)
return err
}
defer t.Close()
// Log the mode of operation and when the player stops.
if len(blp.tables) > 0 {
log.Infof("BinlogPlayer client %v for tables %v starting @ '%v', server: %v",
blp.uid,
blp.tables,
blp.position,
blp.tablet,
)
} else {
log.Infof("BinlogPlayer client %v for keyrange '%v-%v' starting @ '%v', server: %v",
blp.uid,
hex.EncodeToString(blp.keyRange.Start),
hex.EncodeToString(blp.keyRange.End),
blp.position,
blp.tablet,
)
}
if !blp.stopPosition.IsZero() {
// We need to stop at some point. Sanity check the point.
switch {
case blp.position.Equal(blp.stopPosition):
log.Infof("Not starting BinlogPlayer, we're already at the desired position %v", blp.stopPosition)
return nil
case blp.position.AtLeast(blp.stopPosition):
return fmt.Errorf("starting point %v greater than stopping point %v", blp.position, blp.stopPosition)
default:
log.Infof("Will stop player when reaching %v", blp.stopPosition)
}
}
clientFactory, ok := clientFactories[*binlogPlayerProtocol]
if !ok {
return fmt.Errorf("no binlog player client factory named %v", *binlogPlayerProtocol)
}
blplClient := clientFactory()
err = blplClient.Dial(blp.tablet, *BinlogPlayerConnTimeout)
if err != nil {
err := fmt.Errorf("error dialing binlog server: %v", err)
log.Error(err)
return err
}
defer blplClient.Close()
// Get the current charset of our connection, so we can ask the stream server
// to check that they match. The streamer will also only send per-statement
// charset data if that statement's charset is different from what we specify.
if dbClient, ok := blp.dbClient.(*DBClient); ok {
blp.defaultCharset, err = dbClient.dbConn.GetCharset()
if err != nil {
return fmt.Errorf("can't get charset to request binlog stream: %v", err)
}
log.Infof("original charset: %v", blp.defaultCharset)
blp.currentCharset = blp.defaultCharset
// Restore original charset when we're done.
defer func() {
// If the connection has been closed, there's no need to restore
// this connection-specific setting.
if dbClient.dbConn == nil {
return
}
log.Infof("restoring original charset %v", blp.defaultCharset)
if csErr := dbClient.dbConn.SetCharset(blp.defaultCharset); csErr != nil {
log.Errorf("can't restore original charset %v: %v", blp.defaultCharset, csErr)
}
}()
}
var stream BinlogTransactionStream
if len(blp.tables) > 0 {
stream, err = blplClient.StreamTables(ctx, replication.EncodePosition(blp.position), blp.tables, blp.defaultCharset)
} else {
stream, err = blplClient.StreamKeyRange(ctx, replication.EncodePosition(blp.position), blp.keyRange, blp.defaultCharset)
}
if err != nil {
err := fmt.Errorf("error sending streaming query to binlog server: %v", err)
log.Error(err)
return err
}
//.........这里部分代码省略.........
开发者ID:erzel,项目名称:vitess,代码行数:101,代码来源:binlog_player.go
注:本文中的github.com/youtube/vitess/go/vt/mysqlctl/replication.EncodePosition函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论