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>
This commit is contained in:
augustazz
2024-08-16 15:20:00 +08:00
committed by GitHub
parent 8f1f1730e9
commit 0b00706454
14 changed files with 1189 additions and 1082 deletions

View File

@@ -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)
}

View File

@@ -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,
}
}