From 7fd8509eb58e3ba33890cdd761e19d5da5de6493 Mon Sep 17 00:00:00 2001 From: daviszhen Date: Thu, 28 Nov 2024 09:46:38 +0800 Subject: [PATCH 1/6] fix async panic --- pkg/frontend/routine_manager.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/frontend/routine_manager.go b/pkg/frontend/routine_manager.go index 9783b4b50dbc3..929a977984beb 100644 --- a/pkg/frontend/routine_manager.go +++ b/pkg/frontend/routine_manager.go @@ -520,7 +520,12 @@ func NewRoutineManager(ctx context.Context, service string) (*RoutineManager, er default: } rm.KillRoutineConnections() - time.Sleep(time.Duration(time.Duration(getPu(rm.service).SV.KillRountinesInterval) * time.Second)) + pu := getPu(rm.service) + if pu != nil { + time.Sleep(time.Duration(pu.SV.KillRountinesInterval) * time.Second) + } else { + break + } } }() From de8b4a960e769994d7a79e1ec6cd1245e4c5cffa Mon Sep 17 00:00:00 2001 From: daviszhen Date: Thu, 28 Nov 2024 09:55:07 +0800 Subject: [PATCH 2/6] update --- pkg/frontend/routine_manager.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/frontend/routine_manager.go b/pkg/frontend/routine_manager.go index 929a977984beb..feef593ce6472 100644 --- a/pkg/frontend/routine_manager.go +++ b/pkg/frontend/routine_manager.go @@ -524,7 +524,7 @@ func NewRoutineManager(ctx context.Context, service string) (*RoutineManager, er if pu != nil { time.Sleep(time.Duration(pu.SV.KillRountinesInterval) * time.Second) } else { - break + time.Sleep(time.Duration(10) * time.Second) } } }() From 025e914c9730ddc29b61e7e70f70c27798c4ded2 Mon Sep 17 00:00:00 2001 From: daviszhen Date: Thu, 28 Nov 2024 09:46:38 +0800 Subject: [PATCH 3/6] fix async panic update --- pkg/frontend/routine_manager.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/frontend/routine_manager.go b/pkg/frontend/routine_manager.go index 9783b4b50dbc3..feef593ce6472 100644 --- a/pkg/frontend/routine_manager.go +++ b/pkg/frontend/routine_manager.go @@ -520,7 +520,12 @@ func NewRoutineManager(ctx context.Context, service string) (*RoutineManager, er default: } rm.KillRoutineConnections() - time.Sleep(time.Duration(time.Duration(getPu(rm.service).SV.KillRountinesInterval) * time.Second)) + pu := getPu(rm.service) + if pu != nil { + time.Sleep(time.Duration(pu.SV.KillRountinesInterval) * time.Second) + } else { + time.Sleep(time.Duration(10) * time.Second) + } } }() From d98505ba6acfa6871a301381171096871928ffa7 Mon Sep 17 00:00:00 2001 From: daviszhen Date: Thu, 28 Nov 2024 10:04:34 +0800 Subject: [PATCH 4/6] update --- pkg/frontend/routine_manager.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/frontend/routine_manager.go b/pkg/frontend/routine_manager.go index feef593ce6472..929a977984beb 100644 --- a/pkg/frontend/routine_manager.go +++ b/pkg/frontend/routine_manager.go @@ -524,7 +524,7 @@ func NewRoutineManager(ctx context.Context, service string) (*RoutineManager, er if pu != nil { time.Sleep(time.Duration(pu.SV.KillRountinesInterval) * time.Second) } else { - time.Sleep(time.Duration(10) * time.Second) + break } } }() From d8f1bfedbb9f360eaa098a1b8c2ca648905860fd Mon Sep 17 00:00:00 2001 From: daviszhen Date: Thu, 28 Nov 2024 12:02:34 +0800 Subject: [PATCH 5/6] add ut --- pkg/frontend/routine_manager_test.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/pkg/frontend/routine_manager_test.go b/pkg/frontend/routine_manager_test.go index ee01c05386d2d..2efaccc07b5ac 100644 --- a/pkg/frontend/routine_manager_test.go +++ b/pkg/frontend/routine_manager_test.go @@ -23,6 +23,7 @@ import ( "testing" "time" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/matrixorigin/matrixone/pkg/common/moerr" @@ -219,3 +220,18 @@ func TestRoutineManager_killClients(t *testing.T) { }) } } + +func Test_rm(t *testing.T) { + sv, err := getSystemVariables("test/system_vars_config.toml") + if err != nil { + t.Error(err) + } + pu := config.NewParameterUnit(sv, nil, nil, nil) + pu.SV.SkipCheckUser = true + pu.SV.KillRountinesInterval = 1 + setPu("", pu) + _, err = NewRoutineManager(context.Background(), "") + assert.NoError(t, err) + setPu("", nil) + time.Sleep(2 * time.Second) +} From 66246f1c97cff60abca0fcae33422bf36191494a Mon Sep 17 00:00:00 2001 From: daviszhen Date: Thu, 28 Nov 2024 15:17:23 +0800 Subject: [PATCH 6/6] update --- pkg/frontend/routine_manager.go | 9 ++++++--- pkg/frontend/routine_manager_test.go | 4 +++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/pkg/frontend/routine_manager.go b/pkg/frontend/routine_manager.go index 929a977984beb..d39ac1e9a387d 100644 --- a/pkg/frontend/routine_manager.go +++ b/pkg/frontend/routine_manager.go @@ -408,9 +408,12 @@ func (rm *RoutineManager) cleanKillQueue() { ar := rm.accountRoutine ar.killQueueMu.Lock() defer ar.killQueueMu.Unlock() - for toKillAccount, killRecord := range ar.killIdQueue { - if time.Since(killRecord.killTime) > time.Duration(getPu(rm.service).SV.CleanKillQueueInterval)*time.Minute { - delete(ar.killIdQueue, toKillAccount) + pu := getPu(rm.service) + if pu != nil { + for toKillAccount, killRecord := range ar.killIdQueue { + if time.Since(killRecord.killTime) > time.Duration(pu.SV.CleanKillQueueInterval)*time.Minute { + delete(ar.killIdQueue, toKillAccount) + } } } } diff --git a/pkg/frontend/routine_manager_test.go b/pkg/frontend/routine_manager_test.go index 2efaccc07b5ac..98ee546252366 100644 --- a/pkg/frontend/routine_manager_test.go +++ b/pkg/frontend/routine_manager_test.go @@ -230,8 +230,10 @@ func Test_rm(t *testing.T) { pu.SV.SkipCheckUser = true pu.SV.KillRountinesInterval = 1 setPu("", pu) - _, err = NewRoutineManager(context.Background(), "") + rm, err := NewRoutineManager(context.Background(), "") assert.NoError(t, err) + rm.cleanKillQueue() setPu("", nil) time.Sleep(2 * time.Second) + rm.cancelCtx() }