Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
968285e4
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
968285e4
编写于
11月 06, 2020
作者:
S
Shengliang Guan
提交者:
GitHub
11月 06, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #4129 from taosdata/feature/crash_gen
Refactoring crash_gen tool, helping to reproduce TD-1955
上级
c1d7a1a7
9ab8fb5b
变更
5
展开全部
隐藏空白更改
内联
并排
Showing
5 changed file
with
261 addition
and
114 deletion
+261
-114
tests/pytest/crash_gen/crash_gen_main.py
tests/pytest/crash_gen/crash_gen_main.py
+187
-86
tests/pytest/crash_gen/db.py
tests/pytest/crash_gen/db.py
+6
-0
tests/pytest/crash_gen/misc.py
tests/pytest/crash_gen/misc.py
+7
-2
tests/pytest/crash_gen/service_manager.py
tests/pytest/crash_gen/service_manager.py
+60
-25
tests/pytest/crash_gen_bootstrap.py
tests/pytest/crash_gen_bootstrap.py
+1
-1
未找到文件。
tests/pytest/crash_gen/crash_gen.py
→
tests/pytest/crash_gen/crash_gen
_main
.py
浏览文件 @
968285e4
此差异已折叠。
点击以展开。
tests/pytest/crash_gen/db.py
浏览文件 @
968285e4
...
...
@@ -95,6 +95,11 @@ class DbConn:
# print("dbs = {}, str = {}, ret2={}, type2={}".format(dbs, dbName,ret2, type(dbName)))
return
dbName
in
dbs
# TODO: super weird type mangling seen, once here
def
existsSuperTable
(
self
,
stName
):
self
.
query
(
"show stables"
)
sts
=
[
v
[
0
]
for
v
in
self
.
getQueryResult
()]
return
stName
in
sts
def
hasTables
(
self
):
return
self
.
query
(
"show tables"
)
>
0
...
...
@@ -240,6 +245,7 @@ class MyTDSql:
def
_execInternal
(
self
,
sql
):
startTime
=
time
.
time
()
# Logging.debug("Executing SQL: " + sql)
ret
=
self
.
_cursor
.
execute
(
sql
)
# print("\nSQL success: {}".format(sql))
queryTime
=
time
.
time
()
-
startTime
...
...
tests/pytest/crash_gen/misc.py
浏览文件 @
968285e4
...
...
@@ -27,7 +27,7 @@ class LoggingFilter(logging.Filter):
class
MyLoggingAdapter
(
logging
.
LoggerAdapter
):
def
process
(
self
,
msg
,
kwargs
):
return
"[{}] {}"
.
format
(
threading
.
get_ident
()
%
10000
,
msg
),
kwargs
return
"[{
:04d
}] {}"
.
format
(
threading
.
get_ident
()
%
10000
,
msg
),
kwargs
# return '[%s] %s' % (self.extra['connid'], msg), kwargs
...
...
@@ -51,7 +51,7 @@ class Logging:
_logger
.
addHandler
(
ch
)
# Logging adapter, to be used as a logger
print
(
"setting logger variable"
)
#
print("setting logger variable")
# global logger
cls
.
logger
=
MyLoggingAdapter
(
_logger
,
[])
...
...
@@ -166,6 +166,9 @@ class Progress:
SERVICE_RECONNECT_START
=
4
SERVICE_RECONNECT_SUCCESS
=
5
SERVICE_RECONNECT_FAILURE
=
6
SERVICE_START_NAP
=
7
CREATE_TABLE_ATTEMPT
=
8
tokens
=
{
STEP_BOUNDARY
:
'.'
,
BEGIN_THREAD_STEP
:
'['
,
...
...
@@ -174,6 +177,8 @@ class Progress:
SERVICE_RECONNECT_START
:
'<r.'
,
SERVICE_RECONNECT_SUCCESS
:
'.r>'
,
SERVICE_RECONNECT_FAILURE
:
'.xr>'
,
SERVICE_START_NAP
:
'_zz'
,
CREATE_TABLE_ATTEMPT
:
'_c'
,
}
@
classmethod
...
...
tests/pytest/crash_gen/service_manager.py
浏览文件 @
968285e4
...
...
@@ -47,6 +47,17 @@ class TdeInstance():
.
format
(
selfPath
,
projPath
))
return
buildPath
@
classmethod
def
prepareGcovEnv
(
cls
,
env
):
# Ref: https://gcc.gnu.org/onlinedocs/gcc/Cross-profiling.html
bPath
=
cls
.
_getBuildPath
()
# build PATH
numSegments
=
len
(
bPath
.
split
(
'/'
))
-
1
# "/x/TDengine/build" should yield 3
numSegments
=
numSegments
-
1
# DEBUG only
env
[
'GCOV_PREFIX'
]
=
bPath
+
'/svc_gcov'
env
[
'GCOV_PREFIX_STRIP'
]
=
str
(
numSegments
)
# Strip every element, plus, ENV needs strings
Logging
.
info
(
"Preparing GCOV environement to strip {} elements and use path: {}"
.
format
(
numSegments
,
env
[
'GCOV_PREFIX'
]
))
def
__init__
(
self
,
subdir
=
'test'
,
tInstNum
=
0
,
port
=
6030
,
fepPort
=
6030
):
self
.
_buildDir
=
self
.
_getBuildPath
()
self
.
_subdir
=
'/'
+
subdir
# TODO: tolerate "/"
...
...
@@ -217,6 +228,11 @@ class TdeSubProcess:
# raise CrashGenError("Empty instance not allowed in TdeSubProcess")
# self._tInst = tInst # Default create at ServiceManagerThread
def
__repr__
(
self
):
if
self
.
subProcess
is
None
:
return
'[TdeSubProc: Empty]'
return
'[TdeSubProc: pid = {}]'
.
format
(
self
.
getPid
())
def
getStdOut
(
self
):
return
self
.
subProcess
.
stdout
...
...
@@ -235,17 +251,30 @@ class TdeSubProcess:
# Sanity check
if
self
.
subProcess
:
# already there
raise
RuntimeError
(
"Corrupt process state"
)
# Prepare environment variables for coverage information
# Ref: https://stackoverflow.com/questions/2231227/python-subprocess-popen-with-a-modified-environment
myEnv
=
os
.
environ
.
copy
()
TdeInstance
.
prepareGcovEnv
(
myEnv
)
# print(myEnv)
# print(myEnv.items())
# print("Starting TDengine via Shell: {}".format(cmdLineStr))
useShell
=
True
self
.
subProcess
=
subprocess
.
Popen
(
cmdLine
,
shell
=
False
,
' '
.
join
(
cmdLine
)
if
useShell
else
cmdLine
,
shell
=
useShell
,
# svcCmdSingle, shell=True, # capture core dump?
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
,
# bufsize=1, # not supported in binary mode
close_fds
=
ON_POSIX
close_fds
=
ON_POSIX
,
env
=
myEnv
)
# had text=True, which interferred with reading EOF
STOP_SIGNAL
=
signal
.
SIGKILL
# What signal to use (in kill) to stop a taosd process?
def
stop
(
self
):
"""
Stop a sub process, and try to return a meaningful return code.
...
...
@@ -267,7 +296,7 @@ class TdeSubProcess:
SIGUSR2 12
"""
if
not
self
.
subProcess
:
print
(
"Sub process already stopped"
)
Logging
.
error
(
"Sub process already stopped"
)
return
# -1
retCode
=
self
.
subProcess
.
poll
()
# ret -N means killed with signal N, otherwise it's from exit(N)
...
...
@@ -278,20 +307,25 @@ class TdeSubProcess:
return
retCode
# process still alive, let's interrupt it
print
(
"Terminate running process, send SIG_INT and wait..."
)
# sub process should end, then IPC queue should end, causing IO thread to end
# sig = signal.SIGINT
sig
=
signal
.
SIGKILL
self
.
subProcess
.
send_signal
(
sig
)
# SIGNINT or SIGKILL
Logging
.
info
(
"Terminate running process, send SIG_{} and wait..."
.
format
(
self
.
STOP_SIGNAL
))
# sub process should end, then IPC queue should end, causing IO thread to end
topSubProc
=
psutil
.
Process
(
self
.
subProcess
.
pid
)
for
child
in
topSubProc
.
children
(
recursive
=
True
):
# or parent.children() for recursive=False
child
.
send_signal
(
self
.
STOP_SIGNAL
)
time
.
sleep
(
0.2
)
# 200 ms
# topSubProc.send_signal(sig) # now kill the main sub process (likely the Shell)
self
.
subProcess
.
send_signal
(
self
.
STOP_SIGNAL
)
# main sub process (likely the Shell)
self
.
subProcess
.
wait
(
20
)
retCode
=
self
.
subProcess
.
returncode
# should always be there
# May throw subprocess.TimeoutExpired exception above, therefore
# The process is guranteed to have ended by now
self
.
subProcess
=
None
if
retCode
!=
0
:
# != (- signal.SIGINT):
Logging
.
error
(
"TSP.stop(): Failed to stop sub proc properly w/ SIG {}, retCode={}"
.
format
(
sig
,
retCode
))
Logging
.
error
(
"TSP.stop(): Failed to stop sub proc properly w/ SIG {}, retCode={}"
.
format
(
self
.
STOP_SIGNAL
,
retCode
))
else
:
Logging
.
info
(
"TSP.stop(): sub proc successfully terminated with SIG {}"
.
format
(
s
ig
))
Logging
.
info
(
"TSP.stop(): sub proc successfully terminated with SIG {}"
.
format
(
s
elf
.
STOP_SIGNAL
))
return
-
retCode
class
ServiceManager
:
...
...
@@ -439,7 +473,7 @@ class ServiceManager:
time
.
sleep
(
self
.
PAUSE_BETWEEN_IPC_CHECK
)
# pause, before next round
# raise CrashGenError("dummy")
print
(
"Service Manager Thread (with subprocess) ended, main thread exiting..."
)
Logging
.
info
(
"Service Manager Thread (with subprocess) ended, main thread exiting..."
)
def
_getFirstInstance
(
self
):
return
self
.
_tInsts
[
0
]
...
...
@@ -452,7 +486,7 @@ class ServiceManager:
# Find if there's already a taosd service, and then kill it
for
proc
in
psutil
.
process_iter
():
if
proc
.
name
()
==
'taosd'
:
print
(
"Killing an existing TAOSD process in 2 seconds... press CTRL-C to interrupt"
)
Logging
.
info
(
"Killing an existing TAOSD process in 2 seconds... press CTRL-C to interrupt"
)
time
.
sleep
(
2.0
)
proc
.
kill
()
# print("Process: {}".format(proc.name()))
...
...
@@ -559,7 +593,8 @@ class ServiceManagerThread:
for
i
in
range
(
0
,
100
):
time
.
sleep
(
1.0
)
# self.procIpcBatch() # don't pump message during start up
print
(
"_zz_"
,
end
=
""
,
flush
=
True
)
Progress
.
emit
(
Progress
.
SERVICE_START_NAP
)
# print("_zz_", end="", flush=True)
if
self
.
_status
.
isRunning
():
Logging
.
info
(
"[] TDengine service READY to process requests"
)
Logging
.
info
(
"[] TAOS service started: {}"
.
format
(
self
))
...
...
@@ -595,12 +630,12 @@ class ServiceManagerThread:
def
stop
(
self
):
# can be called from both main thread or signal handler
print
(
"Terminating TDengine service running as the sub process..."
)
Logging
.
info
(
"Terminating TDengine service running as the sub process..."
)
if
self
.
getStatus
().
isStopped
():
print
(
"Service already stopped"
)
Logging
.
info
(
"Service already stopped"
)
return
if
self
.
getStatus
().
isStopping
():
print
(
"Service is already being stopped"
)
Logging
.
info
(
"Service is already being stopped"
)
return
# Linux will send Control-C generated SIGINT to the TDengine process
# already, ref:
...
...
@@ -616,10 +651,10 @@ class ServiceManagerThread:
if
retCode
==
signal
.
SIGSEGV
:
# SGV
Logging
.
error
(
"[[--ERROR--]]: TDengine service SEGV fault (check core file!)"
)
except
subprocess
.
TimeoutExpired
as
err
:
print
(
"Time out waiting for TDengine service process to exit"
)
Logging
.
info
(
"Time out waiting for TDengine service process to exit"
)
else
:
if
self
.
_tdeSubProcess
.
isRunning
():
# still running, should now never happen
print
(
"FAILED to stop sub process, it is still running... pid = {}"
.
format
(
Logging
.
error
(
"FAILED to stop sub process, it is still running... pid = {}"
.
format
(
self
.
_tdeSubProcess
.
getPid
()))
else
:
self
.
_tdeSubProcess
=
None
# not running any more
...
...
@@ -683,9 +718,9 @@ class ServiceManagerThread:
return
# we are done with THIS BATCH
else
:
# got line, printing out
if
forceOutput
:
Logging
.
info
(
line
)
Logging
.
info
(
'[TAOSD] '
+
line
)
else
:
Logging
.
debug
(
line
)
Logging
.
debug
(
'[TAOSD] '
+
line
)
print
(
">"
,
end
=
""
,
flush
=
True
)
_ProgressBars
=
[
"--"
,
"//"
,
"||"
,
"
\\\\
"
]
...
...
@@ -728,11 +763,11 @@ class ServiceManagerThread:
# queue.put(line)
# meaning sub process must have died
Logging
.
info
(
"
\n
End of stream detected
for TDengine STDOUT: {}"
.
format
(
self
))
Logging
.
info
(
"
EOF
for TDengine STDOUT: {}"
.
format
(
self
))
out
.
close
()
def
svcErrorReader
(
self
,
err
:
IO
,
queue
):
for
line
in
iter
(
err
.
readline
,
b
''
):
print
(
"
\n
TDengine Service (taosd) ERROR (from stderr)
: {}"
.
format
(
line
))
Logging
.
info
(
"
\n
End of stream detected
for TDengine STDERR: {}"
.
format
(
self
))
Logging
.
info
(
"TDengine STDERR
: {}"
.
format
(
line
))
Logging
.
info
(
"
EOF
for TDengine STDERR: {}"
.
format
(
self
))
err
.
close
()
\ No newline at end of file
tests/pytest/crash_gen_bootstrap.py
浏览文件 @
968285e4
...
...
@@ -11,7 +11,7 @@
###################################################################
import
sys
from
crash_gen.crash_gen
import
MainExec
from
crash_gen.crash_gen
_main
import
MainExec
if
__name__
==
"__main__"
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录