Skip to content

Commit

Permalink
Simplify
Browse files Browse the repository at this point in the history
Signed-off-by: Changxin Miao <miaochangxin@step.ai>
  • Loading branch information
polyrabbit committed Jan 19, 2025
1 parent 1c13135 commit 136c3ae
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions pkg/meta/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"path"
"reflect"
"runtime"
"slices"

Check failure on line 29 in pkg/meta/base.go

View workflow job for this annotation

GitHub Actions / build (1.20)

package slices is not in GOROOT (/opt/hostedtoolcache/go/1.20.14/x64/src/slices)
"sort"
"strings"
"sync"
Expand Down Expand Up @@ -395,21 +396,18 @@ func (r *baseMeta) txBatchLock(inodes ...Ino) func() {
r.txLock(uint(inodes[0]))
return func() { r.txUnlock(uint(inodes[0])) }
default: // for rename and more
sort.Slice(inodes, func(i, j int) bool { return inodes[i]%nlocks < inodes[j]%nlocks })
lockedKeys := make(map[uint]struct{}, 2)
lockedInodes := make([]uint, 0, len(inodes))
for _, ino := range inodes {
ino := uint(ino)
if _, locked := lockedKeys[ino%nlocks]; locked {
continue // Go does not support recursive locks
}
lockedKeys[ino%nlocks] = struct{}{}
r.txLock(ino)
lockedInodes = append(lockedInodes, ino)
inodeSlots := make([]uint, len(inodes))
for i, ino := range inodes {
inodeSlots[i] = uint(ino) % nlocks
}
slices.Sort(inodeSlots)
inodeSlots = slices.Compact(inodeSlots) // Go does not support recursive locks
for _, idx := range inodeSlots {
r.txlocks[idx].Lock()
}
return func() {
for _, ino := range lockedInodes {
r.txUnlock(ino)
for _, idx := range inodeSlots {
r.txlocks[idx].Unlock()
}
}
}
Expand Down

0 comments on commit 136c3ae

Please sign in to comment.