volume_tier.go 1.9 KB

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