Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
镜像
OpenAtomFoundation
pika
提交
64ab01df
pika
项目概览
镜像
/
OpenAtomFoundation
/
pika
11 个月 前同步成功
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
pika
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
64ab01df
编写于
7月 14, 2016
作者:
Z
zhaoanan
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'timestamp-binlog' of github.com:Qihoo360/pika into timestamp-binlog
上级
c805b80e
35813d1c
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
49 addition
and
36 deletion
+49
-36
tools/binlog_tools/binlog_parser.cc
tools/binlog_tools/binlog_parser.cc
+49
-36
未找到文件。
tools/binlog_tools/binlog_parser.cc
浏览文件 @
64ab01df
...
...
@@ -19,28 +19,52 @@ static void Usage()
"
\t
Binlog_parser converts between pika's old binlog(before 2.1.0) and pika's new version binlog in timestamped format
\n
"
"
\t
-h -- show this help
\n
"
"
\t
-c -- convert case: old2new new2old new2read,default: old2new
\n
"
"
\t
-i -- path of input binlog files , default: ./old_log/
\n
"
"
\t
-i -- path of input binlog files , default: ./old_log/
write2file0
\n
"
"
\t
-o -- path to store output binlog files , default: ./new_log/
\n
"
"
\t
-f -- files to convert , seperated by , default: 0
\n
"
" example: ./binlog_parser -c old2new -i old_binlog_path -o new_binlog_path -f 0,1,2,3
\n
"
" example: ./binlog_parser -c old2new -i ./old_log/write2file0,write2file1 -o ./new_log/
\n
"
);
}
int
GetFiles
(
std
::
string
&
files_str
,
std
::
string
&
pattern
,
std
::
vector
<
int
>&
files
)
{
std
::
string
::
size_type
pos
;
std
::
string
file
;
int
GetFilesId
(
std
::
string
&
files_str
,
std
::
vector
<
int
>&
filesId
)
{
std
::
string
::
size_type
pos
;
std
::
string
pattern
=
std
::
string
(
","
);
files_str
+=
pattern
;
int
str_size
=
files_str
.
size
();
int
str_size
=
files_str
.
size
();
std
::
string
file
;
std
::
string
prefix
=
"write2file"
;
std
::
string
::
size_type
id_pos
;
for
(
int
i
=
0
;
i
<
str_size
;
i
++
)
{
pos
=
files_str
.
find
(
pattern
,
i
);
pos
=
files_str
.
find
(
pattern
,
i
);
if
(
pos
!=
(
unsigned
int
)
str_size
)
{
file
=
files_str
.
substr
(
i
,
pos
-
i
);
files
.
push_back
(
atoi
(
file
.
c_str
()));
i
=
pos
+
pattern
.
size
()
-
1
;
}
}
return
files
.
size
();
file
=
files_str
.
substr
(
i
,
pos
-
i
);
id_pos
=
file
.
find
(
prefix
);
if
(
id_pos
==
std
::
string
::
npos
)
{
std
::
cout
<<
"inputfile using wrong prefix,write2file only"
<<
std
::
endl
;
exit
(
-
1
);
}
std
::
string
fileId
=
file
.
substr
(
id_pos
+
prefix
.
size
());
filesId
.
push_back
(
atoi
(
fileId
.
c_str
()));
i
=
pos
+
pattern
.
size
()
-
1
;
}
}
return
filesId
.
size
();
}
int
SplitePathAndFiles
(
std
::
string
input_str
,
std
::
string
&
path_str
,
std
::
vector
<
int
>&
filesId
)
{
std
::
string
pattern
=
std
::
string
(
"/"
);
int
str_size
=
input_str
.
size
();
if
(
str_size
<=
1
)
{
std
::
cout
<<
"input files not valid : make it followed by /write2files"
<<
std
::
endl
;
}
std
::
string
::
size_type
found
;
found
=
input_str
.
find_last_of
(
pattern
);
if
(
found
==
std
::
string
::
npos
||
found
>=
(
unsigned
int
)(
str_size
-
10
))
{
std
::
cout
<<
"input path not valid : make it followed by /write2files"
<<
std
::
endl
;
exit
(
-
1
);
}
path_str
=
input_str
.
substr
(
0
,
found
+
1
);
std
::
string
files_str
=
input_str
.
substr
(
found
+
1
);
return
GetFilesId
(
files_str
,
filesId
);
}
bool
CheckSequential
(
std
::
vector
<
int
>&
seq
)
{
...
...
@@ -62,28 +86,25 @@ int main(int argc, char *argv[]) {
exit
(
-
1
);
}
std
::
string
input_path
=
"./old_log/"
;
std
::
string
output_path
=
"./new_log/"
;
std
::
string
input_path
=
"./new_log/"
;
std
::
string
input_str
=
"./old_log/write2file0"
;
std
::
string
convert_type_str
=
"old2new"
;
std
::
string
files_str
=
"0"
;
// for correct inputs , we use these flags to generate warning to user
bool
default_input_
path
=
true
;
bool
default_input_
str
=
true
;
bool
default_output_path
=
true
;
bool
default_convert_type
=
true
;
bool
default_files
=
true
;
char
c
;
while
(
-
1
!=
(
c
=
getopt
(
argc
,
argv
,
"hi:c:o:
f:
t:"
)))
{
while
(
-
1
!=
(
c
=
getopt
(
argc
,
argv
,
"hi:c:o:t:"
)))
{
switch
(
c
)
{
case
'h'
:
Usage
();
exit
(
-
1
);
case
'i'
:
input_path
=
optarg
;
if
(
input_path
[
input_path
.
length
()
-
1
]
!=
'/'
)
{
input_path
.
append
(
"/"
);
}
default_input_path
=
false
;
input_str
=
optarg
;
default_input_str
=
false
;
break
;
case
'c'
:
convert_type_str
=
optarg
;
...
...
@@ -96,10 +117,6 @@ int main(int argc, char *argv[]) {
}
default_output_path
=
false
;
break
;
case
'f'
:
files_str
=
optarg
;
default_files
=
false
;
break
;
default:
Usage
();
exit
(
-
1
);
...
...
@@ -111,15 +128,12 @@ int main(int argc, char *argv[]) {
fprintf
(
stderr
,
"Error: conflict path for input and output path
\n
"
);
exit
(
-
1
);
}
if
(
default_input_
path
)
{
fprintf
(
stderr
,
"Warning: use default input
file path
\n
"
);
if
(
default_input_
str
)
{
fprintf
(
stderr
,
"Warning: use default input
path and file
\n
"
);
}
if
(
default_output_path
)
{
fprintf
(
stderr
,
"Warning: use default input file path
\n
"
);
}
if
(
default_files
)
{
fprintf
(
stderr
,
"Warning: use default input file number
\n
"
);
}
if
(
default_convert_type
)
{
fprintf
(
stderr
,
"Warning: use default convert type:%s
\n
"
,
convert_type_str
.
c_str
());
}
...
...
@@ -137,8 +151,7 @@ int main(int argc, char *argv[]) {
}
std
::
vector
<
int
>
files
;
std
::
string
comma
=
std
::
string
(
","
);
int
file_num
=
GetFiles
(
files_str
,
comma
,
files
);
int
file_num
=
SplitePathAndFiles
(
input_str
,
input_path
,
files
);
int
start_file
=
files
[
0
];
bool
isSequential
=
CheckSequential
(
files
);
if
(
!
isSequential
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录