Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Xiaomi
soar
提交
c4245898
S
soar
项目概览
Xiaomi
/
soar
大约 1 年 前同步成功
通知
387
Star
8512
Fork
1328
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
soar
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
c4245898
编写于
10月 28, 2018
作者:
W
WithLin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix capture a Ctrl+C signal and run a cleanup function
上级
13982325
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
28 addition
and
5 deletion
+28
-5
cmd/soar/soar.go
cmd/soar/soar.go
+28
-5
未找到文件。
cmd/soar/soar.go
浏览文件 @
c4245898
...
...
@@ -21,8 +21,10 @@ import (
"fmt"
"io/ioutil"
"os"
"os/signal"
"path/filepath"
"strings"
"syscall"
"github.com/XiaoMi/soar/advisor"
"github.com/XiaoMi/soar/ast"
...
...
@@ -51,6 +53,15 @@ func main() {
}
common
.
BaseDir
=
filepath
.
Dir
(
ex
)
// binary文件所在路径
sc
:=
make
(
chan
os
.
Signal
,
1
)
signal
.
Notify
(
sc
,
os
.
Kill
,
os
.
Interrupt
,
syscall
.
SIGHUP
,
syscall
.
SIGINT
,
syscall
.
SIGTERM
,
syscall
.
SIGQUIT
)
//通过信号量的形式让程序优雅退出并且清理测试环境
// 配置文件&命令行参数解析
err
=
common
.
ParseConfig
(
""
)
common
.
LogIfWarn
(
err
,
""
)
...
...
@@ -80,17 +91,29 @@ func main() {
// 环境初始化,连接检查线上环境+构建测试环境
vEnv
,
rEnv
:=
env
.
BuildEnv
()
// 如果使用到测试环境,在这里环境清理
if
common
.
Config
.
DropTestTemporary
{
defer
vEnv
.
CleanUp
()
}
// 使用CleanupTestDatabase命令手动清理残余的`optimizer_xxx`数据库
// 为了保护当前正在评审的SQL,只清除前1小时前的残余
if
common
.
Config
.
CleanupTestDatabase
{
vEnv
.
CleanupTestDatabase
()
}
// 如果使用到测试环境,在这里环境清理
if
common
.
Config
.
DropTestTemporary
{
defer
vEnv
.
CleanUp
()
}
go
func
()
{
select
{
case
n
:=
<-
sc
:
common
.
Log
.
Info
(
"receive signal %v, closing"
,
n
)
// 如果使用到测试环境,在这里环境清理
if
common
.
Config
.
DropTestTemporary
{
vEnv
.
CleanUp
()
}
}
}()
// 对指定的库表进行索引重复检查
if
common
.
Config
.
ReportType
==
"duplicate-key-checker"
{
dupKeySuggest
:=
advisor
.
DuplicateKeyChecker
(
rEnv
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录