Skip to content

Commit

Permalink
meta: get attr from open file cache if possible when updating atime
Browse files Browse the repository at this point in the history
To avoid getting attr from meta server on each atime update.

Signed-off-by: Eryu Guan <[email protected]>
  • Loading branch information
eryugey committed Apr 27, 2023
1 parent 0e90d62 commit 9daa5ed
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 16 deletions.
17 changes: 12 additions & 5 deletions pkg/meta/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -4256,22 +4256,29 @@ func (m *redisMeta) touchAtime(ctx Context, ino Ino) syscall.Errno {

return errno(m.txn(ctx, func(tx *redis.Tx) error {
var attr Attr
a, err := tx.Get(ctx, m.inodeKey(ino)).Bytes()
if err != nil {
return err
cached := m.of.Check(ino, &attr)
if !cached {
a, err := tx.Get(ctx, m.inodeKey(ino)).Bytes()
if err != nil {
return err
}
m.parseAttr(a, &attr)
}
m.parseAttr(a, &attr)

now := time.Now()
if !m.atimeNeedsUpdate(&attr, now) {
return nil
}
attr.Atime = now.Unix()
attr.Atimensec = uint32(now.Nanosecond())
_, err = tx.TxPipelined(ctx, func(pipe redis.Pipeliner) error {
_, err := tx.TxPipelined(ctx, func(pipe redis.Pipeliner) error {
pipe.Set(ctx, m.inodeKey(ino), m.marshal(&attr), 0)
return nil
})

if cached {
m.of.Update(ino, &attr)
}
return err
}, m.inodeKey(ino)))
}
21 changes: 14 additions & 7 deletions pkg/meta/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -3916,12 +3916,15 @@ func (m *dbMeta) touchAtime(ctx Context, ino Ino) syscall.Errno {
return errno(m.txn(func(s *xorm.Session) error {
var cur = node{Inode: ino}
var attr = Attr{}
ok, err := s.ForUpdate().Get(&cur)
if err != nil {
return err
}
if !ok {
return syscall.ENOENT
cached := m.of.Check(ino, &attr)
if !cached {
ok, err := s.ForUpdate().Get(&cur)
if err != nil {
return err
}
if !ok {
return syscall.ENOENT
}
}

now := time.Now()
Expand All @@ -3930,7 +3933,11 @@ func (m *dbMeta) touchAtime(ctx Context, ino Ino) syscall.Errno {
return nil
}
cur.Atime = now.Unix()*1e6 + int64(now.Nanosecond())/1e3
_, err = s.Cols("flags", "mode", "uid", "gid", "atime", "mtime", "ctime").Update(&cur, &node{Inode: ino})
_, err := s.Cols("flags", "mode", "uid", "gid", "atime", "mtime", "ctime").Update(&cur, &node{Inode: ino})

if cached {
m.of.Update(ino, &attr)
}
return err
}))
}
15 changes: 11 additions & 4 deletions pkg/meta/tkv.go
Original file line number Diff line number Diff line change
Expand Up @@ -3395,11 +3395,14 @@ func (m *kvMeta) touchAtime(_ctx Context, ino Ino) syscall.Errno {

return errno(m.txn(func(tx *kvTxn) error {
var attr Attr
a := tx.get(m.inodeKey(ino))
if a == nil {
return syscall.ENOENT
cached := m.of.Check(ino, &attr)
if !cached {
a := tx.get(m.inodeKey(ino))
if a == nil {
return syscall.ENOENT
}
m.parseAttr(a, &attr)
}
m.parseAttr(a, &attr)

now := time.Now()
if !m.atimeNeedsUpdate(&attr, now) {
Expand All @@ -3408,6 +3411,10 @@ func (m *kvMeta) touchAtime(_ctx Context, ino Ino) syscall.Errno {
attr.Atime = now.Unix()
attr.Atimensec = uint32(now.Nanosecond())
tx.set(m.inodeKey(ino), m.marshal(&attr))

if cached {
m.of.Update(ino, &attr)
}
return nil
}))
}

0 comments on commit 9daa5ed

Please sign in to comment.