Skip to content

Commit

Permalink
Merge pull request #5930 from tinyspeck/zmagg_rebuild_srv_schema_no_m…
Browse files Browse the repository at this point in the history
…ulticell

Pass in cell to EnsureVSchema and GetOrCreateShard
  • Loading branch information
rafael authored Apr 20, 2020
2 parents 7b6402c + f8edec4 commit 924824b
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 18 deletions.
19 changes: 12 additions & 7 deletions go/test/endtoend/recovery/recovery_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,19 @@ func VerifyQueriesUsingVtgate(t *testing.T, session *vtgateconn.VTGateSession, q

func RestoreTablet(t *testing.T, localCluster *cluster.LocalProcessCluster, tablet *cluster.Vttablet, restoreKSName string, shardName string, keyspaceName string, commonTabletArg []string) {
tablet.ValidateTabletRestart(t)
tm := time.Now().UTC()
tm.Format(time.RFC3339)
_, err := localCluster.VtctlProcess.ExecuteCommandWithOutput("CreateKeyspace",
"-keyspace_type=SNAPSHOT", "-base_keyspace="+keyspaceName,
"-snapshot_time", tm.Format(time.RFC3339), restoreKSName)
require.Nil(t, err)

replicaTabletArgs := commonTabletArg

_, err := localCluster.VtctlProcess.ExecuteCommandWithOutput("GetKeyspace", restoreKSName)

if err != nil {
tm := time.Now().UTC()
tm.Format(time.RFC3339)
_, err := localCluster.VtctlProcess.ExecuteCommandWithOutput("CreateKeyspace",
"-keyspace_type=SNAPSHOT", "-base_keyspace="+keyspaceName,
"-snapshot_time", tm.Format(time.RFC3339), restoreKSName)
require.Nil(t, err)
}

if UseXb {
replicaTabletArgs = append(replicaTabletArgs, XbArgs...)
}
Expand Down
4 changes: 2 additions & 2 deletions go/vt/topo/shard.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ func (ts *Server) CreateShard(ctx context.Context, keyspace, shard string) (err

// GetOrCreateShard will return the shard object, or create one if it doesn't
// already exist. Note the shard creation is protected by a keyspace Lock.
func (ts *Server) GetOrCreateShard(ctx context.Context, keyspace, shard string) (si *ShardInfo, err error) {
func (ts *Server) GetOrCreateShard(ctx context.Context, keyspace, shard, cell string) (si *ShardInfo, err error) {
log.Info("GetShard %s/%s", keyspace, shard)
si, err = ts.GetShard(ctx, keyspace, shard)
if !IsErrType(err, NoNode) {
Expand All @@ -340,7 +340,7 @@ func (ts *Server) GetOrCreateShard(ctx context.Context, keyspace, shard string)

// make sure a valid vschema has been loaded
log.Info("EnsureVSchema %s/%s", keyspace, shard)
if err = ts.EnsureVSchema(ctx, keyspace); err != nil {
if err = ts.EnsureVSchema(ctx, keyspace, []string{cell}); err != nil {
return nil, vterrors.Wrapf(err, "EnsureVSchema(%v) failed", keyspace)
}

Expand Down
4 changes: 2 additions & 2 deletions go/vt/topo/vschema.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (ts *Server) GetVSchema(ctx context.Context, keyspace string) (*vschemapb.K
}

// EnsureVSchema makes sure that a vschema is present for this keyspace or creates a blank one if it is missing
func (ts *Server) EnsureVSchema(ctx context.Context, keyspace string) error {
func (ts *Server) EnsureVSchema(ctx context.Context, keyspace string, cells []string) error {
vschema, err := ts.GetVSchema(ctx, keyspace)
if err != nil && !IsErrType(err, NoNode) {
log.Info("error in getting vschema for keyspace %s: %v", keyspace, err)
Expand All @@ -89,7 +89,7 @@ func (ts *Server) EnsureVSchema(ctx context.Context, keyspace string) error {
}
}

err = ts.RebuildSrvVSchema(ctx, []string{} /* cells */)
err = ts.RebuildSrvVSchema(ctx, cells)
if err != nil {
log.Errorf("could not rebuild SrvVschema after creating keyspace: %v", err)
return err
Expand Down
5 changes: 3 additions & 2 deletions go/vt/topotools/shard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ func TestGetOrCreateShard(t *testing.T) {
ctx := context.Background()

// Set up topology.
ts := memorytopo.NewServer("test_cell")
cell := "test_cell"
ts := memorytopo.NewServer(cell)

// and do massive parallel GetOrCreateShard
keyspace := "test_keyspace"
Expand All @@ -119,7 +120,7 @@ func TestGetOrCreateShard(t *testing.T) {
for j := 0; j < 100; j++ {
index := rand.Intn(10)
shard := fmt.Sprintf("%v", index)
si, err := ts.GetOrCreateShard(ctx, keyspace, shard)
si, err := ts.GetOrCreateShard(ctx, keyspace, shard, cell)
if err != nil {
t.Errorf("GetOrCreateShard(%v, %v) failed: %v", i, shard, err)
}
Expand Down
7 changes: 6 additions & 1 deletion go/vt/vtctl/vtctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -1620,7 +1620,12 @@ func commandCreateKeyspace(ctx context.Context, wr *wrangler.Wrangler, subFlags
}

if !*allowEmptyVSchema {
err = wr.TopoServer().EnsureVSchema(ctx, keyspace)
cells, err := wr.TopoServer().GetKnownCells(ctx)
if err != nil {
return fmt.Errorf("GetKnownCells failed: %v", err)
}

err = wr.TopoServer().EnsureVSchema(ctx, keyspace, cells)
}

if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion go/vt/vttablet/tabletmanager/init_tablet.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ func (agent *ActionAgent) InitTablet(port, gRPCPort int32) error {
var si *topo.ShardInfo
if err := agent.withRetry(ctx, "creating keyspace and shard", func() error {
var err error
si, err = agent.TopoServer.GetOrCreateShard(ctx, *initKeyspace, shard)
cell := agent.TabletAlias.GetCell()
si, err = agent.TopoServer.GetOrCreateShard(ctx, *initKeyspace, shard, cell)
return err
}); err != nil {
return vterrors.Wrap(err, "InitTablet cannot GetOrCreateShard shard")
Expand Down
2 changes: 1 addition & 1 deletion go/vt/wrangler/tablet.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (wr *Wrangler) InitTablet(ctx context.Context, tablet *topodatapb.Tablet, a

if createShardAndKeyspace {
// create the parent keyspace and shard if needed
si, err = wr.ts.GetOrCreateShard(ctx, tablet.Keyspace, tablet.Shard)
si, err = wr.ts.GetOrCreateShard(ctx, tablet.Keyspace, tablet.Shard, tablet.Alias.GetCell())
} else {
si, err = wr.ts.GetShard(ctx, tablet.Keyspace, tablet.Shard)
if topo.IsErrType(err, topo.NoNode) {
Expand Down
4 changes: 2 additions & 2 deletions go/vt/wrangler/testlib/reparent_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestShardReplicationStatuses(t *testing.T) {
wr := wrangler.New(logutil.NewConsoleLogger(), ts, tmclient.NewTabletManagerClient())

// create shard and tablets
if _, err := ts.GetOrCreateShard(ctx, "test_keyspace", "0"); err != nil {
if _, err := ts.GetOrCreateShard(ctx, "test_keyspace", "0", "cell1"); err != nil {
t.Fatalf("GetOrCreateShard failed: %v", err)
}
master := NewFakeTablet(t, wr, "cell1", 1, topodatapb.TabletType_MASTER, nil)
Expand Down Expand Up @@ -108,7 +108,7 @@ func TestReparentTablet(t *testing.T) {
wr := wrangler.New(logutil.NewConsoleLogger(), ts, tmclient.NewTabletManagerClient())

// create shard and tablets
if _, err := ts.GetOrCreateShard(ctx, "test_keyspace", "0"); err != nil {
if _, err := ts.GetOrCreateShard(ctx, "test_keyspace", "0", "cell1"); err != nil {
t.Fatalf("CreateShard failed: %v", err)
}
master := NewFakeTablet(t, wr, "cell1", 1, topodatapb.TabletType_MASTER, nil)
Expand Down

0 comments on commit 924824b

Please sign in to comment.