From cfc8577f766f80f2dd66b5ab9d606efa46e87012 Mon Sep 17 00:00:00 2001 From: congqixia Date: Wed, 25 Jun 2025 10:12:42 +0800 Subject: [PATCH] fix: [hotfix]Use task timestamp to calculating ttl timestamp (#42925) Cherry-pick from master pr: #42920 Related to #42918 Previously the `CollectionTtlTimestamp` could be overflowed when the guarantee_ts==1, which means using `Eventually` consistency level. This patch use task timestamp, allocated by scheduler, to generate ttl timestamp ignore the potential very small timestamp being used. Also add overflow check for ttl timestamp calculated. Signed-off-by: Congqi Xia --- internal/proxy/task_query.go | 6 +++++- internal/proxy/task_search.go | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/internal/proxy/task_query.go b/internal/proxy/task_query.go index 77fada477e..71046a51ca 100644 --- a/internal/proxy/task_query.go +++ b/internal/proxy/task_query.go @@ -482,9 +482,13 @@ func (t *queryTask) PreExecute(ctx context.Context) error { t.GuaranteeTimestamp = t.request.GetGuaranteeTimestamp() } if collectionInfo.collectionTTL != 0 { - physicalTime, _ := tsoutil.ParseTS(guaranteeTs) + physicalTime := tsoutil.PhysicalTime(t.GetBase().GetTimestamp()) expireTime := physicalTime.Add(-time.Duration(collectionInfo.collectionTTL)) t.CollectionTtlTimestamps = tsoutil.ComposeTSByTime(expireTime, 0) + // preventing overflow, abort ttl timestamp + if t.CollectionTtlTimestamps > t.GetBase().GetTimestamp() { + t.CollectionTtlTimestamps = 0 + } } deadline, ok := t.TraceCtx().Deadline() if ok { diff --git a/internal/proxy/task_search.go b/internal/proxy/task_search.go index fc544a700a..f8818eb568 100644 --- a/internal/proxy/task_search.go +++ b/internal/proxy/task_search.go @@ -265,9 +265,13 @@ func (t *searchTask) PreExecute(ctx context.Context) error { } if collectionInfo.collectionTTL != 0 { - physicalTime, _ := tsoutil.ParseTS(guaranteeTs) + physicalTime := tsoutil.PhysicalTime(t.GetBase().GetTimestamp()) expireTime := physicalTime.Add(-time.Duration(collectionInfo.collectionTTL)) t.CollectionTtlTimestamps = tsoutil.ComposeTSByTime(expireTime, 0) + // preventing overflow, abort ttl timestamp + if t.CollectionTtlTimestamps > t.GetBase().GetTimestamp() { + t.CollectionTtlTimestamps = 0 + } } t.resultBuf = typeutil.NewConcurrentSet[*internalpb.SearchResults]()