请选择 进入手机版 | 继续访问电脑版
  • 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang key.KeyRangesIntersect函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/youtube/vitess/go/vt/key.KeyRangesIntersect函数的典型用法代码示例。如果您正苦于以下问题:Golang KeyRangesIntersect函数的具体用法?Golang KeyRangesIntersect怎么用?Golang KeyRangesIntersect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了KeyRangesIntersect函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: resolveKeyRangeToShards

// This maps a list of keyranges to shard names.
func resolveKeyRangeToShards(topoServer SrvTopoServer, cell, keyspace string, tabletType topo.TabletType, kr key.KeyRange) ([]string, error) {
	srvKeyspace, err := topoServer.GetSrvKeyspace(cell, keyspace)
	if err != nil {
		return nil, fmt.Errorf("Error in reading the keyspace %v", err)
	}

	tabletTypePartition, ok := srvKeyspace.Partitions[tabletType]
	if !ok {
		return nil, fmt.Errorf("No shards available for tablet type '%v' in keyspace '%v'", tabletType, keyspace)
	}

	topo.SrvShardArray(tabletTypePartition.Shards).Sort()

	shards := make([]string, 0, 1)
	if !kr.IsPartial() {
		for j := 0; j < len(tabletTypePartition.Shards); j++ {
			shards = append(shards, tabletTypePartition.Shards[j].ShardName())
		}
		return shards, nil
	}
	for j := 0; j < len(tabletTypePartition.Shards); j++ {
		shard := tabletTypePartition.Shards[j]
		if key.KeyRangesIntersect(kr, shard.KeyRange) {
			shards = append(shards, shard.ShardName())
		}
		if kr.End != key.MaxKey && kr.End < shard.KeyRange.Start {
			break
		}
	}
	return shards, nil
}
开发者ID:krast,项目名称:vitess,代码行数:32,代码来源:topo_utils.go


示例2: CreateShard

// CreateShard creates a new shard and tries to fill in the right information.
func CreateShard(ts Server, keyspace, shard string) error {

	name, keyRange, err := ValidateShardName(shard)
	if err != nil {
		return err
	}
	s := &Shard{KeyRange: keyRange}

	// start the shard with all serving types. If it overlaps with
	// other shards for some serving types, remove them.
	servingTypes := map[TabletType]bool{
		TYPE_MASTER:  true,
		TYPE_REPLICA: true,
		TYPE_RDONLY:  true,
	}
	sis, err := FindAllShardsInKeyspace(ts, keyspace)
	if err != nil && err != ErrNoNode {
		return err
	}
	for _, si := range sis {
		if key.KeyRangesIntersect(si.KeyRange, keyRange) {
			for _, t := range si.ServedTypes {
				delete(servingTypes, t)
			}
		}
	}
	s.ServedTypes = make([]TabletType, 0, len(servingTypes))
	for st := range servingTypes {
		s.ServedTypes = append(s.ServedTypes, st)
	}

	return ts.CreateShard(keyspace, name, s)
}
开发者ID:nangong92t,项目名称:go_src,代码行数:34,代码来源:shard.go


示例3: CreateShard

// CreateShard creates a new shard and tries to fill in the right information.
func CreateShard(ts Server, keyspace, shard string) error {

	name, keyRange, err := ValidateShardName(shard)
	if err != nil {
		return err
	}

	// start the shard with all serving types. If it overlaps with
	// other shards for some serving types, remove them.
	s := &Shard{
		KeyRange: keyRange,
		ServedTypesMap: map[TabletType]*ShardServedType{
			TYPE_MASTER:  &ShardServedType{},
			TYPE_REPLICA: &ShardServedType{},
			TYPE_RDONLY:  &ShardServedType{},
		},
	}

	sis, err := FindAllShardsInKeyspace(ts, keyspace)
	if err != nil && err != ErrNoNode {
		return err
	}
	for _, si := range sis {
		if key.KeyRangesIntersect(si.KeyRange, keyRange) {
			for t, _ := range si.ServedTypesMap {
				delete(s.ServedTypesMap, t)
			}
		}
	}
	if len(s.ServedTypesMap) == 0 {
		s.ServedTypesMap = nil
	}

	return ts.CreateShard(keyspace, name, s)
}
开发者ID:plobsing,项目名称:vitess,代码行数:36,代码来源:shard.go


