diff --git a/pkg/meta/redis.go b/pkg/meta/redis.go index d4e64db316962..1454b902b24dc 100644 --- a/pkg/meta/redis.go +++ b/pkg/meta/redis.go @@ -4269,34 +4269,23 @@ func (m *redisMeta) touchAtime(ctx Context, ino Ino, cur *Attr) (rerr syscall.Er } }() - now := time.Now() - - // Already got attr, update atime without transaction - if attr != nil { - if !m.atimeNeedsUpdate(attr, now) { - return 0 - } - attr.Atime = now.Unix() - attr.Atimensec = uint32(now.Nanosecond()) - updated = true - return errno(m.rdb.Set(ctx, m.inodeKey(ino), m.marshal(attr), 0).Err()) - } - - // Should get attr first, do it in transaction return errno(m.txn(ctx, func(tx *redis.Tx) error { - attr = newAttr - a, err := tx.Get(ctx, m.inodeKey(ino)).Bytes() - if err != nil { - return err + if attr == nil { + attr = newAttr + 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 }) diff --git a/pkg/meta/sql.go b/pkg/meta/sql.go index 427473b77a244..614f69e14a63e 100644 --- a/pkg/meta/sql.go +++ b/pkg/meta/sql.go @@ -3929,38 +3929,25 @@ func (m *dbMeta) touchAtime(ctx Context, ino Ino, cur *Attr) (rerr syscall.Errno } }() - now := time.Now() - - // Already got attr, update atime without transaction - if attr != nil { - if !m.atimeNeedsUpdate(attr, now) { - return 0 - } - curNode.Atime = now.Unix()*1e6 + int64(now.Nanosecond())/1e3 - s := m.db.NewSession() - defer s.Close() - _, err := s.Cols("atime").Update(&curNode, &node{Inode: ino}) - updated = true - return errno(err) - } - - // Should get attr first, do it in transaction return errno(m.txn(func(s *xorm.Session) error { - attr = newAttr - ok, err := s.ForUpdate().Get(&curNode) - if err != nil { - return err - } - if !ok { - return syscall.ENOENT + if attr == nil { + attr = newAttr + ok, err := s.ForUpdate().Get(&curNode) + if err != nil { + return err + } + if !ok { + return syscall.ENOENT + } + m.parseAttr(&curNode, attr) } - m.parseAttr(&curNode, attr) + now := time.Now() if !m.atimeNeedsUpdate(attr, now) { return nil } curNode.Atime = now.Unix()*1e6 + int64(now.Nanosecond())/1e3 - _, err = s.Cols("atime").Update(&curNode, &node{Inode: ino}) + _, err := s.Cols("atime").Update(&curNode, &node{Inode: ino}) updated = true return err })) diff --git a/pkg/meta/tkv.go b/pkg/meta/tkv.go index 8e8af9763cd09..6ff2654b93ea1 100644 --- a/pkg/meta/tkv.go +++ b/pkg/meta/tkv.go @@ -3408,30 +3408,15 @@ func (m *kvMeta) touchAtime(_ctx Context, ino Ino, cur *Attr) (rerr syscall.Errn } }() - now := time.Now() - - // Already got attr, update atime without transaction - if attr != nil { - if !m.atimeNeedsUpdate(attr, now) { - return 0 - } - attr.Atime = now.Unix() - attr.Atimensec = uint32(now.Nanosecond()) - updated = true - return errno(m.client.txn(func(tx *kvTxn) error { - tx.set(m.inodeKey(ino), m.marshal(attr)) - return nil - }, 0)) - } - - // Should get attr first, do it in transaction - return errno(m.txn(func(tx *kvTxn) error { - attr = newAttr - a := tx.get(m.inodeKey(ino)) - if a == nil { - return syscall.ENOENT + return errno(m.client.txn(func(tx *kvTxn) error { + if attr == nil { + attr = newAttr + 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) { @@ -3442,5 +3427,5 @@ func (m *kvMeta) touchAtime(_ctx Context, ino Ino, cur *Attr) (rerr syscall.Errn tx.set(m.inodeKey(ino), m.marshal(attr)) updated = true return nil - })) + }, 0)) }