diff options
| author | Chris Lu <chris.lu@gmail.com> | 2020-04-12 01:06:50 -0700 |
|---|---|---|
| committer | Chris Lu <chris.lu@gmail.com> | 2020-04-12 01:06:50 -0700 |
| commit | 2a1f396df5abd47e7fc4a58c3bc39675e1e84e4f (patch) | |
| tree | 2f43f458b784962cdd6e9318a1488cea99d7afd8 | |
| parent | b9b7da905ef9ef51d3e060ab1612becd63ab272d (diff) | |
| download | seaweedfs-2a1f396df5abd47e7fc4a58c3bc39675e1e84e4f.tar.xz seaweedfs-2a1f396df5abd47e7fc4a58c3bc39675e1e84e4f.zip | |
avoid duplicated setting chunks into cache
| -rw-r--r-- | weed/util/chunk_cache/chunk_cache.go | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/weed/util/chunk_cache/chunk_cache.go b/weed/util/chunk_cache/chunk_cache.go index ead7a8d0b..48e4bfb0d 100644 --- a/weed/util/chunk_cache/chunk_cache.go +++ b/weed/util/chunk_cache/chunk_cache.go @@ -54,6 +54,10 @@ func (c *ChunkCache) GetChunk(fileId string) (data []byte) { c.RLock() defer c.RUnlock() + return c.doGetChunk(fileId) +} + +func (c *ChunkCache) doGetChunk(fileId string) (data []byte) { if data = c.memCache.GetChunk(fileId); data != nil { return data } @@ -86,6 +90,13 @@ func (c *ChunkCache) SetChunk(fileId string, data []byte) { c.Lock() defer c.Unlock() + if existingData := c.doGetChunk(fileId); len(existingData)==0{ + c.doSetChunk(fileId, data) + } +} + +func (c *ChunkCache) doSetChunk(fileId string, data []byte) { + c.memCache.SetChunk(fileId, data) if len(c.diskCaches) == 0 { |
