本文整理汇总了Golang中github.com/youtube/vitess/go/vt/topo.ValidateShardName函数的典型用法代码示例。如果您正苦于以下问题:Golang ValidateShardName函数的具体用法?Golang ValidateShardName怎么用?Golang ValidateShardName使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ValidateShardName函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: createSourceTablet
// createSourceTablet is a helper method to create the source tablet
// in the given keyspace/shard.
func createSourceTablet(t *testing.T, name string, ts topo.Server, keyspace, shard string) {
vshard, kr, err := topo.ValidateShardName(shard)
if err != nil {
t.Fatalf("ValidateShardName(%v) failed: %v", shard, err)
}
ctx := context.Background()
tablet := &topodatapb.Tablet{
Alias: &topodatapb.TabletAlias{
Cell: "cell1",
Uid: 100,
},
Keyspace: keyspace,
Shard: vshard,
Type: topodatapb.TabletType_REPLICA,
KeyRange: kr,
PortMap: map[string]int32{
"vt": 80,
},
}
if err := ts.CreateTablet(ctx, tablet); err != nil {
t.Fatalf("CreateTablet failed: %v", err)
}
// register a tablet conn dialer that will return the instance
// we want
tabletconn.RegisterDialer(name, func(tablet *topodatapb.Tablet, timeout time.Duration) (tabletconn.TabletConn, error) {
return &fakeTabletConn{
tablet: tablet,
}, nil
})
flag.Set("tablet_protocol", name)
}
开发者ID:dumbunny,项目名称:vitess,代码行数:35,代码来源:binlog_players_test.go
示例2: newKeyRange
func newKeyRange(value string) key.KeyRange {
_, result, err := topo.ValidateShardName(value)
if err != nil {
panic(err)
}
return result
}
开发者ID:pranjal5215,项目名称:vitess,代码行数:7,代码来源:testing.go
示例3: createSourceTablet
func createSourceTablet(t *testing.T, ts topo.Server, keyspace, shard string) {
vshard, kr, err := topo.ValidateShardName(shard)
if err != nil {
t.Fatalf("ValidateShardName(%v) failed: %v", shard, err)
}
ctx := context.Background()
tablet := &pb.Tablet{
Alias: &pb.TabletAlias{
Cell: "cell1",
Uid: 100,
},
Type: pb.TabletType_REPLICA,
KeyRange: kr,
Keyspace: keyspace,
Shard: vshard,
PortMap: map[string]int32{
"vt": 80,
},
}
if err := ts.CreateTablet(ctx, tablet); err != nil {
t.Fatalf("CreateTablet failed: %v", err)
}
if err := topotools.UpdateTabletEndpoints(ctx, ts, tablet); err != nil {
t.Fatalf("topotools.UpdateTabletEndpoints failed: %v", err)
}
}
开发者ID:khanchan,项目名称:vitess,代码行数:27,代码来源:binlog_test.go
示例4: addL2VTGateConn
// addL2VTGateConn adds a backend l2vtgate for the provided keyspace / shard.
func (lg *l2VTGateGateway) addL2VTGateConn(addr, keyspace, shard string) error {
lg.mu.Lock()
defer lg.mu.Unlock()
// extract keyrange if it's a range
canonical, kr, err := topo.ValidateShardName(shard)
if err != nil {
return fmt.Errorf("error parsing shard name %v: %v", shard, err)
}
// check for duplicates
for _, c := range lg.connMap[keyspace] {
if c.shard == canonical {
return fmt.Errorf("duplicate %v/%v entry", keyspace, shard)
}
}
// Dial in the background
conn, err := tabletconn.GetDialer()(&topodatapb.Tablet{
Hostname: addr,
}, 0)
if err != nil {
return err
}
lg.connMap[keyspace] = append(lg.connMap[keyspace], &l2VTGateConn{
addr: addr,
keyspace: keyspace,
shard: canonical,
keyRange: kr,
conn: conn,
})
return nil
}
开发者ID:xujianhai,项目名称:vitess,代码行数:35,代码来源:l2vtgategateway.go
示例5: TabletKeyspaceShard
// TabletKeyspaceShard is the option to set the tablet keyspace and shard
func TabletKeyspaceShard(t *testing.T, keyspace, shard string) TabletOption {
return func(tablet *topo.Tablet) {
tablet.Keyspace = keyspace
var err error
tablet.Shard, tablet.KeyRange, err = topo.ValidateShardName(shard)
if err != nil {
t.Fatalf("cannot ValidateShardName value %v", shard)
}
}
}
开发者ID:pranjal5215,项目名称:vitess,代码行数:11,代码来源:fake_tablet.go
示例6: TabletKeyspaceShard
// TabletKeyspaceShard is the option to set the tablet keyspace and shard
func TabletKeyspaceShard(t *testing.T, keyspace, shard string) TabletOption {
return func(tablet *topodatapb.Tablet) {
tablet.Keyspace = keyspace
shard, kr, err := topo.ValidateShardName(shard)
if err != nil {
t.Fatalf("cannot ValidateShardName value %v", shard)
}
tablet.Shard = shard
tablet.KeyRange = kr
}
}
开发者ID:littleyang,项目名称:vitess,代码行数:12,代码来源:fake_tablet.go
示例7: isIncluded
// isIncluded returns true iff the tablet's keyspace and shard should be
// forwarded to the underlying TabletRecorder.
func (fbs *FilterByShard) isIncluded(tablet *topodatapb.Tablet) bool {
canonical, kr, err := topo.ValidateShardName(tablet.Shard)
if err != nil {
log.Errorf("Error parsing shard name %v, will ignore tablet: %v", tablet.Shard, err)
return false
}
for _, c := range fbs.filters[tablet.Keyspace] {
if canonical == c.shard {
// Exact match (probably a non-sharded keyspace).
return true
}
if kr != nil && c.keyRange != nil && key.KeyRangeIncludes(c.keyRange, kr) {
// Our filter's KeyRange includes the provided KeyRange
return true
}
}
return false
}
开发者ID:dumbunny,项目名称:vitess,代码行数:21,代码来源:topology_watcher.go
示例8: createSourceTablet
// createSourceTablet is a helper method to create the source tablet
// in the given keyspace/shard.
func createSourceTablet(t *testing.T, name string, ts topo.Server, keyspace, shard string) {
vshard, kr, err := topo.ValidateShardName(shard)
if err != nil {
t.Fatalf("ValidateShardName(%v) failed: %v", shard, err)
}
ctx := context.Background()
tablet := &pbt.Tablet{
Alias: &pbt.TabletAlias{
Cell: "cell1",
Uid: 100,
},
Type: pbt.TabletType_REPLICA,
KeyRange: kr,
Keyspace: keyspace,
Shard: vshard,
PortMap: map[string]int32{
"vt": 80,
},
}
if err := ts.CreateTablet(ctx, tablet); err != nil {
t.Fatalf("CreateTablet failed: %v", err)
}
if err := topotools.UpdateTabletEndpoints(ctx, ts, tablet); err != nil {
t.Fatalf("topotools.UpdateTabletEndpoints failed: %v", err)
}
// register a tablet conn dialer that will return the instance
// we want
tabletconn.RegisterDialer(name, func(ctx context.Context, endPoint *pbt.EndPoint, k, s string, tabletType pbt.TabletType, timeout time.Duration) (tabletconn.TabletConn, error) {
return &fakeTabletConn{
endPoint: endPoint,
keyspace: keyspace,
shard: vshard,
tabletType: pbt.TabletType_REPLICA,
}, nil
})
flag.Lookup("tablet_protocol").Value.Set(name)
}
开发者ID:c3p0hz,项目名称:vitess,代码行数:41,代码来源:binlog_test.go
示例9: getConn
// getConn returns the right l2VTGateConn for a given keyspace / shard.
func (lg *l2VTGateGateway) getConn(keyspace, shard string) (*l2VTGateConn, error) {
lg.mu.RLock()
defer lg.mu.RUnlock()
canonical, kr, err := topo.ValidateShardName(shard)
if err != nil {
return nil, fmt.Errorf("invalid shard name: %v", shard)
}
for _, c := range lg.connMap[keyspace] {
if canonical == c.shard {
// Exact match (probably a non-sharded keyspace).
return c, nil
}
if kr != nil && c.keyRange != nil && key.KeyRangeIncludes(c.keyRange, kr) {
// The shard KeyRange is included in this destination's
// KeyRange, that's the destination we want.
return c, nil
}
}
return nil, fmt.Errorf("no configured destination for %v/%v", keyspace, shard)
}
开发者ID:yuer2008,项目名称:vitess,代码行数:24,代码来源:l2vtgategateway.go
示例10: getConn
// getConn returns the right l2VTGateConn for a given keyspace / shard.
func (lg *l2VTGateGateway) getConn(keyspace, shard string) (*l2VTGateConn, error) {
lg.mu.RLock()
defer lg.mu.RUnlock()
canonical, kr, err := topo.ValidateShardName(shard)
if err != nil {
return nil, fmt.Errorf("invalid shard name: %v", shard)
}
for _, c := range lg.connMap[keyspace] {
if canonical == c.shard {
// Exact match (probably a non-sharded keyspace).
return c, nil
}
if key.KeyRangesIntersect(kr, c.keyRange) {
// There is overlap, we can just send to the destination.
// FIXME(alainjobart) if canonical is not entirely covered by l2vtgate,
// this is probably an error. We probably want key.KeyRangeIncludes(), NYI.
return c, nil
}
}
return nil, fmt.Errorf("no configured destination for %v/%v", keyspace, shard)
}
开发者ID:xujianhai,项目名称:vitess,代码行数:25,代码来源:l2vtgategateway.go
示例11: NewFilterByShard
// NewFilterByShard creates a new FilterByShard on top of an existing
// TabletRecorder. Each filter is a keyspace|shard entry, where shard
// can either be a shard name, or a keyrange. All tablets that match
// at least one keyspace|shard tuple will be forwarded to the
// underlying TabletRecorder.
func NewFilterByShard(tr TabletRecorder, filters []string) (*FilterByShard, error) {
m := make(map[string][]*filterShard)
for _, filter := range filters {
parts := strings.Split(filter, "|")
if len(parts) != 2 {
return nil, fmt.Errorf("invalid FilterByShard parameter: %v", filter)
}
keyspace := parts[0]
shard := parts[1]
// extract keyrange if it's a range
canonical, kr, err := topo.ValidateShardName(shard)
if err != nil {
return nil, fmt.Errorf("error parsing shard name %v: %v", shard, err)
}
// check for duplicates
for _, c := range m[keyspace] {
if c.shard == canonical {
return nil, fmt.Errorf("duplicate %v/%v entry", keyspace, shard)
}
}
m[keyspace] = append(m[keyspace], &filterShard{
keyspace: keyspace,
shard: canonical,
keyRange: kr,
})
}
return &FilterByShard{
tr: tr,
filters: m,
}, nil
}
开发者ID:dumbunny,项目名称:vitess,代码行数:41,代码来源:topology_watcher.go
示例12: InitTablet
// InitTablet initializes the tablet record if necessary.
func (agent *ActionAgent) InitTablet(port, gRPCPort int32) error {
// only enabled if one of init_tablet_type (when healthcheck
// is disabled) or init_keyspace (when healthcheck is enabled)
// is passed in, then check other parameters
if *initTabletType == "" && *initKeyspace == "" {
return nil
}
// figure out our default target type
var tabletType topodatapb.TabletType
if *initTabletType != "" {
if *targetTabletType != "" {
log.Fatalf("cannot specify both target_tablet_type and init_tablet_type parameters (as they might conflict)")
}
// use the type specified on the command line
var err error
tabletType, err = topoproto.ParseTabletType(*initTabletType)
if err != nil {
log.Fatalf("Invalid init tablet type %v: %v", *initTabletType, err)
}
if tabletType == topodatapb.TabletType_MASTER {
// We disallow MASTER, so we don't have to change
// shard.MasterAlias, and deal with the corner cases.
log.Fatalf("init_tablet_type cannot be %v", tabletType)
}
} else if *targetTabletType != "" {
if strings.ToUpper(*targetTabletType) == topodatapb.TabletType_name[int32(topodatapb.TabletType_MASTER)] {
log.Fatalf("target_tablet_type cannot be '%v'. Use '%v' instead.", tabletType, topodatapb.TabletType_REPLICA)
}
// use spare, the healthcheck will turn us into what
// we need to be eventually
tabletType = topodatapb.TabletType_SPARE
} else {
log.Fatalf("if init tablet is enabled, one of init_tablet_type or target_tablet_type needs to be specified")
}
// create a context for this whole operation
ctx, cancel := context.WithTimeout(agent.batchCtx, *initTimeout)
defer cancel()
// since we're assigned to a shard, make sure it exists, see if
// we are its master, and update its cells list if necessary
if *initKeyspace == "" || *initShard == "" {
log.Fatalf("if init tablet is enabled and the target type is not idle, init_keyspace and init_shard also need to be specified")
}
shard, _, err := topo.ValidateShardName(*initShard)
if err != nil {
log.Fatalf("cannot validate shard name: %v", err)
}
log.Infof("Reading shard record %v/%v", *initKeyspace, shard)
// read the shard, create it if necessary
si, err := topotools.GetOrCreateShard(ctx, agent.TopoServer, *initKeyspace, shard)
if err != nil {
return fmt.Errorf("InitTablet cannot GetOrCreateShard shard: %v", err)
}
if si.MasterAlias != nil && topoproto.TabletAliasEqual(si.MasterAlias, agent.TabletAlias) {
// we are the current master for this shard (probably
// means the master tablet process was just restarted),
// so InitTablet as master.
tabletType = topodatapb.TabletType_MASTER
}
// See if we need to add the tablet's cell to the shard's cell
// list. If we do, it has to be under the shard lock.
if !si.HasCell(agent.TabletAlias.Cell) {
actionNode := actionnode.UpdateShard()
lockPath, err := actionNode.LockShard(ctx, agent.TopoServer, *initKeyspace, shard)
if err != nil {
return fmt.Errorf("LockShard(%v/%v) failed: %v", *initKeyspace, shard, err)
}
// re-read the shard with the lock
si, err = agent.TopoServer.GetShard(ctx, *initKeyspace, shard)
if err != nil {
return actionNode.UnlockShard(ctx, agent.TopoServer, *initKeyspace, shard, lockPath, err)
}
// see if we really need to update it now
if !si.HasCell(agent.TabletAlias.Cell) {
si.Cells = append(si.Cells, agent.TabletAlias.Cell)
// write it back
if err := agent.TopoServer.UpdateShard(ctx, si); err != nil {
return actionNode.UnlockShard(ctx, agent.TopoServer, *initKeyspace, shard, lockPath, err)
}
}
// and unlock
if err := actionNode.UnlockShard(ctx, agent.TopoServer, *initKeyspace, shard, lockPath, nil); err != nil {
return err
}
}
//.........这里部分代码省略.........
开发者ID:BobbWu,项目名称:vitess,代码行数:101,代码来源:init_tablet.go
示例13: InitTablet
// InitTablet initializes the tablet record if necessary.
func (agent *ActionAgent) InitTablet(port, gRPCPort int32) error {
// it should be either we have all three of init_keyspace,
// init_shard and init_tablet_type, or none.
if *initKeyspace == "" && *initShard == "" && *initTabletType == "" {
// not initializing the record
return nil
}
if *initKeyspace == "" || *initShard == "" || *initTabletType == "" {
return fmt.Errorf("either need all of init_keyspace, init_shard and init_tablet_type, or none")
}
// parse init_tablet_type
tabletType, err := topoproto.ParseTabletType(*initTabletType)
if err != nil {
return fmt.Errorf("invalid init_tablet_type %v: %v", *initTabletType, err)
}
if tabletType == topodatapb.TabletType_MASTER {
// We disallow MASTER, so we don't have to change
// shard.MasterAlias, and deal with the corner cases.
return fmt.Errorf("init_tablet_type cannot be master, use replica instead")
}
// parse and validate shard name
shard, _, err := topo.ValidateShardName(*initShard)
if err != nil {
return fmt.Errorf("cannot validate shard name %v: %v", *initShard, err)
}
// create a context for this whole operation
ctx, cancel := context.WithTimeout(agent.batchCtx, *initTimeout)
defer cancel()
// read the shard, create it if necessary
log.Infof("Reading shard record %v/%v", *initKeyspace, shard)
si, err := agent.TopoServer.GetOrCreateShard(ctx, *initKeyspace, shard)
if err != nil {
return fmt.Errorf("InitTablet cannot GetOrCreateShard shard: %v", err)
}
if si.MasterAlias != nil && topoproto.TabletAliasEqual(si.MasterAlias, agent.TabletAlias) {
// We're marked as master in the shard record, which could mean the master
// tablet process was just restarted. However, we need to check if a new
// master is in the process of taking over. In that case, it will let us
// know by forcibly updating the old master's tablet record.
oldTablet, err := agent.TopoServer.GetTablet(ctx, agent.TabletAlias)
switch err {
case topo.ErrNoNode:
// There's no existing tablet record, so we can assume
// no one has left us a message to step down.
tabletType = topodatapb.TabletType_MASTER
case nil:
if oldTablet.Type == topodatapb.TabletType_MASTER {
// We're marked as master in the shard record,
// and our existing tablet record agrees.
tabletType = topodatapb.TabletType_MASTER
}
default:
return fmt.Errorf("InitTablet failed to read existing tablet record: %v", err)
}
}
// See if we need to add the tablet's cell to the shard's cell list.
if !si.HasCell(agent.TabletAlias.Cell) {
si, err = agent.TopoServer.UpdateShardFields(ctx, *initKeyspace, shard, func(si *topo.ShardInfo) error {
if si.HasCell(agent.TabletAlias.Cell) {
// Someone else already did it.
return topo.ErrNoUpdateNeeded
}
si.Cells = append(si.Cells, agent.TabletAlias.Cell)
return nil
})
if err != nil {
return fmt.Errorf("couldn't add tablet's cell to shard record: %v", err)
}
}
log.Infof("Initializing the tablet for type %v", tabletType)
// figure out the hostname
hostname := *tabletHostname
if hostname != "" {
log.Infof("Using hostname: %v from -tablet_hostname flag.", hostname)
} else {
hostname, err := netutil.FullyQualifiedHostname()
if err != nil {
return err
}
log.Infof("Using detected machine hostname: %v To change this, fix your machine network configuration or override it with -tablet_hostname.", hostname)
}
// create and populate tablet record
tablet := &topodatapb.Tablet{
Alias: agent.TabletAlias,
Hostname: hostname,
PortMap: make(map[string]int32),
Keyspace: *initKeyspace,
Shard: *initShard,
Type: tabletType,
DbNameOverride: *initDbNameOverride,
Tags: initTags,
}
//.........这里部分代码省略.........
开发者ID:dumbunny,项目名称:vitess,代码行数:101,代码来源:init_tablet.go
注:本文中的github.com/youtube/vitess/go/vt/topo.ValidateShardName函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论