diff options
| author | chrislu <chris.lu@gmail.com> | 2024-08-07 10:41:58 -0700 |
|---|---|---|
| committer | chrislu <chris.lu@gmail.com> | 2024-08-07 10:42:00 -0700 |
| commit | 57dc39c4516e5f42e77164babfdcfd84be2d0d2d (patch) | |
| tree | c62ee8f6a2d3bbd4cd16769240abe6184c9ae530 /weed | |
| parent | 3e6ca6e7065a84f1a0a2a142358ac0c2fc0e9b48 (diff) | |
| download | seaweedfs-57dc39c4516e5f42e77164babfdcfd84be2d0d2d.tar.xz seaweedfs-57dc39c4516e5f42e77164babfdcfd84be2d0d2d.zip | |
randomizing next file handle id
Diffstat (limited to 'weed')
| -rw-r--r-- | weed/mount/filehandle_map.go | 5 | ||||
| -rw-r--r-- | weed/mount/weedfs_dir_read.go | 3 | ||||
| -rw-r--r-- | weed/util/bytes.go | 6 |
3 files changed, 11 insertions, 3 deletions
diff --git a/weed/mount/filehandle_map.go b/weed/mount/filehandle_map.go index bb78d0b14..288e0135d 100644 --- a/weed/mount/filehandle_map.go +++ b/weed/mount/filehandle_map.go @@ -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 { diff --git a/weed/mount/weedfs_dir_read.go b/weed/mount/weedfs_dir_read.go index 02ed72431..26e523a43 100644 --- a/weed/mount/weedfs_dir_read.go +++ b/weed/mount/weedfs_dir_read.go @@ -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() diff --git a/weed/util/bytes.go b/weed/util/bytes.go index 26da91033..482dc3a48 100644 --- a/weed/util/bytes.go +++ b/weed/util/bytes.go @@ -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) |
