GetRaftEntry gets the entry at the index idx, reads the data from the appropriate offset and converts it to a raftpb.Entry object.
(idx int)
| 155 | // GetRaftEntry gets the entry at the index idx, reads the data from the appropriate |
| 156 | // offset and converts it to a raftpb.Entry object. |
| 157 | func (lf *logFile) GetRaftEntry(idx int) raftpb.Entry { |
| 158 | entry := lf.getEntry(idx) |
| 159 | re := raftpb.Entry{ |
| 160 | Term: entry.Term(), |
| 161 | Index: entry.Index(), |
| 162 | Type: raftpb.EntryType(int32(entry.Type())), |
| 163 | } |
| 164 | if entry.DataOffset() > 0 { |
| 165 | x.AssertTrue(entry.DataOffset() < uint64(len(lf.Data))) |
| 166 | data := lf.Slice(int(entry.DataOffset())) |
| 167 | if len(data) > 0 { |
| 168 | // Copy the data over to allow the mmaped file to be deleted later. |
| 169 | re.Data = append(re.Data, data...) |
| 170 | } |
| 171 | } |
| 172 | // Decrypt the data if encryption is enabled. |
| 173 | if lf.dataKey != nil && len(re.Data) > 0 { |
| 174 | // No need to worry about mmap. Because, XORBlock allocates a byte array to do the |
| 175 | // XOR. So, the given slice is not being mutated. |
| 176 | // NOTE: We can potentially use allocator for this allocation. |
| 177 | decoded, err := y.XORBlockAllocate( |
| 178 | re.Data, lf.dataKey.Data, lf.generateIV(entry.DataOffset())) |
| 179 | x.Check(err) |
| 180 | re.Data = decoded |
| 181 | } |
| 182 | return re |
| 183 | } |
| 184 | |
| 185 | // firstIndex returns the first index in the file. |
| 186 | func (lf *logFile) firstIndex() uint64 { |
no test coverage detected