// parseFreeVolumeIndex parse free index from local. func (s *Store) parseFreeVolumeIndex() (err error) { var ( i int id int32 bfile string ifile string v *volume.Volume data []byte ids []int32 lines []string bfs []string ifs []string ) if data, err = ioutil.ReadAll(s.fvf); err != nil { log.Errorf("ioutil.ReadAll() error(%v)", err) return } lines = strings.Split(string(data), "\n") if _, ids, bfs, ifs, err = s.parseIndex(lines); err != nil { return } for i = 0; i < len(bfs); i++ { id, bfile, ifile = ids[i], bfs[i], ifs[i] if v, err = newVolume(id, bfile, ifile, s.conf); err != nil { return } v.Close() s.FreeVolumes = append(s.FreeVolumes, v) if id = s.fileFreeId(bfile); id > s.FreeId { s.FreeId = id } } log.V(1).Infof("current max free volume id: %d", s.FreeId) return }
// AddFreeVolume add free volumes. func (s *Store) AddFreeVolume(n int, bdir, idir string) (sn int, err error) { var ( i int bfile, ifile string v *volume.Volume ) s.flock.Lock() for i = 0; i < n; i++ { s.FreeId++ bfile, ifile = s.freeFile(s.FreeId, bdir, idir) if myos.Exist(bfile) || myos.Exist(ifile) { continue } if v, err = newVolume(volumeFreeId, bfile, ifile, s.conf); err != nil { // if no free space, delete the file os.Remove(bfile) os.Remove(ifile) break } v.Close() s.FreeVolumes = append(s.FreeVolumes, v) sn++ } err = s.saveFreeVolumeIndex() s.flock.Unlock() return }
// Close close the store. // WARN the global variable store must first set nil and reject any other // requests then safty close. func (s *Store) Close() { var v *volume.Volume if s.vf != nil { s.vf.Close() } if s.fvf != nil { s.fvf.Close() } if s.Volumes != nil { for _, v = range s.Volumes { v.Close() } } if s.zk != nil { s.zk.Close() } return }
// Close close the store. // WARN the global variable store must first set nil and reject any other // requests then safty close. func (s *Store) Close() { log.Info("store close") var v *volume.Volume if s.vf != nil { s.vf.Close() } if s.fvf != nil { s.fvf.Close() } for _, v = range s.Volumes { log.Infof("volume[%d] close", v.Id) v.Close() } if s.zk != nil { s.zk.Close() } return }