Skip to content

Commit

Permalink
fix: DBGC online effectiveness (#6472)
Browse files Browse the repository at this point in the history
* fix dbgc

* fix dbgc

* add testcase

* add testcase
  • Loading branch information
haiqingchq authored Dec 5, 2024
1 parent 0a48220 commit d217119
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
10 changes: 10 additions & 0 deletions internal/tools/pipeline/providers/dbgc/dbgc.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ func (p *provider) doPipelineDatabaseGC(ctx context.Context, req *pb.PipelinePag
}

func needArchive(p spec.Pipeline) bool {
// ensure gc filed is not none
if p.Extra.GC.DatabaseGC == nil {
return true
}
if p.Status == apistructs.PipelineStatusAnalyzed {
if *p.Extra.GC.DatabaseGC.Analyzed.NeedArchive != false {
return *p.Extra.GC.DatabaseGC.Analyzed.NeedArchive
Expand Down Expand Up @@ -203,6 +207,12 @@ func (p *provider) WaitDBGC(pipelineID uint64, ttl uint64, needArchive bool) {
}

func (p *provider) DoDBGC(pipeline *spec.Pipeline, gcOption apistructs.PipelineGCDBOption) error {
defer func() {
r := recover()
if r != nil {
p.Log.Errorf("dbgc recover from panic, pipeline_id: %d, err: %v", pipeline.PipelineID, r)
}
}()
if gcOption.NeedArchive {
// 归档
_, err := p.dbClient.ArchivePipeline(pipeline.ID)
Expand Down
16 changes: 15 additions & 1 deletion internal/tools/pipeline/providers/dbgc/dbgc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import (
)

func TestReconciler_doPipelineDatabaseGC(t *testing.T) {

var pipelines = []spec.Pipeline{
{
PipelineBase: spec.PipelineBase{ID: 1, Status: apistructs.PipelineStatusAnalyzed},
Expand All @@ -53,6 +52,12 @@ func TestReconciler_doPipelineDatabaseGC(t *testing.T) {
},
}},
},
{
PipelineBase: spec.PipelineBase{ID: 1, Status: apistructs.PipelineStatusAnalyzed},
PipelineExtra: spec.PipelineExtra{Extra: spec.PipelineExtraInfo{
GC: basepb.PipelineGC{},
}},
},
{
PipelineBase: spec.PipelineBase{ID: 2, Status: apistructs.PipelineStatusAnalyzed},
PipelineExtra: spec.PipelineExtra{Extra: spec.PipelineExtraInfo{
Expand Down Expand Up @@ -230,3 +235,12 @@ func TestReconciler_doPipelineDatabaseGC1(t *testing.T) {
r.doPipelineDatabaseGC(context.Background(), &pipelinepb.PipelinePagingRequest{PageNum: 1})
})
}

func TestDoDBGC(t *testing.T) {
p := provider{}
pipeline := &spec.Pipeline{}
needArchive := true
assert.Panics(t, func() {
p.DoDBGC(pipeline, apistructs.PipelineGCDBOption{NeedArchive: needArchive})
})
}

0 comments on commit d217119

Please sign in to comment.