示例4: intersect

// intersect returns true if the provided shard intersect with any shard
// in the destination array
func intersect(si *topo.ShardInfo, allShards []*topo.ShardInfo) bool {
	for _, shard := range allShards {
		if key.KeyRangesIntersect(si.KeyRange, shard.KeyRange) {
			return true
		}
	}
	return false
}
开发者ID:nangong92t,项目名称:go_src,代码行数:10,代码来源:split.go


示例5: findIntersectingShard

// findIntersectingShard will go through the map and take the first
// entry in there that intersect with the source array, remove it from
// the map, and return it
func findIntersectingShard(shardMap map[string]*topo.ShardInfo, sourceArray []*topo.ShardInfo) *topo.ShardInfo {
	for name, si := range shardMap {
		for _, sourceShardInfo := range sourceArray {
			if key.KeyRangesIntersect(si.KeyRange, sourceShardInfo.KeyRange) {
				delete(shardMap, name)
				return si
			}
		}
	}
	return nil
}
开发者ID:nangong92t,项目名称:go_src,代码行数:14,代码来源:split.go


示例6: resolveKeyRangeToShards

// This maps a list of keyranges to shard names.
func resolveKeyRangeToShards(allShards []*topodatapb.ShardReference, matches map[string]bool, kr *topodatapb.KeyRange) {
	if !key.KeyRangeIsPartial(kr) {
		for _, shard := range allShards {
			matches[shard.Name] = true
		}
		return
	}
	for _, shard := range allShards {
		if key.KeyRangesIntersect(kr, shard.KeyRange) {
			matches[shard.Name] = true
		}
	}
}
开发者ID:aaijazi,项目名称:vitess,代码行数:14,代码来源:topo_utils.go


示例7: CreateShard

// CreateShard creates a new shard and tries to fill in the right information.
// This should be called while holding the keyspace lock for the shard.
// (call topotools.CreateShard to do that for you).
// In unit tests (that are not parallel), this function can be called directly.
func (ts Server) CreateShard(ctx context.Context, keyspace, shard string) error {
	name, keyRange, err := ValidateShardName(shard)
	if err != nil {
		return err
	}

	// start the shard with all serving types. If it overlaps with
	// other shards for some serving types, remove them.
	servedTypes := map[topodatapb.TabletType]bool{
		topodatapb.TabletType_MASTER:  true,
		topodatapb.TabletType_REPLICA: true,
		topodatapb.TabletType_RDONLY:  true,
	}
	value := &topodatapb.Shard{
		KeyRange: keyRange,
	}

	if IsShardUsingRangeBasedSharding(name) {
		// if we are using range-based sharding, we don't want
		// overlapping shards to all serve and confuse the clients.
		sis, err := ts.FindAllShardsInKeyspace(ctx, keyspace)
		if err != nil && err != ErrNoNode {
			return err
		}
		for _, si := range sis {
			if si.KeyRange == nil || key.KeyRangesIntersect(si.KeyRange, keyRange) {
				for _, st := range si.ServedTypes {
					delete(servedTypes, st.TabletType)
				}
			}
		}
	}

	for st := range servedTypes {
		value.ServedTypes = append(value.ServedTypes, &topodatapb.Shard_ServedType{
			TabletType: st,
		})
	}

	if err := ts.Impl.CreateShard(ctx, keyspace, name, value); err != nil {
		return err
	}

	event.Dispatch(&events.ShardChange{
		KeyspaceName: keyspace,
		ShardName:    shard,
		Shard:        value,
		Status:       "created",
	})
	return nil
}
开发者ID:littleyang,项目名称:vitess,代码行数:55,代码来源:shard.go


示例8: resolveKeyRangeToShards

