Skip to content

Commit

Permalink
fix: check that all keyspaces loaded successfully before using them (#…
Browse files Browse the repository at this point in the history
…10396) (#10401)

* fix: check that all keyspaces loades successfully before using them

Signed-off-by: Andres Taylor <[email protected]>
  • Loading branch information
systay authored Jun 1, 2022
1 parent c79d15e commit 12fc1f0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion go/vt/vtexplain/vtexplain.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func Init(vSchemaStr, sqlSchema, ksShardMapStr string, opts *Options) error {

err = initVtgateExecutor(vSchemaStr, ksShardMapStr, opts)
if err != nil {
return fmt.Errorf("initVtgateExecutor: %v", err)
return fmt.Errorf("initVtgateExecutor: %v", err.Error())
}

return nil
Expand Down
15 changes: 15 additions & 0 deletions go/vt/vtexplain/vtexplain_flaky_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,21 @@ func TestUsingKeyspaceShardMap(t *testing.T) {
}
}

func TestInit(t *testing.T) {
vschema := `{
"ks1": {
"sharded": true,
"tables": {
"table_missing_primary_vindex": {}
}
}
}`
schema := "create table table_missing_primary_vindex (id int primary key)"
err := Init(vschema, schema, "", defaultTestOpts())
require.Error(t, err)
require.Contains(t, err.Error(), "missing primary col vindex")
}

type vtexplainTestTopoVersion struct{}

func (vtexplain *vtexplainTestTopoVersion) String() string { return "vtexplain-test-topo" }
8 changes: 8 additions & 0 deletions go/vt/vtexplain/vtexplain_vtgate.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
"sort"
"strings"

"vitess.io/vitess/go/vt/vtgate/vindexes"

"vitess.io/vitess/go/cache"
"vitess.io/vitess/go/vt/topo"
"vitess.io/vitess/go/vt/topo/memorytopo"
Expand Down Expand Up @@ -112,6 +114,12 @@ func buildTopology(opts *Options, vschemaStr string, ksShardMapStr string, numSh
if err != nil {
return err
}
schema := vindexes.BuildVSchema(&srvVSchema)
for ks, ksSchema := range schema.Keyspaces {
if ksSchema.Error != nil {
return vterrors.Wrapf(ksSchema.Error, "vschema failed to load on keyspace [%s]", ks)
}
}
explainTopo.Keyspaces = srvVSchema.Keyspaces

ksShardMap, err := getKeyspaceShardMap(ksShardMapStr)
Expand Down

0 comments on commit 12fc1f0

Please sign in to comment.