fix(metanode): recover panic when marshal inode failed. #22720099

Signed-off-by: Victor1319 <zengxuewei@oppo.com>
This commit is contained in:
Victor1319 2024-10-25 10:19:43 +08:00 committed by AmazingChi
parent 97af707e01
commit c6f2c51277
2 changed files with 21 additions and 9 deletions

View File

@ -731,12 +731,15 @@ func (i *Inode) MarshalInodeValue(buff *bytes.Buffer) {
log.LogDebugf("MarshalInodeValue ino(%v) storageClass(%v) Reserved(%v)", i.Inode, i.StorageClass, i.Reserved)
// reset reserved, V4EBSExtentsFlag maybe changed after migration .eg
i.Reserved = 0
//defer func() {
// if err := recover(); err != nil {
// log.LogErrorf("MarshalInodeValue ino(%v) storageClass(%v) Recovered from panic:%v",
// i.Inode, i.StorageClass, err)
// }
//}()
defer func() {
if err := recover(); err != nil {
log.LogErrorf("MarshalInodeValue ino(%v) storageClass(%v) reserved(%d) Recovered from panic:%v",
i.String(), i.StorageClass, i.Reserved, err)
log.LogFlush()
panic(err)
}
}()
if err = binary.Write(buff, binary.BigEndian, &i.Type); err != nil {
panic(err)
}
@ -796,7 +799,7 @@ func (i *Inode) MarshalInodeValue(buff *bytes.Buffer) {
if ObjExtents != nil && len(ObjExtents.eks) > 0 {
// i.Reserved |= V4EBSExtentsFlag
i.Reserved |= V2EnableEbsFlag
log.LogDebugf("MarshalInodeValue ino(%v) storageClass(%v) V4EBSExtentsFlag", i.Inode, i.StorageClass)
log.LogDebugf("MarshalInodeValue ino(%v) storageClass(%v) ?", i.Inode, i.StorageClass)
}
}
}
@ -837,10 +840,10 @@ func (i *Inode) MarshalInodeValue(buff *bytes.Buffer) {
panic(err)
}
} else {
log.LogDebugf("MarshalInodeValue ino(%v) storageClass(%v) marshall HybridCouldExtents V4ReplicaExtentsFlag Reserved(%v)",
log.LogDebugf("MarshalInodeValue ino(%v) storageClass(%v) marshall HybridCouldExtents V4ReplicaExtentsFlag or empyt obj exts Reserved(%v)",
i.Inode, i.StorageClass, i.Reserved)
replicaExtents := NewSortedExtents()
if !i.HybridCouldExtents.Empty() {
if i.HybridCouldExtents.HasReplicaExts() {
replicaExtents = i.HybridCouldExtents.sortedEks.(*SortedExtents)
}
extData, err := replicaExtents.MarshalBinary(enableSnapshot)

View File

@ -19,6 +19,15 @@ func (se *SortedHybridCloudExtents) Empty() bool {
return se.sortedEks == nil
}
func (se *SortedHybridCloudExtents) HasReplicaExts() bool {
if se.sortedEks == nil {
return false
}
_, ok := se.sortedEks.(*SortedExtents)
return ok
}
func NewSortedHybridCloudExtents() *SortedHybridCloudExtents {
return &SortedHybridCloudExtents{}
}