rename
This commit is contained in:
@@ -19,7 +19,7 @@ type ChunkReadAt struct {
|
|||||||
readerLock sync.Mutex
|
readerLock sync.Mutex
|
||||||
fileSize int64
|
fileSize int64
|
||||||
|
|
||||||
chunkCache *chunk_cache.ChunkCache
|
chunkCache *chunk_cache.TieredChunkCache
|
||||||
}
|
}
|
||||||
|
|
||||||
// var _ = io.ReaderAt(&ChunkReadAt{})
|
// var _ = io.ReaderAt(&ChunkReadAt{})
|
||||||
@@ -53,7 +53,7 @@ func LookupFn(filerClient filer_pb.FilerClient) LookupFileIdFunctionType {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewChunkReaderAtFromClient(filerClient filer_pb.FilerClient, chunkViews []*ChunkView, chunkCache *chunk_cache.ChunkCache, fileSize int64) *ChunkReadAt {
|
func NewChunkReaderAtFromClient(filerClient filer_pb.FilerClient, chunkViews []*ChunkView, chunkCache *chunk_cache.TieredChunkCache, fileSize int64) *ChunkReadAt {
|
||||||
|
|
||||||
return &ChunkReadAt{
|
return &ChunkReadAt{
|
||||||
chunkViews: chunkViews,
|
chunkViews: chunkViews,
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ type WFS struct {
|
|||||||
root fs.Node
|
root fs.Node
|
||||||
fsNodeCache *FsCache
|
fsNodeCache *FsCache
|
||||||
|
|
||||||
chunkCache *chunk_cache.ChunkCache
|
chunkCache *chunk_cache.TieredChunkCache
|
||||||
metaCache *meta_cache.MetaCache
|
metaCache *meta_cache.MetaCache
|
||||||
}
|
}
|
||||||
type statsCache struct {
|
type statsCache struct {
|
||||||
@@ -87,7 +87,7 @@ func NewSeaweedFileSystem(option *Option) *WFS {
|
|||||||
cacheDir := path.Join(option.CacheDir, cacheUniqueId)
|
cacheDir := path.Join(option.CacheDir, cacheUniqueId)
|
||||||
if option.CacheSizeMB > 0 {
|
if option.CacheSizeMB > 0 {
|
||||||
os.MkdirAll(cacheDir, 0755)
|
os.MkdirAll(cacheDir, 0755)
|
||||||
wfs.chunkCache = chunk_cache.NewChunkCache(256, cacheDir, option.CacheSizeMB)
|
wfs.chunkCache = chunk_cache.NewTieredChunkCache(256, cacheDir, option.CacheSizeMB)
|
||||||
grace.OnInterrupt(func() {
|
grace.OnInterrupt(func() {
|
||||||
wfs.chunkCache.Shutdown()
|
wfs.chunkCache.Shutdown()
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ type WebDavFileSystem struct {
|
|||||||
secret security.SigningKey
|
secret security.SigningKey
|
||||||
filer *filer2.Filer
|
filer *filer2.Filer
|
||||||
grpcDialOption grpc.DialOption
|
grpcDialOption grpc.DialOption
|
||||||
chunkCache *chunk_cache.ChunkCache
|
chunkCache *chunk_cache.TieredChunkCache
|
||||||
}
|
}
|
||||||
|
|
||||||
type FileInfo struct {
|
type FileInfo struct {
|
||||||
@@ -100,7 +100,7 @@ type WebDavFile struct {
|
|||||||
|
|
||||||
func NewWebDavFileSystem(option *WebDavOption) (webdav.FileSystem, error) {
|
func NewWebDavFileSystem(option *WebDavOption) (webdav.FileSystem, error) {
|
||||||
|
|
||||||
chunkCache := chunk_cache.NewChunkCache(256, option.CacheDir, option.CacheSizeMB)
|
chunkCache := chunk_cache.NewTieredChunkCache(256, option.CacheDir, option.CacheSizeMB)
|
||||||
grace.OnInterrupt(func() {
|
grace.OnInterrupt(func() {
|
||||||
chunkCache.Shutdown()
|
chunkCache.Shutdown()
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -14,15 +14,15 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// a global cache for recently accessed file chunks
|
// a global cache for recently accessed file chunks
|
||||||
type ChunkCache struct {
|
type TieredChunkCache struct {
|
||||||
memCache *ChunkCacheInMemory
|
memCache *ChunkCacheInMemory
|
||||||
diskCaches []*OnDiskCacheLayer
|
diskCaches []*OnDiskCacheLayer
|
||||||
sync.RWMutex
|
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),
|
memCache: NewChunkCacheInMemory(maxEntries),
|
||||||
}
|
}
|
||||||
c.diskCaches = make([]*OnDiskCacheLayer, 3)
|
c.diskCaches = make([]*OnDiskCacheLayer, 3)
|
||||||
@@ -33,7 +33,7 @@ func NewChunkCache(maxEntries int64, dir string, diskSizeMB int64) *ChunkCache {
|
|||||||
return c
|
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 {
|
if c == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -44,7 +44,7 @@ func (c *ChunkCache) GetChunk(fileId string, minSize uint64) (data []byte) {
|
|||||||
return c.doGetChunk(fileId, minSize)
|
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 {
|
if minSize < memCacheSizeLimit {
|
||||||
data = c.memCache.GetChunk(fileId)
|
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 {
|
if c == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -94,7 +94,7 @@ func (c *ChunkCache) SetChunk(fileId string, data []byte) {
|
|||||||
c.doSetChunk(fileId, data)
|
c.doSetChunk(fileId, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ChunkCache) doSetChunk(fileId string, data []byte) {
|
func (c *TieredChunkCache) doSetChunk(fileId string, data []byte) {
|
||||||
|
|
||||||
if len(data) < memCacheSizeLimit {
|
if len(data) < memCacheSizeLimit {
|
||||||
c.memCache.SetChunk(fileId, data)
|
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 {
|
if c == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ func TestOnDisk(t *testing.T) {
|
|||||||
|
|
||||||
totalDiskSizeMb := int64(32)
|
totalDiskSizeMb := int64(32)
|
||||||
|
|
||||||
cache := NewChunkCache(0, tmpDir, totalDiskSizeMb)
|
cache := NewTieredChunkCache(0, tmpDir, totalDiskSizeMb)
|
||||||
|
|
||||||
writeCount := 5
|
writeCount := 5
|
||||||
type test_data struct {
|
type test_data struct {
|
||||||
@@ -45,7 +45,7 @@ func TestOnDisk(t *testing.T) {
|
|||||||
|
|
||||||
cache.Shutdown()
|
cache.Shutdown()
|
||||||
|
|
||||||
cache = NewChunkCache(0, tmpDir, totalDiskSizeMb)
|
cache = NewTieredChunkCache(0, tmpDir, totalDiskSizeMb)
|
||||||
|
|
||||||
for i := 0; i < writeCount; i++ {
|
for i := 0; i < writeCount; i++ {
|
||||||
data := cache.GetChunk(testData[i].fileId, testData[i].size)
|
data := cache.GetChunk(testData[i].fileId, testData[i].size)
|
||||||
|
|||||||
Reference in New Issue
Block a user