volume_tier.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. "time"
  12. )
  13. func (v *Volume) GetVolumeInfo() *volume_server_pb.VolumeInfo {
  14. return v.volumeInfo
  15. }
  16. func (v *Volume) maybeLoadVolumeInfo() (found bool) {
  17. var err error
  18. v.volumeInfo, v.hasRemoteFile, found, err = volume_info.MaybeLoadVolumeInfo(v.FileName(".vif"))
  19. if v.volumeInfo.Version == 0 {
  20. v.volumeInfo.Version = uint32(needle.CurrentVersion)
  21. }
  22. if v.hasRemoteFile {
  23. glog.V(0).Infof("volume %d is tiered to %s as %s and read only", v.Id,
  24. v.volumeInfo.Files[0].BackendName(), v.volumeInfo.Files[0].Key)
  25. } else {
  26. if v.volumeInfo.BytesOffset == 0 {
  27. v.volumeInfo.BytesOffset = uint32(types.OffsetSize)
  28. }
  29. }
  30. if v.volumeInfo.BytesOffset != 0 && v.volumeInfo.BytesOffset != uint32(types.OffsetSize) {
  31. var m string
  32. if types.OffsetSize == 5 {
  33. m = "without"
  34. } else {
  35. m = "with"
  36. }
  37. glog.Exitf("BytesOffset mismatch in volume info file %s, try use binary version %s large_disk", v.FileName(".vif"), m)
  38. return
  39. }
  40. if err != nil {
  41. glog.Warningf("load volume %d.vif file: %v", v.Id, err)
  42. return
  43. }
  44. return
  45. }
  46. func (v *Volume) HasRemoteFile() bool {
  47. return v.hasRemoteFile
  48. }
  49. func (v *Volume) LoadRemoteFile() error {
  50. tierFile := v.volumeInfo.GetFiles()[0]
  51. backendStorage := backend.BackendStorages[tierFile.BackendName()]
  52. if v.DataBackend != nil {
  53. v.DataBackend.Close()
  54. }
  55. v.DataBackend = backendStorage.NewStorageFile(tierFile.Key, v.volumeInfo)
  56. return nil
  57. }
  58. func (v *Volume) SaveVolumeInfo() error {
  59. tierFileName := v.FileName(".vif")
  60. if v.Ttl != nil {
  61. ttlSeconds := v.Ttl.ToSeconds()
  62. if ttlSeconds > 0 {
  63. v.volumeInfo.DestroyTime = uint64(time.Now().Unix()) + ttlSeconds //calculated destroy time from the ec volume was created
  64. }
  65. }
  66. return volume_info.SaveVolumeInfo(tierFileName, v.volumeInfo)
  67. }