Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
2c6c3775
T
TDengine
项目概览
慢慢CG
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
2c6c3775
编写于
8月 30, 2020
作者:
S
Steven Li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fixed a major problem in crash_gen tool, now it properly releases DB connections
上级
6c2d8067
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
40 addition
and
25 deletion
+40
-25
tests/pytest/crash_gen.py
tests/pytest/crash_gen.py
+40
-25
未找到文件。
tests/pytest/crash_gen.py
浏览文件 @
2c6c3775
...
...
@@ -766,27 +766,32 @@ class DbConnRest(DbConn):
class
MyTDSql
:
def
__init__
(
self
):
def
__init__
(
self
,
hostAddr
,
cfgPath
):
# Make the DB connection
self
.
_conn
=
taos
.
connect
(
host
=
hostAddr
,
config
=
cfgPath
)
self
.
_cursor
=
self
.
_conn
.
cursor
()
self
.
queryRows
=
0
self
.
queryCols
=
0
self
.
affectedRows
=
0
def
init
(
self
,
cursor
,
log
=
True
):
self
.
cursor
=
cursor
#
def init(self, cursor, log=True):
#
self.cursor = cursor
# if (log):
# caller = inspect.getframeinfo(inspect.stack()[1][0])
# self.cursor.log(caller.filename + ".sql")
def
close
(
self
):
self
.
cursor
.
close
()
self
.
_conn
.
close
()
# TODO: very important, cursor close does NOT close DB connection!
self
.
_cursor
.
close
()
def
query
(
self
,
sql
):
self
.
sql
=
sql
try
:
self
.
cursor
.
execute
(
sql
)
self
.
queryResult
=
self
.
cursor
.
fetchall
()
self
.
_
cursor
.
execute
(
sql
)
self
.
queryResult
=
self
.
_
cursor
.
fetchall
()
self
.
queryRows
=
len
(
self
.
queryResult
)
self
.
queryCols
=
len
(
self
.
cursor
.
description
)
self
.
queryCols
=
len
(
self
.
_
cursor
.
description
)
except
Exception
as
e
:
# caller = inspect.getframeinfo(inspect.stack()[1][0])
# args = (caller.filename, caller.lineno, sql, repr(e))
...
...
@@ -797,7 +802,7 @@ class MyTDSql:
def
execute
(
self
,
sql
):
self
.
sql
=
sql
try
:
self
.
affectedRows
=
self
.
cursor
.
execute
(
sql
)
self
.
affectedRows
=
self
.
_
cursor
.
execute
(
sql
)
except
Exception
as
e
:
# caller = inspect.getframeinfo(inspect.stack()[1][0])
# args = (caller.filename, caller.lineno, sql, repr(e))
...
...
@@ -810,12 +815,13 @@ class DbConnNative(DbConn):
# Class variables
_lock
=
threading
.
Lock
()
_connInfoDisplayed
=
False
totalConnections
=
0
# Not private
def
__init__
(
self
):
super
().
__init__
()
self
.
_type
=
self
.
TYPE_NATIVE
self
.
_conn
=
None
self
.
_cursor
=
None
#
self._cursor = None
def
getBuildPath
(
self
):
selfPath
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
...
...
@@ -832,7 +838,8 @@ class DbConnNative(DbConn):
buildPath
=
root
[:
len
(
root
)
-
len
(
"/build/bin"
)]
break
if
buildPath
==
None
:
raise
RuntimeError
(
"Failed to determine buildPath, selfPath={}, projPath={}"
.
format
(
selfPath
,
projPath
))
raise
RuntimeError
(
"Failed to determine buildPath, selfPath={}, projPath={}"
.
format
(
selfPath
,
projPath
))
return
buildPath
...
...
@@ -840,25 +847,34 @@ class DbConnNative(DbConn):
cfgPath
=
self
.
getBuildPath
()
+
"/test/cfg"
hostAddr
=
"127.0.0.1"
with
self
.
_lock
:
# force single threading for opening DB connections
if
not
self
.
_connInfoDisplayed
:
self
.
__class__
.
_connInfoDisplayed
=
True
# updating CLASS variable
logger
.
info
(
"Initiating TAOS native connection to {}, using config at {}"
.
format
(
hostAddr
,
cfgPath
))
self
.
_conn
=
taos
.
connect
(
host
=
hostAddr
,
config
=
cfgPath
)
# TODO: make configurable
self
.
_cursor
=
self
.
_conn
.
cursor
()
cls
=
self
.
__class__
# Get the class, to access class variables
with
cls
.
_lock
:
# force single threading for opening DB connections. # TODO: whaaat??!!!
if
not
cls
.
_connInfoDisplayed
:
cls
.
_connInfoDisplayed
=
True
# updating CLASS variable
logger
.
info
(
"Initiating TAOS native connection to {}, using config at {}"
.
format
(
hostAddr
,
cfgPath
))
# Make the connection
# self._conn = taos.connect(host=hostAddr, config=cfgPath) # TODO: make configurable
# self._cursor = self._conn.cursor()
# Record the count in the class
self
.
_tdSql
=
MyTDSql
(
hostAddr
,
cfgPath
)
# making DB connection
cls
.
totalConnections
+=
1
self
.
_
cursor
.
execute
(
'reset query cache'
)
self
.
_
tdSql
.
execute
(
'reset query cache'
)
# self._cursor.execute('use db') # do this at the beginning of every
# Open connection
self
.
_tdSql
=
MyTDSql
()
self
.
_tdSql
.
init
(
self
.
_cursor
)
#
self._tdSql = MyTDSql()
#
self._tdSql.init(self._cursor)
def
close
(
self
):
if
(
not
self
.
isOpen
):
raise
RuntimeError
(
"Cannot clean up database until connection is open"
)
self
.
_tdSql
.
close
()
# Decrement the class wide counter
cls
=
self
.
__class__
# Get the class, to access class variables
with
cls
.
_lock
:
cls
.
totalConnections
-=
1
logger
.
debug
(
"[DB] Database connection closed"
)
self
.
isOpen
=
False
...
...
@@ -1694,9 +1710,8 @@ class ExecutionStats:
logger
.
info
(
"| Total Elapsed Time (from wall clock): {:.3f} seconds"
.
format
(
self
.
_elapsedTime
))
logger
.
info
(
"| Top numbers written: {}"
.
format
(
TaskExecutor
.
getBoundedList
()))
logger
.
info
(
"| Top numbers written: {}"
.
format
(
TaskExecutor
.
getBoundedList
()))
logger
.
info
(
"| Total Number of Active DB Native Connections: {}"
.
format
(
DbConnNative
.
totalConnections
))
logger
.
info
(
"----------------------------------------------------------------------"
)
...
...
@@ -2474,7 +2489,7 @@ class ServiceManagerThread:
def
svcErrorReader
(
self
,
err
:
IO
,
queue
):
for
line
in
iter
(
err
.
readline
,
b
''
):
print
(
"
\n
TD
Svc STDERR
: {}"
.
format
(
line
))
print
(
"
\n
TD
engine Service (taosd) ERROR (from stderr)
: {}"
.
format
(
line
))
class
TdeSubProcess
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录