Browse Source

refactor

pull/2063/head
Chris Lu 4 years ago
parent
commit
735e65be17
  1. 7
      weed/filesys/dirty_page.go
  2. 5
      weed/filesys/filehandle.go
  3. 3
      weed/filesys/wfs.go

7
weed/filesys/dirty_page.go

@ -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

5
weed/filesys/filehandle.go

@ -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)

3
weed/filesys/wfs.go

@ -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.writeOnly = writeOnly
fileHandle = newFileHandle(file, uid, gid, writeOnly)
file.isOpen++ file.isOpen++
wfs.handlesLock.Lock() wfs.handlesLock.Lock()

Loading…
Cancel
Save