本文整理汇总了Golang中github.com/youtube/vitess/go/vt/topo.Server.GetVSchema方法的典型用法代码示例。如果您正苦于以下问题:Golang Server.GetVSchema方法的具体用法?Golang Server.GetVSchema怎么用?Golang Server.GetVSchema使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/youtube/vitess/go/vt/topo.Server
的用法示例。
在下文中一共展示了Server.GetVSchema方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: initAPI
//.........这里部分代码省略.........
return nil, errors.New("cell param required")
}
return ts.GetTabletsByCell(ctx, cell)
}
// Get tablet health.
if parts := strings.Split(tabletPath, "/"); len(parts) == 2 && parts[1] == "health" {
tabletAlias, err := topoproto.ParseTabletAlias(parts[0])
if err != nil {
return nil, err
}
return tabletHealthCache.Get(ctx, tabletAlias)
}
tabletAlias, err := topoproto.ParseTabletAlias(tabletPath)
if err != nil {
return nil, err
}
// Perform an action on a tablet.
if r.Method == "POST" {
if err := r.ParseForm(); err != nil {
return nil, err
}
action := r.FormValue("action")
if action == "" {
return nil, errors.New("must specify action")
}
return actions.ApplyTabletAction(ctx, action, tabletAlias, r), nil
}
// Get the tablet record.
return ts.GetTablet(ctx, tabletAlias)
})
// EndPoints
handleCollection("endpoints", func(r *http.Request) (interface{}, error) {
// We expect cell/keyspace/shard/tabletType.
epPath := getItemPath(r.URL.Path)
parts := strings.Split(epPath, "/")
if len(parts) != 4 {
return nil, fmt.Errorf("invalid cell/keyspace/shard/tabletType: %q", epPath)
}
if parts[3] == "" {
// tabletType is empty, so list the tablet types.
return ts.GetSrvTabletTypesPerShard(ctx, parts[0], parts[1], parts[2])
}
tabletType, err := topoproto.ParseTabletType(parts[3])
if err != nil {
return nil, fmt.Errorf("invalid tablet type %v: %v", parts[3], err)
}
// Get the endpoints object for a specific type.
ep, _, err := ts.GetEndPoints(ctx, parts[0], parts[1], parts[2], tabletType)
return ep, err
})
// Schema Change
http.HandleFunc(apiPrefix+"schema/apply", func(w http.ResponseWriter, r *http.Request) {
req := struct{ Keyspace, SQL string }{}
if err := unmarshalRequest(r, &req); err != nil {
httpErrorf(w, r, "can't unmarshal request: %v", err)
return
}
executor := schemamanager.NewTabletExecutor(
tmclient.NewTabletManagerClient(),
ts)
schemamanager.Run(ctx,
schemamanager.NewUIController(req.SQL, req.Keyspace, w), executor)
})
// VSchema
http.HandleFunc(apiPrefix+"vschema/", func(w http.ResponseWriter, r *http.Request) {
// Save VSchema
if r.Method == "POST" {
vschema, err := ioutil.ReadAll(r.Body)
if err != nil {
httpErrorf(w, r, "can't read request body: %v", err)
return
}
if err := ts.SaveVSchema(ctx, string(vschema)); err != nil {
httpErrorf(w, r, "can't save vschema: %v", err)
}
return
}
// Get VSchema
vschema, err := ts.GetVSchema(ctx)
if err != nil {
httpErrorf(w, r, "can't get vschema: %v", err)
return
}
w.Header().Set("Content-Type", jsonContentType)
w.Write([]byte(vschema))
})
}
示例2: 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
}