MCPcopy
hub / github.com/dgraph-io/dgraph / GetRaftEntry

Method GetRaftEntry

raftwal/log.go:157–183  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
157func (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.
186func (lf *logFile) firstIndex() uint64 {

Callers 1

allEntriesMethod · 0.80

Calls 9

getEntryMethod · 0.95
generateIVMethod · 0.95
AssertTrueFunction · 0.92
CheckFunction · 0.92
IndexMethod · 0.80
DataOffsetMethod · 0.80
SliceMethod · 0.80
TypeMethod · 0.65
TermMethod · 0.45

Tested by

no test coverage detected