mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-12-03 00:49:13 +08:00
9f55c7c90e
* Add Rclone storage backend * Support templating the name of files stored via Rclone * Enable Rclone accounting * Remove redundant type conversion * Provide progress information for Rclone download/upload operations * Log error when Rclone can't instantiate filesystem * Remove filename templating functionality for Rclone storage To (maybe) be later reintroduced as a generic functionality for all storage backends. * Remove S3 specific check * Move Rclone config initialisation to init() method
79 lines
2.0 KiB
Go
79 lines
2.0 KiB
Go
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/rclone_backend"
|
|
_ "github.com/seaweedfs/seaweedfs/weed/storage/backend/s3_backend"
|
|
"github.com/seaweedfs/seaweedfs/weed/storage/needle"
|
|
"github.com/seaweedfs/seaweedfs/weed/storage/types"
|
|
"github.com/seaweedfs/seaweedfs/weed/storage/volume_info"
|
|
)
|
|
|
|
func (v *Volume) GetVolumeInfo() *volume_server_pb.VolumeInfo {
|
|
return v.volumeInfo
|
|
}
|
|
|
|
func (v *Volume) maybeLoadVolumeInfo() (found bool) {
|
|
|
|
var err error
|
|
v.volumeInfo, v.hasRemoteFile, found, err = volume_info.MaybeLoadVolumeInfo(v.FileName(".vif"))
|
|
|
|
if v.volumeInfo.Version == 0 {
|
|
v.volumeInfo.Version = uint32(needle.CurrentVersion)
|
|
}
|
|
|
|
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)
|
|
} 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
|
|
}
|
|
|
|
if err != nil {
|
|
glog.Warningf("load volume %d.vif file: %v", v.Id, err)
|
|
return
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
func (v *Volume) HasRemoteFile() bool {
|
|
return v.hasRemoteFile
|
|
}
|
|
|
|
func (v *Volume) LoadRemoteFile() error {
|
|
tierFile := v.volumeInfo.GetFiles()[0]
|
|
backendStorage := backend.BackendStorages[tierFile.BackendName()]
|
|
|
|
if v.DataBackend != nil {
|
|
v.DataBackend.Close()
|
|
}
|
|
|
|
v.DataBackend = backendStorage.NewStorageFile(tierFile.Key, v.volumeInfo)
|
|
return nil
|
|
}
|
|
|
|
func (v *Volume) SaveVolumeInfo() error {
|
|
|
|
tierFileName := v.FileName(".vif")
|
|
|
|
return volume_info.SaveVolumeInfo(tierFileName, v.volumeInfo)
|
|
|
|
}
|