Beispiel #1
0
func (s *nsqdCoordGRpcServer) PutMessages(ctx context.Context, req *pb.RpcPutMessages) (*pb.CoordErr, error) {
	var coordErr pb.CoordErr
	if coordLog.Level() >= levellogger.LOG_DEBUG {
		s := time.Now().Unix()
		defer func() {
			e := time.Now().Unix()
			if e-s > int64(RPC_TIMEOUT/2) {
				coordLog.Infof("PutMessage rpc call used: %v", e-s)
			}
		}()
	}

	tc, err := s.nsqdCoord.checkWriteForGRpcCall(req.TopicData)
	if err != nil {
		coordErr.ErrMsg = err.ErrMsg
		coordErr.ErrCode = int32(err.ErrCode)
		coordErr.ErrType = int32(err.ErrType)
		return &coordErr, nil
	}
	// do local pub message
	var commitData CommitLogData
	commitData.Epoch = EpochType(req.LogData.Epoch)
	commitData.LogID = req.LogData.LogID
	commitData.MsgNum = req.LogData.MsgNum
	commitData.MsgCnt = req.LogData.MsgCnt
	commitData.MsgSize = req.LogData.MsgSize
	commitData.MsgOffset = req.LogData.MsgOffset
	commitData.LastMsgLogID = req.LogData.LastMsgLogID
	var msgs []*nsqd.Message
	for _, pbm := range req.TopicMessage {
		var msg nsqd.Message
		msg.ID = nsqd.MessageID(pbm.ID)
		msg.TraceID = pbm.Trace_ID
		msg.Attempts = uint16(pbm.Attemps)
		msg.Timestamp = pbm.Timestamp
		msg.Body = pbm.Body
		msgs = append(msgs, &msg)
	}

	err = s.nsqdCoord.putMessagesOnSlave(tc, commitData, msgs)
	if err != nil {
		coordErr.ErrMsg = err.ErrMsg
		coordErr.ErrCode = int32(err.ErrCode)
		coordErr.ErrType = int32(err.ErrType)
	}
	return &coordErr, nil
}
Beispiel #2
0
func (s *nsqdCoordGRpcServer) UpdateChannelOffset(ctx context.Context, req *pb.RpcChannelOffsetArg) (*pb.CoordErr, error) {
	var coordErr pb.CoordErr
	tc, err := s.nsqdCoord.checkWriteForGRpcCall(req.TopicData)
	if err != nil {
		coordErr.ErrMsg = err.ErrMsg
		coordErr.ErrCode = int32(err.ErrCode)
		coordErr.ErrType = int32(err.ErrType)
		return &coordErr, nil
	}
	// update local channel offset
	var chOffset ChannelConsumerOffset
	chOffset.Flush = req.ChannelOffset.Flush
	chOffset.VOffset = req.ChannelOffset.Voffset
	chOffset.AllowBackward = req.ChannelOffset.AllowBackward
	err = s.nsqdCoord.updateChannelOffsetOnSlave(tc.GetData(), req.Channel, chOffset)
	if err != nil {
		coordErr.ErrMsg = err.ErrMsg
		coordErr.ErrCode = int32(err.ErrCode)
		coordErr.ErrType = int32(err.ErrType)
	}
	return &coordErr, nil
}