MCPcopy Create free account
hub / github.com/dgraph-io/dgraph / getLogFiles

Function getLogFiles

raftwal/log.go:253–294  ·  view source on GitHub ↗

getLogFiles returns all the log files in the directory sorted by the first index in each file.

(dir string)

Source from the content-addressed store, hash-verified

251// getLogFiles returns all the log files in the directory sorted by the first
252// index in each file.
253func getLogFiles(dir string) ([]*logFile, error) {
254 entryFiles := x.WalkPathFunc(dir, func(path string, isDir bool) bool {
255 if isDir {
256 return false
257 }
258 if strings.HasSuffix(path, logSuffix) {
259 return true
260 }
261 return false
262 })
263
264 var files []*logFile
265 seen := make(map[int64]struct{})
266
267 for _, fpath := range entryFiles {
268 _, fname := filepath.Split(fpath)
269 fname = strings.TrimSuffix(fname, logSuffix)
270
271 fid, err := strconv.ParseInt(fname, 10, 64)
272 if err != nil {
273 return nil, errors.Wrapf(err, "while parsing: %s", fpath)
274 }
275
276 if _, ok := seen[fid]; ok {
277 glog.Fatalf("Entry file with id: %d is repeated", fid)
278 }
279 seen[fid] = struct{}{}
280
281 f, err := openLogFile(dir, fid)
282 if err != nil {
283 return nil, err
284 }
285 glog.Infof("Found file: %d First Index: %d\n", fid, f.firstIndex())
286 files = append(files, f)
287 }
288
289 // Sort files by the first index they store.
290 sort.Slice(files, func(i, j int) bool {
291 return files[i].getEntry(0).Index() < files[j].getEntry(0).Index()
292 })
293 return files, nil
294}
295
296// KeyID returns datakey's ID.
297func (lf *logFile) keyID() uint64 {

Callers 2

TestStorageBigFunction · 0.85
openWalFunction · 0.85

Calls 8

WalkPathFuncFunction · 0.92
openLogFileFunction · 0.85
FatalfMethod · 0.80
InfofMethod · 0.80
SliceMethod · 0.80
IndexMethod · 0.80
getEntryMethod · 0.80
firstIndexMethod · 0.45

Tested by 1

TestStorageBigFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…