2019-12-03 07:08:28 +08:00
|
|
|
package storage
|
|
|
|
|
|
|
|
import (
|
2022-07-29 15:17:28 +08:00
|
|
|
"github.com/seaweedfs/seaweedfs/weed/glog"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/volume_server_pb"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/storage/backend"
|
2023-04-19 05:12:12 +08:00
|
|
|
_ "github.com/seaweedfs/seaweedfs/weed/storage/backend/rclone_backend"
|
2022-07-29 15:17:28 +08:00
|
|
|
_ "github.com/seaweedfs/seaweedfs/weed/storage/backend/s3_backend"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/storage/needle"
|
2022-10-14 15:18:09 +08:00
|
|
|
"github.com/seaweedfs/seaweedfs/weed/storage/types"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/storage/volume_info"
|
2024-08-16 15:20:00 +08:00
|
|
|
"time"
|
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
|
|
|
|
2021-03-01 16:48:30 +08:00
|
|
|
var err error
|
2021-08-27 06:18:34 +08:00
|
|
|
v.volumeInfo, v.hasRemoteFile, found, err = volume_info.MaybeLoadVolumeInfo(v.FileName(".vif"))
|
2021-03-01 16:48:30 +08:00
|
|
|
|
|
|
|
if v.volumeInfo.Version == 0 {
|
|
|
|
v.volumeInfo.Version = uint32(needle.CurrentVersion)
|
|
|
|
}
|
2019-12-03 07:08:28 +08:00
|
|
|
|
2020-01-09 01:45:26 +08:00
|
|
|
if v.hasRemoteFile {
|
2019-12-29 04:28:58 +08:00
|
|
|
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)
|
2022-10-14 15:18:09 +08:00
|
|
|
} else {
|
|
|
|
if v.volumeInfo.BytesOffset == 0 {
|
|
|
|
v.volumeInfo.BytesOffset = uint32(types.OffsetSize)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if v.volumeInfo.BytesOffset != 0 && v.volumeInfo.BytesOffset != uint32(types.OffsetSize) {
|
|
|
|
var m string
|
|
|
|
if types.OffsetSize == 5 {
|
|
|
|
m = "without"
|
|
|
|
} else {
|
|
|
|
m = "with"
|
|
|
|
}
|
|
|
|
glog.Exitf("BytesOffset mismatch in volume info file %s, try use binary version %s large_disk", v.FileName(".vif"), m)
|
|
|
|
return
|
2019-12-03 07:08:28 +08:00
|
|
|
}
|
|
|
|
|
2021-03-01 16:48:30 +08:00
|
|
|
if err != nil {
|
|
|
|
glog.Warningf("load volume %d.vif file: %v", v.Id, err)
|
2021-03-10 04:09:32 +08:00
|
|
|
return
|
2021-03-01 16:48:30 +08:00
|
|
|
}
|
|
|
|
|
2021-03-10 04:09:32 +08:00
|
|
|
return
|
2019-12-29 13:36:15 +08:00
|
|
|
|
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
|
|
|
|
2020-11-27 19:17:10 +08:00
|
|
|
tierFileName := v.FileName(".vif")
|
2024-08-16 15:20:00 +08:00
|
|
|
if v.Ttl != nil {
|
|
|
|
ttlSeconds := v.Ttl.ToSeconds()
|
|
|
|
if ttlSeconds > 0 {
|
2024-10-25 12:35:11 +08:00
|
|
|
v.volumeInfo.ExpireAtSec = uint64(time.Now().Unix()) + ttlSeconds //calculated destroy time from the ec volume was created
|
2024-08-16 15:20:00 +08:00
|
|
|
}
|
|
|
|
}
|
2019-12-03 07:08:28 +08:00
|
|
|
|
2021-08-27 06:18:34 +08:00
|
|
|
return volume_info.SaveVolumeInfo(tierFileName, v.volumeInfo)
|
2019-12-03 07:08:28 +08:00
|
|
|
|
|
|
|
}
|