本文整理汇总了Golang中github.com/absolute8511/nsq/nsqd.Topic.PutMessageOnReplica方法的典型用法代码示例。如果您正苦于以下问题:Golang Topic.PutMessageOnReplica方法的具体用法?Golang Topic.PutMessageOnReplica怎么用?Golang Topic.PutMessageOnReplica使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/absolute8511/nsq/nsqd.Topic
的用法示例。
在下文中一共展示了Topic.PutMessageOnReplica方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: putMessageOnSlave
func (self *NsqdCoordinator) putMessageOnSlave(coord *TopicCoordinator, logData CommitLogData, msg *nsqd.Message) *CoordErr {
var logMgr *TopicCommitLogMgr
var topic *nsqd.Topic
var queueEnd nsqd.BackendQueueEnd
checkDupOnSlave := func(tc *coordData) bool {
if coordLog.Level() >= levellogger.LOG_DETAIL {
topicName := tc.topicInfo.Name
coordLog.Debugf("pub on slave : %v, msg %v", topicName, msg.ID)
}
logMgr = tc.logMgr
if logMgr.IsCommitted(logData.LogID) {
coordLog.Infof("pub the already committed log id : %v", logData.LogID)
return true
}
return false
}
doLocalWriteOnSlave := func(tc *coordData) *CoordErr {
var localErr error
topicName := tc.topicInfo.Name
partition := tc.topicInfo.Partition
topic, localErr = self.localNsqd.GetExistingTopic(topicName, partition)
if localErr != nil {
coordLog.Infof("pub on slave missing topic : %v", topicName)
// leave the isr and try re-sync with leader
return &CoordErr{localErr.Error(), RpcErrTopicNotExist, CoordSlaveErr}
}
if topic.GetTopicPart() != partition {
coordLog.Errorf("topic on slave has different partition : %v vs %v", topic.GetTopicPart(), partition)
return &CoordErr{ErrLocalTopicPartitionMismatch.String(), RpcErrTopicNotExist, CoordSlaveErr}
}
topic.Lock()
queueEnd, localErr = topic.PutMessageOnReplica(msg, nsqd.BackendOffset(logData.MsgOffset))
topic.Unlock()
if localErr != nil {
coordLog.Errorf("put message on slave failed: %v", localErr)
return &CoordErr{localErr.Error(), RpcCommonErr, CoordSlaveErr}
}
return nil
}
doLocalCommit := func() error {
localErr := logMgr.AppendCommitLog(&logData, true)
if localErr != nil {
coordLog.Errorf("write commit log on slave failed: %v", localErr)
return localErr
}
topic.Lock()
topic.UpdateCommittedOffset(queueEnd)
topic.Unlock()
return nil
}
doLocalExit := func(err *CoordErr) {
if err != nil {
coordLog.Infof("slave put message %v error: %v", logData, err)
}
}
return self.doWriteOpOnSlave(coord, checkDupOnSlave, doLocalWriteOnSlave, doLocalCommit, doLocalExit)
}