diff options
| author | bukton <buk_ton2@hotmail.com> | 2020-04-19 00:21:45 +0700 |
|---|---|---|
| committer | bukton <buk_ton2@hotmail.com> | 2020-04-19 00:21:45 +0700 |
| commit | 290c6b7f01f7b148a65ba10dd6536ad2567d7653 (patch) | |
| tree | e1abb141849419c40691097eea032b944fcbd748 /weed/filesys/fscache.go | |
| parent | 6234ea441b6388838a19635c656316047f42917d (diff) | |
| parent | 11f5a6d91346e5f3cbf3b46e0a660e231c5c2998 (diff) | |
| download | seaweedfs-290c6b7f01f7b148a65ba10dd6536ad2567d7653.tar.xz seaweedfs-290c6b7f01f7b148a65ba10dd6536ad2567d7653.zip | |
Merge remote-tracking branch 'origin/master' into filer_mongodb
# Conflicts:
# go.mod
# go.sum
# weed/server/filer_server.go
Diffstat (limited to 'weed/filesys/fscache.go')
| -rw-r--r-- | weed/filesys/fscache.go | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/weed/filesys/fscache.go b/weed/filesys/fscache.go index ca8c7de5b..b146f0615 100644 --- a/weed/filesys/fscache.go +++ b/weed/filesys/fscache.go @@ -9,6 +9,7 @@ import ( type FsCache struct { root *FsNode + sync.RWMutex } type FsNode struct { parent *FsNode @@ -27,6 +28,14 @@ func newFsCache(root fs.Node) *FsCache { } func (c *FsCache) GetFsNode(path util.FullPath) fs.Node { + + c.RLock() + defer c.RUnlock() + + return c.doGetFsNode(path) +} + +func (c *FsCache) doGetFsNode(path util.FullPath) fs.Node { t := c.root for _, p := range path.Split() { t = t.findChild(p) @@ -38,6 +47,14 @@ func (c *FsCache) GetFsNode(path util.FullPath) fs.Node { } func (c *FsCache) SetFsNode(path util.FullPath, node fs.Node) { + + c.Lock() + defer c.Unlock() + + c.doSetFsNode(path, node) +} + +func (c *FsCache) doSetFsNode(path util.FullPath, node fs.Node) { t := c.root for _, p := range path.Split() { t = t.ensureChild(p) @@ -46,16 +63,24 @@ func (c *FsCache) SetFsNode(path util.FullPath, node fs.Node) { } func (c *FsCache) EnsureFsNode(path util.FullPath, genNodeFn func() fs.Node) fs.Node { - t := c.GetFsNode(path) + + c.Lock() + defer c.Unlock() + + t := c.doGetFsNode(path) if t != nil { return t } t = genNodeFn() - c.SetFsNode(path, t) + c.doSetFsNode(path, t) return t } func (c *FsCache) DeleteFsNode(path util.FullPath) { + + c.Lock() + defer c.Unlock() + t := c.root for _, p := range path.Split() { t = t.findChild(p) @@ -72,6 +97,9 @@ func (c *FsCache) DeleteFsNode(path util.FullPath) { // oldPath and newPath are full path including the new name func (c *FsCache) Move(oldPath util.FullPath, newPath util.FullPath) *FsNode { + c.Lock() + defer c.Unlock() + // find old node src := c.root for _, p := range oldPath.Split() { |
