-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Topo splitter #4
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
97a5a80
Skeleton for a 'Tee' topo.Server for migration purposes.
alainjobart 6cd304e
Merge branch 'master' of github.com:youtube/vitess into topo
alainjobart 00e5e39
Merge branch 'master' of github.com:youtube/vitess into topo
alainjobart 9fca690
Now the Tee supports most operations.
alainjobart 39d120b
Renaming a file.
alainjobart 8969356
Updated these files from Ric's feedback.
alainjobart File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
// Copyright 2013, Google Inc. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
// topotools package contains a few utility classes to handle topo.Server | ||
// objects, and transitions. | ||
package topotools | ||
|
||
import ( | ||
"sync" | ||
|
||
"github.com/youtube/vitess/go/relog" | ||
"github.com/youtube/vitess/go/vt/concurrency" | ||
"github.com/youtube/vitess/go/vt/topo" | ||
) | ||
|
||
// CopyKeyspaces will create the keyspaces in the destination topo | ||
func CopyKeyspaces(fromTS, toTS topo.Server) { | ||
keyspaces, err := fromTS.GetKeyspaces() | ||
if err != nil { | ||
relog.Fatal("fromTS.GetKeyspaces failed: %v", err) | ||
} | ||
|
||
wg := sync.WaitGroup{} | ||
rec := concurrency.AllErrorRecorder{} | ||
for _, keyspace := range keyspaces { | ||
wg.Add(1) | ||
go func(keyspace string) { | ||
defer wg.Done() | ||
if err := toTS.CreateKeyspace(keyspace); err != nil { | ||
if err == topo.ErrNodeExists { | ||
relog.Warning("keyspace %v already exists", keyspace) | ||
} else { | ||
rec.RecordError(err) | ||
} | ||
} | ||
}(keyspace) | ||
} | ||
wg.Wait() | ||
if rec.HasErrors() { | ||
relog.Fatal("copyKeyspaces failed: %v", rec.Error()) | ||
} | ||
} | ||
|
||
// CopyShards will create the keyspaces in the destination topo | ||
func CopyShards(fromTS, toTS topo.Server, deleteKeyspaceShards bool) { | ||
keyspaces, err := fromTS.GetKeyspaces() | ||
if err != nil { | ||
relog.Fatal("fromTS.GetKeyspaces failed: %v", err) | ||
} | ||
|
||
wg := sync.WaitGroup{} | ||
rec := concurrency.AllErrorRecorder{} | ||
for _, keyspace := range keyspaces { | ||
wg.Add(1) | ||
go func(keyspace string) { | ||
defer wg.Done() | ||
shards, err := fromTS.GetShardNames(keyspace) | ||
if err != nil { | ||
rec.RecordError(err) | ||
return | ||
} | ||
|
||
if deleteKeyspaceShards { | ||
if err := toTS.DeleteKeyspaceShards(keyspace); err != nil { | ||
rec.RecordError(err) | ||
return | ||
} | ||
} | ||
|
||
for _, shard := range shards { | ||
wg.Add(1) | ||
go func(keyspace, shard string) { | ||
defer wg.Done() | ||
if err := toTS.CreateShard(keyspace, shard); err != nil { | ||
if err == topo.ErrNodeExists { | ||
relog.Warning("shard %v/%v already exists", keyspace, shard) | ||
} else { | ||
rec.RecordError(err) | ||
} | ||
} | ||
}(keyspace, shard) | ||
} | ||
}(keyspace) | ||
} | ||
wg.Wait() | ||
if rec.HasErrors() { | ||
relog.Fatal("copyShards failed: %v", rec.Error()) | ||
} | ||
} | ||
|
||
// CopyTablets will create the tablets in the destination topo | ||
func CopyTablets(fromTS, toTS topo.Server) { | ||
cells, err := fromTS.GetKnownCells() | ||
if err != nil { | ||
relog.Fatal("fromTS.GetKnownCells failed: %v", err) | ||
} | ||
|
||
wg := sync.WaitGroup{} | ||
rec := concurrency.AllErrorRecorder{} | ||
for _, cell := range cells { | ||
wg.Add(1) | ||
go func(cell string) { | ||
defer wg.Done() | ||
tabletAliases, err := fromTS.GetTabletsByCell(cell) | ||
if err != nil { | ||
rec.RecordError(err) | ||
} else { | ||
for _, tabletAlias := range tabletAliases { | ||
wg.Add(1) | ||
go func(tabletAlias topo.TabletAlias) { | ||
defer wg.Done() | ||
|
||
// read the source tablet | ||
ti, err := fromTS.GetTablet(tabletAlias) | ||
if err != nil { | ||
rec.RecordError(err) | ||
return | ||
} | ||
|
||
// try to create the destination | ||
err = toTS.CreateTablet(ti.Tablet) | ||
if err == topo.ErrNodeExists { | ||
// update the destination tablet | ||
_, err = toTS.UpdateTablet(ti, -1) | ||
|
||
} | ||
if err != nil { | ||
rec.RecordError(err) | ||
return | ||
} | ||
|
||
// create the replication paths | ||
// for masters only here | ||
if ti.Type == topo.TYPE_MASTER { | ||
if err = toTS.CreateReplicationPath(ti.Keyspace, ti.Shard, ti.Alias().String()); err != nil && err != topo.ErrNodeExists { | ||
rec.RecordError(err) | ||
} | ||
} | ||
}(tabletAlias) | ||
} | ||
} | ||
}(cell) | ||
} | ||
wg.Wait() | ||
if rec.HasErrors() { | ||
relog.Fatal("copyTablets failed: %v", rec.Error()) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Write a one line explanation of what topotools does.