@@ -88,6 +88,10 @@ type Checkpointer interface {
8888 // versions are emitted before the checkpointing process starts.
8989 WatchCheckpoints () (<- chan uint64 , pubsub.ClosableSubscription , error )
9090
91+ // // WatchCreatedCheckpoints returns a channel that produces a stream of checkpointed versions. The
92+ // versions are emitted immediatelly after the checkpoint is created.
93+ WatchCreatedCheckpoints () (<- chan uint64 , pubsub.ClosableSubscription , error )
94+
9195 // Flush makes the checkpointer immediately process any notifications.
9296 Flush ()
9397
@@ -103,14 +107,15 @@ type Checkpointer interface {
103107type checkpointer struct {
104108 cfg CheckpointerConfig
105109
106- ndb db.NodeDB
107- creator Creator
108- notifyCh * channels.RingChannel
109- forceCh * channels.RingChannel
110- flushCh * channels.RingChannel
111- statusCh chan struct {}
112- pausedCh chan bool
113- cpNotifier * pubsub.Broker
110+ ndb db.NodeDB
111+ creator Creator
112+ notifyCh * channels.RingChannel
113+ forceCh * channels.RingChannel
114+ flushCh * channels.RingChannel
115+ statusCh chan struct {}
116+ pausedCh chan bool
117+ cpNotifier * pubsub.Broker
118+ cpCreatedNotifier * pubsub.Broker
114119
115120 logger * logging.Logger
116121}
@@ -119,16 +124,17 @@ type checkpointer struct {
119124// will automatically generate the configured number of checkpoints.
120125func NewCheckpointer (ndb db.NodeDB , creator Creator , cfg CheckpointerConfig ) Checkpointer {
121126 c := & checkpointer {
122- cfg : cfg ,
123- ndb : ndb ,
124- creator : creator ,
125- notifyCh : channels .NewRingChannel (1 ),
126- forceCh : channels .NewRingChannel (1 ),
127- flushCh : channels .NewRingChannel (1 ),
128- statusCh : make (chan struct {}),
129- pausedCh : make (chan bool ),
130- cpNotifier : pubsub .NewBroker (false ),
131- logger : logging .GetLogger ("storage/mkvs/checkpoint/" + cfg .Name ).With ("namespace" , cfg .Namespace ),
127+ cfg : cfg ,
128+ ndb : ndb ,
129+ creator : creator ,
130+ notifyCh : channels .NewRingChannel (1 ),
131+ forceCh : channels .NewRingChannel (1 ),
132+ flushCh : channels .NewRingChannel (1 ),
133+ statusCh : make (chan struct {}),
134+ pausedCh : make (chan bool ),
135+ cpNotifier : pubsub .NewBroker (false ),
136+ cpCreatedNotifier : pubsub .NewBroker (false ),
137+ logger : logging .GetLogger ("storage/mkvs/checkpoint/" + cfg .Name ).With ("namespace" , cfg .Namespace ),
132138 }
133139 return c
134140}
@@ -152,6 +158,15 @@ func (c *checkpointer) WatchCheckpoints() (<-chan uint64, pubsub.ClosableSubscri
152158 return ch , sub , nil
153159}
154160
161+ // Implements Checkpointer.
162+ func (c * checkpointer ) WatchCreatedCheckpoints () (<- chan uint64 , pubsub.ClosableSubscription , error ) {
163+ ch := make (chan uint64 )
164+ sub := c .cpCreatedNotifier .Subscribe ()
165+ sub .Unwrap (ch )
166+
167+ return ch , sub , nil
168+ }
169+
155170// Implements Checkpointer.
156171func (c * checkpointer ) Flush () {
157172 c .flushCh .In () <- struct {}{}
@@ -311,6 +326,7 @@ func (c *checkpointer) checkpoint(ctx context.Context, version uint64, params *C
311326 )
312327 return fmt .Errorf ("checkpointer: failed to create checkpoint: %w" , err )
313328 }
329+ c .cpCreatedNotifier .Broadcast (version )
314330 }
315331 return nil
316332}
0 commit comments