volume_tier.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package storage
  2. import (
  3. "github.com/chrislusf/seaweedfs/weed/glog"
  4. "github.com/chrislusf/seaweedfs/weed/pb"
  5. "github.com/chrislusf/seaweedfs/weed/pb/volume_server_pb"
  6. "github.com/chrislusf/seaweedfs/weed/storage/backend"
  7. _ "github.com/chrislusf/seaweedfs/weed/storage/backend/s3_backend"
  8. "github.com/chrislusf/seaweedfs/weed/storage/needle"
  9. )
  10. func (v *Volume) GetVolumeInfo() *volume_server_pb.VolumeInfo {
  11. return v.volumeInfo
  12. }
  13. func (v *Volume) maybeLoadVolumeInfo() (found bool) {
  14. var err error
  15. v.volumeInfo, v.hasRemoteFile, found, err = pb.MaybeLoadVolumeInfo(v.FileName(".vif"))
  16. if v.volumeInfo.Version == 0 {
  17. v.volumeInfo.Version = uint32(needle.CurrentVersion)
  18. }
  19. if v.hasRemoteFile {
  20. glog.V(0).Infof("volume %d is tiered to %s as %s and read only", v.Id,
  21. v.volumeInfo.Files[0].BackendName(), v.volumeInfo.Files[0].Key)
  22. }
  23. if err != nil {
  24. glog.Warningf("load volume %d.vif file: %v", v.Id, err)
  25. return
  26. }
  27. return
  28. }
  29. func (v *Volume) HasRemoteFile() bool {
  30. return v.hasRemoteFile
  31. }
  32. func (v *Volume) LoadRemoteFile() error {
  33. tierFile := v.volumeInfo.GetFiles()[0]
  34. backendStorage := backend.BackendStorages[tierFile.BackendName()]
  35. if v.DataBackend != nil {
  36. v.DataBackend.Close()
  37. }
  38. v.DataBackend = backendStorage.NewStorageFile(tierFile.Key, v.volumeInfo)
  39. return nil
  40. }
  41. func (v *Volume) SaveVolumeInfo() error {
  42. tierFileName := v.FileName(".vif")
  43. return pb.SaveVolumeInfo(tierFileName, v.volumeInfo)
  44. }