示例#1
0
文件: player.go 项目: haoqoo/vitess
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
// StatementToProto converts a Statement to a proto3
func StatementToProto(s *Statement) *pb.BinlogTransaction_Statement {
	return &pb.BinlogTransaction_Statement{
		Category: pb.BinlogTransaction_Statement_Category(s.Category),
		Charset:  mproto.CharsetToProto(s.Charset),
		Sql:      s.Sql,
	}
}
示例#3
0
文件: player.go 项目: haoqoo/vitess
func (client *client) StreamTables(ctx context.Context, position string, tables []string, charset *mproto.Charset) (chan *proto.BinlogTransaction, binlogplayer.ErrFunc, error) {
	response := make(chan *proto.BinlogTransaction, 10)
	query := &pb.StreamTablesRequest{
		Position: position,
		Tables:   tables,
		Charset:  mproto.CharsetToProto(charset),
	}

	stream, err := client.c.StreamTables(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
}
示例#4
0
func (client *client) StreamTables(req *proto.TablesRequest, responseChan chan *proto.BinlogTransaction) binlogplayer.BinlogPlayerResponse {
	query := &pb.StreamTablesRequest{
		Position: myproto.ReplicationPositionToProto(req.Position),
		Tables:   req.Tables,
		Charset:  mproto.CharsetToProto(req.Charset),
	}

	response := &response{}
	stream, err := client.c.StreamTables(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
}