feat(meta): return real accessTime for lcnode get req. #22639636

Signed-off-by: Victor1319 <zengxuewei@oppo.com>
This commit is contained in:
Victor1319 2024-09-25 19:36:22 +08:00 committed by AmazingChi
parent 63d0b94f57
commit 2694a71d5d
7 changed files with 62 additions and 6 deletions

View File

@ -54,6 +54,7 @@ func NewSnapshotScanner(adminTask *proto.AdminTask, l *LcNode) (*SnapshotScanner
Masters: l.masters,
Authenticate: false,
ValidateOwner: false,
InnerReq: true,
}
var metaWrapper *meta.MetaWrapper

View File

@ -205,9 +205,7 @@ func (mp *metaPartition) getInode(ino *Inode, listAll bool) (resp *InodeResponse
// if ctime > i.AccessTime {
// i.AccessTime = ctime
// }
respIno := i.Copy().(*Inode)
respIno.AccessTime = timeutil.GetCurrentTimeUnix()
resp.Msg = respIno
resp.Msg = i
return
}

View File

@ -26,6 +26,7 @@ import (
"github.com/cubefs/cubefs/util/auditlog"
"github.com/cubefs/cubefs/util/errors"
"github.com/cubefs/cubefs/util/log"
"github.com/cubefs/cubefs/util/timeutil"
)
func replyInfoNoCheck(info *proto.InodeInfo, ino *Inode) bool {
@ -606,14 +607,20 @@ func (mp *metaPartition) InodeGet(req *InodeGetReq, p *Packet) (err error) {
}
ino = retMsg.Msg
// return current time for user req
if !req.InnerReq {
ino = ino.Copy().(*Inode)
ino.AccessTime = timeutil.GetCurrentTimeUnix()
}
if retMsg.Status == proto.OpOk {
resp := &proto.InodeGetResponse{
Info: &proto.InodeInfo{},
}
if getAllVerInfo {
replyInfoNoCheck(resp.Info, retMsg.Msg)
replyInfoNoCheck(resp.Info, ino)
} else {
if !replyInfo(resp.Info, retMsg.Msg, quotaInfos) {
if !replyInfo(resp.Info, ino, quotaInfos) {
p.PacketErrorWithBody(status, reply)
return
@ -623,7 +630,7 @@ func (mp *metaPartition) InodeGet(req *InodeGetReq, p *Packet) (err error) {
status = proto.OpOk
if getAllVerInfo {
inode := mp.getInodeTopLayer(ino)
log.LogDebugf("req ino[%v], toplayer ino[%v]", retMsg.Msg, inode)
log.LogDebugf("req ino[%v], toplayer ino[%v]", ino, inode)
resp.LayAll = inode.Msg.getAllInodesInfo()
}
reply, err = json.Marshal(resp)

View File

@ -0,0 +1,46 @@
package metanode
import (
"encoding/json"
"testing"
"time"
"github.com/cubefs/cubefs/proto"
"github.com/stretchr/testify/require"
)
func TestInodeGet(t *testing.T) {
initMp(t)
inoId := uint64(time.Now().Unix())
ino := NewInode(inoId, 0)
ino.AccessTime = time.Now().Unix() - 3600
mp.inodeTree.ReplaceOrInsert(ino, false)
req := &InodeGetReq{
Inode: inoId,
}
now := time.Now()
time.Sleep(time.Second)
pkt := &Packet{}
err := mp.InodeGet(req, pkt)
require.True(t, pkt.ResultCode == proto.OpOk)
require.NoError(t, err)
resp := &proto.InodeGetResponse{}
err = json.Unmarshal(pkt.Data, resp)
require.NoError(t, err)
require.True(t, resp.Info.AccessTime.After(now))
req.InnerReq = true
err = mp.InodeGet(req, pkt)
require.NoError(t, err)
err = json.Unmarshal(pkt.Data, resp)
require.NoError(t, err)
require.True(t, resp.Info.AccessTime.Unix() == ino.AccessTime)
}

View File

@ -583,6 +583,7 @@ type InodeGetRequest struct {
Inode uint64 `json:"ino"`
VerSeq uint64 `json:"seq"`
VerAll bool `json:"verAll"`
InnerReq bool `json:"inner"`
}
type LayerInfo struct {

View File

@ -101,6 +101,7 @@ type MetaConfig struct {
TrashRebuildGoroutineLimit int
VerReadSeq uint64
InnerReq bool
}
type MetaWrapper struct {
@ -187,6 +188,7 @@ type MetaWrapper struct {
IsSnapshotEnabled bool
DefaultStorageClass uint32
CacheDpStorageClass uint32
InnerReq bool
}
type uniqidRange struct {

View File

@ -1037,6 +1037,7 @@ func (mw *MetaWrapper) iget(mp *MetaPartition, inode uint64, verSeq uint64) (sta
PartitionID: mp.PartitionID,
Inode: inode,
VerSeq: verSeq,
InnerReq: mw.InnerReq,
}
packet := proto.NewPacketReqID()