backward compatible vif loading

This commit is contained in:
chrislu 2024-10-28 19:44:30 -07:00
parent f17048d32a
commit 9873b033d1
3 changed files with 883 additions and 729 deletions

View File

@ -483,6 +483,15 @@ message VolumeInfo {
uint64 expire_at_sec = 6; // expiration time of ec volume
bool read_only = 7;
}
message OldVersionVolumeInfo {
repeated RemoteFile files = 1;
uint32 version = 2;
string replication = 3;
uint32 BytesOffset = 4;
int64 dat_file_size = 5; // store the original dat file size
uint64 DestroyTime = 6; // expiration time of ec volume
bool read_only = 7;
}
// tiered storage
message VolumeTierMoveDatToRemoteRequest {

File diff suppressed because it is too large Load Diff

View File

@ -2,9 +2,8 @@ package volume_info
import (
"fmt"
"os"
jsonpb "google.golang.org/protobuf/encoding/protojson"
"os"
"github.com/seaweedfs/seaweedfs/weed/glog"
"github.com/seaweedfs/seaweedfs/weed/pb/volume_server_pb"
@ -35,7 +34,7 @@ func MaybeLoadVolumeInfo(fileName string) (volumeInfo *volume_server_pb.VolumeIn
hasVolumeInfoFile = true
glog.V(1).Infof("maybeLoadVolumeInfo reads %s", fileName)
tierData, readErr := os.ReadFile(fileName)
fileData, readErr := os.ReadFile(fileName)
if readErr != nil {
glog.Warningf("fail to read %s : %v", fileName, readErr)
err = fmt.Errorf("fail to read %s : %v", fileName, readErr)
@ -44,10 +43,14 @@ func MaybeLoadVolumeInfo(fileName string) (volumeInfo *volume_server_pb.VolumeIn
}
glog.V(1).Infof("maybeLoadVolumeInfo Unmarshal volume info %v", fileName)
if err = jsonpb.Unmarshal(tierData, volumeInfo); err != nil {
glog.Warningf("unmarshal error: %v", err)
err = fmt.Errorf("unmarshal error: %v", err)
return
if err = jsonpb.Unmarshal(fileData, volumeInfo); err != nil {
if oldVersionErr := tryOldVersionVolumeInfo(fileData, volumeInfo); oldVersionErr != nil {
glog.Warningf("unmarshal error: %v oldFormat: %v", err, oldVersionErr)
err = fmt.Errorf("unmarshal error: %v oldFormat: %v", err, oldVersionErr)
return
} else {
err = nil
}
}
if len(volumeInfo.GetFiles()) == 0 {
@ -82,3 +85,19 @@ func SaveVolumeInfo(fileName string, volumeInfo *volume_server_pb.VolumeInfo) er
return nil
}
func tryOldVersionVolumeInfo(data []byte, volumeInfo *volume_server_pb.VolumeInfo) error {
oldVersionVolumeInfo := &volume_server_pb.OldVersionVolumeInfo{}
if err := jsonpb.Unmarshal(data, oldVersionVolumeInfo); err != nil {
return fmt.Errorf("failed to unmarshal old version volume info: %v", err)
}
volumeInfo.Files = oldVersionVolumeInfo.Files
volumeInfo.Version = oldVersionVolumeInfo.Version
volumeInfo.Replication = oldVersionVolumeInfo.Replication
volumeInfo.BytesOffset = oldVersionVolumeInfo.BytesOffset
volumeInfo.DatFileSize = oldVersionVolumeInfo.DatFileSize
volumeInfo.ExpireAtSec = oldVersionVolumeInfo.DestroyTime
volumeInfo.ReadOnly = oldVersionVolumeInfo.ReadOnly
return nil
}