This is an automated email from the ASF dual-hosted git repository.
hanahmily pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/skywalking-banyandb.git
The following commit(s) were added to refs/heads/main by this push:
new 85e3f9c5 Fix the time range error in the lifecycle (#843)
85e3f9c5 is described below
commit 85e3f9c5d6df6d7494c7425ae0afe2074799c955
Author: mrproliu <[email protected]>
AuthorDate: Tue Nov 11 23:03:58 2025 +0900
Fix the time range error in the lifecycle (#843)
* Fix the time range error in the lifecycle
* Add new case for checking including
---
banyand/internal/storage/visitor.go | 6 +--
banyand/internal/storage/visitor_test.go | 61 ++++++++++++++++++++++
.../measure/testdata/group_stages/sw_metric.json | 4 +-
3 files changed, 66 insertions(+), 5 deletions(-)
diff --git a/banyand/internal/storage/visitor.go
b/banyand/internal/storage/visitor.go
index 2f721903..40e14e1a 100644
--- a/banyand/internal/storage/visitor.go
+++ b/banyand/internal/storage/visitor.go
@@ -52,9 +52,9 @@ func VisitSegmentsInTimeRange(tsdbRootPath string, timeRange
timestamp.TimeRange
endTime := intervalRule.NextTime(startTime)
segTR := timestamp.NewSectionTimeRange(startTime, endTime)
- // Check if segment overlaps with the requested time range
- if !segTR.Overlapping(timeRange) {
- return nil // Skip segments outside the time range
+ // Check if segment is completely included in the requested
time range
+ if !timeRange.Include(segTR) {
+ return nil // Skip segments not fully contained in the
time range
}
segmentPath := filepath.Join(tsdbRootPath,
fmt.Sprintf(segTemplate, suffix))
diff --git a/banyand/internal/storage/visitor_test.go
b/banyand/internal/storage/visitor_test.go
index 8be90c6a..b9b6fc3a 100644
--- a/banyand/internal/storage/visitor_test.go
+++ b/banyand/internal/storage/visitor_test.go
@@ -490,4 +490,65 @@ func TestVisitSegmentsInTimeRange(t *testing.T) {
require.Equal(t, common.ShardID(0), shard.shardID)
}
})
+
+ t.Run("visit with edge case time range boundary", func(t *testing.T) {
+ dir, defFn := test.Space(require.New(t))
+ defer defFn()
+
+ // Create TSDB with daily segments
+ opts := TSDBOpts[*MockTSTable, any]{
+ Location: dir,
+ SegmentInterval: IntervalRule{Unit: DAY, Num: 1},
+ TTL: IntervalRule{Unit: DAY, Num: 7},
+ ShardNum: 1,
+ TSTableCreator: MockTSTableCreator,
+ }
+
+ ctx := context.Background()
+ mc := timestamp.NewMockClock()
+ ts, err := time.ParseInLocation("2006-01-02 15:04:05",
"2025-10-31 00:00:00", time.Local)
+ require.NoError(t, err)
+ mc.Set(ts)
+ ctx = timestamp.SetClock(ctx, mc)
+
+ serviceCache := NewServiceCache()
+ tsdb, err := OpenTSDB(ctx, opts, serviceCache, group)
+ require.NoError(t, err)
+ require.NotNil(t, tsdb)
+
+ segmentDates := []time.Time{
+ ts,
+ ts.AddDate(0, 0, 1),
+ ts.AddDate(0, 0, 2),
+ }
+
+ for _, date := range segmentDates {
+ mc.Set(date)
+ seg, segErr := tsdb.CreateSegmentIfNotExist(date)
+ require.NoError(t, segErr)
+
+ // Create shard for each segment
+ shard, shardErr :=
seg.CreateTSTableIfNotExist(common.ShardID(0))
+ require.NoError(t, shardErr)
+ require.NotNil(t, shard)
+ seg.DecRef()
+ }
+
+ tsdb.Close()
+
+ visitor := NewTestVisitor()
+ tsPlus1Min, err := time.ParseInLocation("2006-01-02 15:04:05",
"2025-11-01 00:01:00", time.Local)
+ require.NoError(t, err)
+ timeRange := timestamp.NewSectionTimeRange(time.Time{},
tsPlus1Min)
+ err = VisitSegmentsInTimeRange(dir, timeRange, visitor,
opts.SegmentInterval)
+ require.NoError(t, err)
+ require.Len(t, visitor.visitedSeries, 1)
+ // Should only oct 31 be including
+ expectedSeriesPath := filepath.Join(dir, "seg-20251031",
seriesIndexDirName)
+ require.Equal(t, expectedSeriesPath, visitor.visitedSeries[0])
+ require.Len(t, visitor.visitedShards, 1)
+ require.Equal(t, common.ShardID(0),
visitor.visitedShards[0].shardID)
+ expectedShardPath := filepath.Join(dir, "seg-20251031",
"shard-0")
+ require.Equal(t, expectedShardPath,
visitor.visitedShards[0].path)
+ })
}
diff --git a/pkg/test/measure/testdata/group_stages/sw_metric.json
b/pkg/test/measure/testdata/group_stages/sw_metric.json
index 703ae9f5..6546e739 100644
--- a/pkg/test/measure/testdata/group_stages/sw_metric.json
+++ b/pkg/test/measure/testdata/group_stages/sw_metric.json
@@ -11,7 +11,7 @@
},
"ttl": {
"unit": "UNIT_DAY",
- "num": 7
+ "num": 3
},
"stages": [
{
@@ -23,7 +23,7 @@
},
"ttl": {
"unit": "UNIT_DAY",
- "num": 30
+ "num": 7
},
"node_selector": "type=warm"
}