Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Xiaomi
soar
提交
176d58ba
S
soar
项目概览
Xiaomi
/
soar
12 个月 前同步成功
通知
380
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,发现更多精彩内容 >>
提交
176d58ba
编写于
10月 27, 2018
作者:
W
WithLin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix issue #48
上级
fe5bba47
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
43 addition
and
2 deletion
+43
-2
cmd/soar/soar.go
cmd/soar/soar.go
+5
-0
common/config.go
common/config.go
+4
-0
env/env.go
env/env.go
+34
-2
未找到文件。
cmd/soar/soar.go
浏览文件 @
176d58ba
...
@@ -80,6 +80,11 @@ func main() {
...
@@ -80,6 +80,11 @@ func main() {
// 环境初始化,连接检查线上环境+构建测试环境
// 环境初始化,连接检查线上环境+构建测试环境
vEnv
,
rEnv
:=
env
.
BuildEnv
()
vEnv
,
rEnv
:=
env
.
BuildEnv
()
//如果使用CleanTestDataBase命令,则清除前1小时的数据库
if
common
.
Config
.
CleanTestDataBase
{
vEnv
.
CleanTestDataBase
()
}
// 如果使用到测试环境,在这里环境清理
// 如果使用到测试环境,在这里环境清理
if
common
.
Config
.
DropTestTemporary
{
if
common
.
Config
.
DropTestTemporary
{
defer
vEnv
.
CleanUp
()
defer
vEnv
.
CleanUp
()
...
...
common/config.go
浏览文件 @
176d58ba
...
@@ -119,6 +119,7 @@ type Configration struct {
...
@@ -119,6 +119,7 @@ type Configration struct {
Verbose
bool
`yaml:"verbose"`
// verbose模式,会多输出一些信息
Verbose
bool
`yaml:"verbose"`
// verbose模式,会多输出一些信息
DryRun
bool
`yaml:"dry-run"`
// 是否在预演环境执行
DryRun
bool
`yaml:"dry-run"`
// 是否在预演环境执行
MaxPrettySQLLength
int
`yaml:"max-pretty-sql-length"`
// 超出该长度的SQL会转换成指纹输出
MaxPrettySQLLength
int
`yaml:"max-pretty-sql-length"`
// 超出该长度的SQL会转换成指纹输出
CleanTestDataBase
bool
`yaml:"clean-test-database"`
// 清理数据库 issue #48
}
}
// getDefaultLogOutput get default log-output by runtime.GOOS
// getDefaultLogOutput get default log-output by runtime.GOOS
...
@@ -219,6 +220,7 @@ var Config = &Configration{
...
@@ -219,6 +220,7 @@ var Config = &Configration{
ListTestSqls
:
false
,
ListTestSqls
:
false
,
ListReportTypes
:
false
,
ListReportTypes
:
false
,
MaxPrettySQLLength
:
1024
,
MaxPrettySQLLength
:
1024
,
CleanTestDataBase
:
false
,
}
}
type
dsn
struct
{
type
dsn
struct
{
...
@@ -545,6 +547,7 @@ func readCmdFlags() error {
...
@@ -545,6 +547,7 @@ func readCmdFlags() error {
verbose
:=
flag
.
Bool
(
"verbose"
,
Config
.
Verbose
,
"Verbose"
)
verbose
:=
flag
.
Bool
(
"verbose"
,
Config
.
Verbose
,
"Verbose"
)
dryrun
:=
flag
.
Bool
(
"dry-run"
,
Config
.
DryRun
,
"是否在预演环境执行"
)
dryrun
:=
flag
.
Bool
(
"dry-run"
,
Config
.
DryRun
,
"是否在预演环境执行"
)
maxPrettySQLLength
:=
flag
.
Int
(
"max-pretty-sql-length"
,
Config
.
MaxPrettySQLLength
,
"MaxPrettySQLLength, 超出该长度的SQL会转换成指纹输出"
)
maxPrettySQLLength
:=
flag
.
Int
(
"max-pretty-sql-length"
,
Config
.
MaxPrettySQLLength
,
"MaxPrettySQLLength, 超出该长度的SQL会转换成指纹输出"
)
cleanTestDataBase
:=
flag
.
Bool
(
"clean-test-database"
,
Config
.
CleanTestDataBase
,
"由于程序异常退出,导致临时数据库的存在,可用此命令删除。"
)
// 一个不存在log-level,用于更新usage。
// 一个不存在log-level,用于更新usage。
// 因为vitess里面也用了flag,这些vitess的参数我们不需要关注
// 因为vitess里面也用了flag,这些vitess的参数我们不需要关注
if
!
Config
.
Verbose
&&
runtime
.
GOOS
!=
"windows"
{
if
!
Config
.
Verbose
&&
runtime
.
GOOS
!=
"windows"
{
...
@@ -648,6 +651,7 @@ func readCmdFlags() error {
...
@@ -648,6 +651,7 @@ func readCmdFlags() error {
Config
.
DryRun
=
*
dryrun
Config
.
DryRun
=
*
dryrun
Config
.
MaxPrettySQLLength
=
*
maxPrettySQLLength
Config
.
MaxPrettySQLLength
=
*
maxPrettySQLLength
Config
.
MaxVarcharLength
=
*
maxVarcharLength
Config
.
MaxVarcharLength
=
*
maxVarcharLength
Config
.
CleanTestDataBase
=
*
cleanTestDataBase
if
*
ver
{
if
*
ver
{
version
()
version
()
...
...
env/env.go
浏览文件 @
176d58ba
...
@@ -18,11 +18,12 @@ package env
...
@@ -18,11 +18,12 @@ package env
import
(
import
(
"fmt"
"fmt"
"strings"
"time"
"github.com/XiaoMi/soar/ast"
"github.com/XiaoMi/soar/ast"
"github.com/XiaoMi/soar/common"
"github.com/XiaoMi/soar/common"
"github.com/XiaoMi/soar/database"
"github.com/XiaoMi/soar/database"
"strings"
"time"
"github.com/dchest/uniuri"
"github.com/dchest/uniuri"
"vitess.io/vitess/go/vt/sqlparser"
"vitess.io/vitess/go/vt/sqlparser"
...
@@ -149,6 +150,37 @@ func (ve VirtualEnv) CleanUp() bool {
...
@@ -149,6 +150,37 @@ func (ve VirtualEnv) CleanUp() bool {
return
true
return
true
}
}
// CleanTestDataBase 清除一小时前的环境
func
(
ve
*
VirtualEnv
)
CleanTestDataBase
()
{
common
.
Log
.
Debug
(
"CleanTestDataBase ..."
)
dbs
,
err
:=
ve
.
Query
(
"show databases like 'optimizer%'"
)
if
err
==
nil
{
for
index
,
row
:=
range
dbs
.
Rows
{
s
:=
strings
.
Split
(
row
.
Str
(
index
),
"_"
)
pastTime
,
err
:=
time
.
Parse
(
"060102150405"
,
s
[
1
])
if
err
!=
nil
{
common
.
Log
.
Error
(
"CleanTestDataBase compute pastTime Error: %s"
,
err
)
}
nowTime
,
err
:=
time
.
Parse
(
"060102150405"
,
time
.
Now
()
.
Format
(
"060102150405"
))
if
err
!=
nil
{
common
.
Log
.
Error
(
"CleanTestDataBase compute nowTime Error: %s"
,
err
)
}
subHour
:=
nowTime
.
Sub
(
pastTime
)
.
Hours
()
if
subHour
>
1
{
_
,
err
:=
ve
.
Query
(
"drop database %s"
,
row
.
Str
(
index
))
if
err
!=
nil
{
common
.
Log
.
Error
(
"CleanTestDataBase failed Error: %s"
,
err
)
}
}
common
.
Log
.
Debug
(
"CleanTestDataBase, done"
)
}
}
else
{
common
.
Log
.
Error
(
"CleanTestDataBase failed Error:%s"
,
err
)
}
}
// BuildVirtualEnv rEnv为SQL源环境,DB使用的信息从接口获取
// BuildVirtualEnv rEnv为SQL源环境,DB使用的信息从接口获取
// 注意:如果是USE,DDL等语句,执行完第一条就会返回,后面的SQL不会执行
// 注意:如果是USE,DDL等语句,执行完第一条就会返回,后面的SQL不会执行
func
(
ve
*
VirtualEnv
)
BuildVirtualEnv
(
rEnv
*
database
.
Connector
,
SQLs
...
string
)
bool
{
func
(
ve
*
VirtualEnv
)
BuildVirtualEnv
(
rEnv
*
database
.
Connector
,
SQLs
...
string
)
bool
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录