Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
8a5427c9
T
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1192
Star
22018
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
8a5427c9
编写于
11月 08, 2022
作者:
W
wenzhouwww@live.cn
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update
上级
17a502f5
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
77 addition
and
19 deletion
+77
-19
tests/pytest/crash_gen/crash_gen_main.py
tests/pytest/crash_gen/crash_gen_main.py
+25
-14
tests/pytest/crash_gen/shared/db.py
tests/pytest/crash_gen/shared/db.py
+52
-5
未找到文件。
tests/pytest/crash_gen/crash_gen_main.py
浏览文件 @
8a5427c9
...
...
@@ -1761,7 +1761,10 @@ class TaskCreateSuperTable(StateTransitionTask):
sTable
=
self
.
_db
.
getFixedSuperTable
()
# type: TdSuperTable
# wt.execSql("use db") # should always be in place
if
sTable
.
hasStreams
(
wt
.
getDbConn
())
or
sTable
.
hasStreamTables
(
wt
.
getDbConn
()):
sTable
.
dropStreams
(
wt
.
getDbConn
())
sTable
.
dropStreamTables
(
wt
.
getDbConn
())
sTable
.
create
(
wt
.
getDbConn
(),
{
'ts'
:
TdDataType
.
TIMESTAMP
,
'speed'
:
TdDataType
.
INT
,
'color'
:
TdDataType
.
BINARY16
},
{
'b'
:
TdDataType
.
BINARY200
,
'f'
:
TdDataType
.
FLOAT
},
...
...
@@ -2557,16 +2560,20 @@ class TaskDeleteData(StateTransitionTask):
# Now read it back and verify, we might encounter an error if table is dropped
if
Config
.
getConfig
().
verify_data
:
# only if command line asks for it
try
:
readBack
=
dbc
.
queryScalar
(
"SELECT * from {}.{} WHERE ts='{}'"
.
dbc
.
query
(
"SELECT * from {}.{} WHERE ts='{}'"
.
format
(
db
.
getName
(),
regTableName
,
nextTick
))
if
readBack
==
None
:
pass
result
=
dbc
.
getQueryResult
()
if
len
(
result
)
==
0
:
# means data has been delete
print
(
"D1"
,
end
=
""
)
# DF means delete failed
else
:
print
(
"DF"
,
end
=
""
)
# DF means delete failed
except
taos
.
error
.
ProgrammingError
as
err
:
errno
=
Helper
.
convertErrno
(
err
.
errno
)
if
errno
==
CrashGenError
.
INVALID_EMPTY_RESULT
:
# empty result
print
(
"D1"
,
end
=
""
)
# D1 means delete data success and only 1 record
#
if errno == CrashGenError.INVALID_EMPTY_RESULT: # empty result
#
print("D1",end="") # D1 means delete data success and only 1 record
elif
errno
in
[
0x218
,
0x3
62
]:
# table doesn't exist
if
errno
in
[
0x218
,
0x362
,
0x26
62
]:
# table doesn't exist
# do nothing
pass
else
:
...
...
@@ -2612,16 +2619,20 @@ class TaskDeleteData(StateTransitionTask):
# Now read it back and verify, we might encounter an error if table is dropped
if
Config
.
getConfig
().
verify_data
:
# only if command line asks for it
try
:
readBack
=
dbc
.
queryScalar
(
"SELECT * from {}.{} "
.
format
(
db
.
getName
(),
regTableName
))
if
readBack
==
None
:
pass
dbc
.
query
(
"SELECT * from {}.{} WHERE ts='{}'"
.
format
(
db
.
getName
(),
regTableName
,
nextTick
))
result
=
dbc
.
getQueryResult
()
if
len
(
result
)
==
0
:
# means data has been delete
print
(
"DA"
,
end
=
""
)
else
:
print
(
"DF"
,
end
=
""
)
# DF means delete failed
except
taos
.
error
.
ProgrammingError
as
err
:
errno
=
Helper
.
convertErrno
(
err
.
errno
)
if
errno
==
CrashGenError
.
INVALID_EMPTY_RESULT
:
# empty result
print
(
"Da"
,
end
=
""
)
# Da means delete data success and for all datas
#
if errno == CrashGenError.INVALID_EMPTY_RESULT: # empty result
#
print("Da",end="") # Da means delete data success and for all datas
elif
errno
in
[
0x218
,
0x3
62
]:
# table doesn't exist
if
errno
in
[
0x218
,
0x362
,
0x26
62
]:
# table doesn't exist
# do nothing
pass
else
:
...
...
tests/pytest/crash_gen/shared/db.py
浏览文件 @
8a5427c9
...
...
@@ -26,9 +26,12 @@ class DbConn:
TYPE_NATIVE
=
"native-c"
TYPE_REST
=
"rest-api"
TYPE_INVALID
=
"invalid"
# class variables
lastSqlFromThreads
:
dict
[
int
,
str
]
=
{}
# stored by thread id, obtained from threading.current_thread().ident%10000
spendThreads
:
dict
[
int
,
float
]
=
{}
# stored by thread id, obtained from threading.current_thread().ident%10000
@
classmethod
def
saveSqlForCurrentThread
(
cls
,
sql
:
str
):
...
...
@@ -37,15 +40,36 @@ class DbConn:
run into a dead-lock situation, we can pick out the deadlocked thread, and use
that information to find what what SQL statement is stuck.
'''
th
=
threading
.
current_thread
()
shortTid
=
th
.
native_id
%
10000
#type: ignore
cls
.
lastSqlFromThreads
[
shortTid
]
=
sql
# Save this for later
@
classmethod
def
fetchSqlForThread
(
cls
,
shortTid
:
int
)
->
str
:
def
fetchSqlForThread
(
cls
,
shortTid
:
int
)
->
str
:
print
(
"======================="
)
if
shortTid
not
in
cls
.
lastSqlFromThreads
:
raise
CrashGenError
(
"No last-attempted-SQL found for thread id: {}"
.
format
(
shortTid
))
return
cls
.
lastSqlFromThreads
[
shortTid
]
return
cls
.
lastSqlFromThreads
[
shortTid
]
@
classmethod
def
sql_exec_spend
(
cls
,
cost
:
float
):
'''
Let us save the last SQL statement on a per-thread basis, so that when later we
run into a dead-lock situation, we can pick out the deadlocked thread, and use
that information to find what what SQL statement is stuck.
'''
th
=
threading
.
current_thread
()
shortTid
=
th
.
native_id
%
10000
#type: ignore
cls
.
spendThreads
[
shortTid
]
=
cost
# Save this for later
@
classmethod
def
get_time_cost
(
cls
)
->
float
:
th
=
threading
.
current_thread
()
shortTid
=
th
.
native_id
%
10000
#type: ignore
return
cls
.
spendThreads
.
get
(
shortTid
)
@
classmethod
def
create
(
cls
,
connType
,
dbTarget
):
...
...
@@ -61,6 +85,7 @@ class DbConn:
def
createNative
(
cls
,
dbTarget
)
->
DbConn
:
return
cls
.
create
(
cls
.
TYPE_NATIVE
,
dbTarget
)
@
classmethod
def
createRest
(
cls
,
dbTarget
)
->
DbConn
:
return
cls
.
create
(
cls
.
TYPE_REST
,
dbTarget
)
...
...
@@ -75,6 +100,7 @@ class DbConn:
return
"[DbConn: type={}, target={}]"
.
format
(
self
.
_type
,
self
.
_dbTarget
)
def
getLastSql
(
self
):
return
self
.
_lastSql
def
open
(
self
):
...
...
@@ -184,13 +210,19 @@ class DbConnRest(DbConn):
def
_doSql
(
self
,
sql
):
self
.
_lastSql
=
sql
# remember this, last SQL attempted
self
.
saveSqlForCurrentThread
(
sql
)
# Save in global structure too. #TODO: combine with above
try
:
time_cost
=
-
1
time_start
=
time
.
time
()
try
:
r
=
requests
.
post
(
self
.
_url
,
data
=
sql
,
auth
=
HTTPBasicAuth
(
'root'
,
'taosdata'
))
auth
=
HTTPBasicAuth
(
'root'
,
'taosdata'
))
except
:
print
(
"REST API Failure (TODO: more info here)"
)
self
.
sql_exec_spend
(
-
2
)
raise
finally
:
time_cost
=
time
.
time
()
-
time_start
self
.
sql_exec_spend
(
time_cost
)
rj
=
r
.
json
()
# Sanity check for the "Json Result"
if
(
'status'
not
in
rj
):
...
...
@@ -223,6 +255,8 @@ class DbConnRest(DbConn):
"[SQL-REST] Execution Result, nRows = {}, SQL = {}"
.
format
(
nRows
,
sql
))
return
nRows
def
query
(
self
,
sql
):
# return rows affected
return
self
.
execute
(
sql
)
...
...
@@ -336,6 +370,7 @@ class MyTDSql:
raise
return
self
.
affectedRows
class
DbTarget
:
def
__init__
(
self
,
cfgPath
,
hostAddr
,
port
):
self
.
cfgPath
=
cfgPath
...
...
@@ -355,6 +390,7 @@ class DbConnNative(DbConn):
# _connInfoDisplayed = False # TODO: find another way to display this
totalConnections
=
0
# Not private
totalRequests
=
0
time_cost
=
-
1
def
__init__
(
self
,
dbTarget
):
super
().
__init__
(
dbTarget
)
...
...
@@ -413,8 +449,19 @@ class DbConnNative(DbConn):
"Cannot exec SQL unless db connection is open"
,
CrashGenError
.
DB_CONNECTION_NOT_OPEN
)
Logging
.
debug
(
"[SQL] Executing SQL: {}"
.
format
(
sql
))
self
.
_lastSql
=
sql
time_cost
=
-
1
nRows
=
0
time_start
=
time
.
time
()
self
.
saveSqlForCurrentThread
(
sql
)
# Save in global structure too. #TODO: combine with above
nRows
=
self
.
_tdSql
.
execute
(
sql
)
try
:
nRows
=
self
.
_tdSql
.
execute
(
sql
)
except
Exception
as
e
:
self
.
sql_exec_spend
(
-
2
)
finally
:
time_cost
=
time
.
time
()
-
time_start
self
.
sql_exec_spend
(
time_cost
)
cls
=
self
.
__class__
cls
.
totalRequests
+=
1
Logging
.
debug
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录