volume_tier.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. )
  9. func (v *Volume) GetVolumeInfo() *volume_server_pb.VolumeInfo {
  10. return v.volumeInfo
  11. }
  12. func (v *Volume) maybeLoadVolumeInfo() (found bool) {
  13. v.volumeInfo, v.hasRemoteFile, _ = pb.MaybeLoadVolumeInfo(v.FileName(".vif"))
  14. if v.hasRemoteFile {
  15. glog.V(0).Infof("volume %d is tiered to %s as %s and read only", v.Id,
  16. v.volumeInfo.Files[0].BackendName(), v.volumeInfo.Files[0].Key)
  17. }
  18. return
  19. }
  20. func (v *Volume) HasRemoteFile() bool {
  21. return v.hasRemoteFile
  22. }
  23. func (v *Volume) LoadRemoteFile() error {
  24. tierFile := v.volumeInfo.GetFiles()[0]
  25. backendStorage := backend.BackendStorages[tierFile.BackendName()]
  26. if v.DataBackend != nil {
  27. v.DataBackend.Close()
  28. }
  29. v.DataBackend = backendStorage.NewStorageFile(tierFile.Key, v.volumeInfo)
  30. return nil
  31. }
  32. func (v *Volume) SaveVolumeInfo() error {
  33. tierFileName := v.FileName(".vif")
  34. return pb.SaveVolumeInfo(tierFileName, v.volumeInfo)
  35. }