From 9c5082a5e680989ea981d0b9c61d994de0a9077e Mon Sep 17 00:00:00 2001 From: Changxin Miao Date: Tue, 28 May 2024 21:45:07 +0800 Subject: [PATCH] Support cache on write Signed-off-by: Changxin Miao --- cmd/flags.go | 4 ++++ cmd/mount.go | 1 + pkg/chunk/cached_store.go | 3 ++- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/cmd/flags.go b/cmd/flags.go index 27d1752f9de2..42ed0c169a68 100644 --- a/cmd/flags.go +++ b/cmd/flags.go @@ -218,6 +218,10 @@ func dataCacheFlags() []cli.Flag { Name: "cache-partial-only", Usage: "cache only random/small read", }, + &cli.BoolFlag{ + Name: "cache-on-write", + Usage: "cache blocks after uploading", + }, &cli.StringFlag{ Name: "verify-cache-checksum", Value: "full", diff --git a/cmd/mount.go b/cmd/mount.go index 0a502db9a6df..f9f98fa87a52 100644 --- a/cmd/mount.go +++ b/cmd/mount.go @@ -352,6 +352,7 @@ func getChunkConf(c *cli.Context, format *meta.Format) *chunk.Config { FreeSpace: float32(c.Float64("free-space-ratio")), CacheMode: os.FileMode(cm), CacheFullBlock: !c.Bool("cache-partial-only"), + CacheOnWrite: c.Bool("cache-on-write"), CacheChecksum: c.String("verify-cache-checksum"), CacheEviction: c.String("cache-eviction"), CacheScanInterval: utils.Duration(c.String("cache-scan-interval")), diff --git a/pkg/chunk/cached_store.go b/pkg/chunk/cached_store.go index d119c5e3c8aa..82225a828d60 100644 --- a/pkg/chunk/cached_store.go +++ b/pkg/chunk/cached_store.go @@ -391,7 +391,7 @@ func (store *cachedStore) upload(key string, block *Page, s *wSlice) error { buf.Acquire() } defer buf.Release() - if sync && blen < store.conf.BlockSize { + if sync && (blen < store.conf.BlockSize || store.conf.CacheOnWrite) { // block will be freed after written into disk store.bcache.cache(key, block, false, false) } @@ -568,6 +568,7 @@ type Config struct { GetTimeout time.Duration PutTimeout time.Duration CacheFullBlock bool + CacheOnWrite bool BufferSize uint64 Readahead int Prefetch int