Exemple #1
0
// AddTablet adds a new tablet to the topology and starts its event
// loop.
func (fix *Fixture) AddTablet(uid int, cell string, tabletType topo.TabletType, master *topo.Tablet) *topo.Tablet {
	tablet := &topo.Tablet{
		Alias:    topo.TabletAlias{Cell: cell, Uid: uint32(uid)},
		Hostname: fmt.Sprintf("%vbsr%v", cell, uid),
		IPAddr:   fmt.Sprintf("212.244.218.%v", uid),
		Portmap: map[string]int{
			"vt":    3333 + 10*uid,
			"mysql": 3334 + 10*uid,
		},
		Keyspace: TestKeyspace,
		Type:     tabletType,
		Shard:    TestShard,
		KeyRange: newKeyRange(TestShard),
	}
	if master != nil {
		tablet.Parent = master.Alias
	}

	if err := fix.Wrangler.InitTablet(tablet, true, true, false); err != nil {
		fix.Fatalf("CreateTablet: %v", err)
	}
	mysqlDaemon := &mysqlctl.FakeMysqlDaemon{}
	if master != nil {
		mysqlDaemon.MasterAddr = master.GetMysqlIpAddr()
	}
	mysqlDaemon.MysqlPort = 3334 + 10*uid

	pack := &tabletPack{Tablet: tablet, mysql: mysqlDaemon}
	fix.startFakeTabletActionLoop(pack)

	fix.tablets[uid] = pack

	return tablet
}