Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4496 topo serving shards refactor #4631

Merged
merged 40 commits into from
Mar 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
196cf77
Move serving state from global topo to srv keyspace
rafael Jan 7, 2019
8128ffe
Update disable query service to be more efficient
rafael Feb 5, 2019
ef7a24d
Bug fixes
rafael Feb 6, 2019
b54bbd4
Fix some bugs in the original implementation of the srvkeyspace helpers
rafael Feb 7, 2019
947817c
Bug fixes and cleanup
rafael Feb 8, 2019
83f0ef7
Update tests due to deprecated fields
rafael Feb 8, 2019
59c7f65
Update shard tests per refactor
rafael Feb 8, 2019
b4271d4
Update cell_info test due to refactor
rafael Feb 8, 2019
0612020
Update vtctld tests
rafael Feb 8, 2019
10df1d9
Updates tabletmanager tests
rafael Feb 9, 2019
6683b34
Fix some bugs that were surfaced by migrate served types tests
rafael Feb 9, 2019
4d48a17
Fix wrangler tests. Mostly generate SrvKeyspace before running them
rafael Feb 11, 2019
31114e1
Fix vtctlient_test
rafael Feb 11, 2019
afe1e17
Re-add existent semantics where no cells provided means all cells
rafael Feb 11, 2019
3b5e117
Fix bugs discovered by test in MigrateServedFrom
rafael Feb 12, 2019
7092679
Fix bugs in new srvKeyspace functions. Update tests to reflect new ch…
rafael Feb 13, 2019
a8dd181
Fix issue with bad dns zookeeper test
rafael Feb 14, 2019
eb7157b
Cleanup deprecated tests
rafael Feb 14, 2019
5402ad0
Fix bugs in v2 sharding tests
rafael Feb 15, 2019
5eda4cf
Fixes uncovered by integration tests
rafael Feb 16, 2019
979cc79
More test fixes
rafael Feb 16, 2019
de49d79
Revert change to test now that underlying fix have been solved
rafael Feb 16, 2019
bd0d967
Fix resharding test
rafael Feb 16, 2019
8694ae8
Fixed bug in srv_keyspace. Adds validations that were missed during m…
rafael Feb 16, 2019
3478e97
Adds utility function to check if query service disabled is set in a …
rafael Feb 16, 2019
f4cd023
Fixes for custom sharding
rafael Feb 16, 2019
d8afcf0
This test does not longer makes sense. We don't have cells in shards …
rafael Feb 16, 2019
b05e8cd
Remove deprecated assertion
rafael Feb 17, 2019
49a99c9
Fix bugs uncovered by tests and add some more tests to resharding int…
rafael Feb 18, 2019
9272b1c
Add ServedType for backwards compatiblilty
rafael Feb 19, 2019
b00627e
Fixes test that broke due to adding back deprecated field
rafael Feb 19, 2019
7eac276
Add tests to srv_keyspace
rafael Mar 5, 2019
d0903f4
Add more tests. Deprecated method in favor of a more generic one.
rafael Mar 7, 2019
42a0d23
Adds tests for MigrateServedType
rafael Mar 7, 2019
9ba5c07
Adds test for multi shard migrate served types
rafael Mar 7, 2019
13aa747
Merge branch 'upstream-master' into 4496-topo-serving-shards-refactor
rafael Mar 7, 2019
227cd84
Error formatting fixes
rafael Mar 8, 2019
b5af454
Adds utility function to manipulate serving keyspace graph
rafael Mar 8, 2019
dbf68ed
Merge branch 'master' of https://github.com/vitessio/vitess into 4496…
rafael Mar 14, 2019
410e20d
Updates per code review
rafael Mar 14, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions go/cmd/vtcombo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ import (
"vitess.io/vitess/go/vt/dbconfigs"
"vitess.io/vitess/go/vt/discovery"
"vitess.io/vitess/go/vt/log"
"vitess.io/vitess/go/vt/logutil"
"vitess.io/vitess/go/vt/mysqlctl"
"vitess.io/vitess/go/vt/servenv"
"vitess.io/vitess/go/vt/srvtopo"
"vitess.io/vitess/go/vt/topo"
"vitess.io/vitess/go/vt/topo/memorytopo"
"vitess.io/vitess/go/vt/topotools"
"vitess.io/vitess/go/vt/vtcombo"
"vitess.io/vitess/go/vt/vtctld"
"vitess.io/vitess/go/vt/vtgate"
Expand Down Expand Up @@ -108,6 +110,14 @@ func main() {
exit.Return(1)
}

// Now that we have fully initialized the tablets, rebuild the keyspace graph. This is what would normally happen in InitTablet.
for _, ks := range tpb.Keyspaces {
err := topotools.RebuildKeyspace(context.Background(), logutil.NewConsoleLogger(), ts, ks.GetName(), tpb.Cells)
if err != nil {
log.Fatalf("Couldn't build srv keyspace for (%v: %v). Got error: %v", ks, tpb.Cells, err)
}
}

// vtgate configuration and init
resilientServer := srvtopo.NewResilientServer(ts, "ResilientSrvTopoServer")
healthCheck := discovery.NewHealthCheck(1*time.Millisecond /*retryDelay*/, 1*time.Hour /*healthCheckTimeout*/)
Expand Down
311 changes: 187 additions & 124 deletions go/vt/proto/topodata/topodata.pb.go

Large diffs are not rendered by default.

13 changes: 0 additions & 13 deletions go/vt/srvtopo/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"vitess.io/vitess/go/sqltypes"
"vitess.io/vitess/go/vt/key"
"vitess.io/vitess/go/vt/logutil"
"vitess.io/vitess/go/vt/topo"
"vitess.io/vitess/go/vt/topo/memorytopo"
"vitess.io/vitess/go/vt/topotools"
"vitess.io/vitess/go/vt/vttablet/queryservice"
Expand Down Expand Up @@ -63,12 +62,6 @@ func initResolver(t *testing.T, name string) *Resolver {
if err := ts.CreateShard(ctx, "sks", shard); err != nil {
t.Fatalf("CreateShard(\"%v\") failed: %v", shard, err)
}
if _, err := ts.UpdateShardFields(ctx, "sks", shard, func(si *topo.ShardInfo) error {
si.Shard.Cells = []string{"cell1"}
return nil
}); err != nil {
t.Fatalf("UpdateShardFields(\"%v\") failed: %v", shard, err)
}
}

// Create unsharded keyspace and shard.
Expand All @@ -78,12 +71,6 @@ func initResolver(t *testing.T, name string) *Resolver {
if err := ts.CreateShard(ctx, "uks", "0"); err != nil {
t.Fatalf("CreateShard(0) failed: %v", err)
}
if _, err := ts.UpdateShardFields(ctx, "uks", "0", func(si *topo.ShardInfo) error {
si.Shard.Cells = []string{"cell1"}
return nil
}); err != nil {
t.Fatalf("UpdateShardFields(0) failed: %v", err)
}

// And rebuild both.
for _, keyspace := range []string{"sks", "uks"} {
Expand Down
28 changes: 10 additions & 18 deletions go/vt/topo/cell_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ limitations under the License.
package topo

import (
"fmt"
"path"

"github.com/golang/protobuf/proto"
"golang.org/x/net/context"
"vitess.io/vitess/go/vt/proto/vtrpc"
"vitess.io/vitess/go/vt/vterrors"

topodatapb "vitess.io/vitess/go/vt/proto/topodata"
Expand Down Expand Up @@ -137,24 +137,16 @@ func (ts *Server) UpdateCellInfoFields(ctx context.Context, cell string, update
// DeleteCellInfo deletes the specified CellInfo.
// We first make sure no Shard record points to the cell.
func (ts *Server) DeleteCellInfo(ctx context.Context, cell string) error {
// Get all keyspaces.
keyspaces, err := ts.GetKeyspaces(ctx)
if err != nil {
return vterrors.Wrap(err, "GetKeyspaces() failed")
}

// For each keyspace, make sure no shard points at the cell.
for _, keyspace := range keyspaces {
shards, err := ts.FindAllShardsInKeyspace(ctx, keyspace)
if err != nil {
return vterrors.Wrapf(err, "FindAllShardsInKeyspace(%v) failed", keyspace)
}

for shard, si := range shards {
if si.HasCell(cell) {
return vterrors.Errorf(vtrpc.Code_FAILED_PRECONDITION, "cell %v is used by shard %v/%v, cannot remove it. Use 'vtctl RemoveShardCell' to remove unused cells in a Shard", cell, keyspace, shard)
}
srvKeyspaces, err := ts.GetSrvKeyspaceNames(ctx, cell)
switch {
case err == nil:
if len(srvKeyspaces) != 0 {
return vterrors.Wrap(err, fmt.Sprintf("cell %v has serving keyspaces. Before deleting, delete keyspace with: DeleteKeyspace", cell))
}
case IsErrType(err, NoNode):
// Nothing to do.
default:
return vterrors.Wrap(err, "GetSrvKeyspaceNames() failed")
}

filePath := pathForCellInfo(cell)
Expand Down
13 changes: 5 additions & 8 deletions go/vt/topo/helpers/compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ func CompareShardReplications(ctx context.Context, fromTS, toTS *topo.Server) er
if err != nil {
return vterrors.Wrapf(err, "fromTS.GetKeyspaces")
}
cells, err := fromTS.GetCellInfoNames(ctx)
if err != nil {
return vterrors.Wrap(err, "GetCellInfoNames()")
}

for _, keyspace := range keyspaces {
shards, err := fromTS.GetShardNames(ctx, keyspace)
Expand All @@ -154,14 +158,7 @@ func CompareShardReplications(ctx context.Context, fromTS, toTS *topo.Server) er
}

for _, shard := range shards {

// read the source shard to get the cells
si, err := fromTS.GetShard(ctx, keyspace, shard)
if err != nil {
return vterrors.Wrapf(err, "GetShard(%v, %v)", keyspace, shard)
}

for _, cell := range si.Shard.Cells {
for _, cell := range cells {
fromSRi, err := fromTS.GetShardReplication(ctx, cell, keyspace, shard)
if err != nil {
return vterrors.Wrapf(err, "GetShardReplication(%v, %v, %v)", cell, keyspace, shard)
Expand Down
14 changes: 6 additions & 8 deletions go/vt/topo/helpers/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,21 +146,19 @@ func CopyShardReplications(ctx context.Context, fromTS, toTS *topo.Server) {
log.Fatalf("fromTS.GetKeyspaces: %v", err)
}

cells, err := fromTS.GetCellInfoNames(ctx)
if err != nil {
log.Fatalf("GetCellInfoNames(): %v", err)
}

for _, keyspace := range keyspaces {
shards, err := fromTS.GetShardNames(ctx, keyspace)
if err != nil {
log.Fatalf("GetShardNames(%v): %v", keyspace, err)
}

for _, shard := range shards {

// read the source shard to get the cells
si, err := fromTS.GetShard(ctx, keyspace, shard)
if err != nil {
log.Fatalf("GetShard(%v, %v): %v", keyspace, shard, err)
}

for _, cell := range si.Shard.Cells {
for _, cell := range cells {
sri, err := fromTS.GetShardReplication(ctx, cell, keyspace, shard)
if err != nil {
log.Fatalf("GetShardReplication(%v, %v, %v): %v", cell, keyspace, shard, err)
Expand Down
13 changes: 0 additions & 13 deletions go/vt/topo/helpers/copy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,6 @@ func createSetup(ctx context.Context, t *testing.T) (*topo.Server, *topo.Server)
if err := fromTS.CreateShard(ctx, "test_keyspace", "0"); err != nil {
t.Fatalf("cannot create shard: %v", err)
}
if _, err := fromTS.UpdateShardFields(ctx, "test_keyspace", "0", func(si *topo.ShardInfo) error {
si.Cells = []string{"test_cell"}
return nil
}); err != nil {
t.Fatalf("cannot update shard: %v", err)
}
tablet1 := &topodatapb.Tablet{
Alias: &topodatapb.TabletAlias{
Cell: "test_cell",
Expand Down Expand Up @@ -120,13 +114,6 @@ func TestBasic(t *testing.T) {
t.Fatalf("unexpected shards: %v", shards)
}
CopyShards(ctx, fromTS, toTS)
si, err := toTS.GetShard(ctx, "test_keyspace", "0")
if err != nil {
t.Fatalf("cannot read shard: %v", err)
}
if len(si.Shard.Cells) != 1 || si.Shard.Cells[0] != "test_cell" {
t.Fatalf("bad shard data: %v", *si.Shard)
}

// check ShardReplication copy
sr, err := fromTS.GetShardReplication(ctx, "test_cell", "test_keyspace", "0")
Expand Down
16 changes: 11 additions & 5 deletions go/vt/topo/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ package topo

import (
"flag"
"fmt"
"sync"

"golang.org/x/net/context"
Expand Down Expand Up @@ -257,12 +258,17 @@ func (ts *Server) ConnForCell(ctx context.Context, cell string) (Conn, error) {

// Create the connection.
conn, err = ts.factory.Create(cell, ci.ServerAddress, ci.Root)
if err != nil {
return nil, vterrors.Wrapf(err, "failed to create topo connection to %v, %v", ci.ServerAddress, ci.Root)
switch {
case err == nil:
conn = NewStatsConn(cell, conn)
ts.cells[cell] = conn
return conn, nil
case IsErrType(err, NoNode):
err = vterrors.Wrap(err, fmt.Sprintf("failed to create topo connection to %v, %v", ci.ServerAddress, ci.Root))
return nil, NewError(NoNode, err.Error())
default:
return nil, vterrors.Wrap(err, fmt.Sprintf("failed to create topo connection to %v, %v", ci.ServerAddress, ci.Root))
}
conn = NewStatsConn(cell, conn)
ts.cells[cell] = conn
return conn, nil
}

// GetRegionByCell returns the region group this `cell` belongs to, if there's none, it returns the `cell` as region.
Expand Down
Loading