Skip to content

Commit

Permalink
Fix compaction view manager ut
Browse files Browse the repository at this point in the history
Signed-off-by: yangxuan <xuan.yang@zilliz.com>
  • Loading branch information
XuanYang-cn committed Mar 13, 2024
1 parent 7f41292 commit d0d9e46
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 15 deletions.
4 changes: 3 additions & 1 deletion internal/datacoord/compaction_trigger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2325,6 +2325,8 @@ func (s *CompactionTriggerSuite) TestEnableCompactionConfigDynamicly() {
}
enableCompKey := paramtable.Get().DataCoordCfg.EnableCompaction.Key
enableAutoCompKey := paramtable.Get().DataCoordCfg.EnableAutoCompaction.Key
defer paramtable.Get().Reset(enableCompKey)
defer paramtable.Get().Reset(enableAutoCompKey)

for _, test := range tests {
s.Run(test.description, func() {
Expand Down Expand Up @@ -2362,7 +2364,7 @@ func (s *CompactionTriggerSuite) TestEnableCompactionConfigDynamicly() {
}
s.tr.stop()

// test if trigger compaction by triggerSingleCompaction and forceTriggerCompaction
// test triggerSingleCompaction and forceTriggerCompaction
if test.triggered {
s.Require().True(autoCompactionEnabled())
err := s.tr.triggerSingleCompaction(s.collectionID, s.partitionID, 1, s.channel, false)
Expand Down
7 changes: 4 additions & 3 deletions internal/datacoord/compaction_view_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/milvus-io/milvus/internal/proto/datapb"
"github.com/milvus-io/milvus/pkg/log"
"github.com/milvus-io/milvus/pkg/util/logutil"
"github.com/milvus-io/milvus/pkg/util/paramtable"
"github.com/milvus-io/milvus/pkg/util/typeutil"
)

Expand Down Expand Up @@ -53,12 +54,12 @@ func (m *CompactionViewManager) checkLoop() {
defer logutil.LogPanic()
defer m.closeWg.Done()

// TODO: Only process L0 compaction now, so just return if its not enabled
// TODO: Only process L0 compaction now
L0SegmentEnabled := func() bool {
return autoCompactionEnabled() && Params.DataCoordCfg.EnableLevelZeroSegment.GetAsBool()
return autoCompactionEnabled() && paramtable.Get().DataCoordCfg.EnableLevelZeroSegment.GetAsBool()
}

interval := Params.DataCoordCfg.GlobalCompactionInterval.GetAsDuration(time.Second)
interval := paramtable.Get().DataCoordCfg.GlobalCompactionInterval.GetAsDuration(time.Second)
checkTicker := time.NewTicker(interval)
defer checkTicker.Stop()

Expand Down
42 changes: 31 additions & 11 deletions internal/datacoord/compaction_view_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ func genSegmentsForMeta(label *CompactionGroupLabel) map[int64]*SegmentInfo {
}

func (s *CompactionViewManagerSuite) SetupTest() {
s.SetupSubTest()
}

func (s *CompactionViewManagerSuite) SetupSubTest() {
s.mockAlloc = NewNMockAllocator(s.T())
s.mockTriggerManager = NewMockTriggerManager(s.T())

Expand All @@ -93,20 +97,36 @@ func (s *CompactionViewManagerSuite) TestCheckLoop() {
s.m.Close()
})

s.Run("Test not enable auto compaction", func() {
paramtable.Get().Save(Params.DataCoordCfg.EnableAutoCompaction.Key, "false")
defer paramtable.Get().Reset(Params.DataCoordCfg.EnableAutoCompaction.Key)

s.Run("Test not enable compaction", func() {
var (
globalIntervalK = paramtable.Get().DataCoordCfg.GlobalCompactionInterval.Key
enableCompK = paramtable.Get().DataCoordCfg.EnableCompaction.Key
enableAutoCompK = paramtable.Get().DataCoordCfg.EnableAutoCompaction.Key
enableL0K = paramtable.Get().DataCoordCfg.EnableLevelZeroSegment.Key
)
defer paramtable.Get().Reset(globalIntervalK)
defer paramtable.Get().Reset(enableCompK)
defer paramtable.Get().Reset(enableAutoCompK)
defer paramtable.Get().Reset(enableL0K)

paramtable.Get().Save(globalIntervalK, "0.01")
paramtable.Get().Save(enableCompK, "false")
paramtable.Get().Save(enableAutoCompK, "true")

// no mocks needed for no events will be triggerred
s.m.Start()
s.m.closeWg.Wait()
})

s.Run("Test not enable levelZero segment", func() {
paramtable.Get().Save(Params.DataCoordCfg.EnableLevelZeroSegment.Key, "false")
defer paramtable.Get().Reset(Params.DataCoordCfg.EnableLevelZeroSegment.Key)
waitDur := 100 * time.Millisecond
<-time.After(waitDur)
paramtable.Get().Save(enableAutoCompK, "false")
paramtable.Get().Save(enableCompK, "true")

s.m.Start()
s.m.closeWg.Wait()
<-time.After(waitDur)
paramtable.Get().Save(enableL0K, "false")
paramtable.Get().Save(enableAutoCompK, "true")

<-time.After(waitDur)
s.m.Close()
})
}

Expand Down

0 comments on commit d0d9e46

Please sign in to comment.