Skip to content

Commit

Permalink
Support cache on write
Browse files Browse the repository at this point in the history
Signed-off-by: Changxin Miao <[email protected]>
  • Loading branch information
polyrabbit committed Oct 29, 2024
1 parent acd2484 commit 9c5082a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
4 changes: 4 additions & 0 deletions cmd/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions cmd/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")),
Expand Down
3 changes: 2 additions & 1 deletion pkg/chunk/cached_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -568,6 +568,7 @@ type Config struct {
GetTimeout time.Duration
PutTimeout time.Duration
CacheFullBlock bool
CacheOnWrite bool
BufferSize uint64
Readahead int
Prefetch int
Expand Down

0 comments on commit 9c5082a

Please sign in to comment.