mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-09-19 14:47:57 +08:00
mount: fix racing conditions
prevent wrong reading when the SingleChunkCacher is started, but not finished yet
This commit is contained in:
@@ -19,6 +19,7 @@ type ReaderCache struct {
|
|||||||
|
|
||||||
type SingleChunkCacher struct {
|
type SingleChunkCacher struct {
|
||||||
sync.RWMutex
|
sync.RWMutex
|
||||||
|
cond *sync.Cond
|
||||||
parent *ReaderCache
|
parent *ReaderCache
|
||||||
chunkFileId string
|
chunkFileId string
|
||||||
data []byte
|
data []byte
|
||||||
@@ -140,6 +141,7 @@ func newSingleChunkCacher(parent *ReaderCache, fileId string, cipherKey []byte,
|
|||||||
chunkSize: chunkSize,
|
chunkSize: chunkSize,
|
||||||
shouldCache: shouldCache,
|
shouldCache: shouldCache,
|
||||||
}
|
}
|
||||||
|
t.cond = sync.NewCond(t)
|
||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -168,6 +170,7 @@ func (s *SingleChunkCacher) startCaching() {
|
|||||||
if s.shouldCache {
|
if s.shouldCache {
|
||||||
s.parent.chunkCache.SetChunk(s.chunkFileId, s.data)
|
s.parent.chunkCache.SetChunk(s.chunkFileId, s.data)
|
||||||
}
|
}
|
||||||
|
s.cond.Broadcast()
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -183,6 +186,10 @@ func (s *SingleChunkCacher) readChunkAt(buf []byte, offset int64) (int, error) {
|
|||||||
s.RLock()
|
s.RLock()
|
||||||
defer s.RUnlock()
|
defer s.RUnlock()
|
||||||
|
|
||||||
|
for s.completedTime.IsZero() {
|
||||||
|
s.cond.Wait()
|
||||||
|
}
|
||||||
|
|
||||||
if s.err != nil {
|
if s.err != nil {
|
||||||
return 0, s.err
|
return 0, s.err
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user