// This maps a list of keyranges to shard names.
func resolveKeyRangeToShards(allShards []*pb.ShardReference, kr *pb.KeyRange) ([]string, error) {
	shards := make([]string, 0, 1)

	if !key.KeyRangeIsPartial(kr) {
		for j := 0; j < len(allShards); j++ {
			shards = append(shards, allShards[j].Name)
		}
		return shards, nil
	}
	for j := 0; j < len(allShards); j++ {
		shard := allShards[j]
		if key.KeyRangesIntersect(kr, shard.KeyRange) {
			shards = append(shards, shard.Name)
		}
	}
	return shards, nil
}
开发者ID:hadmagic,项目名称:vitess,代码行数:18,代码来源:topo_utils.go


示例9: resolveKeyRangeToShards

// This maps a list of keyranges to shard names.
func resolveKeyRangeToShards(allShards []topo.SrvShard, kr key.KeyRange) ([]string, error) {
	shards := make([]string, 0, 1)

	if !kr.IsPartial() {
		for j := 0; j < len(allShards); j++ {
			shards = append(shards, allShards[j].ShardName())
		}
		return shards, nil
	}
	for j := 0; j < len(allShards); j++ {
		shard := allShards[j]
		if key.KeyRangesIntersect(kr, shard.KeyRange) {
			shards = append(shards, shard.ShardName())
		}
	}
	return shards, nil
}
开发者ID:chinna1986,项目名称:vitess,代码行数:18,代码来源:topo_utils.go


示例10: resolveKeyRangeToShards

// This maps a list of keyranges to shard names.
func resolveKeyRangeToShards(allShards []topo.SrvShard, kr key.KeyRange) ([]string, error) {
	shards := make([]string, 0, 1)
	topo.SrvShardArray(allShards).Sort()

	if !kr.IsPartial() {
		for j := 0; j < len(allShards); j++ {
			shards = append(shards, allShards[j].ShardName())
		}
		return shards, nil
	}
	for j := 0; j < len(allShards); j++ {
		shard := allShards[j]
		if key.KeyRangesIntersect(kr, shard.KeyRange) {
			shards = append(shards, shard.ShardName())
		}
		if kr.End != key.MaxKey && kr.End < shard.KeyRange.Start {
			break
		}
	}
	return shards, nil
}
开发者ID:kingpro,项目名称:vitess,代码行数:22,代码来源:topo_utils.go


示例11: CreateShard

// CreateShard creates a new shard and tries to fill in the right information.
// This should be called while holding the keyspace lock for the shard.
// (call topotools.CreateShard to do that for you).
// In unit tests (that are not parallel), this function can be called directly.
func CreateShard(ctx context.Context, ts Server, keyspace, shard string) error {
	name, keyRange, err := ValidateShardName(shard)
	if err != nil {
		return err
	}

	// start the shard with all serving types. If it overlaps with
	// other shards for some serving types, remove them.
	s := &Shard{
		KeyRange: keyRange,
		ServedTypesMap: map[TabletType]*ShardServedType{
			TYPE_MASTER:  &ShardServedType{},
			TYPE_REPLICA: &ShardServedType{},
			TYPE_RDONLY:  &ShardServedType{},
		},
	}

	if IsShardUsingRangeBasedSharding(name) {
		// if we are using range-based sharding, we don't want
		// overlapping shards to all serve and confuse the clients.
		sis, err := FindAllShardsInKeyspace(ctx, ts, keyspace)
		if err != nil && err != ErrNoNode {
			return err
		}
		for _, si := range sis {
			if key.KeyRangesIntersect(si.KeyRange, keyRange) {
				for t := range si.ServedTypesMap {
					delete(s.ServedTypesMap, t)
				}
			}
		}
		if len(s.ServedTypesMap) == 0 {
			s.ServedTypesMap = nil
		}
	}

	return ts.CreateShard(ctx, keyspace, name, s)
}
开发者ID:pranjal5215,项目名称:vitess,代码行数:42,代码来源:shard.go


示例12: 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



注:本文中的github.com/youtube/vitess/go/vt/key.KeyRangesIntersect函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang servenv.RegisterDefaultFlags函数代码示例发布时间:2022-05-29
下一篇:
Golang key.KeyRangeString函数代码示例发布时间:2022-05-29
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap