From 21b40f876284e9ed44fc8a31c95f3d4003d107d9 Mon Sep 17 00:00:00 2001 From: Jamie Date: Tue, 12 Dec 2023 11:44:28 +1300 Subject: [PATCH] rework oplog duration calc --- .../20231128_jellyfish_migration.go | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/migrations/20231128_jellyfish_migration/20231128_jellyfish_migration.go b/migrations/20231128_jellyfish_migration/20231128_jellyfish_migration.go index a08750b1c..49b67c985 100644 --- a/migrations/20231128_jellyfish_migration/20231128_jellyfish_migration.go +++ b/migrations/20231128_jellyfish_migration/20231128_jellyfish_migration.go @@ -217,24 +217,31 @@ func (m *Migration) execute() error { func (m *Migration) getOplogDuration() (time.Duration, error) { type MongoMetaData struct { - Wall time.Time `json:"wall"` + Wall int64 `json:"wall"` } + log.Println("checking oplog duration ") if oplogC := m.getOplogCollection(); oplogC != nil { var oldest MongoMetaData + if err := oplogC.FindOne( - m.ctx, bson.M{}, - options.FindOne().SetSort("$natural"), - options.FindOne().SetProjection(bson.M{"wall": 1})).Decode(&oldest); err != nil { + m.ctx, + bson.M{"wall": bson.M{"$exists": true}}, + options.FindOne().SetSort("$natural")).Decode(&oldest); err != nil { return 0, err } + + log.Printf("oldest %v ", oldest) var newest MongoMetaData - if err := oplogC.FindOne(m.ctx, - bson.M{}, - options.FindOne().SetSort("-$natural"), - options.FindOne().SetProjection(bson.M{"wall": 1})).Decode(&newest); err != nil { + if err := oplogC.FindOne( + m.ctx, + bson.M{"wall": bson.M{"$exists": true}}, + options.FindOne().SetSort("-$natural")).Decode(&newest); err != nil { return 0, err } - oplogDuration := oldest.Wall.Sub(oldest.Wall) + log.Printf("newest %v ", newest) + oldestT := time.UnixMilli(oldest.Wall) + newestT := time.UnixMilli(newest.Wall) + oplogDuration := newestT.Sub(oldestT) log.Printf("oplog duration is currently: %v\n", oplogDuration) return oplogDuration, nil }