mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 10:37:23 +01:00
volume: report the compaction revision with the commit-start status
The commit reloads the superblock before it lets status reads see the live volume again, so a heartbeat in between paired the new compaction revision with the pinned counts, and the changed hash sent that mixed report. The revision is now part of the status the commit pins, in Go and in Rust. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c5a87ebcba
commit
c651a94885
4 files changed
+35
-34
No files matched your search
@@ -1426,7 +1426,7 @@ fn build_heartbeat_with_ec_status(
|
||||
replica_placement: vol.super_block().replica_placement.to_byte() as u32,
|
||||
version: vol.super_block().version.0 as u32,
|
||||
ttl: vol.super_block().ttl.to_u32(),
|
||||
compact_revision: vol.super_block().compaction_revision as u32,
|
||||
compact_revision: status.compaction_revision as u32,
|
||||
// The .dat mtime, as Go reports: the shell's quiet-period
|
||||
// gates read this as "last touched", which a delete has to
|
||||
// count towards even though the TTL clock ignores it.
|
||||
|
||||
@@ -1056,6 +1056,7 @@ pub struct VolumeStatus {
|
||||
pub file_count: i64,
|
||||
pub deleted_count: i64,
|
||||
pub deleted_size: u64,
|
||||
pub compaction_revision: u16,
|
||||
}
|
||||
|
||||
/// Lets `collect_status` read the live volume again once a commit is done.
|
||||
@@ -6089,6 +6090,7 @@ impl Volume {
|
||||
file_count: nm.map_or(0, |nm| nm.file_count()),
|
||||
deleted_count: nm.map_or(0, |nm| nm.deleted_count()),
|
||||
deleted_size: nm.map_or(0, |nm| nm.deleted_size()),
|
||||
compaction_revision: self.super_block.read().unwrap().compaction_revision,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+28
-29
@@ -501,19 +501,20 @@ func (v *Volume) expiredLongEnough(maxDelayMinutes uint32) bool {
|
||||
|
||||
// volumeStatus is what collectStatus reports about a loaded volume.
|
||||
type volumeStatus struct {
|
||||
maxFileKey types.NeedleId
|
||||
datFileSize int64
|
||||
modTime time.Time
|
||||
fileCount uint64
|
||||
deletedCount uint64
|
||||
deletedSize uint64
|
||||
maxFileKey types.NeedleId
|
||||
datFileSize int64
|
||||
modTime time.Time
|
||||
fileCount uint64
|
||||
deletedCount uint64
|
||||
deletedSize uint64
|
||||
compactRevision uint16
|
||||
}
|
||||
|
||||
func (v *Volume) collectStatus() (maxFileKey types.NeedleId, datFileSize int64, modTime time.Time, fileCount, deletedCount, deletedSize uint64, ok bool) {
|
||||
func (v *Volume) collectStatus() (status volumeStatus, ok bool) {
|
||||
v.statusLock.Lock()
|
||||
if s := v.commitStatus; s != nil {
|
||||
if pinned := v.commitStatus; pinned != nil {
|
||||
v.statusLock.Unlock()
|
||||
return s.maxFileKey, s.datFileSize, s.modTime, s.fileCount, s.deletedCount, s.deletedSize, true
|
||||
return *pinned, true
|
||||
}
|
||||
v.dataFileAccessLock.RLock()
|
||||
v.statusLock.Unlock()
|
||||
@@ -523,15 +524,13 @@ func (v *Volume) collectStatus() (maxFileKey types.NeedleId, datFileSize int64,
|
||||
return
|
||||
}
|
||||
|
||||
ok = true
|
||||
|
||||
maxFileKey = v.nm.MaxFileKey()
|
||||
datFileSize, modTime, _ = v.DataBackend.GetStat()
|
||||
fileCount = uint64(v.nm.FileCount())
|
||||
deletedCount = uint64(v.nm.DeletedCount())
|
||||
deletedSize = v.nm.DeletedSize()
|
||||
|
||||
return
|
||||
status.maxFileKey = v.nm.MaxFileKey()
|
||||
status.datFileSize, status.modTime, _ = v.DataBackend.GetStat()
|
||||
status.fileCount = uint64(v.nm.FileCount())
|
||||
status.deletedCount = uint64(v.nm.DeletedCount())
|
||||
status.deletedSize = v.nm.DeletedSize()
|
||||
status.compactRevision = v.SuperBlock.CompactionRevision
|
||||
return status, true
|
||||
}
|
||||
|
||||
// holdStatusForCommit pins what collectStatus reports to the volume's status
|
||||
@@ -540,12 +539,12 @@ func (v *Volume) collectStatus() (maxFileKey types.NeedleId, datFileSize int64,
|
||||
// heartbeat timeout, and the heartbeat reads every volume of the server in
|
||||
// turn. The returned func lets status reads see the live volume again.
|
||||
func (v *Volume) holdStatusForCommit() (release func()) {
|
||||
maxFileKey, datFileSize, modTime, fileCount, deletedCount, deletedSize, ok := v.collectStatus()
|
||||
status, ok := v.collectStatus()
|
||||
if !ok {
|
||||
return func() {}
|
||||
}
|
||||
v.statusLock.Lock()
|
||||
v.commitStatus = &volumeStatus{maxFileKey, datFileSize, modTime, fileCount, deletedCount, deletedSize}
|
||||
v.commitStatus = &status
|
||||
v.statusLock.Unlock()
|
||||
return func() {
|
||||
v.statusLock.Lock()
|
||||
@@ -559,7 +558,7 @@ func (v *Volume) holdStatusForCommit() (release func()) {
|
||||
// the volumes it reports fills the same message for all the rest.
|
||||
func (v *Volume) ToVolumeInformationMessage(into *master_pb.VolumeInformationMessage) (types.NeedleId, *master_pb.VolumeInformationMessage) {
|
||||
|
||||
maxFileKey, volumeSize, modTime, fileCount, deletedCount, deletedSize, ok := v.collectStatus()
|
||||
status, ok := v.collectStatus()
|
||||
|
||||
if !ok {
|
||||
glog.Warningf("Volume %d: needle map or data file is closed - not reporting to master", v.Id)
|
||||
@@ -572,7 +571,7 @@ func (v *Volume) ToVolumeInformationMessage(into *master_pb.VolumeInformationMes
|
||||
// legitimately lives in cloud storage. Only a present .dat is cached for 30s; a
|
||||
// missing one is re-checked every heartbeat so the volume stays suppressed until
|
||||
// the file returns.
|
||||
if fileCount > 0 && !v.HasRemoteFile() {
|
||||
if status.fileCount > 0 && !v.HasRemoteFile() {
|
||||
const diskCheckIntervalNs = 30 * int64(time.Second)
|
||||
now := time.Now().UnixNano()
|
||||
if now-v.lastDiskCheckNs.Load() > diskCheckIntervalNs {
|
||||
@@ -589,22 +588,22 @@ func (v *Volume) ToVolumeInformationMessage(into *master_pb.VolumeInformationMes
|
||||
volumeInfo = &master_pb.VolumeInformationMessage{}
|
||||
}
|
||||
volumeInfo.Id = uint32(v.Id)
|
||||
volumeInfo.Size = uint64(volumeSize)
|
||||
volumeInfo.Size = uint64(status.datFileSize)
|
||||
volumeInfo.Collection = v.Collection
|
||||
volumeInfo.FileCount = fileCount
|
||||
volumeInfo.DeleteCount = deletedCount
|
||||
volumeInfo.DeletedByteCount = deletedSize
|
||||
volumeInfo.FileCount = status.fileCount
|
||||
volumeInfo.DeleteCount = status.deletedCount
|
||||
volumeInfo.DeletedByteCount = status.deletedSize
|
||||
volumeInfo.ReadOnly, volumeInfo.ReadOnlyCanDelete = v.reportedReadOnly()
|
||||
volumeInfo.ReplicaPlacement = uint32(v.ReplicaPlacement.Byte())
|
||||
volumeInfo.Version = uint32(v.Version())
|
||||
volumeInfo.Ttl = v.Ttl.ToUint32()
|
||||
volumeInfo.CompactRevision = uint32(v.SuperBlock.CompactionRevision)
|
||||
volumeInfo.ModifiedAtSecond = modTime.Unix()
|
||||
volumeInfo.CompactRevision = uint32(status.compactRevision)
|
||||
volumeInfo.ModifiedAtSecond = status.modTime.Unix()
|
||||
volumeInfo.DiskType = string(v.location.DiskType)
|
||||
volumeInfo.DiskId = v.diskId
|
||||
volumeInfo.RemoteStorageName, volumeInfo.RemoteStorageKey = v.RemoteStorageNameKey()
|
||||
|
||||
return maxFileKey, volumeInfo
|
||||
return status.maxFileKey, volumeInfo
|
||||
}
|
||||
|
||||
func (v *Volume) RemoteStorageNameKey() (storageName, storageKey string) {
|
||||
|
||||
@@ -331,7 +331,7 @@ func TestCommitCompactWithoutTempFilesKeepsVolumeLoaded(t *testing.T) {
|
||||
if err := v.CommitCompact(); err == nil {
|
||||
t.Fatal("second commit succeeded without .cpd/.cpx")
|
||||
}
|
||||
if _, _, _, _, _, _, ok := v.collectStatus(); !ok {
|
||||
if _, ok := v.collectStatus(); !ok {
|
||||
t.Fatal("volume dropped out of the heartbeat after the refused commit")
|
||||
}
|
||||
if _, err := os.Stat(v.FileName(".cpc")); !os.IsNotExist(err) {
|
||||
@@ -373,7 +373,7 @@ func TestCommitCompactMakeupDiffFailureKeepsVolumeLoaded(t *testing.T) {
|
||||
if err := v.CommitCompact(); err == nil {
|
||||
t.Fatal("commit succeeded with a mismatched compaction revision")
|
||||
}
|
||||
if _, _, _, _, _, _, ok := v.collectStatus(); !ok {
|
||||
if _, ok := v.collectStatus(); !ok {
|
||||
t.Fatal("volume dropped out of the heartbeat after a failed makeupDiff")
|
||||
}
|
||||
for i, want := range written {
|
||||
@@ -1429,11 +1429,11 @@ func TestCommitCompactDoesNotBlockStatus(t *testing.T) {
|
||||
if err := <-committed; err != nil {
|
||||
t.Fatalf("commit: %v", err)
|
||||
}
|
||||
if during == nil || during.FileCount != 3 || during.DeleteCount != 1 {
|
||||
if during == nil || during.FileCount != 3 || during.DeleteCount != 1 || during.CompactRevision != 0 {
|
||||
t.Fatalf("status during the commit = %+v, want the volume as the commit started", during)
|
||||
}
|
||||
_, m := v.ToVolumeInformationMessage(nil)
|
||||
if m == nil || m.FileCount != 2 || m.DeleteCount != 0 {
|
||||
if m == nil || m.FileCount != 2 || m.DeleteCount != 0 || m.CompactRevision != 1 {
|
||||
t.Fatalf("status after the commit = %+v, want the compacted volume", m)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user