@@ -2,6 +2,7 @@ package main
22
33import (
44 "context"
5+ "log/slog"
56 "time"
67
78 "github.com/cinode/go/pkg/cinodefs"
@@ -18,11 +19,13 @@ func NewFlushStrategy(
1819 fs cinodefs.FS ,
1920 cfg FlushStrategyConfig ,
2021 timeSource func () time.Time ,
22+ log * slog.Logger ,
2123) FlushStrategy {
2224 return & flushStrategy {
2325 fs : fs ,
2426 cfg : cfg ,
2527 timeSource : timeSource ,
28+ log : log ,
2629 }
2730}
2831
@@ -38,9 +41,11 @@ type flushStrategy struct {
3841 lastFlushTime time.Time
3942 cfg FlushStrategyConfig
4043 timeSource func () time.Time
44+ log * slog.Logger
4145}
4246
43- func (f * flushStrategy ) flush (ctx context.Context ) error {
47+ func (f * flushStrategy ) flush (ctx context.Context , reason string ) error {
48+ f .log .InfoContext (ctx , "Flushing filesystem" , "reason" , reason )
4449 if err := f .fs .Flush (ctx ); err != nil {
4550 return err
4651 }
@@ -59,29 +64,29 @@ func (f *flushStrategy) FlushOpportunity(ctx context.Context) error {
5964 return nil
6065 }
6166
62- return f .flush (ctx )
67+ return f .flush (ctx , "maxFlushInterval reached" )
6368}
6469
6570func (f * flushStrategy ) ColumnFinished (ctx context.Context , isDetailedRegion bool ) error {
6671 if isDetailedRegion && f .cfg .FlushOnDetailedColumnFinished {
67- return f .flush (ctx )
72+ return f .flush (ctx , "detailed column finished" )
6873 }
6974
7075 if f .cfg .FlushOnColumnFinished {
71- return f .flush (ctx )
76+ return f .flush (ctx , "column finished" )
7277 }
7378
7479 return nil
7580}
7681
7782func (f * flushStrategy ) ZLayerFinished (ctx context.Context ) error {
7883 if f .cfg .FlushOnZLayerFinished {
79- return f .flush (ctx )
84+ return f .flush (ctx , "zoom layer finished" )
8085 }
8186
8287 return nil
8388}
8489
8590func (f * flushStrategy ) ProcessFinished (ctx context.Context ) error {
86- return f .flush (ctx )
91+ return f .flush (ctx , "process finished" )
8792}
0 commit comments