2019-12-03 07:08:28 +08:00
|
|
|
package storage
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/glog"
|
2019-12-29 04:28:58 +08:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/pb"
|
2019-12-03 07:08:28 +08:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/pb/volume_server_pb"
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/storage/backend"
|
2019-12-29 04:28:58 +08:00
|
|
|
_ "github.com/chrislusf/seaweedfs/weed/storage/backend/s3_backend"
|
2019-12-03 07:08:28 +08:00
|
|
|
)
|
|
|
|
|
2019-12-29 03:21:49 +08:00
|
|
|
func (v *Volume) GetVolumeInfo() *volume_server_pb.VolumeInfo {
|
|
|
|
return v.volumeInfo
|
2019-12-03 07:08:28 +08:00
|
|
|
}
|
|
|
|
|
2019-12-29 13:37:29 +08:00
|
|
|
func (v *Volume) maybeLoadVolumeInfo() (found bool) {
|
2019-12-03 07:08:28 +08:00
|
|
|
|
2019-12-29 04:28:58 +08:00
|
|
|
v.volumeInfo, found = pb.MaybeLoadVolumeInfo(v.FileName() + ".vif")
|
2019-12-03 07:08:28 +08:00
|
|
|
|
2019-12-29 04:28:58 +08:00
|
|
|
if found {
|
|
|
|
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)
|
|
|
|
v.hasRemoteFile = true
|
2019-12-03 07:08:28 +08:00
|
|
|
}
|
|
|
|
|
2019-12-29 13:36:15 +08:00
|
|
|
return
|
|
|
|
|
2019-12-03 07:08:28 +08:00
|
|
|
}
|
|
|
|
|
2019-12-26 08:17:58 +08:00
|
|
|
func (v *Volume) HasRemoteFile() bool {
|
2019-12-29 03:35:27 +08:00
|
|
|
return v.hasRemoteFile
|
2019-12-26 08:17:58 +08:00
|
|
|
}
|
|
|
|
|
2019-12-03 07:08:28 +08:00
|
|
|
func (v *Volume) LoadRemoteFile() error {
|
2019-12-29 03:21:49 +08:00
|
|
|
tierFile := v.volumeInfo.GetFiles()[0]
|
2019-12-03 07:08:28 +08:00
|
|
|
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)
|
2019-12-03 07:08:28 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-12-29 03:21:49 +08:00
|
|
|
func (v *Volume) SaveVolumeInfo() error {
|
2019-12-03 07:08:28 +08:00
|
|
|
|
2019-12-29 03:17:39 +08:00
|
|
|
tierFileName := v.FileName() + ".vif"
|
2019-12-03 07:08:28 +08:00
|
|
|
|
2019-12-29 04:28:58 +08:00
|
|
|
return pb.SaveVolumeInfo(tierFileName, v.volumeInfo)
|
2019-12-03 07:08:28 +08:00
|
|
|
|
|
|
|
}
|