本文整理匯總了Golang中github.com/owlfish/forestbus-server/model.Messages.Offsets方法的典型用法代碼示例。如果您正苦於以下問題:Golang Messages.Offsets方法的具體用法?Golang Messages.Offsets怎麽用?Golang Messages.Offsets使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/owlfish/forestbus-server/model.Messages
的用法示例。
在下文中一共展示了Messages.Offsets方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: AppendMessages
/*
AppendMessages checks to see whether the segment is full, and if not it appends the messages to it.
*/
func (seg *Segment) AppendMessages(msgs model.Messages) (appendIndex, lastIndex int64, segmentFull bool, err error) {
seg.lock.Lock()
defer seg.lock.Unlock()
seg.statsAppendMessageCalls++
seg.lastAccessTime = time.Now()
seg.lastModifiedTime = seg.lastAccessTime
if seg.fileSize >= int64(seg.target_max_segment_size)*1024*1024 {
seg.node_log("Segment %v at or beyond target size of %v MB\n", seg.filename, seg.target_max_segment_size)
return 0, seg.firstIndex + int64(seg.msgCount) - 1, true, nil
}
if !seg.segmentOpen {
err := seg.openWhileHoldingLock(false)
if err != nil {
return 0, 0, false, err
}
}
// Go to the end of the file
if seg.filePosition != seg.fileSize {
seg.statsSeekCount++
seg.fileSize, err = seg.file.Seek(0, 2)
seg.filePosition = seg.fileSize
if err != nil {
seg.node_log("Error seeking to end of file in segment file %v: %v\n", seg.filename, err)
return 0, 0, false, err
}
} else {
seg.statsNoSeekAppends++
}
appendIndex = seg.firstIndex + int64(seg.msgCount)
//writer := bufio.NewWriter(seg.file)
seg.writesPendingSync = true
// Try and write out the messages
written, err := msgs.Write(seg.file)
if err != nil {
seg.node_log("Error writing to segment %v: %v\n", seg.filename, err)
return appendIndex, seg.firstIndex + int64(seg.msgCount) - 1, false, err
}
// Populate the offset index list
msgsOffsets, err := msgs.Offsets()
if err != nil {
seg.node_log("Error getting offsets for messages written: %v\n", err)
return appendIndex, seg.firstIndex + int64(seg.msgCount) - 1, false, err
}
for msgIndex, msgOffset := range msgsOffsets {
seg.appendOffsetToIndexHoldingLock(appendIndex+int64(msgIndex), seg.filePosition+int64(msgOffset))
}
seg.msgCount += msgs.GetCount()
seg.fileSize += int64(written)
seg.filePosition = seg.fileSize
return appendIndex, seg.firstIndex + int64(seg.msgCount) - 1, false, nil
}
示例2: AppendFirstMessages
func (mlog *MemoryLogStorage) AppendFirstMessages(msgs model.Messages, leaderFirstIndex int64) (lastIndex int64, err error) {
if len(mlog.offsets) != 0 {
return 0, errors.New("Attempt to add first messages, but segment already has content!")
}
mlog.firstIndex = leaderFirstIndex
msgs.Write(mlog)
// Populate the offsets
// Populate the offsets
msgsOffsets, err := msgs.Offsets()
if err != nil {
return 0, err
}
for _, msgOffset := range msgsOffsets {
mlog.offsets = append(mlog.offsets, msgOffset)
}
return int64(len(mlog.offsets)) + mlog.firstIndex - 1, nil
}
示例3: AppendMessages
func (mlog *MemoryLogStorage) AppendMessages(msgs model.Messages) (lastIndex int64, err error) {
if mlog.firstIndex == 0 {
mlog.firstIndex = 1
}
firstOffset := len(mlog.data)
msgs.Write(mlog)
// Populate the offsets
msgsOffsets, err := msgs.Offsets()
if err != nil {
return 0, err
}
for _, msgOffset := range msgsOffsets {
mlog.offsets = append(mlog.offsets, firstOffset+msgOffset)
}
return int64(len(mlog.offsets)) + mlog.firstIndex - 1, nil
}