Пример #1
0
func (client *client) StreamKeyRange(ctx context.Context, position string, keyspaceIdType key.KeyspaceIdType, keyRange *pbt.KeyRange, charset *mproto.Charset) (chan *proto.BinlogTransaction, binlogplayer.ErrFunc, error) {
	response := make(chan *proto.BinlogTransaction, 10)
	query := &pb.StreamKeyRangeRequest{
		Position:       position,
		KeyspaceIdType: key.KeyspaceIdTypeToProto(keyspaceIdType),
		KeyRange:       keyRange,
		Charset:        mproto.CharsetToProto(charset),
	}

	stream, err := client.c.StreamKeyRange(ctx, query)
	if err != nil {
		return nil, nil, err
	}
	var finalErr error
	go func() {
		for {
			r, err := stream.Recv()
			if err != nil {
				if err != io.EOF {
					finalErr = err
				}
				close(response)
				return
			}
			response <- proto.ProtoToBinlogTransaction(r.BinlogTransaction)
		}
	}()
	return response, func() error {
		return finalErr
	}, nil
}
Пример #2
0
// SrvKeyspaceToProto turns a Tablet into a proto
func SrvKeyspaceToProto(s *SrvKeyspace) *pb.SrvKeyspace {
	result := &pb.SrvKeyspace{
		ShardingColumnName: s.ShardingColumnName,
		ShardingColumnType: key.KeyspaceIdTypeToProto(s.ShardingColumnType),
		SplitShardCount:    s.SplitShardCount,
	}
	for tt, p := range s.Partitions {
		partition := &pb.SrvKeyspace_KeyspacePartition{
			ServedType: TabletTypeToProto(tt),
		}
		for _, sr := range p.ShardReferences {
			partition.ShardReferences = append(partition.ShardReferences, &pb.ShardReference{
				Name:     sr.Name,
				KeyRange: key.KeyRangeToProto(sr.KeyRange),
			})
		}
		result.Partitions = append(result.Partitions, partition)
	}
	for tt, k := range s.ServedFrom {
		result.ServedFrom = append(result.ServedFrom, &pb.SrvKeyspace_ServedFrom{
			TabletType: TabletTypeToProto(tt),
			Keyspace:   k,
		})
	}
	return result
}
Пример #3
0
func (client *client) StreamKeyRange(req *proto.KeyRangeRequest, responseChan chan *proto.BinlogTransaction) binlogplayer.BinlogPlayerResponse {
	query := &pb.StreamKeyRangeRequest{
		Position:       myproto.ReplicationPositionToProto(req.Position),
		KeyspaceIdType: key.KeyspaceIdTypeToProto(req.KeyspaceIdType),
		KeyRange:       key.KeyRangeToProto(req.KeyRange),
		Charset:        mproto.CharsetToProto(req.Charset),
	}

	response := &response{}
	stream, err := client.c.StreamKeyRange(client.ctx, query)
	if err != nil {
		response.err = err
		close(responseChan)
		return response
	}
	go func() {
		for {
			r, err := stream.Recv()
			if err != nil {
				if err != io.EOF {
					response.err = err
				}
				close(responseChan)
				return
			}
			responseChan <- proto.ProtoToBinlogTransaction(r.BinlogTransaction)
		}
	}()
	return response
}