@@ -21,7 +21,9 @@ import (
2121 "github.com/10gen/migration-verifier/internal/reportutils"
2222 "github.com/10gen/migration-verifier/internal/retry"
2323 "github.com/10gen/migration-verifier/internal/types"
24+ "github.com/10gen/migration-verifier/internal/util"
2425 "github.com/10gen/migration-verifier/internal/uuidutil"
26+ "github.com/10gen/migration-verifier/option"
2527 "github.com/olekukonko/tablewriter"
2628 "github.com/pkg/errors"
2729 "github.com/rs/zerolog"
@@ -78,7 +80,7 @@ var timeFormat = time.RFC3339
7880
7981// Verifier is the main state for the migration verifier
8082type Verifier struct {
81- writesOff bool
83+ writesOffTs option. Option [primitive. Timestamp ]
8284 lastGeneration bool
8385 running bool
8486 generation int
@@ -123,12 +125,12 @@ type Verifier struct {
123125 metaDBName string
124126 srcStartAtTs * primitive.Timestamp
125127
126- mux sync.RWMutex
127- changeStreamRunning bool
128- changeStreamEnderChan chan struct {}
129- changeStreamErrChan chan error
130- changeStreamDoneChan chan struct {}
131- lastChangeEventTime * primitive.Timestamp
128+ mux sync.RWMutex
129+ changeStreamRunning bool
130+ changeStreamFinalTsChan chan primitive. Timestamp
131+ changeStreamErrChan chan error
132+ changeStreamDoneChan chan struct {}
133+ lastChangeEventTime * primitive.Timestamp
132134
133135 readConcernSetting ReadConcernSetting
134136
@@ -188,15 +190,15 @@ func NewVerifier(settings VerifierSettings) *Verifier {
188190 }
189191
190192 return & Verifier {
191- phase : Idle ,
192- numWorkers : NumWorkers ,
193- readPreference : readpref .Primary (),
194- partitionSizeInBytes : 400 * 1024 * 1024 ,
195- failureDisplaySize : DefaultFailureDisplaySize ,
196- changeStreamEnderChan : make (chan struct {} ),
197- changeStreamErrChan : make (chan error ),
198- changeStreamDoneChan : make (chan struct {}),
199- readConcernSetting : readConcern ,
193+ phase : Idle ,
194+ numWorkers : NumWorkers ,
195+ readPreference : readpref .Primary (),
196+ partitionSizeInBytes : 400 * 1024 * 1024 ,
197+ failureDisplaySize : DefaultFailureDisplaySize ,
198+ changeStreamFinalTsChan : make (chan primitive. Timestamp ),
199+ changeStreamErrChan : make (chan error ),
200+ changeStreamDoneChan : make (chan struct {}),
201+ readConcernSetting : readConcern ,
200202
201203 // This will get recreated once gen0 starts, but we want it
202204 // here in case the change streams gets an event before then.
@@ -228,18 +230,30 @@ func (verifier *Verifier) SetFailureDisplaySize(size int64) {
228230 verifier .failureDisplaySize = size
229231}
230232
231- func (verifier * Verifier ) WritesOff (ctx context.Context ) {
233+ func (verifier * Verifier ) WritesOff (ctx context.Context ) error {
232234 verifier .logger .Debug ().
233235 Msg ("WritesOff called." )
234236
235237 verifier .mux .Lock ()
236- verifier .writesOff = true
237- verifier .mux .Unlock ()
238+ defer verifier .mux .Unlock ()
239+ writesOffTs , err := GetClusterTime (
240+ ctx ,
241+ verifier .logger ,
242+ verifier .srcClient ,
243+ )
244+
245+ if err != nil {
246+ return errors .Wrapf (err , "failed to fetch source's cluster time" )
247+ }
248+
249+ verifier .writesOffTs = option .Some (writesOffTs )
250+
251+ return nil
238252}
239253
240254func (verifier * Verifier ) WritesOn (ctx context.Context ) {
241255 verifier .mux .Lock ()
242- verifier .writesOff = false
256+ util . ResetToZero ( & verifier .writesOffTs )
243257 verifier .mux .Unlock ()
244258}
245259
0 commit comments