2019-12-02 23:08:28 +00:00
|
|
|
package storage
|
|
|
|
|
|
|
|
import (
|
2020-11-17 06:26:58 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/util/log"
|
2019-12-28 20:28:58 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/pb"
|
2019-12-02 23:08:28 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/pb/volume_server_pb"
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/storage/backend"
|
2019-12-28 20:28:58 +00:00
|
|
|
_ "github.com/chrislusf/seaweedfs/weed/storage/backend/s3_backend"
|
2019-12-02 23:08:28 +00:00
|
|
|
)
|
|
|
|
|
2019-12-28 19:21:49 +00:00
|
|
|
func (v *Volume) GetVolumeInfo() *volume_server_pb.VolumeInfo {
|
|
|
|
return v.volumeInfo
|
2019-12-02 23:08:28 +00:00
|
|
|
}
|
|
|
|
|
2019-12-29 05:37:29 +00:00
|
|
|
func (v *Volume) maybeLoadVolumeInfo() (found bool) {
|
2019-12-02 23:08:28 +00:00
|
|
|
|
2020-02-02 23:37:23 +00:00
|
|
|
v.volumeInfo, v.hasRemoteFile, _ = pb.MaybeLoadVolumeInfo(v.FileName() + ".vif")
|
2019-12-02 23:08:28 +00:00
|
|
|
|
2020-01-08 17:45:26 +00:00
|
|
|
if v.hasRemoteFile {
|
2020-11-17 06:26:58 +00:00
|
|
|
log.Infof("volume %d is tiered to %s as %s and read only", v.Id,
|
2019-12-28 20:28:58 +00:00
|
|
|
v.volumeInfo.Files[0].BackendName(), v.volumeInfo.Files[0].Key)
|
2019-12-02 23:08:28 +00:00
|
|
|
}
|
|
|
|
|
2019-12-29 05:36:15 +00:00
|
|
|
return
|
|
|
|
|
2019-12-02 23:08:28 +00:00
|
|
|
}
|
|
|
|
|
2019-12-26 00:17:58 +00:00
|
|
|
func (v *Volume) HasRemoteFile() bool {
|
2019-12-28 19:35:27 +00:00
|
|
|
return v.hasRemoteFile
|
2019-12-26 00:17:58 +00:00
|
|
|
}
|
|
|
|
|
2019-12-02 23:08:28 +00:00
|
|
|
func (v *Volume) LoadRemoteFile() error {
|
2019-12-28 19:21:49 +00:00
|
|
|
tierFile := v.volumeInfo.GetFiles()[0]
|
2019-12-02 23:08:28 +00:00
|
|
|
backendStorage := backend.BackendStorages[tierFile.BackendName()]
|
|
|
|
|
|
|
|
if v.DataBackend != nil {
|
|
|
|
v.DataBackend.Close()
|
|
|
|
}
|
|
|
|
|
2019-12-28 19:21:49 +00:00
|
|
|
v.DataBackend = backendStorage.NewStorageFile(tierFile.Key, v.volumeInfo)
|
2019-12-02 23:08:28 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-12-28 19:21:49 +00:00
|
|
|
func (v *Volume) SaveVolumeInfo() error {
|
2019-12-02 23:08:28 +00:00
|
|
|
|
2019-12-28 19:17:39 +00:00
|
|
|
tierFileName := v.FileName() + ".vif"
|
2019-12-02 23:08:28 +00:00
|
|
|
|
2019-12-28 20:28:58 +00:00
|
|
|
return pb.SaveVolumeInfo(tierFileName, v.volumeInfo)
|
2019-12-02 23:08:28 +00:00
|
|
|
|
|
|
|
}
|