mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
refactor
This commit is contained in:
parent
93e84a12f2
commit
735e65be17
|
@ -14,7 +14,7 @@ import (
|
||||||
type ContinuousDirtyPages struct {
|
type ContinuousDirtyPages struct {
|
||||||
intervals *ContinuousIntervals
|
intervals *ContinuousIntervals
|
||||||
f *File
|
f *File
|
||||||
fh *FileHandle
|
writeOnly bool
|
||||||
writeWaitGroup sync.WaitGroup
|
writeWaitGroup sync.WaitGroup
|
||||||
chunkAddLock sync.Mutex
|
chunkAddLock sync.Mutex
|
||||||
lastErr error
|
lastErr error
|
||||||
|
@ -22,10 +22,11 @@ type ContinuousDirtyPages struct {
|
||||||
replication string
|
replication string
|
||||||
}
|
}
|
||||||
|
|
||||||
func newDirtyPages(file *File) *ContinuousDirtyPages {
|
func newDirtyPages(file *File, writeOnly bool) *ContinuousDirtyPages {
|
||||||
dirtyPages := &ContinuousDirtyPages{
|
dirtyPages := &ContinuousDirtyPages{
|
||||||
intervals: &ContinuousIntervals{},
|
intervals: &ContinuousIntervals{},
|
||||||
f: file,
|
f: file,
|
||||||
|
writeOnly: writeOnly,
|
||||||
}
|
}
|
||||||
return dirtyPages
|
return dirtyPages
|
||||||
}
|
}
|
||||||
|
@ -106,7 +107,7 @@ func (pages *ContinuousDirtyPages) saveToStorage(reader io.Reader, offset int64,
|
||||||
defer pages.writeWaitGroup.Done()
|
defer pages.writeWaitGroup.Done()
|
||||||
|
|
||||||
reader = io.LimitReader(reader, size)
|
reader = io.LimitReader(reader, size)
|
||||||
chunk, collection, replication, err := pages.f.wfs.saveDataAsChunk(pages.f.fullpath(), pages.fh.writeOnly)(reader, pages.f.Name, offset)
|
chunk, collection, replication, err := pages.f.wfs.saveDataAsChunk(pages.f.fullpath(), pages.writeOnly)(reader, pages.f.Name, offset)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.V(0).Infof("%s saveToStorage [%d,%d): %v", pages.f.fullpath(), offset, offset+size, err)
|
glog.V(0).Infof("%s saveToStorage [%d,%d): %v", pages.f.fullpath(), offset, offset+size, err)
|
||||||
pages.lastErr = err
|
pages.lastErr = err
|
||||||
|
|
|
@ -35,14 +35,13 @@ type FileHandle struct {
|
||||||
writeOnly bool
|
writeOnly bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func newFileHandle(file *File, uid, gid uint32) *FileHandle {
|
func newFileHandle(file *File, uid, gid uint32, writeOnly bool) *FileHandle {
|
||||||
fh := &FileHandle{
|
fh := &FileHandle{
|
||||||
f: file,
|
f: file,
|
||||||
dirtyPages: newDirtyPages(file),
|
dirtyPages: newDirtyPages(file, writeOnly),
|
||||||
Uid: uid,
|
Uid: uid,
|
||||||
Gid: gid,
|
Gid: gid,
|
||||||
}
|
}
|
||||||
fh.dirtyPages.fh = fh
|
|
||||||
entry := fh.f.getEntry()
|
entry := fh.f.getEntry()
|
||||||
if entry != nil {
|
if entry != nil {
|
||||||
entry.Attributes.FileSize = filer.FileSize(entry)
|
entry.Attributes.FileSize = filer.FileSize(entry)
|
||||||
|
|
|
@ -159,8 +159,7 @@ func (wfs *WFS) AcquireHandle(file *File, uid, gid uint32, writeOnly bool) (file
|
||||||
|
|
||||||
entry, _ := file.maybeLoadEntry(context.Background())
|
entry, _ := file.maybeLoadEntry(context.Background())
|
||||||
file.entry = entry
|
file.entry = entry
|
||||||
fileHandle = newFileHandle(file, uid, gid)
|
fileHandle = newFileHandle(file, uid, gid, writeOnly)
|
||||||
fileHandle.writeOnly = writeOnly
|
|
||||||
file.isOpen++
|
file.isOpen++
|
||||||
|
|
||||||
wfs.handlesLock.Lock()
|
wfs.handlesLock.Lock()
|
||||||
|
|
Loading…
Reference in a new issue