Skip to content

Commit

Permalink
cmd/mount: add option skip-dir-mtime to eliminate burst mtime updat…
Browse files Browse the repository at this point in the history
…es of a directory (#4189)
  • Loading branch information
SandyXSD authored Nov 29, 2023
1 parent 52d7c7d commit ec24896
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 20 deletions.
5 changes: 5 additions & 0 deletions cmd/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,11 @@ func metaFlags() []cli.Flag {
Value: 20,
Usage: "number of retries after which the update of directory nlink will be skipped (used for tkv only, 0 means never)",
},
&cli.StringFlag{
Name: "skip-dir-mtime",
Value: "100ms",
Usage: "skip updating attribute of a directory if the mtime difference is smaller than this value",
},
})
}

Expand Down
1 change: 1 addition & 0 deletions cmd/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ func getMetaConf(c *cli.Context, mp string, readOnly bool) *meta.Config {
conf.Heartbeat = duration(c.String("heartbeat"))
conf.MountPoint = mp
conf.Subdir = c.String("subdir")
conf.SkipDirMtime = duration(c.String("skip-dir-mtime"))

atimeMode := c.String("atime-mode")
if atimeMode != meta.RelAtime && atimeMode != meta.StrictAtime && atimeMode != meta.NoAtime {
Expand Down
7 changes: 3 additions & 4 deletions pkg/meta/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,9 @@ import (
)

const (
inodeBatch = 1 << 10
sliceIdBatch = 4 << 10
minUpdateTime = time.Millisecond * 10
nlocks = 1024
inodeBatch = 1 << 10
sliceIdBatch = 4 << 10
nlocks = 1024
)

type engine interface {
Expand Down
1 change: 1 addition & 0 deletions pkg/meta/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type Config struct {
Subdir string
AtimeMode string
DirStatFlushPeriod time.Duration
SkipDirMtime time.Duration
}

func DefaultConf() *Config {
Expand Down
10 changes: 5 additions & 5 deletions pkg/meta/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -1282,7 +1282,7 @@ func (m *redisMeta) doMknod(ctx Context, parent Ino, name string, _type uint8, m
pattr.Nlink++
updateParent = true
}
if updateParent || now.Sub(time.Unix(pattr.Mtime, int64(pattr.Mtimensec))) >= minUpdateTime {
if updateParent || now.Sub(time.Unix(pattr.Mtime, int64(pattr.Mtimensec))) >= m.conf.SkipDirMtime {
pattr.Mtime = now.Unix()
pattr.Mtimensec = uint32(now.Nanosecond())
pattr.Ctime = now.Unix()
Expand Down Expand Up @@ -1393,7 +1393,7 @@ func (m *redisMeta) doUnlink(ctx Context, parent Ino, name string, attr *Attr, s
}
var updateParent bool
now := time.Now()
if !isTrash(parent) && now.Sub(time.Unix(pattr.Mtime, int64(pattr.Mtimensec))) >= minUpdateTime {
if !isTrash(parent) && now.Sub(time.Unix(pattr.Mtime, int64(pattr.Mtimensec))) >= m.conf.SkipDirMtime {
pattr.Mtime = now.Unix()
pattr.Mtimensec = uint32(now.Nanosecond())
pattr.Ctime = now.Unix()
Expand Down Expand Up @@ -1765,14 +1765,14 @@ func (m *redisMeta) doRename(ctx Context, parentSrc Ino, nameSrc string, parentD
iattr.Parent = parentDst
}
}
if supdate || now.Sub(time.Unix(sattr.Mtime, int64(sattr.Mtimensec))) >= minUpdateTime {
if supdate || now.Sub(time.Unix(sattr.Mtime, int64(sattr.Mtimensec))) >= m.conf.SkipDirMtime {
sattr.Mtime = now.Unix()
sattr.Mtimensec = uint32(now.Nanosecond())
sattr.Ctime = now.Unix()
sattr.Ctimensec = uint32(now.Nanosecond())
supdate = true
}
if dupdate || now.Sub(time.Unix(dattr.Mtime, int64(dattr.Mtimensec))) >= minUpdateTime {
if dupdate || now.Sub(time.Unix(dattr.Mtime, int64(dattr.Mtimensec))) >= m.conf.SkipDirMtime {
dattr.Mtime = now.Unix()
dattr.Mtimensec = uint32(now.Nanosecond())
dattr.Ctime = now.Unix()
Expand Down Expand Up @@ -1901,7 +1901,7 @@ func (m *redisMeta) doLink(ctx Context, inode, parent Ino, name string, attr *At
}
var updateParent bool
now := time.Now()
if now.Sub(time.Unix(pattr.Mtime, int64(pattr.Mtimensec))) >= minUpdateTime {
if now.Sub(time.Unix(pattr.Mtime, int64(pattr.Mtimensec))) >= m.conf.SkipDirMtime {
pattr.Mtime = now.Unix()
pattr.Mtimensec = uint32(now.Nanosecond())
pattr.Ctime = now.Unix()
Expand Down
10 changes: 5 additions & 5 deletions pkg/meta/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -1285,7 +1285,7 @@ func (m *dbMeta) doMknod(ctx Context, parent Ino, name string, _type uint8, mode
pn.Nlink++
updateParent = true
}
if updateParent || time.Duration(now-pn.Mtime*1e3-int64(pn.Mtimensec)) >= minUpdateTime {
if updateParent || time.Duration(now-pn.Mtime*1e3-int64(pn.Mtimensec)) >= m.conf.SkipDirMtime {
pn.Mtime = now / 1e3
pn.Ctime = now / 1e3
updateParent = true
Expand Down Expand Up @@ -1426,7 +1426,7 @@ func (m *dbMeta) doUnlink(ctx Context, parent Ino, name string, attr *Attr, skip
defer func() { m.of.InvalidateChunk(e.Inode, invalidateAttrOnly) }()

var updateParent bool
if !isTrash(parent) && time.Duration(now-pn.Mtime*1e3-int64(pn.Mtimensec)) >= minUpdateTime {
if !isTrash(parent) && time.Duration(now-pn.Mtime*1e3-int64(pn.Mtimensec)) >= m.conf.SkipDirMtime {
pn.Mtime = now / 1e3
pn.Ctime = now / 1e3
pn.Mtimensec = int16(now % 1e3)
Expand Down Expand Up @@ -1810,14 +1810,14 @@ func (m *dbMeta) doRename(ctx Context, parentSrc Ino, nameSrc string, parentDst
sn.Parent = parentDst
}
}
if supdate || time.Duration(now-spn.Mtime*1e3-int64(spn.Mtimensec)) >= minUpdateTime {
if supdate || time.Duration(now-spn.Mtime*1e3-int64(spn.Mtimensec)) >= m.conf.SkipDirMtime {
spn.Mtime = now / 1e3
spn.Ctime = now / 1e3
spn.Mtimensec = int16(now % 1e3)
spn.Ctimensec = int16(now % 1e3)
supdate = true
}
if dupdate || time.Duration(now-dpn.Mtime*1e3-int64(dpn.Mtimensec)) >= minUpdateTime {
if dupdate || time.Duration(now-dpn.Mtime*1e3-int64(dpn.Mtimensec)) >= m.conf.SkipDirMtime {
dpn.Mtime = now / 1e3
dpn.Ctime = now / 1e3
dpn.Mtimensec = int16(now % 1e3)
Expand Down Expand Up @@ -1984,7 +1984,7 @@ func (m *dbMeta) doLink(ctx Context, inode, parent Ino, name string, attr *Attr)

var updateParent bool
now := time.Now().UnixNano()
if time.Duration(now-pn.Mtime*1e3-int64(pn.Mtimensec)) >= minUpdateTime {
if time.Duration(now-pn.Mtime*1e3-int64(pn.Mtimensec)) >= m.conf.SkipDirMtime {
pn.Mtime = now / 1e3
pn.Ctime = now / 1e3
updateParent = true
Expand Down
12 changes: 6 additions & 6 deletions pkg/meta/tkv.go
Original file line number Diff line number Diff line change
Expand Up @@ -1173,7 +1173,7 @@ func (m *kvMeta) doMknod(ctx Context, parent Ino, name string, _type uint8, mode
logger.Warnf("Skip updating nlink of directory %d to reduce conflict", parent)
}
}
if updateParent || now.Sub(time.Unix(pattr.Mtime, int64(pattr.Mtimensec))) >= minUpdateTime*time.Duration(tx.retry+1) {
if updateParent || now.Sub(time.Unix(pattr.Mtime, int64(pattr.Mtimensec))) >= m.conf.SkipDirMtime*time.Duration(tx.retry+1) {
pattr.Mtime = now.Unix()
pattr.Mtimensec = uint32(now.Nanosecond())
pattr.Ctime = now.Unix()
Expand Down Expand Up @@ -1303,7 +1303,7 @@ func (m *kvMeta) doUnlink(ctx Context, parent Ino, name string, attr *Attr, skip

defer func() { m.of.InvalidateChunk(inode, invalidateAttrOnly) }()
var updateParent bool
if !isTrash(parent) && now.Sub(time.Unix(pattr.Mtime, int64(pattr.Mtimensec))) >= minUpdateTime*time.Duration(tx.retry+1) {
if !isTrash(parent) && now.Sub(time.Unix(pattr.Mtime, int64(pattr.Mtimensec))) >= m.conf.SkipDirMtime*time.Duration(tx.retry+1) {
pattr.Mtime = now.Unix()
pattr.Mtimensec = uint32(now.Nanosecond())
pattr.Ctime = now.Unix()
Expand Down Expand Up @@ -1426,7 +1426,7 @@ func (m *kvMeta) doRmdir(ctx Context, parent Ino, name string, pinode *Ino, skip
} else {
logger.Warnf("Skip updating nlink of directory %d to reduce conflict", parent)
}
if updateParent || now.Sub(time.Unix(pattr.Mtime, int64(pattr.Mtimensec))) >= minUpdateTime*time.Duration(tx.retry+1) {
if updateParent || now.Sub(time.Unix(pattr.Mtime, int64(pattr.Mtimensec))) >= m.conf.SkipDirMtime*time.Duration(tx.retry+1) {
pattr.Mtime = now.Unix()
pattr.Mtimensec = uint32(now.Nanosecond())
pattr.Ctime = now.Unix()
Expand Down Expand Up @@ -1611,14 +1611,14 @@ func (m *kvMeta) doRename(ctx Context, parentSrc Ino, nameSrc string, parentDst
iattr.Parent = parentDst
}
}
if supdate || now.Sub(time.Unix(sattr.Mtime, int64(sattr.Mtimensec))) >= minUpdateTime*time.Duration(tx.retry+1) {
if supdate || now.Sub(time.Unix(sattr.Mtime, int64(sattr.Mtimensec))) >= m.conf.SkipDirMtime*time.Duration(tx.retry+1) {
sattr.Mtime = now.Unix()
sattr.Mtimensec = uint32(now.Nanosecond())
sattr.Ctime = now.Unix()
sattr.Ctimensec = uint32(now.Nanosecond())
supdate = true
}
if dupdate || now.Sub(time.Unix(dattr.Mtime, int64(dattr.Mtimensec))) >= minUpdateTime*time.Duration(tx.retry+1) {
if dupdate || now.Sub(time.Unix(dattr.Mtime, int64(dattr.Mtimensec))) >= m.conf.SkipDirMtime*time.Duration(tx.retry+1) {
dattr.Mtime = now.Unix()
dattr.Mtimensec = uint32(now.Nanosecond())
dattr.Ctime = now.Unix()
Expand Down Expand Up @@ -1746,7 +1746,7 @@ func (m *kvMeta) doLink(ctx Context, inode, parent Ino, name string, attr *Attr)

var updateParent bool
now := time.Now()
if now.Sub(time.Unix(pattr.Mtime, int64(pattr.Mtimensec))) >= minUpdateTime*time.Duration(tx.retry+1) {
if now.Sub(time.Unix(pattr.Mtime, int64(pattr.Mtimensec))) >= m.conf.SkipDirMtime*time.Duration(tx.retry+1) {
pattr.Mtime = now.Unix()
pattr.Mtimensec = uint32(now.Nanosecond())
pattr.Ctime = now.Unix()
Expand Down

0 comments on commit ec24896

Please sign in to comment.