volume_tier.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package storage
  2. import (
  3. "github.com/seaweedfs/seaweedfs/weed/glog"
  4. "github.com/seaweedfs/seaweedfs/weed/pb/volume_server_pb"
  5. "github.com/seaweedfs/seaweedfs/weed/storage/backend"
  6. _ "github.com/seaweedfs/seaweedfs/weed/storage/backend/rclone_backend"
  7. _ "github.com/seaweedfs/seaweedfs/weed/storage/backend/s3_backend"
  8. "github.com/seaweedfs/seaweedfs/weed/storage/needle"
  9. "github.com/seaweedfs/seaweedfs/weed/storage/types"
  10. "github.com/seaweedfs/seaweedfs/weed/storage/volume_info"
  11. )
  12. func (v *Volume) GetVolumeInfo() *volume_server_pb.VolumeInfo {
  13. return v.volumeInfo
  14. }
  15. func (v *Volume) maybeLoadVolumeInfo() (found bool) {
  16. var err error
  17. v.volumeInfo, v.hasRemoteFile, found, err = volume_info.MaybeLoadVolumeInfo(v.FileName(".vif"))
  18. if v.volumeInfo.Version == 0 {
  19. v.volumeInfo.Version = uint32(needle.CurrentVersion)
  20. }
  21. if v.hasRemoteFile {
  22. glog.V(0).Infof("volume %d is tiered to %s as %s and read only", v.Id,
  23. v.volumeInfo.Files[0].BackendName(), v.volumeInfo.Files[0].Key)
  24. } else {
  25. if v.volumeInfo.BytesOffset == 0 {
  26. v.volumeInfo.BytesOffset = uint32(types.OffsetSize)
  27. }
  28. }
  29. if v.volumeInfo.BytesOffset != 0 && v.volumeInfo.BytesOffset != uint32(types.OffsetSize) {
  30. var m string
  31. if types.OffsetSize == 5 {
  32. m = "without"
  33. } else {
  34. m = "with"
  35. }
  36. glog.Exitf("BytesOffset mismatch in volume info file %s, try use binary version %s large_disk", v.FileName(".vif"), m)
  37. return
  38. }
  39. if err != nil {
  40. glog.Warningf("load volume %d.vif file: %v", v.Id, err)
  41. return
  42. }
  43. return
  44. }
  45. func (v *Volume) HasRemoteFile() bool {
  46. return v.hasRemoteFile
  47. }
  48. func (v *Volume) LoadRemoteFile() error {
  49. tierFile := v.volumeInfo.GetFiles()[0]
  50. backendStorage := backend.BackendStorages[tierFile.BackendName()]
  51. if v.DataBackend != nil {
  52. v.DataBackend.Close()
  53. }
  54. v.DataBackend = backendStorage.NewStorageFile(tierFile.Key, v.volumeInfo)
  55. return nil
  56. }
  57. func (v *Volume) SaveVolumeInfo() error {
  58. tierFileName := v.FileName(".vif")
  59. return volume_info.SaveVolumeInfo(tierFileName, v.volumeInfo)
  60. }