From fca563bb0a492e57e3af7e715f0430d6955d87aa Mon Sep 17 00:00:00 2001 From: Yogendra Acharya Date: Mon, 31 Jan 2022 20:18:41 +0530 Subject: [PATCH] MB-50664: Indexes stuck at state building in travel-sample bucket In checkInitialBuildDone if buildTs is zero we mark the initBuildDone as true and proceed with TK_INIT_BUILD_DONE. This is not sufficent in OSO mode as flushTs can have open OSO snapshots. When MAINT_STREAM is not yet started this flushTs with its openOSOSnapshot flag gets set on the MAINT_STREAM. Later in checkInitStreamReadyToMerge it can get set back to INIT_STREAM. Due to this even when actual ts does not have any OSOSnapshot markers the openOSOSnapshot flag on ts is true which prevents the INIT_STREAM from merging into MAINT_STREAM with error - has open OSO snapshot. Fix: In the cehckInitialBuildDone for buildTs is all zero case additionally check flushTs is snapAligned and for OSO mode it should not have any OpenOSOSnap. Change-Id: I7c1e53d5fa21ea5e1fe3f9311e3f1ed3b0d27ff3 --- secondary/common/timestamp.go | 4 ++-- secondary/indexer/timekeeper.go | 19 ++++++++++++++----- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/secondary/common/timestamp.go b/secondary/common/timestamp.go index 62d4e2a00..27121fd2d 100644 --- a/secondary/common/timestamp.go +++ b/secondary/common/timestamp.go @@ -466,9 +466,9 @@ func (ts *TsVbuuid) Clone() *TsVbuuid { func (ts *TsVbuuid) String() string { var buf bytes.Buffer vbnos := ts.GetVbnos() - fmsg := "bucket: %v, scopeId: %v, collectionId: %v, vbuckets: %v Crc64: %v snapType %v -\n" + fmsg := "bucket: %v, scopeId: %v, collectionId: %v, vbuckets: %v Crc64: %v snapType %v OpenOSOSnap %v -\n" buf.WriteString(fmt.Sprintf(fmsg, ts.Bucket, ts.ScopeId, ts.CollectionId, - len(vbnos), ts.Crc64, ts.SnapType)) + len(vbnos), ts.Crc64, ts.SnapType, ts.OpenOSOSnap)) if ts.OSOCount == nil { fmsg = " {vbno, vbuuid, manifest, seqno, snapshot-start, snapshot-end}\n" diff --git a/secondary/indexer/timekeeper.go b/secondary/indexer/timekeeper.go index 880f49ce6..6ece0f760 100644 --- a/secondary/indexer/timekeeper.go +++ b/secondary/indexer/timekeeper.go @@ -2272,14 +2272,23 @@ func (tk *timekeeper) checkInitialBuildDone(streamId common.StreamId, if buildInfo.buildTs == nil { initBuildDone = false - } else if buildInfo.buildTs.IsZeroTs() { //if buildTs is zero, initial build is done + } else if buildInfo.buildTs.IsZeroTs() && flushTs.IsSnapAligned() && (!enableOSO || !flushTs.HasOpenOSOSnap()) { + // if buildTs is zero, initial build is considered as done under following cases + // flushTs is nil (isSnapAligned and hasOpenOSOSnap would handled nil flushTs correctly) + // flushTs is non-nil but is snapAligned in non-OSO mode + // flushTs is non-nil, is snapAligned and does not have OpenOSOSnapShot for OSO mode + // + // Also note that we can not remove the check for buildTs.isZeroTs as there are cases where flushTs can be nil, + // and given that, a non-zero buildTs with nil flushTs is considered as initialBuildDone = false (as covered by next condition). + // even if last else condition ts.GreaterThanEqual would take care of zero buildTs we will not reach there if flushTs is nil and we do not have + // special handling of buildInfo.buildTs.IsZeroTs() conditon here. initBuildDone = true - } else if flushTs == nil { + } else if flushTs == nil { // in case of non-zero buildTs we can not have nil flushTs to complete the initialBuild. initBuildDone = false - } else if enableOSO && (flushTs.HasOpenOSOSnap() || !flushTs.IsSnapAligned()) { - //build is not complete till all OSO Snap Ends have been received + } else if !flushTs.IsSnapAligned() { // non-Zero buildTs, non-nil flushTs, flushTs must be snap aligned. initBuildDone = false - } else if !enableOSO && !flushTs.IsSnapAligned() { + } else if enableOSO && flushTs.HasOpenOSOSnap() { + //build is not complete till all OSO Snap Ends have been received initBuildDone = false } else { //check if the flushTS is greater than buildTS