mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-11-27 12:49:41 +08:00
randomizing next file handle id
This commit is contained in:
parent
3e6ca6e706
commit
57dc39c451
@ -1,6 +1,7 @@
|
||||
package mount
|
||||
|
||||
import (
|
||||
"github.com/seaweedfs/seaweedfs/weed/util"
|
||||
"sync"
|
||||
|
||||
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
|
||||
@ -17,7 +18,7 @@ func NewFileHandleToInode() *FileHandleToInode {
|
||||
return &FileHandleToInode{
|
||||
inode2fh: make(map[uint64]*FileHandle),
|
||||
fh2inode: make(map[FileHandleId]uint64),
|
||||
nextFh: 0,
|
||||
nextFh: FileHandleId(util.RandomUint64()),
|
||||
}
|
||||
}
|
||||
|
||||
@ -44,7 +45,7 @@ func (i *FileHandleToInode) AcquireFileHandle(wfs *WFS, inode uint64, entry *fil
|
||||
fh, found := i.inode2fh[inode]
|
||||
if !found {
|
||||
fh = newFileHandle(wfs, i.nextFh, inode, entry)
|
||||
i.nextFh++
|
||||
i.nextFh = FileHandleId(util.RandomUint64())
|
||||
i.inode2fh[inode] = fh
|
||||
i.fh2inode[fh.fh] = inode
|
||||
} else {
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"github.com/seaweedfs/seaweedfs/weed/filer"
|
||||
"github.com/seaweedfs/seaweedfs/weed/glog"
|
||||
"github.com/seaweedfs/seaweedfs/weed/mount/meta_cache"
|
||||
"github.com/seaweedfs/seaweedfs/weed/util"
|
||||
"math"
|
||||
"sync"
|
||||
)
|
||||
@ -45,7 +46,7 @@ func NewDirectoryHandleToInode() *DirectoryHandleToInode {
|
||||
func (wfs *WFS) AcquireDirectoryHandle() (DirectoryHandleId, *DirectoryHandle) {
|
||||
wfs.fhmap.Lock()
|
||||
fh := wfs.fhmap.nextFh
|
||||
wfs.fhmap.nextFh++
|
||||
wfs.fhmap.nextFh = FileHandleId(util.RandomUint64())
|
||||
wfs.fhmap.Unlock()
|
||||
|
||||
wfs.dhmap.Lock()
|
||||
|
@ -148,6 +148,12 @@ func RandomInt32() int32 {
|
||||
return int32(BytesToUint32(buf))
|
||||
}
|
||||
|
||||
func RandomUint64() int32 {
|
||||
buf := make([]byte, 8)
|
||||
rand.Read(buf)
|
||||
return int32(BytesToUint64(buf))
|
||||
}
|
||||
|
||||
func RandomBytes(byteCount int) []byte {
|
||||
buf := make([]byte, byteCount)
|
||||
rand.Read(buf)
|
||||
|
Loading…
Reference in New Issue
Block a user