当前位置: 首页>>代码示例>>Golang>>正文


Golang proto.SplitQueryResult类代码示例

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


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

示例1: SplitQuery

// SplitQuery splits a query into sub queries by appending keyranges and
// primary key range clauses. Rows corresponding to the sub queries
// are guaranteed to be non-overlapping and will add up to the rows of
// original query. Number of sub queries will be a multiple of N that is
// greater than or equal to SplitQueryRequest.SplitCount, where N is the
// number of shards.
func (vtg *VTGate) SplitQuery(ctx context.Context, req *proto.SplitQueryRequest, reply *proto.SplitQueryResult) error {
	sc := vtg.resolver.scatterConn
	keyspace, srvKeyspace, shards, err := getKeyspaceShards(ctx, sc.toposerv, sc.cell, req.Keyspace, topo.TYPE_RDONLY)
	if err != nil {
		return err
	}
	perShardSplitCount := int(math.Ceil(float64(req.SplitCount) / float64(len(shards))))
	if srvKeyspace.ShardingColumnName != "" {
		// we are using range-based sharding, so the result
		// will be a list of Splits with KeyRange clauses
		keyRangeByShard := map[string]kproto.KeyRange{}
		for _, shard := range shards {
			keyRangeByShard[shard.Name] = shard.KeyRange
		}
		splits, err := vtg.resolver.scatterConn.SplitQueryKeyRange(ctx, req.Query, req.SplitColumn, perShardSplitCount, keyRangeByShard, keyspace)
		if err != nil {
			return err
		}
		reply.Splits = splits
		return nil
	}

	// we are using custom sharding, so the result
	// will be a list of Splits with Shard clauses
	shardNames := make([]string, len(shards))
	for i, shard := range shards {
		shardNames[i] = shard.Name
	}
	splits, err := vtg.resolver.scatterConn.SplitQueryCustomSharding(ctx, req.Query, req.SplitColumn, perShardSplitCount, shardNames, keyspace)
	if err != nil {
		return err
	}
	reply.Splits = splits
	return nil
}
开发者ID:anusornc,项目名称:vitess,代码行数:41,代码来源:vtgate.go

示例2: SplitQuery

// SplitQuery splits a query into sub queries by appending keyranges and
// primary key range clauses. Rows corresponding to the sub queries
// are guaranteed to be non-overlapping and will add up to the rows of
// original query. Number of sub queries will be a multiple of N that is
// greater than or equal to SplitQueryRequest.SplitCount, where N is the
// number of shards.
func (vtg *VTGate) SplitQuery(ctx context.Context, keyspace string, sql string, bindVariables map[string]interface{}, splitColumn string, splitCount int, reply *proto.SplitQueryResult) error {
	keyspace, srvKeyspace, shards, err := getKeyspaceShards(ctx, vtg.resolver.toposerv, vtg.resolver.cell, keyspace, pb.TabletType_RDONLY)
	if err != nil {
		return err
	}
	perShardSplitCount := int(math.Ceil(float64(splitCount) / float64(len(shards))))
	if srvKeyspace.ShardingColumnName != "" {
		// we are using range-based sharding, so the result
		// will be a list of Splits with KeyRange clauses
		keyRangeByShard := make(map[string]*pb.KeyRange)
		for _, shard := range shards {
			keyRangeByShard[shard.Name] = shard.KeyRange
		}
		splits, err := vtg.resolver.scatterConn.SplitQueryKeyRange(ctx, sql, bindVariables, splitColumn, perShardSplitCount, keyRangeByShard, keyspace)
		if err != nil {
			return err
		}
		reply.Splits = splits
		return nil
	}

	// we are using custom sharding, so the result
	// will be a list of Splits with Shard clauses
	shardNames := make([]string, len(shards))
	for i, shard := range shards {
		shardNames[i] = shard.Name
	}
	splits, err := vtg.resolver.scatterConn.SplitQueryCustomSharding(ctx, sql, bindVariables, splitColumn, perShardSplitCount, shardNames, keyspace)
	if err != nil {
		return err
	}
	reply.Splits = splits
	return nil
}
开发者ID:xgwubin,项目名称:vitess,代码行数:40,代码来源:vtgate.go

