Beispiel #1
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
}
Beispiel #2
0
func (s *server) PromoteSlave(ctx context.Context, request *pb.PromoteSlaveRequest) (*pb.PromoteSlaveResponse, error) {
	ctx = callinfo.GRPCCallInfo(ctx)
	response := &pb.PromoteSlaveResponse{}
	return response, s.agent.RPCWrapLockAction(ctx, actionnode.TabletActionPromoteSlave, request, response, true, func() error {
		position, err := s.agent.PromoteSlave(ctx)
		if err == nil {
			response.Position = myproto.ReplicationPositionToProto(position)
		}
		return err
	})
}
Beispiel #3
0
func (s *server) RunBlpUntil(ctx context.Context, request *pb.RunBlpUntilRequest) (*pb.RunBlpUntilResponse, error) {
	ctx = callinfo.GRPCCallInfo(ctx)
	response := &pb.RunBlpUntilResponse{}
	return response, s.agent.RPCWrapLock(ctx, actionnode.TabletActionRunBLPUntil, request, response, true, func() error {
		position, err := s.agent.RunBlpUntil(ctx, blproto.ProtoToBlpPositionList(request.BlpPositions), time.Duration(request.WaitTimeout))
		if err == nil {
			response.Position = myproto.ReplicationPositionToProto(*position)
		}
		return err
	})
}
Beispiel #4
0
func (s *server) StopSlaveMinimum(ctx context.Context, request *pb.StopSlaveMinimumRequest) (*pb.StopSlaveMinimumResponse, error) {
	ctx = callinfo.GRPCCallInfo(ctx)
	response := &pb.StopSlaveMinimumResponse{}
	return response, s.agent.RPCWrapLock(ctx, actionnode.TabletActionStopSlaveMinimum, request, response, true, func() error {
		position, err := s.agent.StopSlaveMinimum(ctx, myproto.ProtoToReplicationPosition(request.Position), time.Duration(request.WaitTimeout))
		if err == nil {
			response.Position = myproto.ReplicationPositionToProto(position)
		}
		return err
	})
}
Beispiel #5
0
// InitSlave is part of the tmclient.TabletManagerClient interface
func (client *Client) InitSlave(ctx context.Context, tablet *topo.TabletInfo, parent topo.TabletAlias, replicationPosition myproto.ReplicationPosition, timeCreatedNS int64) error {
	cc, c, err := client.dial(ctx, tablet)
	if err != nil {
		return err
	}
	defer cc.Close()
	_, err = c.InitSlave(ctx, &pb.InitSlaveRequest{
		Parent:              topo.TabletAliasToProto(parent),
		ReplicationPosition: myproto.ReplicationPositionToProto(replicationPosition),
		TimeCreatedNs:       timeCreatedNS,
	})
	return err
}
Beispiel #6
0
// PromoteSlaveWhenCaughtUp is part of the tmclient.TabletManagerClient interface
func (client *Client) PromoteSlaveWhenCaughtUp(ctx context.Context, tablet *topo.TabletInfo, pos myproto.ReplicationPosition) (myproto.ReplicationPosition, error) {
	cc, c, err := client.dial(ctx, tablet)
	if err != nil {
		return myproto.ReplicationPosition{}, err
	}
	defer cc.Close()
	response, err := c.PromoteSlaveWhenCaughtUp(ctx, &pb.PromoteSlaveWhenCaughtUpRequest{
		Position: myproto.ReplicationPositionToProto(pos),
	})
	if err != nil {
		return myproto.ReplicationPosition{}, err
	}
	return myproto.ProtoToReplicationPosition(response.Position), err
}
Beispiel #7
0
// PopulateReparentJournal is part of the tmclient.TabletManagerClient interface
func (client *Client) PopulateReparentJournal(ctx context.Context, tablet *topo.TabletInfo, timeCreatedNS int64, actionName string, masterAlias topo.TabletAlias, pos myproto.ReplicationPosition) error {
	cc, c, err := client.dial(ctx, tablet)
	if err != nil {
		return err
	}
	defer cc.Close()
	_, err = c.PopulateReparentJournal(ctx, &pb.PopulateReparentJournalRequest{
		TimeCreatedNs:       timeCreatedNS,
		ActionName:          actionName,
		MasterAlias:         topo.TabletAliasToProto(masterAlias),
		ReplicationPosition: myproto.ReplicationPositionToProto(pos),
	})
	return err
}
Beispiel #8
0
// StopSlaveMinimum is part of the tmclient.TabletManagerClient interface
func (client *Client) StopSlaveMinimum(ctx context.Context, tablet *topo.TabletInfo, minPos myproto.ReplicationPosition, waitTime time.Duration) (myproto.ReplicationPosition, error) {
	cc, c, err := client.dial(ctx, tablet)
	if err != nil {
		return myproto.ReplicationPosition{}, err
	}
	defer cc.Close()
	response, err := c.StopSlaveMinimum(ctx, &pb.StopSlaveMinimumRequest{
		Position:    myproto.ReplicationPositionToProto(minPos),
		WaitTimeout: int64(waitTime),
	})
	if err != nil {
		return myproto.ReplicationPosition{}, err
	}
	return myproto.ProtoToReplicationPosition(response.Position), err
}
Beispiel #9
0
// BlpPositionToProto converts a BlpPosition to a proto3
func BlpPositionToProto(b *BlpPosition) *pbt.BlpPosition {
	return &pbt.BlpPosition{
		Uid:      b.Uid,
		Position: myproto.ReplicationPositionToProto(b.Position),
	}
}