seaweedfs/weed/storage/volume_tier.go

62 lines
1.5 KiB
Go
Raw Normal View History

package storage
import (
"github.com/seaweedfs/seaweedfs/weed/glog"
"github.com/seaweedfs/seaweedfs/weed/pb/volume_server_pb"
"github.com/seaweedfs/seaweedfs/weed/storage/backend"
_ "github.com/seaweedfs/seaweedfs/weed/storage/backend/s3_backend"
"github.com/seaweedfs/seaweedfs/weed/storage/needle"
volume_info "github.com/seaweedfs/seaweedfs/weed/storage/volume_info"
)
2019-12-29 03:21:49 +08:00
func (v *Volume) GetVolumeInfo() *volume_server_pb.VolumeInfo {
return v.volumeInfo
}
2019-12-29 13:37:29 +08:00
func (v *Volume) maybeLoadVolumeInfo() (found bool) {
var err error
2021-08-27 06:18:34 +08:00
v.volumeInfo, v.hasRemoteFile, found, err = volume_info.MaybeLoadVolumeInfo(v.FileName(".vif"))
if v.volumeInfo.Version == 0 {
v.volumeInfo.Version = uint32(needle.CurrentVersion)
}
2020-01-09 01:45:26 +08:00
if v.hasRemoteFile {
glog.V(0).Infof("volume %d is tiered to %s as %s and read only", v.Id,
v.volumeInfo.Files[0].BackendName(), v.volumeInfo.Files[0].Key)
}
if err != nil {
glog.Warningf("load volume %d.vif file: %v", v.Id, err)
return
}
return
2019-12-29 13:36:15 +08:00
}
2019-12-26 08:17:58 +08:00
func (v *Volume) HasRemoteFile() bool {
return v.hasRemoteFile
2019-12-26 08:17:58 +08:00
}
func (v *Volume) LoadRemoteFile() error {
2019-12-29 03:21:49 +08:00
tierFile := v.volumeInfo.GetFiles()[0]
backendStorage := backend.BackendStorages[tierFile.BackendName()]
if v.DataBackend != nil {
v.DataBackend.Close()
}
2019-12-29 03:21:49 +08:00
v.DataBackend = backendStorage.NewStorageFile(tierFile.Key, v.volumeInfo)
return nil
}
2019-12-29 03:21:49 +08:00
func (v *Volume) SaveVolumeInfo() error {
tierFileName := v.FileName(".vif")
2021-08-27 06:18:34 +08:00
return volume_info.SaveVolumeInfo(tierFileName, v.volumeInfo)
}