|
@ -3,7 +3,6 @@ package filesys |
|
|
import ( |
|
|
import ( |
|
|
"bytes" |
|
|
"bytes" |
|
|
"io" |
|
|
"io" |
|
|
"runtime" |
|
|
|
|
|
"sync" |
|
|
"sync" |
|
|
"time" |
|
|
"time" |
|
|
|
|
|
|
|
@ -16,8 +15,6 @@ type ContinuousDirtyPages struct { |
|
|
f *File |
|
|
f *File |
|
|
writeWaitGroup sync.WaitGroup |
|
|
writeWaitGroup sync.WaitGroup |
|
|
chunkAddLock sync.Mutex |
|
|
chunkAddLock sync.Mutex |
|
|
chunkSaveErrChan chan error |
|
|
|
|
|
chunkSaveErrChanClosed bool |
|
|
|
|
|
lastErr error |
|
|
lastErr error |
|
|
collection string |
|
|
collection string |
|
|
replication string |
|
|
replication string |
|
@ -27,15 +24,7 @@ func newDirtyPages(file *File) *ContinuousDirtyPages { |
|
|
dirtyPages := &ContinuousDirtyPages{ |
|
|
dirtyPages := &ContinuousDirtyPages{ |
|
|
intervals: &ContinuousIntervals{}, |
|
|
intervals: &ContinuousIntervals{}, |
|
|
f: file, |
|
|
f: file, |
|
|
chunkSaveErrChan: make(chan error, runtime.NumCPU()), |
|
|
|
|
|
} |
|
|
} |
|
|
go func() { |
|
|
|
|
|
for t := range dirtyPages.chunkSaveErrChan { |
|
|
|
|
|
if t != nil { |
|
|
|
|
|
dirtyPages.lastErr = t |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
}() |
|
|
|
|
|
return dirtyPages |
|
|
return dirtyPages |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -94,15 +83,6 @@ func (pages *ContinuousDirtyPages) saveExistingLargestPageToStorage() (hasSavedD |
|
|
|
|
|
|
|
|
func (pages *ContinuousDirtyPages) saveToStorage(reader io.Reader, offset int64, size int64) { |
|
|
func (pages *ContinuousDirtyPages) saveToStorage(reader io.Reader, offset int64, size int64) { |
|
|
|
|
|
|
|
|
errChanSize := pages.f.wfs.option.ConcurrentWriters |
|
|
|
|
|
if errChanSize == 0 { |
|
|
|
|
|
errChanSize = runtime.NumCPU() |
|
|
|
|
|
} |
|
|
|
|
|
if pages.chunkSaveErrChanClosed { |
|
|
|
|
|
pages.chunkSaveErrChan = make(chan error, errChanSize) |
|
|
|
|
|
pages.chunkSaveErrChanClosed = false |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
mtime := time.Now().UnixNano() |
|
|
mtime := time.Now().UnixNano() |
|
|
pages.writeWaitGroup.Add(1) |
|
|
pages.writeWaitGroup.Add(1) |
|
|
writer := func() { |
|
|
writer := func() { |
|
@ -112,7 +92,7 @@ func (pages *ContinuousDirtyPages) saveToStorage(reader io.Reader, offset int64, |
|
|
chunk, collection, replication, err := pages.f.wfs.saveDataAsChunk(pages.f.fullpath())(reader, pages.f.Name, offset) |
|
|
chunk, collection, replication, err := pages.f.wfs.saveDataAsChunk(pages.f.fullpath())(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.chunkSaveErrChan <- err |
|
|
|
|
|
|
|
|
pages.lastErr = err |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
chunk.Mtime = mtime |
|
|
chunk.Mtime = mtime |
|
|