From 003d48da21b0ecd0758d79bfed234cb2bf820398 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Sat, 15 Aug 2020 19:55:28 -0700 Subject: adjust logs --- weed/util/chunk_cache/chunk_cache.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'weed/util/chunk_cache/chunk_cache.go') diff --git a/weed/util/chunk_cache/chunk_cache.go b/weed/util/chunk_cache/chunk_cache.go index 17b64fb6c..b54b40dbb 100644 --- a/weed/util/chunk_cache/chunk_cache.go +++ b/weed/util/chunk_cache/chunk_cache.go @@ -89,7 +89,7 @@ func (c *ChunkCache) SetChunk(fileId string, data []byte) { c.Lock() defer c.Unlock() - glog.V(4).Infof("SetChunk %s size %d\n", fileId, len(data)) + glog.V(5).Infof("SetChunk %s size %d\n", fileId, len(data)) c.doSetChunk(fileId, data) } -- cgit v1.2.3 From 97e54a80d4e20ea10a258c281df01efca2fb03dc Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Mon, 17 Aug 2020 16:05:13 -0700 Subject: rename variables --- weed/util/chunk_cache/chunk_cache.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'weed/util/chunk_cache/chunk_cache.go') diff --git a/weed/util/chunk_cache/chunk_cache.go b/weed/util/chunk_cache/chunk_cache.go index b54b40dbb..6c6a45920 100644 --- a/weed/util/chunk_cache/chunk_cache.go +++ b/weed/util/chunk_cache/chunk_cache.go @@ -33,7 +33,7 @@ func NewChunkCache(maxEntries int64, dir string, diskSizeMB int64) *ChunkCache { return c } -func (c *ChunkCache) GetChunk(fileId string, chunkSize uint64) (data []byte) { +func (c *ChunkCache) GetChunk(fileId string, minSize uint64) (data []byte) { if c == nil { return } @@ -41,14 +41,14 @@ func (c *ChunkCache) GetChunk(fileId string, chunkSize uint64) (data []byte) { c.RLock() defer c.RUnlock() - return c.doGetChunk(fileId, chunkSize) + return c.doGetChunk(fileId, minSize) } -func (c *ChunkCache) doGetChunk(fileId string, chunkSize uint64) (data []byte) { +func (c *ChunkCache) doGetChunk(fileId string, minSize uint64) (data []byte) { - if chunkSize < memCacheSizeLimit { + if minSize < memCacheSizeLimit { data = c.memCache.GetChunk(fileId) - if len(data) >= int(chunkSize) { + if len(data) >= int(minSize) { return data } } @@ -59,21 +59,21 @@ func (c *ChunkCache) doGetChunk(fileId string, chunkSize uint64) (data []byte) { return nil } - if chunkSize < onDiskCacheSizeLimit0 { + if minSize < onDiskCacheSizeLimit0 { data = c.diskCaches[0].getChunk(fid.Key) - if len(data) >= int(chunkSize) { + if len(data) >= int(minSize) { return data } } - if chunkSize < onDiskCacheSizeLimit1 { + if minSize < onDiskCacheSizeLimit1 { data = c.diskCaches[1].getChunk(fid.Key) - if len(data) >= int(chunkSize) { + if len(data) >= int(minSize) { return data } } { data = c.diskCaches[2].getChunk(fid.Key) - if len(data) >= int(chunkSize) { + if len(data) >= int(minSize) { return data } } -- cgit v1.2.3 From be4d42b8e2bffd4a5ff650611f2cfb8c058ca26b Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Mon, 17 Aug 2020 20:15:53 -0700 Subject: rename --- weed/util/chunk_cache/chunk_cache.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'weed/util/chunk_cache/chunk_cache.go') diff --git a/weed/util/chunk_cache/chunk_cache.go b/weed/util/chunk_cache/chunk_cache.go index 6c6a45920..d01e2163b 100644 --- a/weed/util/chunk_cache/chunk_cache.go +++ b/weed/util/chunk_cache/chunk_cache.go @@ -14,15 +14,15 @@ const ( ) // a global cache for recently accessed file chunks -type ChunkCache struct { +type TieredChunkCache struct { memCache *ChunkCacheInMemory diskCaches []*OnDiskCacheLayer sync.RWMutex } -func NewChunkCache(maxEntries int64, dir string, diskSizeMB int64) *ChunkCache { +func NewTieredChunkCache(maxEntries int64, dir string, diskSizeMB int64) *TieredChunkCache { - c := &ChunkCache{ + c := &TieredChunkCache{ memCache: NewChunkCacheInMemory(maxEntries), } c.diskCaches = make([]*OnDiskCacheLayer, 3) @@ -33,7 +33,7 @@ func NewChunkCache(maxEntries int64, dir string, diskSizeMB int64) *ChunkCache { return c } -func (c *ChunkCache) GetChunk(fileId string, minSize uint64) (data []byte) { +func (c *TieredChunkCache) GetChunk(fileId string, minSize uint64) (data []byte) { if c == nil { return } @@ -44,7 +44,7 @@ func (c *ChunkCache) GetChunk(fileId string, minSize uint64) (data []byte) { return c.doGetChunk(fileId, minSize) } -func (c *ChunkCache) doGetChunk(fileId string, minSize uint64) (data []byte) { +func (c *TieredChunkCache) doGetChunk(fileId string, minSize uint64) (data []byte) { if minSize < memCacheSizeLimit { data = c.memCache.GetChunk(fileId) @@ -82,7 +82,7 @@ func (c *ChunkCache) doGetChunk(fileId string, minSize uint64) (data []byte) { } -func (c *ChunkCache) SetChunk(fileId string, data []byte) { +func (c *TieredChunkCache) SetChunk(fileId string, data []byte) { if c == nil { return } @@ -94,7 +94,7 @@ func (c *ChunkCache) SetChunk(fileId string, data []byte) { c.doSetChunk(fileId, data) } -func (c *ChunkCache) doSetChunk(fileId string, data []byte) { +func (c *TieredChunkCache) doSetChunk(fileId string, data []byte) { if len(data) < memCacheSizeLimit { c.memCache.SetChunk(fileId, data) @@ -116,7 +116,7 @@ func (c *ChunkCache) doSetChunk(fileId string, data []byte) { } -func (c *ChunkCache) Shutdown() { +func (c *TieredChunkCache) Shutdown() { if c == nil { return } -- cgit v1.2.3 From 09e126bae50dac2fe2dee2b074789c6c6e06bf8c Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Mon, 17 Aug 2020 20:20:08 -0700 Subject: refactoring: use interface --- weed/util/chunk_cache/chunk_cache.go | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'weed/util/chunk_cache/chunk_cache.go') diff --git a/weed/util/chunk_cache/chunk_cache.go b/weed/util/chunk_cache/chunk_cache.go index d01e2163b..a1a054215 100644 --- a/weed/util/chunk_cache/chunk_cache.go +++ b/weed/util/chunk_cache/chunk_cache.go @@ -13,6 +13,11 @@ const ( onDiskCacheSizeLimit1 = 4 * memCacheSizeLimit ) +type ChunkCache interface { + GetChunk(fileId string, minSize uint64) (data []byte) + SetChunk(fileId string, data []byte) +} + // a global cache for recently accessed file chunks type TieredChunkCache struct { memCache *ChunkCacheInMemory -- cgit v1.2.3