Skip to content

Commit

Permalink
Merge pull request #1012 from yaoshengzhe/fix_tolerant_nil_master_ali…
Browse files Browse the repository at this point in the history
…as_in_schemamanager

SchemaManager should be able to handle nil ShardInfo.MasterAlias.
  • Loading branch information
yaoshengzhe committed Aug 20, 2015
2 parents 81a119c + 6bf9319 commit bcb38b7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
11 changes: 8 additions & 3 deletions go/vt/schemamanager/schemamanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ func (client *fakeTabletManagerClient) ExecuteFetchAsDba(ctx context.Context, ta

type fakeTopo struct {
faketopo.FakeTopo
WithEmptyMasterAlias bool
}

func newFakeTopo() *fakeTopo {
Expand All @@ -284,11 +285,15 @@ func (topoServer *fakeTopo) GetShardNames(ctx context.Context, keyspace string)
}

func (topoServer *fakeTopo) GetShard(ctx context.Context, keyspace string, shard string) (*topo.ShardInfo, error) {
value := &pb.Shard{
MasterAlias: &pb.TabletAlias{
var masterAlias *pb.TabletAlias
if !topoServer.WithEmptyMasterAlias {
masterAlias = &pb.TabletAlias{
Cell: "test_cell",
Uid: 0,
},
}
}
value := &pb.Shard{
MasterAlias: masterAlias,
}
return topo.NewShardInfo(keyspace, shard, value, 0), nil
}
Expand Down
4 changes: 4 additions & 0 deletions go/vt/schemamanager/tablet_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ func (exec *TabletExecutor) Open(ctx context.Context, keyspace string) error {
if err != nil {
return fmt.Errorf("unable to get shard info, keyspace: %s, shard: %s, error: %v", keyspace, shardName, err)
}
if !shardInfo.HasMaster() {
log.Errorf("shard: %s does not have a master", shardName)
return fmt.Errorf("shard: %s does not have a master", shardName)
}
tabletInfo, err := exec.topoServer.GetTablet(ctx, shardInfo.MasterAlias)
if err != nil {
return fmt.Errorf("unable to get master tablet info, keyspace: %s, shard: %s, error: %v", keyspace, shardName, err)
Expand Down
14 changes: 14 additions & 0 deletions go/vt/schemamanager/tablet_executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@ func TestTabletExecutorOpen(t *testing.T) {
}
}

func TestTabletExecutorOpenWithEmptyMasterAlias(t *testing.T) {
fakeTopo := newFakeTopo()
fakeTopo.WithEmptyMasterAlias = true
executor := NewTabletExecutor(
newFakeTabletManagerClient(),
fakeTopo)
ctx := context.Background()

if err := executor.Open(ctx, "test_keyspace"); err == nil {
t.Fatalf("executor.Open() = nil, want error")
}
executor.Close()
}

func TestTabletExecutorValidate(t *testing.T) {
fakeTmc := newFakeTabletManagerClient()

Expand Down

0 comments on commit bcb38b7

Please sign in to comment.