From f3423149534a50a6d1bd707b20a212abf723d5fb Mon Sep 17 00:00:00 2001 From: Sugu Sougoumarane Date: Sat, 25 Apr 2020 20:16:04 -0700 Subject: [PATCH 1/2] vtctld: make cell optional This change makes the cell flag optional for vtctld. This removes the catch-22 that you have to create a cell before launching vtctld. But then, how do you create a cell without a vtctld? This required a one-time use of vtctl tool to create this initial cell. If you don't specify a cell, vtctld will choose one at random. I believe the main use case for this is for identifying which shards are serving vs. non-serving. This info is now available in global topo itself as the "IsMasterServing" flag. But, we'll need to go into the UI to make this change, which is non-trivial right now. Signed-off-by: Sugu Sougoumarane --- go/vt/vtctld/api.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/go/vt/vtctld/api.go b/go/vt/vtctld/api.go index ede03e98815..48f6f98224f 100644 --- a/go/vt/vtctld/api.go +++ b/go/vt/vtctld/api.go @@ -286,10 +286,21 @@ func initAPI(ctx context.Context, ts *topo.Server, actions *ActionRepository, re keyspace := parts[1] if cell == "local" { + aliases, err := ts.GetCellsAliases(ctx, false) + if err != nil { + return nil, fmt.Errorf("could not fetch cell info: %v", err) + } + if len(aliases) == 0 { + return nil, fmt.Errorf("no local cells have been created yet") + } if *localCell == "" { - return nil, fmt.Errorf("local cell requested, but not specified. Please set with -cell flag") + // Choose a random cell. + for cell = range aliases { + break + } + } else { + cell = *localCell } - cell = *localCell } // If a keyspace is provided then return the specified srvkeyspace. From 14a4fa4b14448fe3e00e61b5f46e8dfd640f10f8 Mon Sep 17 00:00:00 2001 From: Sugu Sougoumarane Date: Sun, 26 Apr 2020 09:24:18 -0700 Subject: [PATCH 2/2] vtctld: use correct API to get cells Also use the API only if localcell is not specified. Signed-off-by: Sugu Sougoumarane --- go/vt/vtctld/api.go | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/go/vt/vtctld/api.go b/go/vt/vtctld/api.go index 48f6f98224f..01706e1a2fd 100644 --- a/go/vt/vtctld/api.go +++ b/go/vt/vtctld/api.go @@ -286,18 +286,15 @@ func initAPI(ctx context.Context, ts *topo.Server, actions *ActionRepository, re keyspace := parts[1] if cell == "local" { - aliases, err := ts.GetCellsAliases(ctx, false) - if err != nil { - return nil, fmt.Errorf("could not fetch cell info: %v", err) - } - if len(aliases) == 0 { - return nil, fmt.Errorf("no local cells have been created yet") - } if *localCell == "" { - // Choose a random cell. - for cell = range aliases { - break + cells, err := ts.GetCellInfoNames(ctx) + if err != nil { + return nil, fmt.Errorf("could not fetch cell info: %v", err) + } + if len(cells) == 0 { + return nil, fmt.Errorf("no local cells have been created yet") } + cell = cells[0] } else { cell = *localCell }