Skip to content

Commit

Permalink
Merge pull request #2688 from actiontech/fix_instance_not_existed
Browse files Browse the repository at this point in the history
fix: panic when instance is deleted
  • Loading branch information
ColdWaterLW authored Oct 25, 2024
2 parents 08c4cd9 + 5710d6c commit 9742078
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
6 changes: 5 additions & 1 deletion sqle/server/auditplan/task_type_mysql_processlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package auditplan
import (
"context"
"fmt"
"github.com/actiontech/sqle/sqle/errors"
"strconv"
"time"

Expand Down Expand Up @@ -77,10 +78,13 @@ func (at *MySQLProcessListTaskV2) ExtractSQL(logger *logrus.Entry, ap *AuditPlan
ctx, cancel := context.WithTimeout(context.Background(), time.Second*20)
defer cancel()

instance, _, err := dms.GetInstancesById(ctx, ap.InstanceID)
instance, exist, err := dms.GetInstancesById(ctx, ap.InstanceID)
if err != nil {
return nil, fmt.Errorf("get instance fail, error: %v", err)
}
if !exist {
return nil, errors.NewInstanceNoExistErr()
}

db, err := executor.NewExecutor(logger, &driverV2.DSN{
Host: instance.Host,
Expand Down
6 changes: 5 additions & 1 deletion sqle/server/auditplan/task_type_mysql_schema_meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/actiontech/sqle/sqle/errors"
"strconv"
"time"

Expand Down Expand Up @@ -47,10 +48,13 @@ func (at *BaseSchemaMetaTaskV2) extractSQL(logger *logrus.Entry, ap *AuditPlan,
sqls := []*SchemaMetaSQL{}
ctx, cancel := context.WithTimeout(context.Background(), time.Second*20)
defer cancel()
instance, _, err := dms.GetInstancesById(ctx, ap.InstanceID)
instance, exist, err := dms.GetInstancesById(ctx, ap.InstanceID)
if err != nil {
return nil, fmt.Errorf("get instance fail, error: %v", err)
}
if !exist {
return nil, errors.NewInstanceNoExistErr()
}
db, err := executor.NewExecutor(logger, &driverV2.DSN{
Host: instance.Host,
Port: instance.Port,
Expand Down
6 changes: 5 additions & 1 deletion sqle/server/auditplan/task_type_oracle_topsql.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package auditplan
import (
"context"
"fmt"
"github.com/actiontech/sqle/sqle/errors"
"strconv"
"time"

Expand Down Expand Up @@ -95,10 +96,13 @@ func (at *OracleTopSQLTaskV2) ExtractSQL(logger *logrus.Entry, ap *AuditPlan, pe

ctx, cancel := context.WithTimeout(context.Background(), time.Second*20)
defer cancel()
inst, _, err := dms.GetInstancesById(ctx, ap.InstanceID)
inst, exist, err := dms.GetInstancesById(ctx, ap.InstanceID)
if err != nil {
return nil, fmt.Errorf("get instance fail, error: %v", err)
}
if !exist {
return nil, errors.NewInstanceNoExistErr()
}
// This depends on: https://github.com/actiontech/sqle-oracle-plugin.
// If your Oracle db plugin does not implement the parameter `service_name`,
// you can only use the default service name `XE`.
Expand Down
6 changes: 5 additions & 1 deletion sqle/server/pipeline/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package pipeline
import (
"context"
"fmt"
"github.com/actiontech/sqle/sqle/errors"
"net"
"net/url"
"time"
Expand Down Expand Up @@ -41,10 +42,13 @@ func (node PipelineNode) IntegrationInfo(ctx context.Context, projectName string
return "", err
}
if node.InstanceID != 0 {
instance, _, err := dms.GetInstancesById(context.TODO(), fmt.Sprint(node.InstanceID))
instance, exist, err := dms.GetInstancesById(context.TODO(), fmt.Sprint(node.InstanceID))
if err != nil {
return "", err
}
if !exist {
return "", errors.NewInstanceNoExistErr()
}
node.InstanceName = instance.Name
}

Expand Down

0 comments on commit 9742078

Please sign in to comment.