8000 [enhance]: need to check rollup Interval when memory database refreshing by stone1100 · Pull Request #947 · lindb/lindb · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[enhance]: need to check rollup Interval when memory database refreshing #947

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion tsdb/data_family.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,16 @@ func (f *dataFamily) NeedFlush() bool {
// no data
return false
}

intervals := f.shard.Database().GetOption().Intervals
ttl := config.GlobalStorageConfig().TSDB.MutableMemDBTTL.Duration()
if len(intervals) > 1 {
// if set rollup interval, need check if ttl > smallest rollup interval.
// using small interval check flush ttl.
smallestRollupInterval := time.Duration(intervals[1].Interval.Int64() * int64(time.Millisecond))
if smallestRollupInterval < ttl {
ttl = smallestRollupInterval
}
}
maxMemDBSize := config.GlobalStorageConfig().TSDB.MaxMemDBSize

f.logger.Info("check memory database if need flush",
Expand Down
25 changes: 22 additions & 3 deletions tsdb/data_family_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ func TestDataFamily_Filter(t *testing.T) {
func TestDataFamily_NeedFlush(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
db := NewMockDatabase(ctrl)
shard := NewMockShard(ctrl)
shard.EXPECT().Database().Return(db).AnyTimes()

cases := []struct {
name string
Expand Down Expand Up @@ -262,12 +265,15 @@ func TestDataFamily_NeedFlush(t *testing.T) {
prepare: func(f *dataFamily) {
cfg := config.NewDefaultStorageBase()
cfg.TSDB.MutableMemDBTTL = ltoml.Duration(time.Second)
db.EXPECT().GetOption().Return(&option.DatabaseOption{
Intervals: option.Intervals{{Interval: timeutil.Interval(timeutil.OneSecond)}},
})
config.SetGlobalStorageConfig(cfg)
memDB := memdb.NewMockMemoryDatabase(ctrl)
f.mutableMemDB = memDB
memDB.EXPECT().MemSize().Return(int64(10))
memDB.EXPECT().NumOfMetrics().Return(10)
memDB.EXPECT().Uptime().Return(time.Duration(timeutil.Now() - timeutil.OneMinute)).MaxTimes(2)
memDB.EXPECT().Uptime().Return(time.Minute).MaxTimes(2)
},
needFlush: true,
},
Expand All @@ -276,12 +282,18 @@ func TestDataFamily_NeedFlush(t *testing.T) {
prepare: func(f *dataFamily) {
cfg := config.NewDefaultStorageBase()
cfg.TSDB.MutableMemDBTTL = ltoml.Duration(time.Hour)
db.EXPECT().GetOption().Return(&option.DatabaseOption{
Intervals: option.Intervals{
{Interval: timeutil.Interval(timeutil.OneSecond)},
{Interval: timeutil.Interval(timeutil.OneMinute * 5)},
},
})
cfg.TSDB.MaxMemDBSize = 10
config.SetGlobalStorageConfig(cfg)
memDB := memdb.NewMockMemoryDatabase(ctrl)
f.mutableMemDB = memDB
memDB.EXPECT().NumOfMetrics().Return(10)
memDB.EXPECT().Uptime().Return(time.Duration(timeutil.Now() - timeutil.OneMinute)).MaxTimes(2)
memDB.EXPECT().Uptime().Return(time.Minute).MaxTimes(2)
memDB.EXPECT().MemSize().Return(int64(1000)).MaxTimes(2)
},
needFlush: true,
Expand All @@ -292,11 +304,17 @@ func TestDataFamily_NeedFlush(t *testing.T) {
cfg := config.NewDefaultStorageBase()
cfg.TSDB.MutableMemDBTTL = ltoml.Duration(time.Hour)
cfg.TSDB.MaxMemDBSize = 10000
db.EXPECT().GetOption().Return(&option.DatabaseOption{
Intervals: option.Intervals{
{Interval: timeutil.Interval(timeutil.OneSecond)},
{Interval: timeutil.Interval(timeutil.OneMinute * 5)},
},
})
config.SetGlobalStorageConfig(cfg)
memDB := memdb.NewMockMemoryDatabase(ctrl)
f.mutableMemDB = memDB
memDB.EXPECT().NumOfMetrics().Return(10)
memDB.EXPECT().Uptime().Return(time.Duration(timeutil.Now() - timeutil.OneMinute)).MaxTimes(2)
memDB.EXPECT().Uptime().Return(time.Minute).MaxTimes(2)
memDB.EXPECT().MemSize().Return(int64(10)).MaxTimes(2)
},
needFlush: false,
Expand All @@ -310,6 +328,7 @@ func TestDataFamily_NeedFlush(t *testing.T) {
config.SetGlobalStorageConfig(config.NewDefaultStorageBase())
}()
f := &dataFamily{
shard: shard,
logger: logger.GetLogger("TSDB", "Test"),
}
if tt.prepare != nil {
Expand Down
0