Exemplo n.º 1
0
// ProtoToEntityIds converts an array of EntityId from proto3
func ProtoToEntityIds(l []*pb.ExecuteEntityIdsRequest_EntityId) []EntityId {
	if len(l) == 0 {
		return nil
	}
	result := make([]EntityId, len(l))
	for i, e := range l {
		result[i].KeyspaceID = e.KeyspaceId
		v, err := tproto.SQLToNative(e.XidType, e.XidValue)
		if err != nil {
			panic(err)
		}
		result[i].ExternalID = v
	}
	return result
}
Exemplo n.º 2
0
func mapEntityIdsToShards(ctx context.Context, topoServ SrvTopoServer, cell, keyspace string, entityIds []*pbg.ExecuteEntityIdsRequest_EntityId, tabletType pb.TabletType) (string, map[string][]interface{}, error) {
	keyspace, _, allShards, err := getKeyspaceShards(ctx, topoServ, cell, keyspace, tabletType)
	if err != nil {
		return "", nil, err
	}
	var shards = make(map[string][]interface{})
	for _, eid := range entityIds {
		shard, err := getShardForKeyspaceID(allShards, eid.KeyspaceId)
		if err != nil {
			return "", nil, err
		}
		v, _ := tproto.SQLToNative(eid.XidType, eid.XidValue)
		shards[shard] = append(shards[shard], v)
	}
	return keyspace, shards, nil
}