Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Xiaomi
soar
提交
6c47c870
S
soar
项目概览
Xiaomi
/
soar
大约 1 年 前同步成功
通知
386
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,发现更多精彩内容 >>
提交
6c47c870
编写于
11月 02, 2018
作者:
L
liipx
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix -cleanup-test-database with out query
上级
963eb4b5
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
36 addition
and
30 deletion
+36
-30
cmd/soar/soar.go
cmd/soar/soar.go
+1
-0
database/sampling.go
database/sampling.go
+3
-3
env/env.go
env/env.go
+32
-27
未找到文件。
cmd/soar/soar.go
浏览文件 @
6c47c870
...
...
@@ -83,6 +83,7 @@ func main() {
// 使用 -cleanup-test-database 命令手动清理残余的 optimizer_xxx 数据库
if
common
.
Config
.
CleanupTestDatabase
{
vEnv
.
CleanupTestDatabase
()
return
}
// 如果使用到测试环境,在这里环境清理
...
...
database/sampling.go
浏览文件 @
6c47c870
...
...
@@ -174,10 +174,10 @@ func startSampling(conn, localConn mysql.Conn, database, table string, factor fl
// str = ""
case
[]
byte
:
// 先尝试转成数字,如果报错则转换成string
v
,
err
:=
row
.
Int64Err
(
i
)
values
[
i
]
=
strconv
.
FormatInt
(
v
,
10
)
if
err
!=
nil
{
if
v
,
err
:=
row
.
Int64Err
(
i
);
err
!=
nil
{
values
[
i
]
=
string
(
data
)
}
else
{
values
[
i
]
=
strconv
.
FormatInt
(
v
,
10
)
}
case
time
.
Time
:
values
[
i
]
=
mysql
.
TimeString
(
data
)
...
...
env/env.go
浏览文件 @
6c47c870
...
...
@@ -153,37 +153,42 @@ func (ve VirtualEnv) CleanUp() bool {
// CleanupTestDatabase 清除一小时前的环境
func
(
ve
*
VirtualEnv
)
CleanupTestDatabase
()
{
common
.
Log
.
Debug
(
"CleanupTestDatabase ..."
)
dbs
,
err
:=
ve
.
Query
(
"show databases like 'optimizer%'"
)
if
err
==
nil
{
for
_
,
row
:=
range
dbs
.
Rows
{
testDatabase
:=
row
.
Str
(
0
)
// test temporary database format `optimizer_YYMMDDHHmmss_randomString(16)`
if
len
(
testDatabase
)
!=
39
{
common
.
Log
.
Debug
(
"CleanupTestDatabase by pass %s"
,
testDatabase
)
continue
}
s
:=
strings
.
Split
(
testDatabase
,
"_"
)
pastTime
,
err
:=
time
.
Parse
(
"060102150405"
,
s
[
1
])
if
err
!=
nil
{
common
.
Log
.
Error
(
"CleanupTestDatabase compute pastTime Error: %s"
,
err
.
Error
())
dbs
,
err
:=
ve
.
Query
(
"show databases like 'optimizer%%'"
)
if
err
!=
nil
{
common
.
Log
.
Error
(
"CleanupTestDatabase failed Error:%s"
,
err
.
Error
())
return
}
// TODO: 1 hour should be config-able
minHour
:=
1
for
_
,
row
:=
range
dbs
.
Rows
{
testDatabase
:=
row
.
Str
(
0
)
// test temporary database format `optimizer_YYMMDDHHmmss_randomString(16)`
if
len
(
testDatabase
)
!=
39
{
common
.
Log
.
Debug
(
"CleanupTestDatabase by pass %s"
,
testDatabase
)
continue
}
s
:=
strings
.
Split
(
testDatabase
,
"_"
)
pastTime
,
err
:=
time
.
Parse
(
"060102150405"
,
s
[
1
])
if
err
!=
nil
{
common
.
Log
.
Error
(
"CleanupTestDatabase compute pastTime Error: %s"
,
err
.
Error
())
continue
}
subHour
:=
time
.
Now
()
.
Sub
(
pastTime
)
.
Hours
()
if
subHour
>
float64
(
minHour
)
{
if
_
,
err
:=
ve
.
Query
(
"drop database %s"
,
testDatabase
);
err
!=
nil
{
common
.
Log
.
Error
(
"CleanupTestDatabase failed Error: %s"
,
err
.
Error
())
continue
}
// TODO: 1 hour should be config-able
subHour
:=
time
.
Now
()
.
Sub
(
pastTime
)
.
Hours
()
if
subHour
>
1
{
_
,
err
:=
ve
.
Query
(
"drop database %s"
,
testDatabase
)
if
err
!=
nil
{
common
.
Log
.
Error
(
"CleanupTestDatabase failed Error: %s"
,
err
.
Error
())
continue
}
common
.
Log
.
Debug
(
"CleanupTestDatabase drop database %s success"
,
testDatabase
)
}
else
{
common
.
Log
.
Debug
(
"CleanupTestDatabase by pass database %s, less than %d hours"
,
testDatabase
,
subHour
)
}
common
.
Log
.
Debug
(
"CleanupTestDatabase drop database %s success"
,
testDatabase
)
continue
}
}
else
{
common
.
Log
.
Error
(
"CleanupTestDatabase failed Error:%s"
,
err
.
Error
())
common
.
Log
.
Debug
(
"CleanupTestDatabase by pass database %s, %.2f less than %d hours"
,
testDatabase
,
subHour
,
minHour
)
}
common
.
Log
.
Debug
(
"CleanupTestDatabase done"
)
return
}
// BuildVirtualEnv rEnv为SQL源环境,DB使用的信息从接口获取
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录