From 74ce7e29b1086d3ecdbb879b51ab61eeb8b2b6e1 Mon Sep 17 00:00:00 2001 From: Arthur Neves Date: Thu, 19 Apr 2018 20:37:24 +0200 Subject: [PATCH 1/3] Move vtcombo initTabletMap func to vtcombo package The idea is so another commands can reuse the initTabletMap. In my case, I am building a new command and importing libs from vitess. In my cmd I am faking a topology(using memory) and starting vttablets for it. Similar on what vtcombo does. Signed-off-by: Arthur Neves --- go/cmd/vtcombo/main.go | 3 ++- go/{cmd => vt}/vtcombo/tablet_map.go | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) rename go/{cmd => vt}/vtcombo/tablet_map.go (99%) diff --git a/go/cmd/vtcombo/main.go b/go/cmd/vtcombo/main.go index a6e97ff1372..1e423dcf156 100644 --- a/go/cmd/vtcombo/main.go +++ b/go/cmd/vtcombo/main.go @@ -38,6 +38,7 @@ import ( "vitess.io/vitess/go/vt/srvtopo" "vitess.io/vitess/go/vt/topo" "vitess.io/vitess/go/vt/topo/memorytopo" + "vitess.io/vitess/go/vt/vtcombo" "vitess.io/vitess/go/vt/vtctld" "vitess.io/vitess/go/vt/vtgate" "vitess.io/vitess/go/vt/vttablet/tabletserver/tabletenv" @@ -109,7 +110,7 @@ func main() { servenv.OnClose(mysqld.Close) // tablets configuration and init - if err := initTabletMap(ts, tpb, mysqld, *dbcfgs, *schemaDir, mycnf); err != nil { + if err := vtcombo.InitTabletMap(ts, tpb, mysqld, *dbcfgs, *schemaDir, mycnf); err != nil { log.Errorf("initTabletMapProto failed: %v", err) exit.Return(1) } diff --git a/go/cmd/vtcombo/tablet_map.go b/go/vt/vtcombo/tablet_map.go similarity index 99% rename from go/cmd/vtcombo/tablet_map.go rename to go/vt/vtcombo/tablet_map.go index 89035f0da66..56bb233ba3c 100644 --- a/go/cmd/vtcombo/tablet_map.go +++ b/go/vt/vtcombo/tablet_map.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package main +package vtcombo import ( "flag" @@ -106,7 +106,7 @@ func createTablet(ctx context.Context, ts *topo.Server, cell string, uid uint32, // initTabletMap creates the action agents and associated data structures // for all tablets, based on the vttest proto parameter. -func initTabletMap(ts *topo.Server, tpb *vttestpb.VTTestTopology, mysqld mysqlctl.MysqlDaemon, dbcfgs dbconfigs.DBConfigs, schemaDir string, mycnf *mysqlctl.Mycnf) error { +func InitTabletMap(ts *topo.Server, tpb *vttestpb.VTTestTopology, mysqld mysqlctl.MysqlDaemon, dbcfgs dbconfigs.DBConfigs, schemaDir string, mycnf *mysqlctl.Mycnf) error { tabletMap = make(map[uint32]*tablet) ctx := context.Background() From b9142b34c7eb3eadbdf46a5fba97186fb24ac43d Mon Sep 17 00:00:00 2001 From: Arthur Neves Date: Mon, 23 Apr 2018 09:45:47 -0700 Subject: [PATCH 2/3] Fix method name on comment Signed-off-by: Arthur Neves --- go/vt/vtcombo/tablet_map.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go/vt/vtcombo/tablet_map.go b/go/vt/vtcombo/tablet_map.go index b391db31f07..186fc4586d0 100644 --- a/go/vt/vtcombo/tablet_map.go +++ b/go/vt/vtcombo/tablet_map.go @@ -104,7 +104,7 @@ func createTablet(ctx context.Context, ts *topo.Server, cell string, uid uint32, return nil } -// initTabletMap creates the action agents and associated data structures +// InitTabletMap creates the action agents and associated data structures // for all tablets, based on the vttest proto parameter. func InitTabletMap(ts *topo.Server, tpb *vttestpb.VTTestTopology, mysqld mysqlctl.MysqlDaemon, dbcfgs dbconfigs.DBConfigs, schemaDir string, mycnf *mysqlctl.Mycnf) error { tabletMap = make(map[uint32]*tablet) From 4398d36baf3479d44cfd7a318a655ce5297610a0 Mon Sep 17 00:00:00 2001 From: Arthur Neves Date: Mon, 23 Apr 2018 09:48:15 -0700 Subject: [PATCH 3/3] Expose CreateTablet too Signed-off-by: Arthur Neves --- go/vt/vtcombo/tablet_map.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/go/vt/vtcombo/tablet_map.go b/go/vt/vtcombo/tablet_map.go index 186fc4586d0..9fc9cfa36b4 100644 --- a/go/vt/vtcombo/tablet_map.go +++ b/go/vt/vtcombo/tablet_map.go @@ -71,9 +71,9 @@ type tablet struct { // tabletMap maps the tablet uid to the tablet record var tabletMap map[uint32]*tablet -// createTablet creates an individual tablet, with its agent, and adds +// CreateTablet creates an individual tablet, with its agent, and adds // it to the map. If it's a master tablet, it also issues a TER. -func createTablet(ctx context.Context, ts *topo.Server, cell string, uid uint32, keyspace, shard, dbname string, tabletType topodatapb.TabletType, mysqld mysqlctl.MysqlDaemon, dbcfgs dbconfigs.DBConfigs) error { +func CreateTablet(ctx context.Context, ts *topo.Server, cell string, uid uint32, keyspace, shard, dbname string, tabletType topodatapb.TabletType, mysqld mysqlctl.MysqlDaemon, dbcfgs dbconfigs.DBConfigs) error { alias := &topodatapb.TabletAlias{ Cell: cell, Uid: uid, @@ -183,7 +183,7 @@ func InitTabletMap(ts *topo.Server, tpb *vttestpb.VTTestTopology, mysqld mysqlct replicas-- // create the master - if err := createTablet(ctx, ts, cell, uid, keyspace, shard, dbname, topodatapb.TabletType_MASTER, mysqld, dbcfgs); err != nil { + if err := CreateTablet(ctx, ts, cell, uid, keyspace, shard, dbname, topodatapb.TabletType_MASTER, mysqld, dbcfgs); err != nil { return err } uid++ @@ -191,7 +191,7 @@ func InitTabletMap(ts *topo.Server, tpb *vttestpb.VTTestTopology, mysqld mysqlct for i := 0; i < replicas; i++ { // create a replica slave - if err := createTablet(ctx, ts, cell, uid, keyspace, shard, dbname, topodatapb.TabletType_REPLICA, mysqld, dbcfgs); err != nil { + if err := CreateTablet(ctx, ts, cell, uid, keyspace, shard, dbname, topodatapb.TabletType_REPLICA, mysqld, dbcfgs); err != nil { return err } uid++ @@ -199,7 +199,7 @@ func InitTabletMap(ts *topo.Server, tpb *vttestpb.VTTestTopology, mysqld mysqlct for i := 0; i < rdonlys; i++ { // create a rdonly slave - if err := createTablet(ctx, ts, cell, uid, keyspace, shard, dbname, topodatapb.TabletType_RDONLY, mysqld, dbcfgs); err != nil { + if err := CreateTablet(ctx, ts, cell, uid, keyspace, shard, dbname, topodatapb.TabletType_RDONLY, mysqld, dbcfgs); err != nil { return err } uid++