func (self *NsqdRpcClient) PutMessages(leaderSession *TopicLeaderSession, info *TopicPartitionMetaInfo, log CommitLogData, messages []*nsqd.Message) *CoordErr { if self.grpcClient != nil && false { ctx, cancel := context.WithTimeout(context.Background(), RPC_TIMEOUT_SHORT) var req pb.RpcPutMessages var rpcData pb.RpcTopicData rpcData.TopicName = info.Name rpcData.TopicPartition = int32(info.Partition) rpcData.TopicWriteEpoch = int64(info.EpochForWrite) rpcData.Epoch = int64(info.Epoch) rpcData.TopicLeaderSessionEpoch = int64(leaderSession.LeaderEpoch) rpcData.TopicLeaderSession = leaderSession.Session req.TopicData = &rpcData var pbLogData pb.CommitLogData pbLogData.LogID = log.LogID pbLogData.Epoch = int64(log.Epoch) pbLogData.MsgNum = log.MsgNum pbLogData.MsgCnt = log.MsgCnt pbLogData.MsgSize = log.MsgSize pbLogData.MsgOffset = log.MsgOffset pbLogData.LastMsgLogID = log.LastMsgLogID req.LogData = &pbLogData for _, message := range messages { var msg pb.NsqdMessage msg.ID = uint64(message.ID) msg.Body = message.Body msg.Trace_ID = message.TraceID msg.Attemps = uint32(message.Attempts) msg.Timestamp = message.Timestamp req.TopicMessage = append(req.TopicMessage, &msg) } retErr, err := self.grpcClient.PutMessages(ctx, &req) cancel() if err == nil { return convertRpcError(err, retErr) } // maybe old server not implemented the grpc method. } var putData RpcPutMessages putData.LogData = log putData.TopicName = info.Name putData.TopicPartition = info.Partition putData.TopicMessages = messages putData.TopicWriteEpoch = info.EpochForWrite putData.Epoch = info.Epoch putData.TopicLeaderSessionEpoch = leaderSession.LeaderEpoch putData.TopicLeaderSession = leaderSession.Session retErr, err := self.CallWithRetry("PutMessages", &putData) return convertRpcError(err, retErr) }
func (self *NsqdRpcClient) UpdateChannelOffset(leaderSession *TopicLeaderSession, info *TopicPartitionMetaInfo, channel string, offset ChannelConsumerOffset) *CoordErr { // it seems grpc is slower, so disable it. if self.grpcClient != nil && false { var req pb.RpcChannelOffsetArg var rpcData pb.RpcTopicData rpcData.TopicName = info.Name rpcData.TopicPartition = int32(info.Partition) rpcData.TopicWriteEpoch = int64(info.EpochForWrite) rpcData.Epoch = int64(info.Epoch) rpcData.TopicLeaderSessionEpoch = int64(leaderSession.LeaderEpoch) rpcData.TopicLeaderSession = leaderSession.Session req.TopicData = &rpcData req.Channel = channel req.ChannelOffset.Voffset = offset.VOffset req.ChannelOffset.Flush = offset.Flush req.ChannelOffset.AllowBackward = offset.AllowBackward ctx, cancel := context.WithTimeout(context.Background(), RPC_TIMEOUT_SHORT) retErr, err := self.grpcClient.UpdateChannelOffset(ctx, &req) cancel() if err == nil { return convertRpcError(err, retErr) } // maybe old server not implemented the grpc method. } var updateInfo RpcChannelOffsetArg updateInfo.TopicName = info.Name updateInfo.TopicPartition = info.Partition updateInfo.TopicWriteEpoch = info.EpochForWrite updateInfo.Epoch = info.Epoch updateInfo.TopicLeaderSessionEpoch = leaderSession.LeaderEpoch updateInfo.TopicLeaderSession = leaderSession.Session updateInfo.Channel = channel updateInfo.ChannelOffset = offset retErr, err := self.CallFast("UpdateChannelOffset", &updateInfo) return convertRpcError(err, retErr) }