示例3: SplitQuery

func (c *echoClient) SplitQuery(ctx context.Context, keyspace string, sql string, bindVariables map[string]interface{}, splitColumn string, splitCount int, reply *proto.SplitQueryResult) error {
	if strings.HasPrefix(sql, EchoPrefix) {
		reply.Splits = append(reply.Splits, proto.SplitQueryPart{
			Query: &proto.KeyRangeQuery{
				Sql:           fmt.Sprintf("%v:%v:%v", sql, splitColumn, splitCount),
				BindVariables: bindVariables,
				Keyspace:      keyspace,
			},
		})
		return nil
	}
	return c.fallback.SplitQuery(ctx, sql, keyspace, bindVariables, splitColumn, splitCount, reply)
}
开发者ID:yinyousong,项目名称:vitess,代码行数:13,代码来源:echo.go

示例4: SplitQuery

// SplitQuery is the RPC version of vtgateservice.VTGateService method
func (vtg *VTGate) SplitQuery(ctx context.Context, request *proto.SplitQueryRequest, reply *proto.SplitQueryResult) (err error) {
	defer vtg.server.HandlePanic(&err)
	ctx, cancel := context.WithDeadline(ctx, time.Now().Add(*rpcTimeout))
	defer cancel()
	ctx = callerid.NewContext(ctx,
		callerid.GoRPCEffectiveCallerID(request.CallerID),
		callerid.NewImmediateCallerID("gorpc client"))
	splits, vtgErr := vtg.server.SplitQuery(ctx,
		request.Keyspace,
		request.Query.Sql,
		request.Query.BindVariables,
		request.SplitColumn,
		request.SplitCount)
	reply.Splits = splits
	vtgate.AddVtGateError(vtgErr, &reply.Err)
	return nil
}
开发者ID:hadmagic,项目名称:vitess,代码行数:18,代码来源:server.go

示例5: SplitQuery

// SplitQuery splits a query into sub queries by appending keyranges and
// primary key range clauses. Rows corresponding to the sub queries
// are guaranteed to be non-overlapping and will add up to the rows of
// original query. Number of sub queries will be a multiple of N that is
// greater than or equal to SplitQueryRequest.SplitCount, where N is the
// number of shards.
func (vtg *VTGate) SplitQuery(context context.Context, req *proto.SplitQueryRequest, reply *proto.SplitQueryResult) (err error) {
	defer handlePanic(&err)
	sc := vtg.resolver.scatterConn
	keyspace, shards, err := getKeyspaceShards(sc.toposerv, sc.cell, req.Keyspace, topo.TYPE_RDONLY)
	if err != nil {
		return err
	}
	keyRangeByShard := map[string]kproto.KeyRange{}
	for _, shard := range shards {
		keyRangeByShard[shard.ShardName()] = shard.KeyRange
	}
	perShardSplitCount := int(math.Ceil(float64(req.SplitCount) / float64(len(shards))))
	splits, err := vtg.resolver.scatterConn.SplitQuery(context, req.Query, perShardSplitCount, keyRangeByShard, keyspace)
	if err != nil {
		return err
	}
	reply.Splits = splits
	return nil
}
开发者ID:plobsing,项目名称:vitess,代码行数:25,代码来源:vtgate.go

示例6: AddVtGateErrorToSplitQueryResult

// AddVtGateErrorToSplitQueryResult will mutate a SplitQueryResult struct to fill in the Err
// field with details from the VTGate error.
func AddVtGateErrorToSplitQueryResult(err error, reply *proto.SplitQueryResult) {
	if err == nil {
		return
	}
	reply.Err = rpcErrFromVtGateError(err)
}
开发者ID:afrolovskiy,项目名称:vitess,代码行数:8,代码来源:vtgate_error.go


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