| 868 | } |
| 869 | |
| 870 | func (vlog *valueLog) populateFilesMap() error { |
| 871 | vlog.filesMap = make(map[uint32]*logFile) |
| 872 | |
| 873 | files, err := ioutil.ReadDir(vlog.dirPath) |
| 874 | if err != nil { |
| 875 | return errFile(err, vlog.dirPath, "Unable to open log dir.") |
| 876 | } |
| 877 | |
| 878 | found := make(map[uint64]struct{}) |
| 879 | for _, file := range files { |
| 880 | if !strings.HasSuffix(file.Name(), ".vlog") { |
| 881 | continue |
| 882 | } |
| 883 | fsz := len(file.Name()) |
| 884 | fid, err := strconv.ParseUint(file.Name()[:fsz-5], 10, 32) |
| 885 | if err != nil { |
| 886 | return errFile(err, file.Name(), "Unable to parse log id.") |
| 887 | } |
| 888 | if _, ok := found[fid]; ok { |
| 889 | return errFile(err, file.Name(), "Duplicate file found. Please delete one.") |
| 890 | } |
| 891 | found[fid] = struct{}{} |
| 892 | |
| 893 | lf := &logFile{ |
| 894 | fid: uint32(fid), |
| 895 | path: vlog.fpath(uint32(fid)), |
| 896 | loadingMode: vlog.opt.ValueLogLoadingMode, |
| 897 | registry: vlog.db.registry, |
| 898 | } |
| 899 | vlog.filesMap[uint32(fid)] = lf |
| 900 | if vlog.maxFid < uint32(fid) { |
| 901 | vlog.maxFid = uint32(fid) |
| 902 | } |
| 903 | } |
| 904 | return nil |
| 905 | } |
| 906 | |
| 907 | func (lf *logFile) open(path string, flags uint32) error { |
| 908 | var err error |