diff options
| author | chrislu <chris.lu@gmail.com> | 2022-07-08 00:29:39 -0700 |
|---|---|---|
| committer | chrislu <chris.lu@gmail.com> | 2022-07-08 00:29:39 -0700 |
| commit | 28add5a53451aa0be30cc03c2fda22c4056d602b (patch) | |
| tree | 42b4edc36230778f143fe4bec95f4aac9b602ee3 | |
| parent | a85ed3fe8fe8e6d5c69cf96836f6c80ce340ee8c (diff) | |
| download | seaweedfs-28add5a53451aa0be30cc03c2fda22c4056d602b.tar.xz seaweedfs-28add5a53451aa0be30cc03c2fda22c4056d602b.zip | |
mount: fix racing conditions
prevent wrong reading when the SingleChunkCacher is started, but not finished yet
| -rw-r--r-- | weed/filer/reader_cache.go | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/weed/filer/reader_cache.go b/weed/filer/reader_cache.go index bce97cc49..c319f6c78 100644 --- a/weed/filer/reader_cache.go +++ b/weed/filer/reader_cache.go @@ -19,6 +19,7 @@ type ReaderCache struct { type SingleChunkCacher struct { sync.RWMutex + cond *sync.Cond parent *ReaderCache chunkFileId string data []byte @@ -140,6 +141,7 @@ func newSingleChunkCacher(parent *ReaderCache, fileId string, cipherKey []byte, chunkSize: chunkSize, shouldCache: shouldCache, } + t.cond = sync.NewCond(t) return t } @@ -168,6 +170,7 @@ func (s *SingleChunkCacher) startCaching() { if s.shouldCache { s.parent.chunkCache.SetChunk(s.chunkFileId, s.data) } + s.cond.Broadcast() return } @@ -183,6 +186,10 @@ func (s *SingleChunkCacher) readChunkAt(buf []byte, offset int64) (int, error) { s.RLock() defer s.RUnlock() + for s.completedTime.IsZero() { + s.cond.Wait() + } + if s.err != nil { return 0, s.err } |
