Skip to content

Commit

Permalink
meta: update atime in transaction
Browse files Browse the repository at this point in the history
Signed-off-by: Eryu Guan <[email protected]>
  • Loading branch information
eryugey committed May 9, 2023
1 parent 13bd564 commit abbe13e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 53 deletions.
23 changes: 8 additions & 15 deletions pkg/meta/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -4262,29 +4262,22 @@ func (m *redisMeta) touchAtime(ctx Context, ino Ino, cur *Attr) (rerr syscall.Er
attr = newAttr
}

now := time.Now()
if attr != nil && !m.atimeNeedsUpdate(attr, now) {
return 0
}

updated := false
defer func() {
if rerr == 0 && m.of.IsOpen(ino) && updated {
m.of.Update(ino, attr)
}
}()

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
if attr == nil {
attr = newAttr
}
a, err := tx.Get(ctx, m.inodeKey(ino)).Bytes()
if err != nil {
return err
Expand Down
27 changes: 9 additions & 18 deletions pkg/meta/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -3922,40 +3922,31 @@ func (m *dbMeta) touchAtime(ctx Context, ino Ino, cur *Attr) (rerr syscall.Errno
attr = newAttr
}

now := time.Now()
if attr != nil && !m.atimeNeedsUpdate(attr, now) {
return 0
}

updated := false
defer func() {
if rerr == 0 && m.of.IsOpen(ino) && updated {
m.of.Update(ino, attr)
}
}()

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
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)

if !m.atimeNeedsUpdate(attr, now) {
return nil
}
Expand Down
29 changes: 9 additions & 20 deletions pkg/meta/tkv.go
Original file line number Diff line number Diff line change
Expand Up @@ -3401,39 +3401,28 @@ func (m *kvMeta) touchAtime(_ctx Context, ino Ino, cur *Attr) (rerr syscall.Errn
attr = newAttr
}

now := time.Now()
if attr != nil && !m.atimeNeedsUpdate(attr, now) {
return 0
}

updated := false
defer func() {
if rerr == 0 && m.of.IsOpen(ino) && updated {
m.of.Update(ino, attr)
}
}()

now := time.Now()

// Already got attr, update atime without transaction
if attr != nil {
if !m.atimeNeedsUpdate(attr, now) {
return 0
return errno(m.client.txn(func(tx *kvTxn) error {
if attr == nil {
attr = newAttr
}
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
}
m.parseAttr(a, attr)

now := time.Now()
if !m.atimeNeedsUpdate(attr, now) {
return nil
}
Expand All @@ -3442,5 +3431,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))
}

0 comments on commit abbe13e

Please sign in to comment.