MCPcopy
hub / github.com/dgraph-io/badger / createVlogFile

Method createVlogFile

value.go:986–1025  ·  view source on GitHub ↗
(fid uint32)

Source from the content-addressed store, hash-verified

984}
985
986func (vlog *valueLog) createVlogFile(fid uint32) (*logFile, error) {
987 path := vlog.fpath(fid)
988
989 lf := &logFile{
990 fid: fid,
991 path: path,
992 loadingMode: vlog.opt.ValueLogLoadingMode,
993 registry: vlog.db.registry,
994 }
995 // writableLogOffset is only written by write func, by read by Read func.
996 // To avoid a race condition, all reads and updates to this variable must be
997 // done via atomics.
998 var err error
999 if lf.fd, err = y.CreateSyncedFile(path, vlog.opt.SyncWrites); err != nil {
1000 return nil, errFile(err, lf.path, "Create value log file")
1001 }
1002
1003 if err = lf.bootstrap(); err != nil {
1004 return nil, err
1005 }
1006
1007 if err = syncDir(vlog.dirPath); err != nil {
1008 return nil, errFile(err, vlog.dirPath, "Sync value log dir")
1009 }
1010 if err = lf.mmap(2 * vlog.opt.ValueLogFileSize); err != nil {
1011 return nil, errFile(err, lf.path, "Mmap value log file")
1012 }
1013
1014 vlog.filesLock.Lock()
1015 vlog.filesMap[fid] = lf
1016 vlog.maxFid = fid
1017 // writableLogOffset is only written by write func, by read by Read func.
1018 // To avoid a race condition, all reads and updates to this variable must be
1019 // done via atomics.
1020 atomic.StoreUint32(&vlog.writableLogOffset, vlogHeaderSize)
1021 vlog.numEntriesWritten = 0
1022 vlog.filesLock.Unlock()
1023
1024 return lf, nil
1025}
1026
1027func errFile(err error, path string, msg string) error {
1028 return fmt.Errorf("%s. Path=%s. Error=%v", msg, path, err)

Callers 3

dropAllMethod · 0.95
openMethod · 0.95
writeMethod · 0.95

Calls 6

fpathMethod · 0.95
bootstrapMethod · 0.95
mmapMethod · 0.95
CreateSyncedFileFunction · 0.92
errFileFunction · 0.85
syncDirFunction · 0.70

Tested by

no test coverage detected