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.

61 lines
1.4 KiB

5 years ago
  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. }