本文整理匯總了Golang中github.com/youtube/vitess/go/vt/topo.Server.CreateReplicationPath方法的典型用法代碼示例。如果您正苦於以下問題:Golang Server.CreateReplicationPath方法的具體用法?Golang Server.CreateReplicationPath怎麽用?Golang Server.CreateReplicationPath使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/youtube/vitess/go/vt/topo.Server
的用法示例。
在下文中一共展示了Server.CreateReplicationPath方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: CopyTablets
// CopyTablets will create the tablets in the destination topo
func CopyTablets(fromTS, toTS topo.Server) {
cells, err := fromTS.GetKnownCells()
if err != nil {
log.Fatalf("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
log.Warningf("tablet %v already exists, updating it", tabletAlias)
err = toTS.UpdateTabletFields(ti.Alias(), func(t *topo.Tablet) error {
*t = *ti.Tablet
return nil
})
}
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() {
log.Fatalf("copyTablets failed: %v", rec.Error())
}
}
示例2: CheckReplicationPaths
func CheckReplicationPaths(t *testing.T, ts topo.Server) {
if _, err := ts.GetReplicationPaths("test_keyspace", "-10", "/"); err != topo.ErrNoNode {
t.Errorf("GetReplicationPaths(bad shard): %v", err)
}
if err := ts.CreateKeyspace("test_keyspace"); err != nil {
t.Errorf("CreateKeyspace: %v", err)
}
if err := topo.CreateShard(ts, "test_keyspace", "-10"); err != nil {
t.Errorf("CreateShard: %v", err)
}
if paths, err := ts.GetReplicationPaths("test_keyspace", "-10", "/"); err != nil || len(paths) != 0 {
t.Errorf("GetReplicationPaths(empty shard): %v, %v", err, paths)
}
if _, err := ts.GetReplicationPaths("test_keyspace", "-10", "/666"); err != topo.ErrNoNode {
t.Errorf("GetReplicationPaths(non-existing path): %v", err)
}
if err := ts.CreateReplicationPath("test_keyspace", "-10", "/cell-0000000001"); err != nil {
t.Errorf("CreateReplicationPath: %v", err)
}
if err := ts.CreateReplicationPath("test_keyspace", "-10", "/cell-0000000001"); err != topo.ErrNodeExists {
t.Errorf("CreateReplicationPath(again): %v", err)
}
if paths, err := ts.GetReplicationPaths("test_keyspace", "-10", "/"); err != nil || len(paths) != 1 || paths[0].String() != "cell-0000000001" {
t.Errorf("GetReplicationPaths(root): %v, %v", err, paths)
}
if err := ts.CreateReplicationPath("test_keyspace", "-10", "/cell-0000000001/cell-0000000002"); err != nil {
t.Errorf("CreateReplicationPath(2): %v", err)
}
if err := ts.CreateReplicationPath("test_keyspace", "-10", "/cell-0000000001/cell-0000000003"); err != nil {
t.Errorf("CreateReplicationPath(3): %v", err)
}
if paths, err := ts.GetReplicationPaths("test_keyspace", "-10", "/cell-0000000001"); err != nil || len(paths) != 2 || paths[0].String() != "cell-0000000002" || paths[1].String() != "cell-0000000003" {
t.Errorf("GetReplicationPaths(master): %v, %v", err, paths)
}
if err := ts.DeleteReplicationPath("test_keyspace", "-10", "/cell-0000000001"); err != topo.ErrNotEmpty {
t.Errorf("DeleteReplicationPath(master with slaves): %v", err)
}
if err := ts.DeleteReplicationPath("test_keyspace", "-10", "/cell-0000000001/cell-0000000002"); err != nil {
t.Errorf("DeleteReplicationPath(slave1): %v", err)
}
if paths, err := ts.GetReplicationPaths("test_keyspace", "-10", "/cell-0000000001"); err != nil || len(paths) != 1 || paths[0].String() != "cell-0000000003" {
t.Errorf("GetReplicationPaths(master): %v, %v", err, paths)
}
if err := ts.DeleteReplicationPath("test_keyspace", "-10", "/cell-0000000001/cell-0000000003"); err != nil {
t.Errorf("DeleteReplicationPath(slave2): %v", err)
}
if paths, err := ts.GetReplicationPaths("test_keyspace", "-10", "/cell-0000000001"); err != nil || len(paths) != 0 {
t.Errorf("GetReplicationPaths(master): %v, %v", err, paths)
}
if err := ts.DeleteReplicationPath("test_keyspace", "-10", "/cell-0000000001"); err != nil {
t.Errorf("DeleteReplicationPath(master): %v", err)
}
if paths, err := ts.GetReplicationPaths("test_keyspace", "-10", "/"); err != nil || len(paths) != 0 {
t.Errorf("GetReplicationPaths(root): %v, %v", err, paths)
}
}