Example #1
0
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
}
Example #2
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
}
Example #3
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
}