Beispiel #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 = key.KeyspaceId(e.KeyspaceId)
		bv := &pbq.BindVariable{
			Type:  e.XidType,
			Value: e.XidValue,
		}
		v, err := tproto.BindVariableToNative(bv)
		if err != nil {
			panic(err)
		}
		result[i].ExternalID = v
	}
	return result
}
Beispiel #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
		}
		bv := &query.BindVariable{
			Type:  eid.XidType,
			Value: eid.XidValue,
		}
		v, _ := tproto.BindVariableToNative(bv)
		shards[shard] = append(shards[shard], v)
	}
	return keyspace, shards, nil
}