diff options
| author | augustazz <102299780+augustazz@users.noreply.github.com> | 2024-08-16 15:20:00 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-16 00:20:00 -0700 |
| commit | 0b00706454478abbb246af2f0d30d34c79b09b40 (patch) | |
| tree | be46e19b7a2afa26b8e2f388b456cee05e95bb2b /weed/storage/erasure_coding | |
| parent | 8f1f1730e9925c2f9e5e01867f806dcaac3dde11 (diff) | |
| download | seaweedfs-0b00706454478abbb246af2f0d30d34c79b09b40.tar.xz seaweedfs-0b00706454478abbb246af2f0d30d34c79b09b40.zip | |
EC volume supports expiration and displays expiration message when executing volume.list (#5895)
* ec volume expire
* volume.list show DestroyTime
* comments
* code optimization
---------
Co-authored-by: xuwenfeng <xuwenfeng1@zto.com>
Diffstat (limited to 'weed/storage/erasure_coding')
| -rw-r--r-- | weed/storage/erasure_coding/ec_volume.go | 18 | ||||
| -rw-r--r-- | weed/storage/erasure_coding/ec_volume_info.go | 21 |
2 files changed, 26 insertions, 13 deletions
diff --git a/weed/storage/erasure_coding/ec_volume.go b/weed/storage/erasure_coding/ec_volume.go index ea869c475..ac25d1112 100644 --- a/weed/storage/erasure_coding/ec_volume.go +++ b/weed/storage/erasure_coding/ec_volume.go @@ -3,6 +3,7 @@ package erasure_coding import ( "errors" "fmt" + "github.com/seaweedfs/seaweedfs/weed/glog" "math" "os" "sync" @@ -20,7 +21,8 @@ import ( ) var ( - NotFoundError = errors.New("needle not found") + NotFoundError = errors.New("needle not found") + destroyDelaySeconds int64 = 0 ) type EcVolume struct { @@ -40,6 +42,7 @@ type EcVolume struct { ecjFileAccessLock sync.Mutex diskType types.DiskType datFileSize int64 + DestroyTime uint64 //ec volume destroy time, calculated from the ec volume was created } func NewEcVolume(diskType types.DiskType, dir string, dirIdx string, collection string, vid needle.VolumeId) (ev *EcVolume, err error) { @@ -70,7 +73,9 @@ func NewEcVolume(diskType types.DiskType, dir string, dirIdx string, collection if volumeInfo, _, found, _ := volume_info.MaybeLoadVolumeInfo(dataBaseFileName + ".vif"); found { ev.Version = needle.Version(volumeInfo.Version) ev.datFileSize = volumeInfo.DatFileSize + ev.DestroyTime = volumeInfo.DestroyTime } else { + glog.Warningf("vif file not found,volumeId:%d, filename:%s", vid, dataBaseFileName) volume_info.SaveVolumeInfo(dataBaseFileName+".vif", &volume_server_pb.VolumeInfo{Version: uint32(ev.Version)}) } @@ -198,9 +203,10 @@ func (ev *EcVolume) ToVolumeEcShardInformationMessage() (messages []*master_pb.V for _, s := range ev.Shards { if s.VolumeId != prevVolumeId { m = &master_pb.VolumeEcShardInformationMessage{ - Id: uint32(s.VolumeId), - Collection: s.Collection, - DiskType: string(ev.diskType), + Id: uint32(s.VolumeId), + Collection: s.Collection, + DiskType: string(ev.diskType), + DestroyTime: ev.DestroyTime, } messages = append(messages, m) } @@ -269,3 +275,7 @@ func SearchNeedleFromSortedIndex(ecxFile *os.File, ecxFileSize int64, needleId t err = NotFoundError return } + +func (ev *EcVolume) IsTimeToDestroy() bool { + return ev.DestroyTime > 0 && time.Now().Unix() > (int64(ev.DestroyTime)+destroyDelaySeconds) +} diff --git a/weed/storage/erasure_coding/ec_volume_info.go b/weed/storage/erasure_coding/ec_volume_info.go index 76ace0d13..5bfc8f5f6 100644 --- a/weed/storage/erasure_coding/ec_volume_info.go +++ b/weed/storage/erasure_coding/ec_volume_info.go @@ -7,18 +7,20 @@ import ( // data structure used in master type EcVolumeInfo struct { - VolumeId needle.VolumeId - Collection string - ShardBits ShardBits - DiskType string + VolumeId needle.VolumeId + Collection string + ShardBits ShardBits + DiskType string + DestroyTime uint64 //ec volume destroy time, calculated from the ec volume was created } -func NewEcVolumeInfo(diskType string, collection string, vid needle.VolumeId, shardBits ShardBits) *EcVolumeInfo { +func NewEcVolumeInfo(diskType string, collection string, vid needle.VolumeId, shardBits ShardBits, destroyTime uint64) *EcVolumeInfo { return &EcVolumeInfo{ - Collection: collection, - VolumeId: vid, - ShardBits: shardBits, - DiskType: diskType, + Collection: collection, + VolumeId: vid, + ShardBits: shardBits, + DiskType: diskType, + DestroyTime: destroyTime, } } @@ -59,6 +61,7 @@ func (ecInfo *EcVolumeInfo) ToVolumeEcShardInformationMessage() (ret *master_pb. EcIndexBits: uint32(ecInfo.ShardBits), Collection: ecInfo.Collection, DiskType: ecInfo.DiskType, + DestroyTime: ecInfo.DestroyTime, } } |
