Example #1
0
// fetchByFetchlist fetches the messages in the supplied fetchlist and sends them to the message-channel
func (p *messagePartition) fetchByFetchlist(fetchList *indexList, req *store.FetchRequest) error {
	return fetchList.mapWithPredicate(func(index *index, _ int) error {
		if req.IsDone() {
			return store.ErrRequestDone
		}

		filename := p.composeMsgFilenameForPosition(uint64(index.fileID))
		file, err := os.Open(filename)
		if err != nil {
			return err
		}
		defer file.Close()

		msg := make([]byte, index.size, index.size)
		_, err = file.ReadAt(msg, int64(index.offset))
		if err != nil {
			logger.WithFields(log.Fields{
				"err":    err,
				"offset": index.offset,
			}).Error("Error ReadAt")
			return err
		}

		req.Push(index.id, msg)
		return nil
	})
}