load volume info from .vif file, use superblock as a backup
This commit is contained in:
@@ -1,66 +1,29 @@
|
||||
package storage
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
|
||||
_ "github.com/chrislusf/seaweedfs/weed/storage/backend/s3_backend"
|
||||
|
||||
"github.com/golang/protobuf/jsonpb"
|
||||
|
||||
"github.com/chrislusf/seaweedfs/weed/glog"
|
||||
"github.com/chrislusf/seaweedfs/weed/pb"
|
||||
"github.com/chrislusf/seaweedfs/weed/pb/volume_server_pb"
|
||||
"github.com/chrislusf/seaweedfs/weed/storage/backend"
|
||||
_ "github.com/chrislusf/seaweedfs/weed/storage/backend/s3_backend"
|
||||
)
|
||||
|
||||
func (v *Volume) GetVolumeInfo() *volume_server_pb.VolumeInfo {
|
||||
return v.volumeInfo
|
||||
}
|
||||
|
||||
func (v *Volume) maybeLoadVolumeInfo() bool {
|
||||
func (v *Volume) maybeLoadVolumeInfo() {
|
||||
|
||||
v.volumeInfo = &volume_server_pb.VolumeInfo{}
|
||||
var found bool
|
||||
|
||||
tierFileName := v.FileName() + ".vif"
|
||||
v.volumeInfo, found = pb.MaybeLoadVolumeInfo(v.FileName() + ".vif")
|
||||
|
||||
if exists, canRead, _, _, _ := checkFile(tierFileName); !exists || !canRead {
|
||||
if !exists {
|
||||
return false
|
||||
}
|
||||
if !canRead {
|
||||
glog.Warningf("can not read %s", tierFileName)
|
||||
}
|
||||
return false
|
||||
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
|
||||
}
|
||||
|
||||
glog.V(0).Infof("maybeLoadVolumeInfo loading volume %d check file", v.Id)
|
||||
|
||||
tierData, readErr := ioutil.ReadFile(tierFileName)
|
||||
if readErr != nil {
|
||||
glog.Warningf("fail to read %s : %v", tierFileName, readErr)
|
||||
return false
|
||||
}
|
||||
|
||||
glog.V(0).Infof("maybeLoadVolumeInfo loading volume %d ReadFile", v.Id)
|
||||
|
||||
if err := jsonpb.Unmarshal(bytes.NewReader(tierData), v.volumeInfo); err != nil {
|
||||
glog.Warningf("unmarshal error: %v", err)
|
||||
return false
|
||||
}
|
||||
|
||||
glog.V(0).Infof("maybeLoadVolumeInfo loading volume %d Unmarshal tierInfo %v", v.Id, v.volumeInfo)
|
||||
|
||||
if len(v.volumeInfo.GetFiles()) == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func (v *Volume) HasRemoteFile() bool {
|
||||
@@ -83,24 +46,6 @@ func (v *Volume) SaveVolumeInfo() error {
|
||||
|
||||
tierFileName := v.FileName() + ".vif"
|
||||
|
||||
if exists, _, canWrite, _, _ := checkFile(tierFileName); exists && !canWrite {
|
||||
return fmt.Errorf("%s not writable", tierFileName)
|
||||
}
|
||||
return pb.SaveVolumeInfo(tierFileName, v.volumeInfo)
|
||||
|
||||
m := jsonpb.Marshaler{
|
||||
EmitDefaults: true,
|
||||
Indent: " ",
|
||||
}
|
||||
|
||||
text, marshalErr := m.MarshalToString(v.GetVolumeInfo())
|
||||
if marshalErr != nil {
|
||||
return fmt.Errorf("marshal volume %d tier info: %v", v.Id, marshalErr)
|
||||
}
|
||||
|
||||
writeErr := ioutil.WriteFile(tierFileName, []byte(text), 0755)
|
||||
if writeErr != nil {
|
||||
return fmt.Errorf("fail to write %s : %v", tierFileName, writeErr)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user