本文整理匯總了Golang中github.com/youtube/vitess/go/vt/topo.Server.UpdateSrvVSchema方法的典型用法代碼示例。如果您正苦於以下問題:Golang Server.UpdateSrvVSchema方法的具體用法?Golang Server.UpdateSrvVSchema怎麽用?Golang Server.UpdateSrvVSchema使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/youtube/vitess/go/vt/topo.Server
的用法示例。
在下文中一共展示了Server.UpdateSrvVSchema方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: RebuildVSchema
// RebuildVSchema rebuilds the SrvVSchema for the provided cell list
// (or all cells if cell list is empty).
func RebuildVSchema(ctx context.Context, log logutil.Logger, ts topo.Server, cells []string) error {
// get the actual list of cells
if len(cells) == 0 {
var err error
cells, err = ts.GetKnownCells(ctx)
if err != nil {
return fmt.Errorf("GetKnownCells failed: %v", err)
}
}
// get the keyspaces
keyspaces, err := ts.GetKeyspaces(ctx)
if err != nil {
return fmt.Errorf("GetKeyspaces failed: %v", err)
}
// build the SrvVSchema in parallel, protected by mu
wg := sync.WaitGroup{}
mu := sync.Mutex{}
var finalErr error
srvVSchema := &vschemapb.SrvVSchema{
Keyspaces: map[string]*vschemapb.Keyspace{},
}
for _, keyspace := range keyspaces {
wg.Add(1)
go func(keyspace string) {
defer wg.Done()
k, err := ts.GetVSchema(ctx, keyspace)
if err == topo.ErrNoNode {
err = nil
k = &vschemapb.Keyspace{}
}
mu.Lock()
defer mu.Unlock()
if err != nil {
log.Errorf("GetVSchema(%v) failed: %v", keyspace, err)
finalErr = err
return
}
srvVSchema.Keyspaces[keyspace] = k
}(keyspace)
}
wg.Wait()
if finalErr != nil {
return finalErr
}
// now save the SrvVSchema in all cells in parallel
for _, cell := range cells {
wg.Add(1)
go func(cell string) {
defer wg.Done()
if err := ts.UpdateSrvVSchema(ctx, cell, srvVSchema); err != nil {
log.Errorf("UpdateSrvVSchema(%v) failed: %v", cell, err)
mu.Lock()
finalErr = err
mu.Unlock()
}
}(cell)
}
wg.Wait()
return finalErr
}