fix(metanode): inodeOnce marshall compatible with meta 3.3.2

Signed-off-by: chihe <chihe@oppo.com>
This commit is contained in:
chihe 2024-11-21 09:24:55 +08:00 committed by AmazingChi
parent 1d196732dc
commit bff1bbca48
3 changed files with 40 additions and 19 deletions

View File

@ -90,18 +90,19 @@ func (mp *metaPartition) Apply(command []byte, index uint64) (resp interface{},
}
resp = mp.fsmUnlinkInode(ino, 0)
case opFSMUnlinkInodeOnce:
var inoOnce *InodeOnce
if inoOnce, err = InodeOnceUnmarshal(msg.V); err != nil {
var inoOnceWithVersion *InodeOnceWithVersion
if inoOnceWithVersion, err = InodeOnceUnmarshal(msg.V); err != nil {
return
}
status := mp.inodeInTx(inoOnce.Inode)
status := mp.inodeInTx(inoOnceWithVersion.Inode)
if status != proto.OpOk {
resp = &InodeResponse{Status: status}
return
}
ino := NewInode(inoOnce.Inode, 0)
ino.setVer(inoOnce.VerSeq)
resp = mp.fsmUnlinkInode(ino, inoOnce.UniqID)
ino := NewInode(inoOnceWithVersion.Inode, 0)
ino.setVer(inoOnceWithVersion.VerSeq)
resp = mp.fsmUnlinkInode(ino, inoOnceWithVersion.UniqID)
case opFSMUnlinkInodeBatch:
inodes, err := InodeBatchUnmarshal(msg.V)
if err != nil {
@ -126,17 +127,18 @@ func (mp *metaPartition) Apply(command []byte, index uint64) (resp interface{},
}
resp = mp.fsmCreateLinkInode(ino, 0)
case opFSMCreateLinkInodeOnce:
var inoOnce *InodeOnce
if inoOnce, err = InodeOnceUnmarshal(msg.V); err != nil {
var inoOnceWithVersion *InodeOnceWithVersion
if inoOnceWithVersion, err = InodeOnceUnmarshal(msg.V); err != nil {
return
}
status := mp.inodeInTx(inoOnce.Inode)
status := mp.inodeInTx(inoOnceWithVersion.Inode)
if status != proto.OpOk {
resp = &InodeResponse{Status: status}
return
}
ino := NewInode(inoOnce.Inode, 0)
resp = mp.fsmCreateLinkInode(ino, inoOnce.UniqID)
ino := NewInode(inoOnceWithVersion.Inode, 0)
ino.setVer(inoOnceWithVersion.VerSeq)
resp = mp.fsmCreateLinkInode(ino, inoOnceWithVersion.UniqID)
case opFSMEvictInode:
ino := NewInode(0, 0)
if err = ino.Unmarshal(msg.V); err != nil {

View File

@ -347,9 +347,9 @@ func (mp *metaPartition) UnlinkInode(req *UnlinkInoReq, p *Packet, remoteAddr st
p.PacketErrorWithBody(proto.OpNotExistErr, []byte(err.Error()))
return
}
enableSnapshot := mp.manager != nil && mp.manager.metaNode != nil && mp.manager.metaNode.clusterEnableSnapshot
if req.UniqID > 0 {
val = InodeOnceUnlinkMarshal(req)
val = InodeOnceUnlinkMarshal(req, enableSnapshot)
r, err = mp.submit(opFSMUnlinkInodeOnce, val)
} else {
ino.setVer(req.VerSeq)

View File

@ -92,10 +92,22 @@ var (
type InodeOnce struct {
UniqID uint64
Inode uint64 // Inode ID
}
type InodeOnceWithVersion struct {
UniqID uint64
Inode uint64 // Inode ID
VerSeq uint64
}
func (i *InodeOnce) Marshal() (val []byte) {
val = make([]byte, inodeOnceSize)
binary.BigEndian.PutUint64(val[0:8], i.UniqID)
binary.BigEndian.PutUint64(val[8:16], i.Inode)
return val
}
func (i *InodeOnceWithVersion) Marshal() (val []byte) {
val = make([]byte, newInodeOnceSize)
binary.BigEndian.PutUint64(val[0:8], i.UniqID)
binary.BigEndian.PutUint64(val[8:16], i.Inode)
@ -103,13 +115,20 @@ func (i *InodeOnce) Marshal() (val []byte) {
return val
}
func InodeOnceUnlinkMarshal(req *UnlinkInoReq) []byte {
inoOnce := &InodeOnce{
func InodeOnceUnlinkMarshal(req *UnlinkInoReq, enableSnapshot bool) []byte {
if !enableSnapshot {
inoOnce := &InodeOnce{
UniqID: req.UniqID,
Inode: req.Inode,
}
return inoOnce.Marshal()
}
inoOnceWithVersion := &InodeOnceWithVersion{
UniqID: req.UniqID,
Inode: req.Inode,
VerSeq: req.VerSeq,
}
return inoOnce.Marshal()
return inoOnceWithVersion.Marshal()
}
func InodeOnceLinkMarshal(req *LinkInodeReq) []byte {
@ -120,14 +139,14 @@ func InodeOnceLinkMarshal(req *LinkInodeReq) []byte {
return inoOnce.Marshal()
}
func InodeOnceUnmarshal(val []byte) (i *InodeOnce, err error) {
i = &InodeOnce{}
func InodeOnceUnmarshal(val []byte) (i *InodeOnceWithVersion, err error) {
i = &InodeOnceWithVersion{}
if len(val) < inodeOnceSize {
return i, fmt.Errorf("size incorrect")
}
i.UniqID = binary.BigEndian.Uint64(val[0:8])
i.Inode = binary.BigEndian.Uint64(val[8:16])
if len(val) == 24 {
if len(val) == newInodeOnceSize {
i.VerSeq = binary.BigEndian.Uint64(val[16:24])
}
return