Skip to content

Commit

Permalink
fix: panic when instance is deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
littleniannian committed Oct 16, 2024
1 parent d9a3a74 commit 230c55e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
5 changes: 4 additions & 1 deletion sqle/server/auditplan/task_type_mysql_processlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,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, fmt.Errorf("instance: %v is not exist", ap.InstanceID)
}

db, err := executor.NewExecutor(logger, &driverV2.DSN{
Host: instance.Host,
Expand Down
5 changes: 4 additions & 1 deletion sqle/server/auditplan/task_type_mysql_schema_meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,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, fmt.Errorf("instance: %v is not exist", ap.InstanceID)
}
db, err := executor.NewExecutor(logger, &driverV2.DSN{
Host: instance.Host,
Port: instance.Port,
Expand Down
5 changes: 4 additions & 1 deletion sqle/server/auditplan/task_type_oracle_topsql.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,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, fmt.Errorf("instance: %v is not exist", ap.InstanceID)
}
// 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
5 changes: 4 additions & 1 deletion sqle/server/pipeline/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,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 "", fmt.Errorf("instance: %v is not exist", node.InstanceID)
}
node.InstanceName = instance.Name
}

Expand Down

0 comments on commit 230c55e

Please sign in to comment.