You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.2 KiB

  1. package storage
  2. import (
  3. "io/ioutil"
  4. "strings"
  5. "github.com/chrislusf/seaweedfs/go/glog"
  6. )
  7. type DiskLocation struct {
  8. Directory string
  9. MaxVolumeCount int
  10. volumes map[VolumeId]*Volume
  11. }
  12. func (mn *DiskLocation) reset() {
  13. }
  14. func (l *DiskLocation) loadExistingVolumes(needleMapKind NeedleMapType) {
  15. if dirs, err := ioutil.ReadDir(l.Directory); err == nil {
  16. for _, dir := range dirs {
  17. name := dir.Name()
  18. if !dir.IsDir() && strings.HasSuffix(name, ".dat") {
  19. collection := ""
  20. base := name[:len(name)-len(".dat")]
  21. i := strings.LastIndex(base, "_")
  22. if i > 0 {
  23. collection, base = base[0:i], base[i+1:]
  24. }
  25. if vid, err := NewVolumeId(base); err == nil {
  26. if l.volumes[vid] == nil {
  27. if v, e := NewVolume(l.Directory, collection, vid, needleMapKind, nil, nil); e == nil {
  28. l.volumes[vid] = v
  29. glog.V(0).Infof("data file %s, replicaPlacement=%s v=%d size=%d ttl=%s", l.Directory+"/"+name, v.ReplicaPlacement, v.Version(), v.Size(), v.Ttl.String())
  30. } else {
  31. glog.V(0).Infof("new volume %s error %s", name, e)
  32. }
  33. }
  34. }
  35. }
  36. }
  37. }
  38. glog.V(0).Infoln("Store started on dir:", l.Directory, "with", len(l.volumes), "volumes", "max", l.MaxVolumeCount)
  39. }