Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
4c185833
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1187
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看板
提交
4c185833
编写于
8月 14, 2021
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'master' into feature/master1
上级
e87118e5
9161244c
变更
21
隐藏空白更改
内联
并排
Showing
21 changed file
with
1127 addition
and
550 deletion
+1127
-550
.drone.yml
.drone.yml
+16
-12
deps/MsvcLibX/src/iconv.c
deps/MsvcLibX/src/iconv.c
+4
-2
deps/MsvcLibX/src/main.c
deps/MsvcLibX/src/main.c
+6
-2
deps/MsvcLibX/src/realpath.c
deps/MsvcLibX/src/realpath.c
+12
-4
src/balance/src/bnScore.c
src/balance/src/bnScore.c
+11
-2
src/client/src/tscPrepare.c
src/client/src/tscPrepare.c
+3
-2
src/client/src/tscSql.c
src/client/src/tscSql.c
+3
-1
src/client/src/tscSubquery.c
src/client/src/tscSubquery.c
+4
-0
src/client/src/tscUtil.c
src/client/src/tscUtil.c
+9
-3
src/common/inc/tdataformat.h
src/common/inc/tdataformat.h
+6
-4
src/common/src/tdataformat.c
src/common/src/tdataformat.c
+3
-2
src/connector/nodejs/nodetaos/cinterface.js
src/connector/nodejs/nodetaos/cinterface.js
+24
-2
src/connector/nodejs/test/testnchar.js
src/connector/nodejs/test/testnchar.js
+33
-0
src/kit/shell/src/shellCheck.c
src/kit/shell/src/shellCheck.c
+3
-2
src/kit/taosdemo/taosdemo.c
src/kit/taosdemo/taosdemo.c
+953
-499
src/kit/taospack/taospack.c
src/kit/taospack/taospack.c
+4
-1
src/mnode/src/mnodeTable.c
src/mnode/src/mnodeTable.c
+3
-2
src/os/src/detail/osMemory.c
src/os/src/detail/osMemory.c
+3
-2
src/os/src/windows/wGetline.c
src/os/src/windows/wGetline.c
+4
-2
src/query/src/qTsbuf.c
src/query/src/qTsbuf.c
+5
-2
tests/script/general/parser/function.sim
tests/script/general/parser/function.sim
+18
-4
未找到文件。
.drone.yml
浏览文件 @
4c185833
...
...
@@ -15,7 +15,7 @@ steps:
-
mkdir debug
-
cd debug
-
cmake ..
-
make
-
make
-j4
trigger
:
event
:
-
pull_request
...
...
@@ -23,6 +23,7 @@ steps:
branch
:
-
develop
-
master
-
2.0
---
kind
:
pipeline
name
:
test_arm64_bionic
...
...
@@ -39,7 +40,7 @@ steps:
-
mkdir debug
-
cd debug
-
cmake .. -DCPUTYPE=aarch64 > /dev/null
-
make
-
make
-j4
trigger
:
event
:
-
pull_request
...
...
@@ -66,7 +67,7 @@ steps:
-
mkdir debug
-
cd debug
-
cmake .. -DCPUTYPE=aarch64 > /dev/null
-
make
-
make
-j4
trigger
:
event
:
-
pull_request
...
...
@@ -91,7 +92,7 @@ steps:
-
mkdir debug
-
cd debug
-
cmake .. -DCPUTYPE=aarch64 > /dev/null
-
make
-
make
-j4
trigger
:
event
:
-
pull_request
...
...
@@ -116,7 +117,7 @@ steps:
-
mkdir debug
-
cd debug
-
cmake .. -DCPUTYPE=aarch64 > /dev/null
-
make
-
make
-j4
trigger
:
event
:
-
pull_request
...
...
@@ -142,7 +143,7 @@ steps:
-
mkdir debug
-
cd debug
-
cmake .. -DCPUTYPE=aarch32 > /dev/null
-
make
-
make
-j4
trigger
:
event
:
-
pull_request
...
...
@@ -150,6 +151,7 @@ steps:
branch
:
-
develop
-
master
-
2.0
---
kind
:
pipeline
name
:
build_trusty
...
...
@@ -168,7 +170,7 @@ steps:
-
mkdir debug
-
cd debug
-
cmake ..
-
make
-
make
-j4
trigger
:
event
:
-
pull_request
...
...
@@ -176,6 +178,7 @@ steps:
branch
:
-
develop
-
master
-
2.0
---
kind
:
pipeline
name
:
build_xenial
...
...
@@ -193,7 +196,7 @@ steps:
-
mkdir debug
-
cd debug
-
cmake ..
-
make
-
make
-j4
trigger
:
event
:
-
pull_request
...
...
@@ -201,7 +204,7 @@ steps:
branch
:
-
develop
-
master
-
2.0
---
kind
:
pipeline
name
:
build_bionic
...
...
@@ -218,7 +221,7 @@ steps:
-
mkdir debug
-
cd debug
-
cmake ..
-
make
-
make
-j4
trigger
:
event
:
-
pull_request
...
...
@@ -226,6 +229,7 @@ steps:
branch
:
-
develop
-
master
-
2.0
---
kind
:
pipeline
name
:
build_centos7
...
...
@@ -241,7 +245,7 @@ steps:
-
mkdir debug
-
cd debug
-
cmake ..
-
make
-
make
-j4
trigger
:
event
:
-
pull_request
...
...
@@ -249,4 +253,4 @@ steps:
branch
:
-
develop
-
master
-
2.0
\ No newline at end of file
deps/MsvcLibX/src/iconv.c
浏览文件 @
4c185833
...
...
@@ -98,6 +98,7 @@ int ConvertString(char *buf, size_t nBytes, UINT cpFrom, UINT cpTo, LPCSTR lpDef
char
*
DupAndConvert
(
const
char
*
string
,
UINT
cpFrom
,
UINT
cpTo
,
LPCSTR
lpDefaultChar
)
{
int
nBytes
;
char
*
pBuf
;
char
*
pBuf1
;
nBytes
=
4
*
((
int
)
lstrlen
(
string
)
+
1
);
/* Worst case for the size needed */
pBuf
=
(
char
*
)
malloc
(
nBytes
);
if
(
!
pBuf
)
{
...
...
@@ -110,8 +111,9 @@ char *DupAndConvert(const char *string, UINT cpFrom, UINT cpTo, LPCSTR lpDefault
free
(
pBuf
);
return
NULL
;
}
pBuf
=
realloc
(
pBuf
,
nBytes
+
1
);
return
pBuf
;
pBuf1
=
realloc
(
pBuf
,
nBytes
+
1
);
if
(
pBuf1
==
NULL
&&
pBuf
!=
NULL
)
free
(
pBuf
);
return
pBuf1
;
}
int
CountCharacters
(
const
char
*
string
,
UINT
cp
)
{
...
...
deps/MsvcLibX/src/main.c
浏览文件 @
4c185833
...
...
@@ -68,6 +68,7 @@ int BreakArgLine(LPSTR pszCmdLine, char ***pppszArg) {
int
iString
=
FALSE
;
/* TRUE = string mode; FALSE = non-string mode */
int
nBackslash
=
0
;
char
**
ppszArg
;
char
**
ppszArg1
;
int
iArg
=
FALSE
;
/* TRUE = inside an argument; FALSE = between arguments */
ppszArg
=
(
char
**
)
malloc
((
argc
+
1
)
*
sizeof
(
char
*
));
...
...
@@ -89,7 +90,10 @@ int BreakArgLine(LPSTR pszCmdLine, char ***pppszArg) {
if
((
!
iArg
)
&&
(
c
!=
' '
)
&&
(
c
!=
'\t'
))
{
/* Beginning of a new argument */
iArg
=
TRUE
;
ppszArg
[
argc
++
]
=
pszCopy
+
j
;
ppszArg
=
(
char
**
)
realloc
(
ppszArg
,
(
argc
+
1
)
*
sizeof
(
char
*
));
ppszArg1
=
(
char
**
)
realloc
(
ppszArg
,
(
argc
+
1
)
*
sizeof
(
char
*
));
if
(
ppszArg1
==
NULL
&&
ppszArg
!=
NULL
)
free
(
ppszArg
);
ppszArg
=
ppszArg1
;
if
(
!
ppszArg
)
return
-
1
;
pszCopy
[
j
]
=
c0
=
'\0'
;
}
...
...
@@ -212,7 +216,7 @@ int _initU(void) {
fprintf
(
stderr
,
"Warning: Can't convert the argument line to UTF-8
\n
"
);
_acmdln
[
0
]
=
'\0'
;
}
realloc
(
_acmdln
,
n
+
1
);
/* Resize the memory block to fit the UTF-8 line */
//
realloc(_acmdln, n+1); /* Resize the memory block to fit the UTF-8 line */
/* Should not fail since we make it smaller */
/* Record the console code page, to allow converting the output accordingly */
...
...
deps/MsvcLibX/src/realpath.c
浏览文件 @
4c185833
...
...
@@ -196,6 +196,7 @@ not_compact_enough:
/* Normally defined in stdlib.h. Output buf must contain PATH_MAX bytes */
char
*
realpath
(
const
char
*
path
,
char
*
outbuf
)
{
char
*
pOutbuf
=
outbuf
;
char
*
pOutbuf1
;
int
iErr
;
const
char
*
pc
;
...
...
@@ -242,8 +243,11 @@ realpath_failed:
return
NULL
;
}
if
(
!
outbuf
)
pOutbuf
=
realloc
(
pOutbuf
,
strlen
(
pOutbuf
)
+
1
);
return
pOutbuf
;
if
(
!
outbuf
)
{
pOutbuf1
=
realloc
(
pOutbuf
,
strlen
(
pOutbuf
)
+
1
);
if
(
pOutbuf1
==
NULL
&&
pOutbuf
)
free
(
pOutbuf
);
}
return
pOutbuf1
;
}
#endif
...
...
@@ -517,6 +521,7 @@ int ResolveLinksA(const char *path, char *buf, size_t bufsize) {
/* Normally defined in stdlib.h. Output buf must contain PATH_MAX bytes */
char
*
realpathU
(
const
char
*
path
,
char
*
outbuf
)
{
char
*
pOutbuf
=
outbuf
;
char
*
pOutbuf1
;
char
*
pPath1
=
NULL
;
char
*
pPath2
=
NULL
;
int
iErr
;
...
...
@@ -590,10 +595,13 @@ realpathU_failed:
}
DEBUG_LEAVE
((
"return 0x%p; //
\"
%s
\"\n
"
,
pOutbuf
,
pOutbuf
));
if
(
!
outbuf
)
pOutbuf
=
realloc
(
pOutbuf
,
strlen
(
pOutbuf
)
+
1
);
if
(
!
outbuf
)
{
pOutbuf1
=
realloc
(
pOutbuf
,
strlen
(
pOutbuf
)
+
1
);
if
(
pOutbuf1
==
NULL
&&
pOutbuf
)
free
(
pOutbuf
);
}
free
(
pPath1
);
free
(
pPath2
);
return
pOutbuf
;
return
pOutbuf
1
;
}
#endif
/* defined(_WIN32) */
...
...
src/balance/src/bnScore.c
浏览文件 @
4c185833
...
...
@@ -116,8 +116,17 @@ void bnCleanupDnodes() {
static
void
bnCheckDnodesSize
(
int32_t
dnodesNum
)
{
if
(
tsBnDnodes
.
maxSize
<=
dnodesNum
)
{
tsBnDnodes
.
maxSize
=
dnodesNum
*
2
;
tsBnDnodes
.
list
=
realloc
(
tsBnDnodes
.
list
,
tsBnDnodes
.
maxSize
*
sizeof
(
SDnodeObj
*
));
int32_t
maxSize
=
dnodesNum
*
2
;
SDnodeObj
**
list1
=
NULL
;
int32_t
retry
=
0
;
while
(
list1
==
NULL
&&
retry
++
<
3
)
{
list1
=
realloc
(
tsBnDnodes
.
list
,
maxSize
*
sizeof
(
SDnodeObj
*
));
}
if
(
list1
)
{
tsBnDnodes
.
list
=
list1
;
tsBnDnodes
.
maxSize
=
maxSize
;
}
}
}
...
...
src/client/src/tscPrepare.c
浏览文件 @
4c185833
...
...
@@ -1527,8 +1527,9 @@ int taos_stmt_prepare(TAOS_STMT* stmt, const char* sql, unsigned long length) {
pCmd
->
insertParam
.
insertType
=
TSDB_QUERY_TYPE_STMT_INSERT
;
pCmd
->
insertParam
.
objectId
=
pSql
->
self
;
pSql
->
sqlstr
=
realloc
(
pSql
->
sqlstr
,
sqlLen
+
1
);
char
*
sqlstr
=
realloc
(
pSql
->
sqlstr
,
sqlLen
+
1
);
if
(
sqlstr
==
NULL
&&
pSql
->
sqlstr
)
free
(
pSql
->
sqlstr
);
pSql
->
sqlstr
=
sqlstr
;
if
(
pSql
->
sqlstr
==
NULL
)
{
tscError
(
"%p failed to malloc sql string buffer"
,
pSql
);
STMT_RET
(
TSDB_CODE_TSC_OUT_OF_MEMORY
);
...
...
src/client/src/tscSql.c
浏览文件 @
4c185833
...
...
@@ -887,7 +887,9 @@ int taos_validate_sql(TAOS *taos, const char *sql) {
return
TSDB_CODE_TSC_EXCEED_SQL_LIMIT
;
}
pSql
->
sqlstr
=
realloc
(
pSql
->
sqlstr
,
sqlLen
+
1
);
char
*
sqlstr
=
realloc
(
pSql
->
sqlstr
,
sqlLen
+
1
);
if
(
sqlstr
==
NULL
&&
pSql
->
sqlstr
)
free
(
pSql
->
sqlstr
);
pSql
->
sqlstr
=
sqlstr
;
if
(
pSql
->
sqlstr
==
NULL
)
{
tscError
(
"0x%"
PRIx64
" failed to malloc sql string buffer"
,
pSql
->
self
);
tfree
(
pSql
);
...
...
src/client/src/tscSubquery.c
浏览文件 @
4c185833
...
...
@@ -2397,6 +2397,10 @@ int32_t tscHandleFirstRoundStableQuery(SSqlObj *pSql) {
}
else
{
SSchema
ss
=
{.
type
=
(
uint8_t
)
pCol
->
info
.
type
,
.
bytes
=
pCol
->
info
.
bytes
,
.
colId
=
(
int16_t
)
pCol
->
columnIndex
};
tscColumnListInsert
(
pNewQueryInfo
->
colList
,
pCol
->
columnIndex
,
pCol
->
tableUid
,
&
ss
);
int32_t
ti
=
tscColumnExists
(
pNewQueryInfo
->
colList
,
pCol
->
columnIndex
,
pCol
->
tableUid
);
assert
(
ti
>=
0
);
SColumn
*
x
=
taosArrayGetP
(
pNewQueryInfo
->
colList
,
ti
);
tscColumnCopy
(
x
,
pCol
);
}
}
}
...
...
src/client/src/tscUtil.c
浏览文件 @
4c185833
...
...
@@ -625,8 +625,10 @@ static void setResRawPtrImpl(SSqlRes* pRes, SInternalField* pInfo, int32_t i, bo
}
else
if
(
convertNchar
&&
pInfo
->
field
.
type
==
TSDB_DATA_TYPE_NCHAR
)
{
// convert unicode to native code in a temporary buffer extra one byte for terminated symbol
pRes
->
buffer
[
i
]
=
realloc
(
pRes
->
buffer
[
i
],
pInfo
->
field
.
bytes
*
pRes
->
numOfRows
);
char
*
buffer
=
realloc
(
pRes
->
buffer
[
i
],
pInfo
->
field
.
bytes
*
pRes
->
numOfRows
);
if
(
buffer
==
NULL
)
return
;
pRes
->
buffer
[
i
]
=
buffer
;
// string terminated char for binary data
memset
(
pRes
->
buffer
[
i
],
0
,
pInfo
->
field
.
bytes
*
pRes
->
numOfRows
);
...
...
@@ -4363,6 +4365,7 @@ int32_t tscCreateTableMetaFromSTableMeta(STableMeta** ppChild, const char* name,
STableMeta
*
p
=
NULL
;
size_t
sz
=
0
;
STableMeta
*
pChild
=
*
ppChild
;
STableMeta
*
pChild1
;
taosHashGetCloneExt
(
tscTableMetaMap
,
pChild
->
sTableName
,
strnlen
(
pChild
->
sTableName
,
TSDB_TABLE_FNAME_LEN
),
NULL
,
(
void
**
)
&
p
,
&
sz
);
...
...
@@ -4373,7 +4376,10 @@ int32_t tscCreateTableMetaFromSTableMeta(STableMeta** ppChild, const char* name,
int32_t
totalBytes
=
(
p
->
tableInfo
.
numOfColumns
+
p
->
tableInfo
.
numOfTags
)
*
sizeof
(
SSchema
);
int32_t
tableMetaSize
=
sizeof
(
STableMeta
)
+
totalBytes
;
if
(
*
tableMetaCapacity
<
tableMetaSize
)
{
pChild
=
realloc
(
pChild
,
tableMetaSize
);
pChild1
=
realloc
(
pChild
,
tableMetaSize
);
if
(
pChild1
==
NULL
)
return
-
1
;
pChild
=
pChild1
;
*
tableMetaCapacity
=
(
size_t
)
tableMetaSize
;
}
...
...
src/common/inc/tdataformat.h
浏览文件 @
4c185833
...
...
@@ -547,8 +547,9 @@ SKVRow tdGetKVRowFromBuilder(SKVRowBuilder *pBuilder);
static
FORCE_INLINE
int
tdAddColToKVRow
(
SKVRowBuilder
*
pBuilder
,
int16_t
colId
,
int8_t
type
,
void
*
value
)
{
if
(
pBuilder
->
nCols
>=
pBuilder
->
tCols
)
{
pBuilder
->
tCols
*=
2
;
pBuilder
->
pColIdx
=
(
SColIdx
*
)
realloc
((
void
*
)(
pBuilder
->
pColIdx
),
sizeof
(
SColIdx
)
*
pBuilder
->
tCols
);
if
(
pBuilder
->
pColIdx
==
NULL
)
return
-
1
;
SColIdx
*
pColIdx
=
(
SColIdx
*
)
realloc
((
void
*
)(
pBuilder
->
pColIdx
),
sizeof
(
SColIdx
)
*
pBuilder
->
tCols
);
if
(
pColIdx
==
NULL
)
return
-
1
;
pBuilder
->
pColIdx
=
pColIdx
;
}
pBuilder
->
pColIdx
[
pBuilder
->
nCols
].
colId
=
colId
;
...
...
@@ -561,8 +562,9 @@ static FORCE_INLINE int tdAddColToKVRow(SKVRowBuilder *pBuilder, int16_t colId,
while
(
tlen
>
pBuilder
->
alloc
-
pBuilder
->
size
)
{
pBuilder
->
alloc
*=
2
;
}
pBuilder
->
buf
=
realloc
(
pBuilder
->
buf
,
pBuilder
->
alloc
);
if
(
pBuilder
->
buf
==
NULL
)
return
-
1
;
void
*
buf
=
realloc
(
pBuilder
->
buf
,
pBuilder
->
alloc
);
if
(
buf
==
NULL
)
return
-
1
;
pBuilder
->
buf
=
buf
;
}
memcpy
(
POINTER_SHIFT
(
pBuilder
->
buf
,
pBuilder
->
size
),
value
,
tlen
);
...
...
src/common/src/tdataformat.c
浏览文件 @
4c185833
...
...
@@ -138,8 +138,9 @@ int tdAddColToSchema(STSchemaBuilder *pBuilder, int8_t type, int16_t colId, int1
if
(
pBuilder
->
nCols
>=
pBuilder
->
tCols
)
{
pBuilder
->
tCols
*=
2
;
pBuilder
->
columns
=
(
STColumn
*
)
realloc
(
pBuilder
->
columns
,
sizeof
(
STColumn
)
*
pBuilder
->
tCols
);
if
(
pBuilder
->
columns
==
NULL
)
return
-
1
;
STColumn
*
columns
=
(
STColumn
*
)
realloc
(
pBuilder
->
columns
,
sizeof
(
STColumn
)
*
pBuilder
->
tCols
);
if
(
columns
==
NULL
)
return
-
1
;
pBuilder
->
columns
=
columns
;
}
STColumn
*
pCol
=
&
(
pBuilder
->
columns
[
pBuilder
->
nCols
]);
...
...
src/connector/nodejs/nodetaos/cinterface.js
浏览文件 @
4c185833
...
...
@@ -109,6 +109,24 @@ function convertDouble(data, num_of_rows, nbytes = 0, offset = 0, precision = 0)
return
res
;
}
function
convertBinary
(
data
,
num_of_rows
,
nbytes
=
0
,
offset
=
0
,
precision
=
0
)
{
data
=
ref
.
reinterpret
(
data
.
deref
(),
nbytes
*
num_of_rows
,
offset
);
let
res
=
[];
let
currOffset
=
0
;
while
(
currOffset
<
data
.
length
)
{
let
len
=
data
.
readIntLE
(
currOffset
,
2
);
let
dataEntry
=
data
.
slice
(
currOffset
+
2
,
currOffset
+
len
+
2
);
//one entry in a row under a column;
if
(
dataEntry
[
0
]
==
255
)
{
res
.
push
(
null
)
}
else
{
res
.
push
(
dataEntry
.
toString
(
"
utf-8
"
));
}
currOffset
+=
nbytes
;
}
return
res
;
}
function
convertNchar
(
data
,
num_of_rows
,
nbytes
=
0
,
offset
=
0
,
precision
=
0
)
{
data
=
ref
.
reinterpret
(
data
.
deref
(),
nbytes
*
num_of_rows
,
offset
);
let
res
=
[];
...
...
@@ -117,7 +135,11 @@ function convertNchar(data, num_of_rows, nbytes = 0, offset = 0, precision = 0)
while
(
currOffset
<
data
.
length
)
{
let
len
=
data
.
readIntLE
(
currOffset
,
2
);
let
dataEntry
=
data
.
slice
(
currOffset
+
2
,
currOffset
+
len
+
2
);
//one entry in a row under a column;
res
.
push
(
dataEntry
.
toString
(
"
utf-8
"
));
if
(
dataEntry
[
0
]
==
255
&&
dataEntry
[
1
]
==
255
)
{
res
.
push
(
null
)
}
else
{
res
.
push
(
dataEntry
.
toString
(
"
utf-8
"
));
}
currOffset
+=
nbytes
;
}
return
res
;
...
...
@@ -132,7 +154,7 @@ let convertFunctions = {
[
FieldTypes
.
C_BIGINT
]:
convertBigint
,
[
FieldTypes
.
C_FLOAT
]:
convertFloat
,
[
FieldTypes
.
C_DOUBLE
]:
convertDouble
,
[
FieldTypes
.
C_BINARY
]:
convert
Nchar
,
[
FieldTypes
.
C_BINARY
]:
convert
Binary
,
[
FieldTypes
.
C_TIMESTAMP
]:
convertTimestamp
,
[
FieldTypes
.
C_NCHAR
]:
convertNchar
}
...
...
src/connector/nodejs/test/testnchar.js
0 → 100644
浏览文件 @
4c185833
const
taos
=
require
(
'
../tdengine
'
);
var
conn
=
taos
.
connect
({
host
:
"
localhost
"
});
var
c1
=
conn
.
cursor
();
function
checkData
(
data
,
row
,
col
,
expect
)
{
let
checkdata
=
data
[
row
][
col
];
if
(
checkdata
==
expect
)
{
// console.log('check pass')
}
else
{
console
.
log
(
'
check failed, expect
'
+
expect
+
'
, but is
'
+
checkdata
)
}
}
c1
.
execute
(
'
drop database if exists testnodejsnchar
'
)
c1
.
execute
(
'
create database testnodejsnchar
'
)
c1
.
execute
(
'
use testnodejsnchar
'
);
c1
.
execute
(
'
create table tb (ts timestamp, value float, text binary(200))
'
)
c1
.
execute
(
"
insert into tb values('2021-06-10 00:00:00', 24.7, '中文10000000000000000000000');
"
)
-
c1
.
execute
(
'
insert into tb values(1623254400150, 24.7, NULL);
'
)
c1
.
execute
(
'
import into tb values(1623254400300, 24.7, "中文3中文10000000000000000000000中文10000000000000000000000中文10000000000000000000000中文10000000000000000000000");
'
)
sql
=
'
select * from tb;
'
console
.
log
(
'
*******************************************
'
)
c1
.
execute
(
sql
);
data
=
c1
.
fetchall
();
console
.
log
(
data
)
//check data about insert data
checkData
(
data
,
0
,
2
,
'
中文10000000000000000000000
'
)
checkData
(
data
,
1
,
2
,
null
)
checkData
(
data
,
2
,
2
,
'
中文3中文10000000000000000000000中文10000000000000000000000中文10000000000000000000000中文10000000000000000000000
'
)
\ No newline at end of file
src/kit/shell/src/shellCheck.c
浏览文件 @
4c185833
...
...
@@ -72,12 +72,13 @@ static int32_t shellShowTables(TAOS *con, char *db) {
int32_t
tbIndex
=
tbNum
++
;
if
(
tbMallocNum
<
tbNum
)
{
tbMallocNum
=
(
tbMallocNum
*
2
+
1
);
tbNames
=
realloc
(
tbNames
,
tbMallocNum
*
sizeof
(
char
*
));
if
(
tbNames
==
NULL
)
{
char
**
tbNames1
=
realloc
(
tbNames
,
tbMallocNum
*
sizeof
(
char
*
));
if
(
tbNames
1
==
NULL
)
{
fprintf
(
stdout
,
"failed to malloc tablenames, num:%d
\n
"
,
tbMallocNum
);
code
=
TSDB_CODE_TSC_OUT_OF_MEMORY
;
break
;
}
tbNames
=
tbNames1
;
}
tbNames
[
tbIndex
]
=
malloc
(
TSDB_TABLE_NAME_LEN
);
...
...
src/kit/taosdemo/taosdemo.c
浏览文件 @
4c185833
...
...
@@ -295,6 +295,9 @@ typedef struct SSuperTable_S {
uint64_t
lenOfTagOfOneRow
;
char
*
sampleDataBuf
;
#if STMT_IFACE_ENABLED == 1
char
*
sampleBindArray
;
#endif
//int sampleRowCount;
//int sampleUsePos;
...
...
@@ -441,6 +444,7 @@ typedef struct SQueryMetaInfo_S {
typedef
struct
SThreadInfo_S
{
TAOS
*
taos
;
TAOS_STMT
*
stmt
;
int64_t
*
bind_ts
;
int
threadID
;
char
db_name
[
TSDB_DB_NAME_LEN
];
uint32_t
time_precision
;
...
...
@@ -454,7 +458,7 @@ typedef struct SThreadInfo_S {
int64_t
start_time
;
char
*
cols
;
bool
use_metric
;
SSuperTable
*
s
uperTbl
Info
;
SSuperTable
*
s
tb
Info
;
char
*
buffer
;
// sql cmd buffer
// for async insert
...
...
@@ -674,7 +678,7 @@ static FILE * g_fpOfInsertResult = NULL;
///////////////////////////////////////////////////
static
void
ERROR_EXIT
(
const
char
*
msg
)
{
perror
(
msg
);
exit
(
-
1
);
}
static
void
ERROR_EXIT
(
const
char
*
msg
)
{
errorPrint
(
"%s"
,
msg
);
exit
(
-
1
);
}
#ifndef TAOSDEMO_COMMIT_SHA1
#define TAOSDEMO_COMMIT_SHA1 "unknown"
...
...
@@ -1136,8 +1140,7 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) {
}
if
(
0
==
columnCount
)
{
perror
(
"data type error!"
);
exit
(
-
1
);
ERROR_EXIT
(
"data type error!"
);
}
g_args
.
num_of_CPR
=
columnCount
;
...
...
@@ -1337,8 +1340,8 @@ static char *rand_bool_str(){
static
int32_t
rand_bool
(){
static
int
cursor
;
cursor
++
;
cursor
=
cursor
%
MAX_PREPARED_RAND
;
return
g_randint
[
cursor
]
%
2
;
if
(
cursor
>
(
MAX_PREPARED_RAND
-
1
))
cursor
=
0
;
return
g_randint
[
cursor
%
MAX_PREPARED_RAND
]
%
2
;
}
static
char
*
rand_tinyint_str
()
...
...
@@ -1353,8 +1356,8 @@ static int32_t rand_tinyint()
{
static
int
cursor
;
cursor
++
;
cursor
=
cursor
%
MAX_PREPARED_RAND
;
return
g_randint
[
cursor
]
%
128
;
if
(
cursor
>
(
MAX_PREPARED_RAND
-
1
))
cursor
=
0
;
return
g_randint
[
cursor
%
MAX_PREPARED_RAND
]
%
128
;
}
static
char
*
rand_smallint_str
()
...
...
@@ -1369,8 +1372,8 @@ static int32_t rand_smallint()
{
static
int
cursor
;
cursor
++
;
cursor
=
cursor
%
MAX_PREPARED_RAND
;
return
g_randint
[
cursor
]
%
32767
;
if
(
cursor
>
(
MAX_PREPARED_RAND
-
1
))
cursor
=
0
;
return
g_randint
[
cursor
%
MAX_PREPARED_RAND
]
%
32767
;
}
static
char
*
rand_int_str
()
...
...
@@ -1385,8 +1388,8 @@ static int32_t rand_int()
{
static
int
cursor
;
cursor
++
;
cursor
=
cursor
%
MAX_PREPARED_RAND
;
return
g_randint
[
cursor
];
if
(
cursor
>
(
MAX_PREPARED_RAND
-
1
))
cursor
=
0
;
return
g_randint
[
cursor
%
MAX_PREPARED_RAND
];
}
static
char
*
rand_bigint_str
()
...
...
@@ -1401,8 +1404,8 @@ static int64_t rand_bigint()
{
static
int
cursor
;
cursor
++
;
cursor
=
cursor
%
MAX_PREPARED_RAND
;
return
g_randbigint
[
cursor
];
if
(
cursor
>
(
MAX_PREPARED_RAND
-
1
))
cursor
=
0
;
return
g_randbigint
[
cursor
%
MAX_PREPARED_RAND
];
}
static
char
*
rand_float_str
()
...
...
@@ -1418,8 +1421,8 @@ static float rand_float()
{
static
int
cursor
;
cursor
++
;
cursor
=
cursor
%
MAX_PREPARED_RAND
;
return
g_randfloat
[
cursor
];
if
(
cursor
>
(
MAX_PREPARED_RAND
-
1
))
cursor
=
0
;
return
g_randfloat
[
cursor
%
MAX_PREPARED_RAND
];
}
static
char
*
demo_current_float_str
()
...
...
@@ -1434,8 +1437,9 @@ static float UNUSED_FUNC demo_current_float()
{
static
int
cursor
;
cursor
++
;
cursor
=
cursor
%
MAX_PREPARED_RAND
;
return
(
float
)(
9
.
8
+
0
.
04
*
(
g_randint
[
cursor
]
%
10
)
+
g_randfloat
[
cursor
]
/
1000000000
);
if
(
cursor
>
(
MAX_PREPARED_RAND
-
1
))
cursor
=
0
;
return
(
float
)(
9
.
8
+
0
.
04
*
(
g_randint
[
cursor
%
MAX_PREPARED_RAND
]
%
10
)
+
g_randfloat
[
cursor
%
MAX_PREPARED_RAND
]
/
1000000000
);
}
static
char
*
demo_voltage_int_str
()
...
...
@@ -1450,8 +1454,8 @@ static int32_t UNUSED_FUNC demo_voltage_int()
{
static
int
cursor
;
cursor
++
;
cursor
=
cursor
%
MAX_PREPARED_RAND
;
return
215
+
g_randint
[
cursor
]
%
10
;
if
(
cursor
>
(
MAX_PREPARED_RAND
-
1
))
cursor
=
0
;
return
215
+
g_randint
[
cursor
%
MAX_PREPARED_RAND
]
%
10
;
}
static
char
*
demo_phase_float_str
()
{
...
...
@@ -1464,8 +1468,9 @@ static char *demo_phase_float_str() {
static
float
UNUSED_FUNC
demo_phase_float
(){
static
int
cursor
;
cursor
++
;
cursor
=
cursor
%
MAX_PREPARED_RAND
;
return
(
float
)((
115
+
g_randint
[
cursor
]
%
10
+
g_randfloat
[
cursor
]
/
1000000000
)
/
360
);
if
(
cursor
>
(
MAX_PREPARED_RAND
-
1
))
cursor
=
0
;
return
(
float
)((
115
+
g_randint
[
cursor
%
MAX_PREPARED_RAND
]
%
10
+
g_randfloat
[
cursor
%
MAX_PREPARED_RAND
]
/
1000000000
)
/
360
);
}
#if 0
...
...
@@ -2425,14 +2430,14 @@ static int postProceSql(char *host, struct sockaddr_in *pServAddr, uint16_t port
#endif
debugPrint
(
"%s() LN%d, sockfd=%d
\n
"
,
__func__
,
__LINE__
,
sockfd
);
free
(
request_buf
);
ERROR_EXIT
(
"
ERROR
opening socket"
);
ERROR_EXIT
(
"opening socket"
);
}
int
retConn
=
connect
(
sockfd
,
(
struct
sockaddr
*
)
pServAddr
,
sizeof
(
struct
sockaddr
));
debugPrint
(
"%s() LN%d connect() return %d
\n
"
,
__func__
,
__LINE__
,
retConn
);
if
(
retConn
<
0
)
{
free
(
request_buf
);
ERROR_EXIT
(
"
ERROR
connecting"
);
ERROR_EXIT
(
"connecting"
);
}
memset
(
base64_buf
,
0
,
INPUT_BUF_LEN
);
...
...
@@ -2465,7 +2470,7 @@ static int postProceSql(char *host, struct sockaddr_in *pServAddr, uint16_t port
auth
,
strlen
(
sqlstr
),
sqlstr
);
if
(
r
>=
req_buf_len
)
{
free
(
request_buf
);
ERROR_EXIT
(
"
ERROR
too long request"
);
ERROR_EXIT
(
"too long request"
);
}
verbosePrint
(
"%s() LN%d: Request:
\n
%s
\n
"
,
__func__
,
__LINE__
,
request_buf
);
...
...
@@ -2478,7 +2483,7 @@ static int postProceSql(char *host, struct sockaddr_in *pServAddr, uint16_t port
bytes
=
write
(
sockfd
,
request_buf
+
sent
,
req_str_len
-
sent
);
#endif
if
(
bytes
<
0
)
ERROR_EXIT
(
"
ERROR
writing message to socket"
);
ERROR_EXIT
(
"writing message to socket"
);
if
(
bytes
==
0
)
break
;
sent
+=
bytes
;
...
...
@@ -2495,7 +2500,7 @@ static int postProceSql(char *host, struct sockaddr_in *pServAddr, uint16_t port
#endif
if
(
bytes
<
0
)
{
free
(
request_buf
);
ERROR_EXIT
(
"
ERROR
reading response from socket"
);
ERROR_EXIT
(
"reading response from socket"
);
}
if
(
bytes
==
0
)
break
;
...
...
@@ -2504,7 +2509,7 @@ static int postProceSql(char *host, struct sockaddr_in *pServAddr, uint16_t port
if
(
received
==
resp_len
)
{
free
(
request_buf
);
ERROR_EXIT
(
"
ERROR
storing complete response from socket"
);
ERROR_EXIT
(
"storing complete response from socket"
);
}
response_buf
[
RESP_BUF_LEN
-
1
]
=
'\0'
;
...
...
@@ -2667,8 +2672,8 @@ static int calcRowLen(SSuperTable* superTbls) {
}
else
if
(
strcasecmp
(
dataType
,
"TIMESTAMP"
)
==
0
)
{
lenOfOneRow
+=
TIMESTAMP_BUFF_LEN
;
}
else
{
printf
(
"get error data type : %s
\n
"
,
dataType
);
exit
(
-
1
);
errorPrint
(
"get error data type : %s
\n
"
,
dataType
);
exit
(
EXIT_FAILURE
);
}
}
...
...
@@ -2698,8 +2703,8 @@ static int calcRowLen(SSuperTable* superTbls) {
}
else
if
(
strcasecmp
(
dataType
,
"DOUBLE"
)
==
0
)
{
lenOfTagOfOneRow
+=
superTbls
->
tags
[
tagIndex
].
dataLen
+
DOUBLE_BUFF_LEN
;
}
else
{
printf
(
"get error tag type : %s
\n
"
,
dataType
);
exit
(
-
1
);
errorPrint
(
"get error tag type : %s
\n
"
,
dataType
);
exit
(
EXIT_FAILURE
);
}
}
...
...
@@ -2737,7 +2742,7 @@ static int getChildNameOfSuperTableWithLimitAndOffset(TAOS * taos,
taos_close
(
taos
);
errorPrint
(
"%s() LN%d, failed to run command %s
\n
"
,
__func__
,
__LINE__
,
command
);
exit
(
-
1
);
exit
(
EXIT_FAILURE
);
}
int64_t
childTblCount
=
(
limit
<
0
)
?
10000
:
limit
;
...
...
@@ -2748,7 +2753,7 @@ static int getChildNameOfSuperTableWithLimitAndOffset(TAOS * taos,
taos_free_result
(
res
);
taos_close
(
taos
);
errorPrint
(
"%s() LN%d, failed to allocate memory!
\n
"
,
__func__
,
__LINE__
);
exit
(
-
1
);
exit
(
EXIT_FAILURE
);
}
}
...
...
@@ -2759,7 +2764,7 @@ static int getChildNameOfSuperTableWithLimitAndOffset(TAOS * taos,
if
(
0
==
strlen
((
char
*
)
row
[
0
]))
{
errorPrint
(
"%s() LN%d, No.%"
PRId64
" table return empty name
\n
"
,
__func__
,
__LINE__
,
count
);
exit
(
-
1
);
exit
(
EXIT_FAILURE
);
}
tstrncpy
(
pTblName
,
(
char
*
)
row
[
0
],
len
[
0
]
+
1
);
...
...
@@ -2775,12 +2780,12 @@ static int getChildNameOfSuperTableWithLimitAndOffset(TAOS * taos,
(
size_t
)((
childTblCount
-
count
)
*
TSDB_TABLE_NAME_LEN
));
}
else
{
// exit, if allocate more memory failed
errorPrint
(
"%s() LN%d, realloc fail for save child table name of %s.%s
\n
"
,
__func__
,
__LINE__
,
dbName
,
sTblName
);
tmfree
(
childTblName
);
taos_free_result
(
res
);
taos_close
(
taos
);
exit
(
-
1
);
errorPrint
(
"%s() LN%d, realloc fail for save child table name of %s.%s
\n
"
,
__func__
,
__LINE__
,
dbName
,
sTblName
);
exit
(
EXIT_FAILURE
);
}
}
pTblName
=
childTblName
+
count
*
TSDB_TABLE_NAME_LEN
;
...
...
@@ -2964,10 +2969,10 @@ static int createSuperTable(
lenOfOneRow
+=
TIMESTAMP_BUFF_LEN
;
}
else
{
taos_close
(
taos
);
free
(
command
);
errorPrint
(
"%s() LN%d, config error data type : %s
\n
"
,
__func__
,
__LINE__
,
dataType
);
free
(
command
);
exit
(
-
1
);
exit
(
EXIT_FAILURE
);
}
}
...
...
@@ -2976,11 +2981,11 @@ static int createSuperTable(
// save for creating child table
superTbl
->
colsOfCreateChildTable
=
(
char
*
)
calloc
(
len
+
20
,
1
);
if
(
NULL
==
superTbl
->
colsOfCreateChildTable
)
{
errorPrint
(
"%s() LN%d, Failed when calloc, size:%d"
,
__func__
,
__LINE__
,
len
+
1
);
taos_close
(
taos
);
free
(
command
);
exit
(
-
1
);
errorPrint
(
"%s() LN%d, Failed when calloc, size:%d"
,
__func__
,
__LINE__
,
len
+
1
);
exit
(
EXIT_FAILURE
);
}
snprintf
(
superTbl
->
colsOfCreateChildTable
,
len
+
20
,
"(ts timestamp%s)"
,
cols
);
...
...
@@ -3054,10 +3059,10 @@ static int createSuperTable(
lenOfTagOfOneRow
+=
superTbl
->
tags
[
tagIndex
].
dataLen
+
DOUBLE_BUFF_LEN
;
}
else
{
taos_close
(
taos
);
free
(
command
);
errorPrint
(
"%s() LN%d, config error tag type : %s
\n
"
,
__func__
,
__LINE__
,
dataType
);
free
(
command
);
exit
(
-
1
);
exit
(
EXIT_FAILURE
);
}
}
...
...
@@ -3089,7 +3094,7 @@ int createDatabasesAndStables(char *command) {
errorPrint
(
"Failed to connect to TDengine, reason:%s
\n
"
,
taos_errstr
(
NULL
));
return
-
1
;
}
for
(
int
i
=
0
;
i
<
g_Dbs
.
dbCount
;
i
++
)
{
if
(
g_Dbs
.
db
[
i
].
drop
)
{
sprintf
(
command
,
"drop database if exists %s;"
,
g_Dbs
.
db
[
i
].
dbName
);
...
...
@@ -3100,35 +3105,43 @@ int createDatabasesAndStables(char *command) {
int
dataLen
=
0
;
dataLen
+=
snprintf
(
command
+
dataLen
,
BUFFER_SIZE
-
dataLen
,
"create database if not exists %s"
,
g_Dbs
.
db
[
i
].
dbName
);
BUFFER_SIZE
-
dataLen
,
"create database if not exists %s"
,
g_Dbs
.
db
[
i
].
dbName
);
if
(
g_Dbs
.
db
[
i
].
dbCfg
.
blocks
>
0
)
{
dataLen
+=
snprintf
(
command
+
dataLen
,
BUFFER_SIZE
-
dataLen
,
" blocks %d"
,
g_Dbs
.
db
[
i
].
dbCfg
.
blocks
);
BUFFER_SIZE
-
dataLen
,
" blocks %d"
,
g_Dbs
.
db
[
i
].
dbCfg
.
blocks
);
}
if
(
g_Dbs
.
db
[
i
].
dbCfg
.
cache
>
0
)
{
dataLen
+=
snprintf
(
command
+
dataLen
,
BUFFER_SIZE
-
dataLen
,
" cache %d"
,
g_Dbs
.
db
[
i
].
dbCfg
.
cache
);
BUFFER_SIZE
-
dataLen
,
" cache %d"
,
g_Dbs
.
db
[
i
].
dbCfg
.
cache
);
}
if
(
g_Dbs
.
db
[
i
].
dbCfg
.
days
>
0
)
{
dataLen
+=
snprintf
(
command
+
dataLen
,
BUFFER_SIZE
-
dataLen
,
" days %d"
,
g_Dbs
.
db
[
i
].
dbCfg
.
days
);
BUFFER_SIZE
-
dataLen
,
" days %d"
,
g_Dbs
.
db
[
i
].
dbCfg
.
days
);
}
if
(
g_Dbs
.
db
[
i
].
dbCfg
.
keep
>
0
)
{
dataLen
+=
snprintf
(
command
+
dataLen
,
BUFFER_SIZE
-
dataLen
,
" keep %d"
,
g_Dbs
.
db
[
i
].
dbCfg
.
keep
);
BUFFER_SIZE
-
dataLen
,
" keep %d"
,
g_Dbs
.
db
[
i
].
dbCfg
.
keep
);
}
if
(
g_Dbs
.
db
[
i
].
dbCfg
.
quorum
>
1
)
{
dataLen
+=
snprintf
(
command
+
dataLen
,
BUFFER_SIZE
-
dataLen
,
" quorum %d"
,
g_Dbs
.
db
[
i
].
dbCfg
.
quorum
);
BUFFER_SIZE
-
dataLen
,
" quorum %d"
,
g_Dbs
.
db
[
i
].
dbCfg
.
quorum
);
}
if
(
g_Dbs
.
db
[
i
].
dbCfg
.
replica
>
0
)
{
dataLen
+=
snprintf
(
command
+
dataLen
,
BUFFER_SIZE
-
dataLen
,
" replica %d"
,
g_Dbs
.
db
[
i
].
dbCfg
.
replica
);
BUFFER_SIZE
-
dataLen
,
" replica %d"
,
g_Dbs
.
db
[
i
].
dbCfg
.
replica
);
}
if
(
g_Dbs
.
db
[
i
].
dbCfg
.
update
>
0
)
{
dataLen
+=
snprintf
(
command
+
dataLen
,
BUFFER_SIZE
-
dataLen
,
" update %d"
,
g_Dbs
.
db
[
i
].
dbCfg
.
update
);
BUFFER_SIZE
-
dataLen
,
" update %d"
,
g_Dbs
.
db
[
i
].
dbCfg
.
update
);
}
//if (g_Dbs.db[i].dbCfg.maxtablesPerVnode > 0) {
// dataLen += snprintf(command + dataLen,
...
...
@@ -3136,42 +3149,48 @@ int createDatabasesAndStables(char *command) {
//}
if
(
g_Dbs
.
db
[
i
].
dbCfg
.
minRows
>
0
)
{
dataLen
+=
snprintf
(
command
+
dataLen
,
BUFFER_SIZE
-
dataLen
,
" minrows %d"
,
g_Dbs
.
db
[
i
].
dbCfg
.
minRows
);
BUFFER_SIZE
-
dataLen
,
" minrows %d"
,
g_Dbs
.
db
[
i
].
dbCfg
.
minRows
);
}
if
(
g_Dbs
.
db
[
i
].
dbCfg
.
maxRows
>
0
)
{
dataLen
+=
snprintf
(
command
+
dataLen
,
BUFFER_SIZE
-
dataLen
,
" maxrows %d"
,
g_Dbs
.
db
[
i
].
dbCfg
.
maxRows
);
BUFFER_SIZE
-
dataLen
,
" maxrows %d"
,
g_Dbs
.
db
[
i
].
dbCfg
.
maxRows
);
}
if
(
g_Dbs
.
db
[
i
].
dbCfg
.
comp
>
0
)
{
dataLen
+=
snprintf
(
command
+
dataLen
,
BUFFER_SIZE
-
dataLen
,
" comp %d"
,
g_Dbs
.
db
[
i
].
dbCfg
.
comp
);
BUFFER_SIZE
-
dataLen
,
" comp %d"
,
g_Dbs
.
db
[
i
].
dbCfg
.
comp
);
}
if
(
g_Dbs
.
db
[
i
].
dbCfg
.
walLevel
>
0
)
{
dataLen
+=
snprintf
(
command
+
dataLen
,
BUFFER_SIZE
-
dataLen
,
" wal %d"
,
g_Dbs
.
db
[
i
].
dbCfg
.
walLevel
);
BUFFER_SIZE
-
dataLen
,
" wal %d"
,
g_Dbs
.
db
[
i
].
dbCfg
.
walLevel
);
}
if
(
g_Dbs
.
db
[
i
].
dbCfg
.
cacheLast
>
0
)
{
dataLen
+=
snprintf
(
command
+
dataLen
,
BUFFER_SIZE
-
dataLen
,
" cachelast %d"
,
g_Dbs
.
db
[
i
].
dbCfg
.
cacheLast
);
BUFFER_SIZE
-
dataLen
,
" cachelast %d"
,
g_Dbs
.
db
[
i
].
dbCfg
.
cacheLast
);
}
if
(
g_Dbs
.
db
[
i
].
dbCfg
.
fsync
>
0
)
{
dataLen
+=
snprintf
(
command
+
dataLen
,
BUFFER_SIZE
-
dataLen
,
" fsync %d"
,
g_Dbs
.
db
[
i
].
dbCfg
.
fsync
);
}
if
((
0
==
strncasecmp
(
g_Dbs
.
db
[
i
].
dbCfg
.
precision
,
"ms"
,
strlen
(
"ms"
)
))
if
((
0
==
strncasecmp
(
g_Dbs
.
db
[
i
].
dbCfg
.
precision
,
"ms"
,
2
))
#if NANO_SECOND_ENABLED == 1
||
(
0
==
strncasecmp
(
g_Dbs
.
db
[
i
].
dbCfg
.
precision
,
"ns"
,
strlen
(
"ns"
)
))
"ns"
,
2
))
#endif
||
(
0
==
strncasecmp
(
g_Dbs
.
db
[
i
].
dbCfg
.
precision
,
"us"
,
strlen
(
"us"
))))
{
"us"
,
2
)))
{
dataLen
+=
snprintf
(
command
+
dataLen
,
BUFFER_SIZE
-
dataLen
,
" precision
\'
%s
\'
;"
,
g_Dbs
.
db
[
i
].
dbCfg
.
precision
);
}
if
(
0
!=
queryDbExec
(
taos
,
command
,
NO_INSERT_TYPE
,
false
))
{
taos_close
(
taos
);
errorPrint
(
"
\n
create database %s failed!
\n\n
"
,
g_Dbs
.
db
[
i
].
dbName
);
errorPrint
(
"
\n
create database %s failed!
\n\n
"
,
g_Dbs
.
db
[
i
].
dbName
);
return
-
1
;
}
printf
(
"
\n
create database %s success!
\n\n
"
,
g_Dbs
.
db
[
i
].
dbName
);
...
...
@@ -3218,7 +3237,7 @@ int createDatabasesAndStables(char *command) {
static
void
*
createTable
(
void
*
sarg
)
{
threadInfo
*
pThreadInfo
=
(
threadInfo
*
)
sarg
;
SSuperTable
*
s
uperTblInfo
=
pThreadInfo
->
superTbl
Info
;
SSuperTable
*
s
tbInfo
=
pThreadInfo
->
stb
Info
;
setThreadName
(
"createTable"
);
...
...
@@ -3229,7 +3248,7 @@ static void* createTable(void *sarg)
pThreadInfo
->
buffer
=
calloc
(
buff_len
,
1
);
if
(
pThreadInfo
->
buffer
==
NULL
)
{
errorPrint
(
"%s() LN%d, Memory allocated failed!
\n
"
,
__func__
,
__LINE__
);
exit
(
-
1
);
exit
(
EXIT_FAILURE
);
}
int
len
=
0
;
...
...
@@ -3248,11 +3267,11 @@ static void* createTable(void *sarg)
g_args
.
tb_prefix
,
i
,
pThreadInfo
->
cols
);
}
else
{
if
(
superTblInfo
==
NULL
)
{
if
(
stbInfo
==
NULL
)
{
free
(
pThreadInfo
->
buffer
);
errorPrint
(
"%s() LN%d, use metric, but super table info is NULL
\n
"
,
__func__
,
__LINE__
);
free
(
pThreadInfo
->
buffer
);
exit
(
-
1
);
exit
(
EXIT_FAILURE
);
}
else
{
if
(
0
==
len
)
{
batchNum
=
0
;
...
...
@@ -3260,29 +3279,35 @@ static void* createTable(void *sarg)
len
+=
snprintf
(
pThreadInfo
->
buffer
+
len
,
buff_len
-
len
,
"create table "
);
}
char
*
tagsValBuf
=
NULL
;
if
(
0
==
s
uperTbl
Info
->
tagSource
)
{
tagsValBuf
=
generateTagValuesForStb
(
s
uperTbl
Info
,
i
);
if
(
0
==
s
tb
Info
->
tagSource
)
{
tagsValBuf
=
generateTagValuesForStb
(
s
tb
Info
,
i
);
}
else
{
if
(
0
==
stbInfo
->
tagSampleCount
)
{
free
(
pThreadInfo
->
buffer
);
ERROR_EXIT
(
"use sample file for tag, but has no content!
\n
"
);
}
tagsValBuf
=
getTagValueFromTagSample
(
s
uperTbl
Info
,
i
%
s
uperTbl
Info
->
tagSampleCount
);
s
tb
Info
,
i
%
s
tb
Info
->
tagSampleCount
);
}
if
(
NULL
==
tagsValBuf
)
{
free
(
pThreadInfo
->
buffer
);
return
NULL
;
ERROR_EXIT
(
"use metric, but tag buffer is NULL
\n
"
)
;
}
len
+=
snprintf
(
pThreadInfo
->
buffer
+
len
,
buff_len
-
len
,
"if not exists %s.%s%"
PRIu64
" using %s.%s tags %s "
,
pThreadInfo
->
db_name
,
s
uperTbl
Info
->
childTblPrefix
,
pThreadInfo
->
db_name
,
s
tb
Info
->
childTblPrefix
,
i
,
pThreadInfo
->
db_name
,
s
uperTbl
Info
->
sTblName
,
tagsValBuf
);
s
tb
Info
->
sTblName
,
tagsValBuf
);
free
(
tagsValBuf
);
batchNum
++
;
if
((
batchNum
<
s
uperTbl
Info
->
batchCreateTableNum
)
if
((
batchNum
<
s
tb
Info
->
batchCreateTableNum
)
&&
((
buff_len
-
len
)
>=
(
s
uperTbl
Info
->
lenOfTagOfOneRow
+
256
)))
{
>=
(
s
tb
Info
->
lenOfTagOfOneRow
+
256
)))
{
continue
;
}
}
...
...
@@ -3317,14 +3342,13 @@ static void* createTable(void *sarg)
static
int
startMultiThreadCreateChildTable
(
char
*
cols
,
int
threads
,
uint64_t
tableFrom
,
int64_t
ntables
,
char
*
db_name
,
SSuperTable
*
s
uperTbl
Info
)
{
char
*
db_name
,
SSuperTable
*
s
tb
Info
)
{
pthread_t
*
pids
=
calloc
(
1
,
threads
*
sizeof
(
pthread_t
));
threadInfo
*
infos
=
calloc
(
1
,
threads
*
sizeof
(
threadInfo
));
if
((
NULL
==
pids
)
||
(
NULL
==
infos
))
{
printf
(
"malloc failed
\n
"
);
exit
(
-
1
);
ERROR_EXIT
(
"createChildTable malloc failed
\n
"
);
}
if
(
threads
<
1
)
{
...
...
@@ -3344,7 +3368,7 @@ static int startMultiThreadCreateChildTable(
threadInfo
*
pThreadInfo
=
infos
+
i
;
pThreadInfo
->
threadID
=
i
;
tstrncpy
(
pThreadInfo
->
db_name
,
db_name
,
TSDB_DB_NAME_LEN
);
pThreadInfo
->
s
uperTblInfo
=
superTbl
Info
;
pThreadInfo
->
s
tbInfo
=
stb
Info
;
verbosePrint
(
"%s() %d db_name: %s
\n
"
,
__func__
,
__LINE__
,
db_name
);
pThreadInfo
->
taos
=
taos_connect
(
g_Dbs
.
host
,
...
...
@@ -3451,26 +3475,26 @@ static void createChildTables() {
/*
Read 10000 lines at most. If more than 10000 lines, continue to read after using
*/
static
int
readTagFromCsvFileToMem
(
SSuperTable
*
s
uperTbl
Info
)
{
static
int
readTagFromCsvFileToMem
(
SSuperTable
*
s
tb
Info
)
{
size_t
n
=
0
;
ssize_t
readLen
=
0
;
char
*
line
=
NULL
;
FILE
*
fp
=
fopen
(
s
uperTbl
Info
->
tagsFile
,
"r"
);
FILE
*
fp
=
fopen
(
s
tb
Info
->
tagsFile
,
"r"
);
if
(
fp
==
NULL
)
{
printf
(
"Failed to open tags file: %s, reason:%s
\n
"
,
s
uperTbl
Info
->
tagsFile
,
strerror
(
errno
));
s
tb
Info
->
tagsFile
,
strerror
(
errno
));
return
-
1
;
}
if
(
s
uperTbl
Info
->
tagDataBuf
)
{
free
(
s
uperTbl
Info
->
tagDataBuf
);
s
uperTbl
Info
->
tagDataBuf
=
NULL
;
if
(
s
tb
Info
->
tagDataBuf
)
{
free
(
s
tb
Info
->
tagDataBuf
);
s
tb
Info
->
tagDataBuf
=
NULL
;
}
int
tagCount
=
10000
;
int
count
=
0
;
char
*
tagDataBuf
=
calloc
(
1
,
s
uperTbl
Info
->
lenOfTagOfOneRow
*
tagCount
);
char
*
tagDataBuf
=
calloc
(
1
,
s
tb
Info
->
lenOfTagOfOneRow
*
tagCount
);
if
(
tagDataBuf
==
NULL
)
{
printf
(
"Failed to calloc, reason:%s
\n
"
,
strerror
(
errno
));
fclose
(
fp
);
...
...
@@ -3486,20 +3510,20 @@ static int readTagFromCsvFileToMem(SSuperTable * superTblInfo) {
continue
;
}
memcpy
(
tagDataBuf
+
count
*
s
uperTbl
Info
->
lenOfTagOfOneRow
,
line
,
readLen
);
memcpy
(
tagDataBuf
+
count
*
s
tb
Info
->
lenOfTagOfOneRow
,
line
,
readLen
);
count
++
;
if
(
count
>=
tagCount
-
1
)
{
char
*
tmp
=
realloc
(
tagDataBuf
,
(
size_t
)
tagCount
*
1
.
5
*
s
uperTbl
Info
->
lenOfTagOfOneRow
);
(
size_t
)
tagCount
*
1
.
5
*
s
tb
Info
->
lenOfTagOfOneRow
);
if
(
tmp
!=
NULL
)
{
tagDataBuf
=
tmp
;
tagCount
=
(
int
)(
tagCount
*
1
.
5
);
memset
(
tagDataBuf
+
count
*
s
uperTbl
Info
->
lenOfTagOfOneRow
,
0
,
(
size_t
)((
tagCount
-
count
)
*
s
uperTbl
Info
->
lenOfTagOfOneRow
));
memset
(
tagDataBuf
+
count
*
s
tb
Info
->
lenOfTagOfOneRow
,
0
,
(
size_t
)((
tagCount
-
count
)
*
s
tb
Info
->
lenOfTagOfOneRow
));
}
else
{
// exit, if allocate more memory failed
printf
(
"realloc fail for save tag val from %s
\n
"
,
s
uperTbl
Info
->
tagsFile
);
printf
(
"realloc fail for save tag val from %s
\n
"
,
s
tb
Info
->
tagsFile
);
tmfree
(
tagDataBuf
);
free
(
line
);
fclose
(
fp
);
...
...
@@ -3508,8 +3532,8 @@ static int readTagFromCsvFileToMem(SSuperTable * superTblInfo) {
}
}
s
uperTbl
Info
->
tagDataBuf
=
tagDataBuf
;
s
uperTbl
Info
->
tagSampleCount
=
count
;
s
tb
Info
->
tagDataBuf
=
tagDataBuf
;
s
tb
Info
->
tagSampleCount
=
count
;
free
(
line
);
fclose
(
fp
);
...
...
@@ -3520,28 +3544,28 @@ static int readTagFromCsvFileToMem(SSuperTable * superTblInfo) {
Read 10000 lines at most. If more than 10000 lines, continue to read after using
*/
static
int
readSampleFromCsvFileToMem
(
SSuperTable
*
s
uperTbl
Info
)
{
SSuperTable
*
s
tb
Info
)
{
size_t
n
=
0
;
ssize_t
readLen
=
0
;
char
*
line
=
NULL
;
int
getRows
=
0
;
FILE
*
fp
=
fopen
(
s
uperTbl
Info
->
sampleFile
,
"r"
);
FILE
*
fp
=
fopen
(
s
tb
Info
->
sampleFile
,
"r"
);
if
(
fp
==
NULL
)
{
errorPrint
(
"Failed to open sample file: %s, reason:%s
\n
"
,
s
uperTbl
Info
->
sampleFile
,
strerror
(
errno
));
s
tb
Info
->
sampleFile
,
strerror
(
errno
));
return
-
1
;
}
assert
(
s
uperTbl
Info
->
sampleDataBuf
);
memset
(
s
uperTbl
Info
->
sampleDataBuf
,
0
,
MAX_SAMPLES_ONCE_FROM_FILE
*
s
uperTbl
Info
->
lenOfOneRow
);
assert
(
s
tb
Info
->
sampleDataBuf
);
memset
(
s
tb
Info
->
sampleDataBuf
,
0
,
MAX_SAMPLES_ONCE_FROM_FILE
*
s
tb
Info
->
lenOfOneRow
);
while
(
1
)
{
readLen
=
tgetline
(
&
line
,
&
n
,
fp
);
if
(
-
1
==
readLen
)
{
if
(
0
!=
fseek
(
fp
,
0
,
SEEK_SET
))
{
errorPrint
(
"Failed to fseek file: %s, reason:%s
\n
"
,
s
uperTbl
Info
->
sampleFile
,
strerror
(
errno
));
s
tb
Info
->
sampleFile
,
strerror
(
errno
));
fclose
(
fp
);
return
-
1
;
}
...
...
@@ -3556,13 +3580,13 @@ static int readSampleFromCsvFileToMem(
continue
;
}
if
(
readLen
>
s
uperTbl
Info
->
lenOfOneRow
)
{
if
(
readLen
>
s
tb
Info
->
lenOfOneRow
)
{
printf
(
"sample row len[%d] overflow define schema len[%"
PRIu64
"], so discard this row
\n
"
,
(
int32_t
)
readLen
,
s
uperTbl
Info
->
lenOfOneRow
);
(
int32_t
)
readLen
,
s
tb
Info
->
lenOfOneRow
);
continue
;
}
memcpy
(
s
uperTblInfo
->
sampleDataBuf
+
getRows
*
superTbl
Info
->
lenOfOneRow
,
memcpy
(
s
tbInfo
->
sampleDataBuf
+
getRows
*
stb
Info
->
lenOfOneRow
,
line
,
readLen
);
getRows
++
;
...
...
@@ -5047,6 +5071,23 @@ static void postFreeResource() {
free
(
g_Dbs
.
db
[
i
].
superTbls
[
j
].
sampleDataBuf
);
g_Dbs
.
db
[
i
].
superTbls
[
j
].
sampleDataBuf
=
NULL
;
}
#if STMT_IFACE_ENABLED == 1
if
(
g_Dbs
.
db
[
i
].
superTbls
[
j
].
sampleBindArray
)
{
for
(
int
k
=
0
;
k
<
MAX_SAMPLES_ONCE_FROM_FILE
;
k
++
)
{
uintptr_t
*
tmp
=
(
uintptr_t
*
)(
*
(
uintptr_t
*
)(
g_Dbs
.
db
[
i
].
superTbls
[
j
].
sampleBindArray
+
sizeof
(
uintptr_t
*
)
*
k
));
for
(
int
c
=
1
;
c
<
g_Dbs
.
db
[
i
].
superTbls
[
j
].
columnCount
+
1
;
c
++
)
{
TAOS_BIND
*
bind
=
(
TAOS_BIND
*
)((
char
*
)
tmp
+
(
sizeof
(
TAOS_BIND
)
*
c
));
if
(
bind
)
tmfree
(
bind
->
buffer
);
}
tmfree
((
char
*
)
tmp
);
}
}
tmfree
((
char
*
)
g_Dbs
.
db
[
i
].
superTbls
[
j
].
sampleBindArray
);
#endif
if
(
0
!=
g_Dbs
.
db
[
i
].
superTbls
[
j
].
tagDataBuf
)
{
free
(
g_Dbs
.
db
[
i
].
superTbls
[
j
].
tagDataBuf
);
g_Dbs
.
db
[
i
].
superTbls
[
j
].
tagDataBuf
=
NULL
;
...
...
@@ -5067,21 +5108,14 @@ static void postFreeResource() {
tmfree
(
g_randfloat_buff
);
tmfree
(
g_rand_current_buff
);
tmfree
(
g_rand_phase_buff
);
tmfree
(
g_randdouble_buff
);
}
static
int
getRowDataFromSample
(
char
*
dataBuf
,
int64_t
maxLen
,
int64_t
timestamp
,
SSuperTable
*
s
uperTbl
Info
,
int64_t
*
sampleUsePos
)
SSuperTable
*
s
tb
Info
,
int64_t
*
sampleUsePos
)
{
if
((
*
sampleUsePos
)
==
MAX_SAMPLES_ONCE_FROM_FILE
)
{
/* int ret = readSampleFromCsvFileToMem(superTblInfo);
if (0 != ret) {
tmfree(superTblInfo->sampleDataBuf);
superTblInfo->sampleDataBuf = NULL;
return -1;
}
*/
*
sampleUsePos
=
0
;
}
...
...
@@ -5091,8 +5125,8 @@ static int getRowDataFromSample(
"(%"
PRId64
", "
,
timestamp
);
dataLen
+=
snprintf
(
dataBuf
+
dataLen
,
maxLen
-
dataLen
,
"%s"
,
s
uperTbl
Info
->
sampleDataBuf
+
s
uperTbl
Info
->
lenOfOneRow
*
(
*
sampleUsePos
));
s
tb
Info
->
sampleDataBuf
+
s
tb
Info
->
lenOfOneRow
*
(
*
sampleUsePos
));
dataLen
+=
snprintf
(
dataBuf
+
dataLen
,
maxLen
-
dataLen
,
")"
);
(
*
sampleUsePos
)
++
;
...
...
@@ -5248,7 +5282,7 @@ static int64_t generateData(char *recBuf, char **data_type,
if
(
s
==
NULL
)
{
errorPrint
(
"%s() LN%d, memory allocation %d bytes failed
\n
"
,
__func__
,
__LINE__
,
lenOfBinary
+
1
);
exit
(
-
1
);
exit
(
EXIT_FAILURE
);
}
rand_string
(
s
,
lenOfBinary
);
pstr
+=
sprintf
(
pstr
,
",
\"
%s
\"
"
,
s
);
...
...
@@ -5258,7 +5292,7 @@ static int64_t generateData(char *recBuf, char **data_type,
if
(
s
==
NULL
)
{
errorPrint
(
"%s() LN%d, memory allocation %d bytes failed
\n
"
,
__func__
,
__LINE__
,
lenOfBinary
+
1
);
exit
(
-
1
);
exit
(
EXIT_FAILURE
);
}
rand_string
(
s
,
lenOfBinary
);
pstr
+=
sprintf
(
pstr
,
",
\"
%s
\"
"
,
s
);
...
...
@@ -5266,8 +5300,7 @@ static int64_t generateData(char *recBuf, char **data_type,
}
if
(
strlen
(
recBuf
)
>
MAX_DATA_SIZE
)
{
perror
(
"column length too long, abort"
);
exit
(
-
1
);
ERROR_EXIT
(
"column length too long, abort"
);
}
}
...
...
@@ -5278,27 +5311,27 @@ static int64_t generateData(char *recBuf, char **data_type,
return
(
int32_t
)
strlen
(
recBuf
);
}
static
int
prepareSampleDataForSTable
(
SSuperTable
*
s
uperTbl
Info
)
{
static
int
prepareSampleDataForSTable
(
SSuperTable
*
s
tb
Info
)
{
char
*
sampleDataBuf
=
NULL
;
sampleDataBuf
=
calloc
(
s
uperTbl
Info
->
lenOfOneRow
*
MAX_SAMPLES_ONCE_FROM_FILE
,
1
);
s
tb
Info
->
lenOfOneRow
*
MAX_SAMPLES_ONCE_FROM_FILE
,
1
);
if
(
sampleDataBuf
==
NULL
)
{
errorPrint
(
"%s() LN%d, Failed to calloc %"
PRIu64
" Bytes, reason:%s
\n
"
,
__func__
,
__LINE__
,
s
uperTbl
Info
->
lenOfOneRow
*
MAX_SAMPLES_ONCE_FROM_FILE
,
s
tb
Info
->
lenOfOneRow
*
MAX_SAMPLES_ONCE_FROM_FILE
,
strerror
(
errno
));
return
-
1
;
}
s
uperTbl
Info
->
sampleDataBuf
=
sampleDataBuf
;
int
ret
=
readSampleFromCsvFileToMem
(
s
uperTbl
Info
);
s
tb
Info
->
sampleDataBuf
=
sampleDataBuf
;
int
ret
=
readSampleFromCsvFileToMem
(
s
tb
Info
);
if
(
0
!=
ret
)
{
errorPrint
(
"%s() LN%d, read sample from csv file failed.
\n
"
,
__func__
,
__LINE__
);
tmfree
(
sampleDataBuf
);
s
uperTbl
Info
->
sampleDataBuf
=
NULL
;
s
tb
Info
->
sampleDataBuf
=
NULL
;
return
-
1
;
}
...
...
@@ -5308,14 +5341,14 @@ static int prepareSampleDataForSTable(SSuperTable *superTblInfo) {
static
int32_t
execInsert
(
threadInfo
*
pThreadInfo
,
uint32_t
k
)
{
int32_t
affectedRows
;
SSuperTable
*
s
uperTblInfo
=
pThreadInfo
->
superTbl
Info
;
SSuperTable
*
s
tbInfo
=
pThreadInfo
->
stb
Info
;
verbosePrint
(
"[%d] %s() LN%d %s
\n
"
,
pThreadInfo
->
threadID
,
__func__
,
__LINE__
,
pThreadInfo
->
buffer
);
uint16_t
iface
;
if
(
s
uperTbl
Info
)
iface
=
s
uperTbl
Info
->
iface
;
if
(
s
tb
Info
)
iface
=
s
tb
Info
->
iface
;
else
{
if
(
g_args
.
iface
==
INTERFACE_BUT
)
iface
=
TAOSC_IFACE
;
...
...
@@ -5355,7 +5388,7 @@ static int32_t execInsert(threadInfo *pThreadInfo, uint32_t k)
__func__
,
__LINE__
,
taos_stmt_errstr
(
pThreadInfo
->
stmt
));
fprintf
(
stderr
,
"
\n\033
[31m === Please reduce batch number if WAL size exceeds limit. ===
\033
[0m
\n\n
"
);
exit
(
-
1
);
exit
(
EXIT_FAILURE
);
}
affectedRows
=
k
;
break
;
...
...
@@ -5363,7 +5396,7 @@ static int32_t execInsert(threadInfo *pThreadInfo, uint32_t k)
default:
errorPrint
(
"%s() LN%d: unknown insert mode: %d
\n
"
,
__func__
,
__LINE__
,
s
uperTbl
Info
->
iface
);
__func__
,
__LINE__
,
s
tb
Info
->
iface
);
affectedRows
=
0
;
}
...
...
@@ -5373,24 +5406,24 @@ static int32_t execInsert(threadInfo *pThreadInfo, uint32_t k)
static
void
getTableName
(
char
*
pTblName
,
threadInfo
*
pThreadInfo
,
uint64_t
tableSeq
)
{
SSuperTable
*
s
uperTblInfo
=
pThreadInfo
->
superTbl
Info
;
if
(
s
uperTbl
Info
)
{
if
(
AUTO_CREATE_SUBTBL
!=
s
uperTbl
Info
->
autoCreateTable
)
{
if
(
s
uperTbl
Info
->
childTblLimit
>
0
)
{
SSuperTable
*
s
tbInfo
=
pThreadInfo
->
stb
Info
;
if
(
s
tb
Info
)
{
if
(
AUTO_CREATE_SUBTBL
!=
s
tb
Info
->
autoCreateTable
)
{
if
(
s
tb
Info
->
childTblLimit
>
0
)
{
snprintf
(
pTblName
,
TSDB_TABLE_NAME_LEN
,
"%s"
,
s
uperTbl
Info
->
childTblName
+
(
tableSeq
-
s
uperTbl
Info
->
childTblOffset
)
*
TSDB_TABLE_NAME_LEN
);
s
tb
Info
->
childTblName
+
(
tableSeq
-
s
tb
Info
->
childTblOffset
)
*
TSDB_TABLE_NAME_LEN
);
}
else
{
verbosePrint
(
"[%d] %s() LN%d: from=%"
PRIu64
" count=%"
PRId64
" seq=%"
PRIu64
"
\n
"
,
pThreadInfo
->
threadID
,
__func__
,
__LINE__
,
pThreadInfo
->
start_table_from
,
pThreadInfo
->
ntables
,
tableSeq
);
snprintf
(
pTblName
,
TSDB_TABLE_NAME_LEN
,
"%s"
,
s
uperTbl
Info
->
childTblName
+
tableSeq
*
TSDB_TABLE_NAME_LEN
);
s
tb
Info
->
childTblName
+
tableSeq
*
TSDB_TABLE_NAME_LEN
);
}
}
else
{
snprintf
(
pTblName
,
TSDB_TABLE_NAME_LEN
,
"%s%"
PRIu64
""
,
s
uperTbl
Info
->
childTblPrefix
,
tableSeq
);
s
tb
Info
->
childTblPrefix
,
tableSeq
);
}
}
else
{
snprintf
(
pTblName
,
TSDB_TABLE_NAME_LEN
,
"%s%"
PRIu64
""
,
...
...
@@ -5471,7 +5504,7 @@ static int64_t getTSRandTail(int64_t timeStampStep, int32_t seq,
}
static
int32_t
generateStbDataTail
(
SSuperTable
*
s
uperTbl
Info
,
SSuperTable
*
s
tb
Info
,
uint32_t
batch
,
char
*
buffer
,
int64_t
remainderBufLen
,
int64_t
insertRows
,
uint64_t
recordFrom
,
int64_t
startTime
,
...
...
@@ -5481,7 +5514,7 @@ static int32_t generateStbDataTail(
char
*
pstr
=
buffer
;
bool
tsRand
;
if
(
0
==
strncasecmp
(
s
uperTbl
Info
->
dataSource
,
"rand"
,
strlen
(
"rand"
)))
{
if
(
0
==
strncasecmp
(
s
tb
Info
->
dataSource
,
"rand"
,
strlen
(
"rand"
)))
{
tsRand
=
true
;
}
else
{
tsRand
=
false
;
...
...
@@ -5496,26 +5529,26 @@ static int32_t generateStbDataTail(
int64_t
lenOfRow
=
0
;
if
(
tsRand
)
{
if
(
s
uperTbl
Info
->
disorderRatio
>
0
)
{
lenOfRow
=
generateStbRowData
(
s
uperTbl
Info
,
data
,
if
(
s
tb
Info
->
disorderRatio
>
0
)
{
lenOfRow
=
generateStbRowData
(
s
tb
Info
,
data
,
remainderBufLen
,
startTime
+
getTSRandTail
(
s
uperTbl
Info
->
timeStampStep
,
k
,
s
uperTbl
Info
->
disorderRatio
,
s
uperTbl
Info
->
disorderRange
)
s
tb
Info
->
timeStampStep
,
k
,
s
tb
Info
->
disorderRatio
,
s
tb
Info
->
disorderRange
)
);
}
else
{
lenOfRow
=
generateStbRowData
(
s
uperTbl
Info
,
data
,
lenOfRow
=
generateStbRowData
(
s
tb
Info
,
data
,
remainderBufLen
,
startTime
+
s
uperTbl
Info
->
timeStampStep
*
k
startTime
+
s
tb
Info
->
timeStampStep
*
k
);
}
}
else
{
lenOfRow
=
getRowDataFromSample
(
data
,
(
remainderBufLen
<
MAX_DATA_SIZE
)
?
remainderBufLen
:
MAX_DATA_SIZE
,
startTime
+
s
uperTbl
Info
->
timeStampStep
*
k
,
s
uperTbl
Info
,
startTime
+
s
tb
Info
->
timeStampStep
*
k
,
s
tb
Info
,
pSamplePos
);
}
...
...
@@ -5571,7 +5604,7 @@ static int generateSQLHeadWithoutStb(char *tableName,
}
static
int
generateStbSQLHead
(
SSuperTable
*
s
uperTbl
Info
,
SSuperTable
*
s
tb
Info
,
char
*
tableName
,
int64_t
tableSeq
,
char
*
dbName
,
char
*
buffer
,
int
remainderBufLen
)
...
...
@@ -5580,14 +5613,14 @@ static int generateStbSQLHead(
char
headBuf
[
HEAD_BUFF_LEN
];
if
(
AUTO_CREATE_SUBTBL
==
s
uperTbl
Info
->
autoCreateTable
)
{
if
(
AUTO_CREATE_SUBTBL
==
s
tb
Info
->
autoCreateTable
)
{
char
*
tagsValBuf
=
NULL
;
if
(
0
==
s
uperTbl
Info
->
tagSource
)
{
tagsValBuf
=
generateTagValuesForStb
(
s
uperTbl
Info
,
tableSeq
);
if
(
0
==
s
tb
Info
->
tagSource
)
{
tagsValBuf
=
generateTagValuesForStb
(
s
tb
Info
,
tableSeq
);
}
else
{
tagsValBuf
=
getTagValueFromTagSample
(
s
uperTbl
Info
,
tableSeq
%
s
uperTbl
Info
->
tagSampleCount
);
s
tb
Info
,
tableSeq
%
s
tb
Info
->
tagSampleCount
);
}
if
(
NULL
==
tagsValBuf
)
{
errorPrint
(
"%s() LN%d, tag buf failed to allocate memory
\n
"
,
...
...
@@ -5602,10 +5635,10 @@ static int generateStbSQLHead(
dbName
,
tableName
,
dbName
,
s
uperTbl
Info
->
sTblName
,
s
tb
Info
->
sTblName
,
tagsValBuf
);
tmfree
(
tagsValBuf
);
}
else
if
(
TBL_ALREADY_EXISTS
==
s
uperTbl
Info
->
childTblExists
)
{
}
else
if
(
TBL_ALREADY_EXISTS
==
s
tb
Info
->
childTblExists
)
{
len
=
snprintf
(
headBuf
,
HEAD_BUFF_LEN
,
...
...
@@ -5630,12 +5663,12 @@ static int generateStbSQLHead(
}
static
int32_t
generateStbInterlaceData
(
SSuperTable
*
superTbl
Info
,
threadInfo
*
pThread
Info
,
char
*
tableName
,
uint32_t
batchPerTbl
,
uint64_t
i
,
uint32_t
batchPerTblTimes
,
uint64_t
tableSeq
,
threadInfo
*
pThreadInfo
,
char
*
buffer
,
char
*
buffer
,
int64_t
insertRows
,
int64_t
startTime
,
uint64_t
*
pRemainderBufLen
)
...
...
@@ -5643,8 +5676,9 @@ static int32_t generateStbInterlaceData(
assert
(
buffer
);
char
*
pstr
=
buffer
;
SSuperTable
*
stbInfo
=
pThreadInfo
->
stbInfo
;
int
headLen
=
generateStbSQLHead
(
s
uperTbl
Info
,
s
tb
Info
,
tableName
,
tableSeq
,
pThreadInfo
->
db_name
,
pstr
,
*
pRemainderBufLen
);
...
...
@@ -5664,12 +5698,12 @@ static int32_t generateStbInterlaceData(
pThreadInfo
->
threadID
,
__func__
,
__LINE__
,
i
,
batchPerTblTimes
,
batchPerTbl
);
if
(
0
==
strncasecmp
(
s
uperTbl
Info
->
startTimestamp
,
"now"
,
3
))
{
if
(
0
==
strncasecmp
(
s
tb
Info
->
startTimestamp
,
"now"
,
3
))
{
startTime
=
taosGetTimestamp
(
pThreadInfo
->
time_precision
);
}
int32_t
k
=
generateStbDataTail
(
s
uperTbl
Info
,
s
tb
Info
,
batchPerTbl
,
pstr
,
*
pRemainderBufLen
,
insertRows
,
0
,
startTime
,
&
(
pThreadInfo
->
samplePos
),
&
dataLen
);
...
...
@@ -5732,8 +5766,206 @@ static int64_t generateInterlaceDataWithoutStb(
}
#if STMT_IFACE_ENABLED == 1
static
int32_t
prepareStmtBindArrayByType
(
TAOS_BIND
*
bind
,
char
*
dataType
,
int32_t
dataLen
,
char
**
ptr
,
char
*
value
)
static
int32_t
prepareStmtBindArrayByType
(
TAOS_BIND
*
bind
,
char
*
dataType
,
int32_t
dataLen
,
int32_t
timePrec
,
char
*
value
)
{
if
(
0
==
strncasecmp
(
dataType
,
"BINARY"
,
strlen
(
"BINARY"
)))
{
if
(
dataLen
>
TSDB_MAX_BINARY_LEN
)
{
errorPrint
(
"binary length overflow, max size:%u
\n
"
,
(
uint32_t
)
TSDB_MAX_BINARY_LEN
);
return
-
1
;
}
char
*
bind_binary
;
bind
->
buffer_type
=
TSDB_DATA_TYPE_BINARY
;
if
(
value
)
{
bind_binary
=
calloc
(
1
,
strlen
(
value
)
+
1
);
strncpy
(
bind_binary
,
value
,
strlen
(
value
));
bind
->
buffer_length
=
strlen
(
bind_binary
);
}
else
{
bind_binary
=
calloc
(
1
,
dataLen
+
1
);
rand_string
(
bind_binary
,
dataLen
);
bind
->
buffer_length
=
dataLen
;
}
bind
->
length
=
&
bind
->
buffer_length
;
bind
->
buffer
=
bind_binary
;
bind
->
is_null
=
NULL
;
}
else
if
(
0
==
strncasecmp
(
dataType
,
"NCHAR"
,
strlen
(
"NCHAR"
)))
{
if
(
dataLen
>
TSDB_MAX_BINARY_LEN
)
{
errorPrint
(
"nchar length overflow, max size:%u
\n
"
,
(
uint32_t
)
TSDB_MAX_BINARY_LEN
);
return
-
1
;
}
char
*
bind_nchar
;
bind
->
buffer_type
=
TSDB_DATA_TYPE_NCHAR
;
if
(
value
)
{
bind_nchar
=
calloc
(
1
,
strlen
(
value
)
+
1
);
strncpy
(
bind_nchar
,
value
,
strlen
(
value
));
}
else
{
bind_nchar
=
calloc
(
1
,
dataLen
+
1
);
rand_string
(
bind_nchar
,
dataLen
);
}
bind
->
buffer_length
=
strlen
(
bind_nchar
);
bind
->
buffer
=
bind_nchar
;
bind
->
length
=
&
bind
->
buffer_length
;
bind
->
is_null
=
NULL
;
}
else
if
(
0
==
strncasecmp
(
dataType
,
"INT"
,
strlen
(
"INT"
)))
{
int32_t
*
bind_int
=
malloc
(
sizeof
(
int32_t
));
if
(
value
)
{
*
bind_int
=
atoi
(
value
);
}
else
{
*
bind_int
=
rand_int
();
}
bind
->
buffer_type
=
TSDB_DATA_TYPE_INT
;
bind
->
buffer_length
=
sizeof
(
int32_t
);
bind
->
buffer
=
bind_int
;
bind
->
length
=
&
bind
->
buffer_length
;
bind
->
is_null
=
NULL
;
}
else
if
(
0
==
strncasecmp
(
dataType
,
"BIGINT"
,
strlen
(
"BIGINT"
)))
{
int64_t
*
bind_bigint
=
malloc
(
sizeof
(
int64_t
));
if
(
value
)
{
*
bind_bigint
=
atoll
(
value
);
}
else
{
*
bind_bigint
=
rand_bigint
();
}
bind
->
buffer_type
=
TSDB_DATA_TYPE_BIGINT
;
bind
->
buffer_length
=
sizeof
(
int64_t
);
bind
->
buffer
=
bind_bigint
;
bind
->
length
=
&
bind
->
buffer_length
;
bind
->
is_null
=
NULL
;
}
else
if
(
0
==
strncasecmp
(
dataType
,
"FLOAT"
,
strlen
(
"FLOAT"
)))
{
float
*
bind_float
=
malloc
(
sizeof
(
float
));
if
(
value
)
{
*
bind_float
=
(
float
)
atof
(
value
);
}
else
{
*
bind_float
=
rand_float
();
}
bind
->
buffer_type
=
TSDB_DATA_TYPE_FLOAT
;
bind
->
buffer_length
=
sizeof
(
float
);
bind
->
buffer
=
bind_float
;
bind
->
length
=
&
bind
->
buffer_length
;
bind
->
is_null
=
NULL
;
}
else
if
(
0
==
strncasecmp
(
dataType
,
"DOUBLE"
,
strlen
(
"DOUBLE"
)))
{
double
*
bind_double
=
malloc
(
sizeof
(
double
));
if
(
value
)
{
*
bind_double
=
atof
(
value
);
}
else
{
*
bind_double
=
rand_double
();
}
bind
->
buffer_type
=
TSDB_DATA_TYPE_DOUBLE
;
bind
->
buffer_length
=
sizeof
(
double
);
bind
->
buffer
=
bind_double
;
bind
->
length
=
&
bind
->
buffer_length
;
bind
->
is_null
=
NULL
;
}
else
if
(
0
==
strncasecmp
(
dataType
,
"SMALLINT"
,
strlen
(
"SMALLINT"
)))
{
int16_t
*
bind_smallint
=
malloc
(
sizeof
(
int16_t
));
if
(
value
)
{
*
bind_smallint
=
(
int16_t
)
atoi
(
value
);
}
else
{
*
bind_smallint
=
rand_smallint
();
}
bind
->
buffer_type
=
TSDB_DATA_TYPE_SMALLINT
;
bind
->
buffer_length
=
sizeof
(
int16_t
);
bind
->
buffer
=
bind_smallint
;
bind
->
length
=
&
bind
->
buffer_length
;
bind
->
is_null
=
NULL
;
}
else
if
(
0
==
strncasecmp
(
dataType
,
"TINYINT"
,
strlen
(
"TINYINT"
)))
{
int8_t
*
bind_tinyint
=
malloc
(
sizeof
(
int8_t
));
if
(
value
)
{
*
bind_tinyint
=
(
int8_t
)
atoi
(
value
);
}
else
{
*
bind_tinyint
=
rand_tinyint
();
}
bind
->
buffer_type
=
TSDB_DATA_TYPE_TINYINT
;
bind
->
buffer_length
=
sizeof
(
int8_t
);
bind
->
buffer
=
bind_tinyint
;
bind
->
length
=
&
bind
->
buffer_length
;
bind
->
is_null
=
NULL
;
}
else
if
(
0
==
strncasecmp
(
dataType
,
"BOOL"
,
strlen
(
"BOOL"
)))
{
int8_t
*
bind_bool
=
malloc
(
sizeof
(
int8_t
));
if
(
value
)
{
if
(
strncasecmp
(
value
,
"true"
,
4
))
{
*
bind_bool
=
true
;
}
else
{
*
bind_bool
=
false
;
}
}
else
{
*
bind_bool
=
rand_bool
();
}
bind
->
buffer_type
=
TSDB_DATA_TYPE_BOOL
;
bind
->
buffer_length
=
sizeof
(
int8_t
);
bind
->
buffer
=
bind_bool
;
bind
->
length
=
&
bind
->
buffer_length
;
bind
->
is_null
=
NULL
;
}
else
if
(
0
==
strncasecmp
(
dataType
,
"TIMESTAMP"
,
strlen
(
"TIMESTAMP"
)))
{
int64_t
*
bind_ts2
=
malloc
(
sizeof
(
int64_t
));
if
(
value
)
{
if
(
strchr
(
value
,
':'
)
&&
strchr
(
value
,
'-'
))
{
int
i
=
0
;
while
(
value
[
i
]
!=
'\0'
)
{
if
(
value
[
i
]
==
'\"'
||
value
[
i
]
==
'\''
)
{
value
[
i
]
=
' '
;
}
i
++
;
}
int64_t
tmpEpoch
;
if
(
TSDB_CODE_SUCCESS
!=
taosParseTime
(
value
,
&
tmpEpoch
,
strlen
(
value
),
timePrec
,
0
))
{
errorPrint
(
"Input %s, time format error!
\n
"
,
value
);
return
-
1
;
}
*
bind_ts2
=
tmpEpoch
;
}
else
{
*
bind_ts2
=
atoll
(
value
);
}
}
else
{
*
bind_ts2
=
rand_bigint
();
}
bind
->
buffer_type
=
TSDB_DATA_TYPE_TIMESTAMP
;
bind
->
buffer_length
=
sizeof
(
int64_t
);
bind
->
buffer
=
bind_ts2
;
bind
->
length
=
&
bind
->
buffer_length
;
bind
->
is_null
=
NULL
;
}
else
{
errorPrint
(
"No support data type: %s
\n
"
,
dataType
);
return
-
1
;
}
return
0
;
}
static
int32_t
prepareStmtBindArrayByTypeForRand
(
TAOS_BIND
*
bind
,
char
*
dataType
,
int32_t
dataLen
,
int32_t
timePrec
,
char
**
ptr
,
char
*
value
)
{
if
(
0
==
strncasecmp
(
dataType
,
"BINARY"
,
strlen
(
"BINARY"
)))
{
...
...
@@ -5814,7 +6046,7 @@ static int32_t prepareStmtBindArrayByType(TAOS_BIND *bind,
*
ptr
+=
bind
->
buffer_length
;
}
else
if
(
0
==
strncasecmp
(
dataType
,
"FLOAT"
,
strlen
(
"FLOAT"
)))
{
float
*
bind_float
=
(
float
*
)
*
ptr
;
float
*
bind_float
=
(
float
*
)
*
ptr
;
if
(
value
)
{
*
bind_float
=
(
float
)
atof
(
value
);
...
...
@@ -5830,7 +6062,7 @@ static int32_t prepareStmtBindArrayByType(TAOS_BIND *bind,
*
ptr
+=
bind
->
buffer_length
;
}
else
if
(
0
==
strncasecmp
(
dataType
,
"DOUBLE"
,
strlen
(
"DOUBLE"
)))
{
double
*
bind_double
=
(
double
*
)
*
ptr
;
double
*
bind_double
=
(
double
*
)
*
ptr
;
if
(
value
)
{
*
bind_double
=
atof
(
value
);
...
...
@@ -5862,7 +6094,7 @@ static int32_t prepareStmtBindArrayByType(TAOS_BIND *bind,
*
ptr
+=
bind
->
buffer_length
;
}
else
if
(
0
==
strncasecmp
(
dataType
,
"TINYINT"
,
strlen
(
"TINYINT"
)))
{
int8_t
*
bind_tinyint
=
(
int8_t
*
)
*
ptr
;
int8_t
*
bind_tinyint
=
(
int8_t
*
)
*
ptr
;
if
(
value
)
{
*
bind_tinyint
=
(
int8_t
)
atoi
(
value
);
...
...
@@ -5874,12 +6106,21 @@ static int32_t prepareStmtBindArrayByType(TAOS_BIND *bind,
bind
->
buffer
=
bind_tinyint
;
bind
->
length
=
&
bind
->
buffer_length
;
bind
->
is_null
=
NULL
;
*
ptr
+=
bind
->
buffer_length
;
}
else
if
(
0
==
strncasecmp
(
dataType
,
"BOOL"
,
strlen
(
"BOOL"
)))
{
int8_t
*
bind_bool
=
(
int8_t
*
)
*
ptr
;
int8_t
*
bind_bool
=
(
int8_t
*
)
*
ptr
;
*
bind_bool
=
rand_bool
();
if
(
value
)
{
if
(
strncasecmp
(
value
,
"true"
,
4
))
{
*
bind_bool
=
true
;
}
else
{
*
bind_bool
=
false
;
}
}
else
{
*
bind_bool
=
rand_bool
();
}
bind
->
buffer_type
=
TSDB_DATA_TYPE_BOOL
;
bind
->
buffer_length
=
sizeof
(
int8_t
);
bind
->
buffer
=
bind_bool
;
...
...
@@ -5889,10 +6130,28 @@ static int32_t prepareStmtBindArrayByType(TAOS_BIND *bind,
*
ptr
+=
bind
->
buffer_length
;
}
else
if
(
0
==
strncasecmp
(
dataType
,
"TIMESTAMP"
,
strlen
(
"TIMESTAMP"
)))
{
int64_t
*
bind_ts2
=
(
int64_t
*
)
*
ptr
;
int64_t
*
bind_ts2
=
(
int64_t
*
)
*
ptr
;
if
(
value
)
{
*
bind_ts2
=
atoll
(
value
);
if
(
strchr
(
value
,
':'
)
&&
strchr
(
value
,
'-'
))
{
int
i
=
0
;
while
(
value
[
i
]
!=
'\0'
)
{
if
(
value
[
i
]
==
'\"'
||
value
[
i
]
==
'\''
)
{
value
[
i
]
=
' '
;
}
i
++
;
}
int64_t
tmpEpoch
;
if
(
TSDB_CODE_SUCCESS
!=
taosParseTime
(
value
,
&
tmpEpoch
,
strlen
(
value
),
timePrec
,
0
))
{
errorPrint
(
"Input %s, time format error!
\n
"
,
value
);
return
-
1
;
}
*
bind_ts2
=
tmpEpoch
;
}
else
{
*
bind_ts2
=
atoll
(
value
);
}
}
else
{
*
bind_ts2
=
rand_bigint
();
}
...
...
@@ -5912,13 +6171,14 @@ static int32_t prepareStmtBindArrayByType(TAOS_BIND *bind,
}
static
int32_t
prepareStmtWithoutStb
(
TAOS_STMT
*
stmt
,
threadInfo
*
pThreadInfo
,
char
*
tableName
,
uint32_t
batch
,
int64_t
insertRows
,
int64_t
recordFrom
,
int64_t
startTime
)
{
TAOS_STMT
*
stmt
=
pThreadInfo
->
stmt
;
int
ret
=
taos_stmt_set_tbname
(
stmt
,
tableName
);
if
(
ret
!=
0
)
{
errorPrint
(
"failed to execute taos_stmt_set_tbname(%s). return 0x%x. reason: %s
\n
"
,
...
...
@@ -5938,15 +6198,11 @@ static int32_t prepareStmtWithoutStb(
int32_t
k
=
0
;
for
(
k
=
0
;
k
<
batch
;)
{
/* columnCount + 1 (ts) */
char
data
[
MAX_DATA_SIZE
];
memset
(
data
,
0
,
MAX_DATA_SIZE
);
char
*
ptr
=
data
;
TAOS_BIND
*
bind
=
(
TAOS_BIND
*
)(
bindArray
+
0
);
int64_t
*
bind_ts
;
int64_t
*
bind_ts
=
pThreadInfo
->
bind_ts
;
bind_ts
=
(
int64_t
*
)
ptr
;
bind
->
buffer_type
=
TSDB_DATA_TYPE_TIMESTAMP
;
if
(
g_args
.
disorderRatio
)
{
...
...
@@ -5962,8 +6218,6 @@ static int32_t prepareStmtWithoutStb(
bind
->
length
=
&
bind
->
buffer_length
;
bind
->
is_null
=
NULL
;
ptr
+=
bind
->
buffer_length
;
for
(
int
i
=
0
;
i
<
g_args
.
num_of_CPR
;
i
++
)
{
bind
=
(
TAOS_BIND
*
)((
char
*
)
bindArray
+
(
sizeof
(
TAOS_BIND
)
*
(
i
+
1
)));
...
...
@@ -5971,7 +6225,8 @@ static int32_t prepareStmtWithoutStb(
bind
,
data_type
[
i
],
g_args
.
len_of_binary
,
&
ptr
,
NULL
))
{
pThreadInfo
->
time_precision
,
NULL
))
{
return
-
1
;
}
}
...
...
@@ -5998,10 +6253,10 @@ static int32_t prepareStmtWithoutStb(
return
k
;
}
static
int32_t
prepareStbStmtBind
(
char
*
bindArray
,
SSuperTable
*
stbInfo
,
bool
sourceRand
,
int64_t
startTime
,
int32_t
recSeq
,
bool
isColumn
)
static
int32_t
prepareStbStmtBind
Tag
(
char
*
bindArray
,
SSuperTable
*
stbInfo
,
char
*
tagsVal
,
int32_t
timePrec
)
{
char
*
bindBuffer
=
calloc
(
1
,
DOUBLE_BUFF_LEN
);
// g_args.len_of_binary);
if
(
bindBuffer
==
NULL
)
{
...
...
@@ -6010,127 +6265,130 @@ static int32_t prepareStbStmtBind(
return
-
1
;
}
char
data
[
MAX_DATA_SIZE
];
memset
(
data
,
0
,
MAX_DATA_SIZE
);
char
*
ptr
=
data
;
TAOS_BIND
*
tag
;
TAOS_BIND
*
bind
;
for
(
int
t
=
0
;
t
<
stbInfo
->
tagCount
;
t
++
)
{
tag
=
(
TAOS_BIND
*
)((
char
*
)
bindArray
+
(
sizeof
(
TAOS_BIND
)
*
t
));
if
(
-
1
==
prepareStmtBindArrayByType
(
tag
,
stbInfo
->
tags
[
t
].
dataType
,
stbInfo
->
tags
[
t
].
dataLen
,
timePrec
,
NULL
))
{
free
(
bindBuffer
);
return
-
1
;
}
}
if
(
isColumn
)
{
int
cursor
=
0
;
free
(
bindBuffer
);
return
0
;
}
for
(
int
i
=
0
;
i
<
stbInfo
->
columnCount
+
1
;
i
++
)
{
bind
=
(
TAOS_BIND
*
)((
char
*
)
bindArray
+
(
sizeof
(
TAOS_BIND
)
*
i
));
static
int32_t
prepareStbStmtBindRand
(
int64_t
*
ts
,
char
*
bindArray
,
SSuperTable
*
stbInfo
,
int64_t
startTime
,
int32_t
recSeq
,
int32_t
timePrec
)
{
char
*
bindBuffer
=
calloc
(
1
,
DOUBLE_BUFF_LEN
);
// g_args.len_of_binary);
if
(
bindBuffer
==
NULL
)
{
errorPrint
(
"%s() LN%d, Failed to allocate %d bind buffer
\n
"
,
__func__
,
__LINE__
,
g_args
.
len_of_binary
);
return
-
1
;
}
if
(
i
==
0
)
{
int64_t
*
bind_ts
;
char
data
[
MAX_DATA_SIZE
];
memset
(
data
,
0
,
MAX_DATA_SIZE
);
char
*
ptr
=
data
;
bind_ts
=
(
int64_t
*
)
ptr
;
bind
->
buffer_type
=
TSDB_DATA_TYPE_TIMESTAMP
;
if
(
stbInfo
->
disorderRatio
)
{
*
bind_ts
=
startTime
+
getTSRandTail
(
stbInfo
->
timeStampStep
,
recSeq
,
stbInfo
->
disorderRatio
,
stbInfo
->
disorderRange
);
}
else
{
*
bind_ts
=
startTime
+
stbInfo
->
timeStampStep
*
recSeq
;
}
bind
->
buffer_length
=
sizeof
(
int64_t
);
bind
->
buffer
=
bind_ts
;
bind
->
length
=
&
bind
->
buffer_length
;
bind
->
is_null
=
NULL
;
TAOS_BIND
*
bind
;
ptr
+=
bind
->
buffer_length
;
}
else
{
for
(
int
i
=
0
;
i
<
stbInfo
->
columnCount
+
1
;
i
++
)
{
bind
=
(
TAOS_BIND
*
)((
char
*
)
bindArray
+
(
sizeof
(
TAOS_BIND
)
*
i
));
if
(
sourceRand
)
{
if
(
-
1
==
prepareStmtBindArrayByType
(
bind
,
stbInfo
->
columns
[
i
-
1
].
dataType
,
stbInfo
->
columns
[
i
-
1
].
dataLen
,
&
ptr
,
NULL
))
{
free
(
bindBuffer
);
return
-
1
;
}
}
else
{
char
*
restStr
=
stbInfo
->
sampleDataBuf
+
cursor
;
int
lengthOfRest
=
strlen
(
restStr
);
int
index
=
0
;
for
(
index
=
0
;
index
<
lengthOfRest
;
index
++
)
{
if
(
restStr
[
index
]
==
','
)
{
break
;
}
}
if
(
i
==
0
)
{
int64_t
*
bind_ts
=
ts
;
memset
(
bindBuffer
,
0
,
g_args
.
len_of_binary
);
strncpy
(
bindBuffer
,
restStr
,
index
);
cursor
+=
index
+
1
;
// skip ',' too
if
(
-
1
==
prepareStmtBindArrayByType
(
bind
,
stbInfo
->
columns
[
i
-
1
].
dataType
,
stbInfo
->
columns
[
i
-
1
].
dataLen
,
&
ptr
,
bindBuffer
))
{
free
(
bindBuffer
);
return
-
1
;
}
}
}
bind
->
buffer_type
=
TSDB_DATA_TYPE_TIMESTAMP
;
if
(
stbInfo
->
disorderRatio
)
{
*
bind_ts
=
startTime
+
getTSRandTail
(
stbInfo
->
timeStampStep
,
recSeq
,
stbInfo
->
disorderRatio
,
stbInfo
->
disorderRange
);
}
else
{
*
bind_ts
=
startTime
+
stbInfo
->
timeStampStep
*
recSeq
;
}
bind
->
buffer_length
=
sizeof
(
int64_t
);
bind
->
buffer
=
bind_ts
;
bind
->
length
=
&
bind
->
buffer_length
;
bind
->
is_null
=
NULL
;
ptr
+=
bind
->
buffer_length
;
}
else
if
(
-
1
==
prepareStmtBindArrayByTypeForRand
(
bind
,
stbInfo
->
columns
[
i
-
1
].
dataType
,
stbInfo
->
columns
[
i
-
1
].
dataLen
,
timePrec
,
&
ptr
,
NULL
))
{
tmfree
(
bindBuffer
);
return
-
1
;
}
}
else
{
TAOS_BIND
*
tag
;
}
for
(
int
t
=
0
;
t
<
stbInfo
->
tagCount
;
t
++
)
{
tag
=
(
TAOS_BIND
*
)((
char
*
)
bindArray
+
(
sizeof
(
TAOS_BIND
)
*
t
));
if
(
-
1
==
prepareStmtBindArrayByType
(
tag
,
stbInfo
->
tags
[
t
].
dataType
,
stbInfo
->
tags
[
t
].
dataLen
,
&
ptr
,
NULL
))
{
free
(
bindBuffer
);
return
-
1
;
}
}
tmfree
(
bindBuffer
);
return
0
;
}
static
int32_t
prepareStbStmtBindWithSample
(
int64_t
*
ts
,
char
*
bindArray
,
SSuperTable
*
stbInfo
,
int64_t
startTime
,
int32_t
recSeq
,
int32_t
timePrec
,
int64_t
samplePos
)
{
TAOS_BIND
*
bind
;
bind
=
(
TAOS_BIND
*
)
bindArray
;
int64_t
*
bind_ts
=
ts
;
bind
->
buffer_type
=
TSDB_DATA_TYPE_TIMESTAMP
;
if
(
stbInfo
->
disorderRatio
)
{
*
bind_ts
=
startTime
+
getTSRandTail
(
stbInfo
->
timeStampStep
,
recSeq
,
stbInfo
->
disorderRatio
,
stbInfo
->
disorderRange
);
}
else
{
*
bind_ts
=
startTime
+
stbInfo
->
timeStampStep
*
recSeq
;
}
bind
->
buffer_length
=
sizeof
(
int64_t
);
bind
->
buffer
=
bind_ts
;
bind
->
length
=
&
bind
->
buffer_length
;
bind
->
is_null
=
NULL
;
free
(
bindBuffer
);
return
0
;
}
static
int32_t
prepareStbStmt
(
SSuperTable
*
stbInfo
,
TAOS_STMT
*
stmt
,
static
int32_t
prepareStbStmtRand
(
threadInfo
*
pThreadInfo
,
char
*
tableName
,
int64_t
tableSeq
,
uint32_t
batch
,
uint64_t
insertRows
,
uint64_t
recordFrom
,
int64_t
startTime
,
int64_t
*
pSamplePos
)
int64_t
startTime
)
{
int
ret
;
bool
sourceRand
;
if
(
0
==
strncasecmp
(
stbInfo
->
dataSource
,
"rand"
,
strlen
(
"rand"
)))
{
sourceRand
=
true
;
}
else
{
sourceRand
=
false
;
// from sample data file
}
SSuperTable
*
stbInfo
=
pThreadInfo
->
stbInfo
;
TAOS_STMT
*
stmt
=
pThreadInfo
->
stmt
;
if
(
AUTO_CREATE_SUBTBL
==
stbInfo
->
autoCreateTable
)
{
char
*
tagsValBuf
=
NULL
;
bool
tagRand
;
if
(
0
==
stbInfo
->
tagSource
)
{
tagRand
=
true
;
tagsValBuf
=
generateTagValuesForStb
(
stbInfo
,
tableSeq
);
}
else
{
tagRand
=
false
;
tagsValBuf
=
getTagValueFromTagSample
(
stbInfo
,
tableSeq
%
stbInfo
->
tagSampleCount
);
...
...
@@ -6150,8 +6408,9 @@ static int32_t prepareStbStmt(
return
-
1
;
}
if
(
-
1
==
prepareStbStmtBind
(
tagsArray
,
stbInfo
,
tagRand
,
-
1
,
-
1
,
false
/* is tag */
))
{
if
(
-
1
==
prepareStbStmtBindTag
(
tagsArray
,
stbInfo
,
tagsValBuf
,
pThreadInfo
->
time_precision
/* is tag */
))
{
tmfree
(
tagsValBuf
);
tmfree
(
tagsArray
);
return
-
1
;
...
...
@@ -6186,8 +6445,12 @@ static int32_t prepareStbStmt(
uint32_t
k
;
for
(
k
=
0
;
k
<
batch
;)
{
/* columnCount + 1 (ts) */
if
(
-
1
==
prepareStbStmtBind
(
bindArray
,
stbInfo
,
sourceRand
,
startTime
,
k
,
true
/* is column */
))
{
if
(
-
1
==
prepareStbStmtBindRand
(
pThreadInfo
->
bind_ts
,
bindArray
,
stbInfo
,
startTime
,
k
,
pThreadInfo
->
time_precision
/* is column */
))
{
free
(
bindArray
);
return
-
1
;
}
...
...
@@ -6210,10 +6473,6 @@ static int32_t prepareStbStmt(
k
++
;
recordFrom
++
;
if
(
!
sourceRand
)
{
(
*
pSamplePos
)
++
;
}
if
(
recordFrom
>=
insertRows
)
{
break
;
}
...
...
@@ -6223,9 +6482,8 @@ static int32_t prepareStbStmt(
return
k
;
}
static
int32_t
prepareStbStmtInterlace
(
SSuperTable
*
stbInfo
,
TAOS_STMT
*
stmt
,
static
int32_t
prepareStbStmtWithSample
(
threadInfo
*
pThreadInfo
,
char
*
tableName
,
int64_t
tableSeq
,
uint32_t
batch
,
...
...
@@ -6234,41 +6492,109 @@ static int32_t prepareStbStmtInterlace(
int64_t
startTime
,
int64_t
*
pSamplePos
)
{
return
prepareStbStmt
(
stbInfo
,
stmt
,
tableName
,
tableSeq
,
batch
,
insertRows
,
0
,
startTime
,
pSamplePos
);
}
int
ret
;
SSuperTable
*
stbInfo
=
pThreadInfo
->
stbInfo
;
TAOS_STMT
*
stmt
=
pThreadInfo
->
stmt
;
static
int32_t
prepareStbStmtProgressive
(
SSuperTable
*
stbInfo
,
TAOS_STMT
*
stmt
,
char
*
tableName
,
int64_t
tableSeq
,
uint32_t
batch
,
uint64_t
insertRows
,
uint64_t
recordFrom
,
int64_t
startTime
,
int64_t
*
pSamplePos
)
{
return
prepareStbStmt
(
stbInfo
,
stmt
,
tableName
,
tableSeq
,
g_args
.
num_of_RPR
,
insertRows
,
recordFrom
,
startTime
,
pSamplePos
);
}
if
(
AUTO_CREATE_SUBTBL
==
stbInfo
->
autoCreateTable
)
{
char
*
tagsValBuf
=
NULL
;
if
(
0
==
stbInfo
->
tagSource
)
{
tagsValBuf
=
generateTagValuesForStb
(
stbInfo
,
tableSeq
);
}
else
{
tagsValBuf
=
getTagValueFromTagSample
(
stbInfo
,
tableSeq
%
stbInfo
->
tagSampleCount
);
}
if
(
NULL
==
tagsValBuf
)
{
errorPrint
(
"%s() LN%d, tag buf failed to allocate memory
\n
"
,
__func__
,
__LINE__
);
return
-
1
;
}
char
*
tagsArray
=
calloc
(
1
,
sizeof
(
TAOS_BIND
)
*
stbInfo
->
tagCount
);
if
(
NULL
==
tagsArray
)
{
tmfree
(
tagsValBuf
);
errorPrint
(
"%s() LN%d, tag buf failed to allocate memory
\n
"
,
__func__
,
__LINE__
);
return
-
1
;
}
if
(
-
1
==
prepareStbStmtBindTag
(
tagsArray
,
stbInfo
,
tagsValBuf
,
pThreadInfo
->
time_precision
/* is tag */
))
{
tmfree
(
tagsValBuf
);
tmfree
(
tagsArray
);
return
-
1
;
}
ret
=
taos_stmt_set_tbname_tags
(
stmt
,
tableName
,
(
TAOS_BIND
*
)
tagsArray
);
tmfree
(
tagsValBuf
);
tmfree
(
tagsArray
);
if
(
0
!=
ret
)
{
errorPrint
(
"%s() LN%d, stmt_set_tbname_tags() failed! reason: %s
\n
"
,
__func__
,
__LINE__
,
taos_stmt_errstr
(
stmt
));
return
-
1
;
}
}
else
{
ret
=
taos_stmt_set_tbname
(
stmt
,
tableName
);
if
(
0
!=
ret
)
{
errorPrint
(
"%s() LN%d, stmt_set_tbname() failed! reason: %s
\n
"
,
__func__
,
__LINE__
,
taos_stmt_errstr
(
stmt
));
return
-
1
;
}
}
uint32_t
k
;
for
(
k
=
0
;
k
<
batch
;)
{
char
*
bindArray
=
(
char
*
)(
*
((
uintptr_t
*
)
(
stbInfo
->
sampleBindArray
+
(
sizeof
(
char
*
))
*
(
*
pSamplePos
))));
/* columnCount + 1 (ts) */
if
(
-
1
==
prepareStbStmtBindWithSample
(
pThreadInfo
->
bind_ts
,
bindArray
,
stbInfo
,
startTime
,
k
,
pThreadInfo
->
time_precision
,
*
pSamplePos
/* is column */
))
{
return
-
1
;
}
ret
=
taos_stmt_bind_param
(
stmt
,
(
TAOS_BIND
*
)
bindArray
);
if
(
0
!=
ret
)
{
errorPrint
(
"%s() LN%d, stmt_bind_param() failed! reason: %s
\n
"
,
__func__
,
__LINE__
,
taos_stmt_errstr
(
stmt
));
return
-
1
;
}
// if msg > 3MB, break
ret
=
taos_stmt_add_batch
(
stmt
);
if
(
0
!=
ret
)
{
errorPrint
(
"%s() LN%d, stmt_add_batch() failed! reason: %s
\n
"
,
__func__
,
__LINE__
,
taos_stmt_errstr
(
stmt
));
return
-
1
;
}
k
++
;
recordFrom
++
;
(
*
pSamplePos
)
++
;
if
((
*
pSamplePos
)
==
MAX_SAMPLES_ONCE_FROM_FILE
)
{
*
pSamplePos
=
0
;
}
if
(
recordFrom
>=
insertRows
)
{
break
;
}
}
return
k
;
}
#endif
static
int32_t
generateStbProgressiveData
(
SSuperTable
*
s
uperTbl
Info
,
SSuperTable
*
s
tb
Info
,
char
*
tableName
,
int64_t
tableSeq
,
char
*
dbName
,
char
*
buffer
,
...
...
@@ -6282,7 +6608,7 @@ static int32_t generateStbProgressiveData(
memset
(
pstr
,
0
,
*
pRemainderBufLen
);
int64_t
headLen
=
generateStbSQLHead
(
s
uperTbl
Info
,
s
tb
Info
,
tableName
,
tableSeq
,
dbName
,
buffer
,
*
pRemainderBufLen
);
...
...
@@ -6294,7 +6620,7 @@ static int32_t generateStbProgressiveData(
int64_t
dataLen
;
return
generateStbDataTail
(
s
uperTbl
Info
,
return
generateStbDataTail
(
s
tb
Info
,
g_args
.
num_of_RPR
,
pstr
,
*
pRemainderBufLen
,
insertRows
,
recordFrom
,
startTime
,
...
...
@@ -6354,26 +6680,34 @@ static void* syncWriteInterlace(threadInfo *pThreadInfo) {
int64_t
nTimeStampStep
;
uint64_t
insert_interval
;
SSuperTable
*
superTblInfo
=
pThreadInfo
->
superTblInfo
;
bool
sourceRand
;
SSuperTable
*
stbInfo
=
pThreadInfo
->
stbInfo
;
if
(
s
uperTbl
Info
)
{
insertRows
=
s
uperTbl
Info
->
insertRows
;
if
(
s
tb
Info
)
{
insertRows
=
s
tb
Info
->
insertRows
;
if
((
s
uperTbl
Info
->
interlaceRows
==
0
)
if
((
s
tb
Info
->
interlaceRows
==
0
)
&&
(
g_args
.
interlace_rows
>
0
))
{
interlaceRows
=
g_args
.
interlace_rows
;
}
else
{
interlaceRows
=
superTblInfo
->
interlaceRows
;
interlaceRows
=
stbInfo
->
interlaceRows
;
}
maxSqlLen
=
stbInfo
->
maxSqlLen
;
nTimeStampStep
=
stbInfo
->
timeStampStep
;
insert_interval
=
stbInfo
->
insertInterval
;
if
(
0
==
strncasecmp
(
stbInfo
->
dataSource
,
"rand"
,
4
))
{
sourceRand
=
true
;
}
else
{
sourceRand
=
false
;
// from sample data file
}
maxSqlLen
=
superTblInfo
->
maxSqlLen
;
nTimeStampStep
=
superTblInfo
->
timeStampStep
;
insert_interval
=
superTblInfo
->
insertInterval
;
}
else
{
insertRows
=
g_args
.
num_of_DPT
;
interlaceRows
=
g_args
.
interlace_rows
;
maxSqlLen
=
g_args
.
max_sql_len
;
nTimeStampStep
=
g_args
.
timestamp_step
;
insert_interval
=
g_args
.
insert_interval
;
sourceRand
=
true
;
}
debugPrint
(
"[%d] %s() LN%d: start_table_from=%"
PRIu64
" ntables=%"
PRId64
" insertRows=%"
PRIu64
"
\n
"
,
...
...
@@ -6456,28 +6790,38 @@ static void* syncWriteInterlace(threadInfo *pThreadInfo) {
uint64_t
oldRemainderLen
=
remainderBufLen
;
int32_t
generated
;
if
(
s
uperTbl
Info
)
{
if
(
s
uperTbl
Info
->
iface
==
STMT_IFACE
)
{
if
(
s
tb
Info
)
{
if
(
s
tb
Info
->
iface
==
STMT_IFACE
)
{
#if STMT_IFACE_ENABLED == 1
generated
=
prepareStbStmtInterlace
(
superTblInfo
,
pThreadInfo
->
stmt
,
tableName
,
tableSeq
,
batchPerTbl
,
insertRows
,
i
,
startTime
,
&
(
pThreadInfo
->
samplePos
));
if
(
sourceRand
)
{
generated
=
prepareStbStmtRand
(
pThreadInfo
,
tableName
,
tableSeq
,
batchPerTbl
,
insertRows
,
0
,
startTime
);
}
else
{
generated
=
prepareStbStmtWithSample
(
pThreadInfo
,
tableName
,
tableSeq
,
batchPerTbl
,
insertRows
,
0
,
startTime
,
&
(
pThreadInfo
->
samplePos
));
}
#else
generated
=
-
1
;
#endif
}
else
{
generated
=
generateStbInterlaceData
(
superTbl
Info
,
pThread
Info
,
tableName
,
batchPerTbl
,
i
,
batchPerTblTimes
,
tableSeq
,
p
ThreadInfo
,
p
str
,
pstr
,
insertRows
,
startTime
,
&
remainderBufLen
);
...
...
@@ -6490,7 +6834,8 @@ static void* syncWriteInterlace(threadInfo *pThreadInfo) {
tableName
,
batchPerTbl
,
startTime
);
#if STMT_IFACE_ENABLED == 1
generated
=
prepareStmtWithoutStb
(
pThreadInfo
->
stmt
,
tableName
,
pThreadInfo
,
tableName
,
batchPerTbl
,
insertRows
,
i
,
startTime
);
...
...
@@ -6639,12 +6984,12 @@ free_of_interlace:
static
void
*
syncWriteProgressive
(
threadInfo
*
pThreadInfo
)
{
debugPrint
(
"%s() LN%d: ### progressive write
\n
"
,
__func__
,
__LINE__
);
SSuperTable
*
s
uperTblInfo
=
pThreadInfo
->
superTbl
Info
;
uint64_t
maxSqlLen
=
s
uperTblInfo
?
superTbl
Info
->
maxSqlLen
:
g_args
.
max_sql_len
;
SSuperTable
*
s
tbInfo
=
pThreadInfo
->
stb
Info
;
uint64_t
maxSqlLen
=
s
tbInfo
?
stb
Info
->
maxSqlLen
:
g_args
.
max_sql_len
;
int64_t
timeStampStep
=
s
uperTblInfo
?
superTbl
Info
->
timeStampStep
:
g_args
.
timestamp_step
;
s
tbInfo
?
stb
Info
->
timeStampStep
:
g_args
.
timestamp_step
;
int64_t
insertRows
=
(
s
uperTblInfo
)
?
superTbl
Info
->
insertRows
:
g_args
.
num_of_DPT
;
(
s
tbInfo
)
?
stb
Info
->
insertRows
:
g_args
.
num_of_DPT
;
verbosePrint
(
"%s() LN%d insertRows=%"
PRId64
"
\n
"
,
__func__
,
__LINE__
,
insertRows
);
...
...
@@ -6663,6 +7008,17 @@ static void* syncWriteProgressive(threadInfo *pThreadInfo) {
pThreadInfo
->
totalInsertRows
=
0
;
pThreadInfo
->
totalAffectedRows
=
0
;
bool
sourceRand
;
if
(
stbInfo
)
{
if
(
0
==
strncasecmp
(
stbInfo
->
dataSource
,
"rand"
,
4
))
{
sourceRand
=
true
;
}
else
{
sourceRand
=
false
;
// from sample data file
}
}
else
{
sourceRand
=
true
;
}
pThreadInfo
->
samplePos
=
0
;
int
percentComplete
=
0
;
...
...
@@ -6696,24 +7052,35 @@ static void* syncWriteProgressive(threadInfo *pThreadInfo) {
remainderBufLen
-=
len
;
int32_t
generated
;
if
(
s
uperTbl
Info
)
{
if
(
s
uperTbl
Info
->
iface
==
STMT_IFACE
)
{
if
(
s
tb
Info
)
{
if
(
s
tb
Info
->
iface
==
STMT_IFACE
)
{
#if STMT_IFACE_ENABLED == 1
generated
=
prepareStbStmtProgressive
(
superTblInfo
,
pThreadInfo
->
stmt
,
tableName
,
tableSeq
,
g_args
.
num_of_RPR
,
insertRows
,
i
,
start_time
,
&
(
pThreadInfo
->
samplePos
));
if
(
sourceRand
)
{
generated
=
prepareStbStmtRand
(
pThreadInfo
,
tableName
,
tableSeq
,
g_args
.
num_of_RPR
,
insertRows
,
i
,
start_time
);
}
else
{
generated
=
prepareStbStmtWithSample
(
pThreadInfo
,
tableName
,
tableSeq
,
g_args
.
num_of_RPR
,
insertRows
,
i
,
start_time
,
&
(
pThreadInfo
->
samplePos
));
}
#else
generated
=
-
1
;
#endif
}
else
{
generated
=
generateStbProgressiveData
(
superTblInfo
,
tableName
,
tableSeq
,
pThreadInfo
->
db_name
,
pstr
,
stbInfo
,
tableName
,
tableSeq
,
pThreadInfo
->
db_name
,
pstr
,
insertRows
,
i
,
start_time
,
&
(
pThreadInfo
->
samplePos
),
&
remainderBufLen
);
...
...
@@ -6722,7 +7089,7 @@ static void* syncWriteProgressive(threadInfo *pThreadInfo) {
if
(
g_args
.
iface
==
STMT_IFACE
)
{
#if STMT_IFACE_ENABLED == 1
generated
=
prepareStmtWithoutStb
(
pThreadInfo
->
stmt
,
pThreadInfo
,
tableName
,
g_args
.
num_of_RPR
,
insertRows
,
i
,
...
...
@@ -6792,9 +7159,9 @@ static void* syncWriteProgressive(threadInfo *pThreadInfo) {
}
// num_of_DPT
if
((
g_args
.
verbose_print
)
&&
(
tableSeq
==
pThreadInfo
->
ntables
-
1
)
&&
(
s
uperTbl
Info
)
(
tableSeq
==
pThreadInfo
->
ntables
-
1
)
&&
(
s
tb
Info
)
&&
(
0
==
strncasecmp
(
s
uperTbl
Info
->
dataSource
,
s
tb
Info
->
dataSource
,
"sample"
,
strlen
(
"sample"
))))
{
verbosePrint
(
"%s() LN%d samplePos=%"
PRId64
"
\n
"
,
__func__
,
__LINE__
,
pThreadInfo
->
samplePos
);
...
...
@@ -6812,18 +7179,18 @@ free_of_progressive:
static
void
*
syncWrite
(
void
*
sarg
)
{
threadInfo
*
pThreadInfo
=
(
threadInfo
*
)
sarg
;
SSuperTable
*
s
uperTblInfo
=
pThreadInfo
->
superTbl
Info
;
SSuperTable
*
s
tbInfo
=
pThreadInfo
->
stb
Info
;
setThreadName
(
"syncWrite"
);
uint32_t
interlaceRows
;
if
(
s
uperTbl
Info
)
{
if
((
s
uperTbl
Info
->
interlaceRows
==
0
)
if
(
s
tb
Info
)
{
if
((
s
tb
Info
->
interlaceRows
==
0
)
&&
(
g_args
.
interlace_rows
>
0
))
{
interlaceRows
=
g_args
.
interlace_rows
;
}
else
{
interlaceRows
=
s
uperTbl
Info
->
interlaceRows
;
interlaceRows
=
s
tb
Info
->
interlaceRows
;
}
}
else
{
interlaceRows
=
g_args
.
interlace_rows
;
...
...
@@ -6840,10 +7207,10 @@ static void* syncWrite(void *sarg) {
static
void
callBack
(
void
*
param
,
TAOS_RES
*
res
,
int
code
)
{
threadInfo
*
pThreadInfo
=
(
threadInfo
*
)
param
;
SSuperTable
*
s
uperTblInfo
=
pThreadInfo
->
superTbl
Info
;
SSuperTable
*
s
tbInfo
=
pThreadInfo
->
stb
Info
;
int
insert_interval
=
s
uperTblInfo
?
superTbl
Info
->
insertInterval
:
g_args
.
insert_interval
;
s
tbInfo
?
stb
Info
->
insertInterval
:
g_args
.
insert_interval
;
if
(
insert_interval
)
{
pThreadInfo
->
et
=
taosGetTimestampMs
();
if
((
pThreadInfo
->
et
-
pThreadInfo
->
st
)
<
insert_interval
)
{
...
...
@@ -6851,13 +7218,13 @@ static void callBack(void *param, TAOS_RES *res, int code) {
}
}
char
*
buffer
=
calloc
(
1
,
pThreadInfo
->
s
uperTbl
Info
->
maxSqlLen
);
char
*
buffer
=
calloc
(
1
,
pThreadInfo
->
s
tb
Info
->
maxSqlLen
);
char
data
[
MAX_DATA_SIZE
];
char
*
pstr
=
buffer
;
pstr
+=
sprintf
(
pstr
,
"insert into %s.%s%"
PRId64
" values"
,
pThreadInfo
->
db_name
,
pThreadInfo
->
tb_prefix
,
pThreadInfo
->
start_table_from
);
// if (pThreadInfo->counter >= pThreadInfo->s
uperTbl
Info->insertRows) {
// if (pThreadInfo->counter >= pThreadInfo->s
tb
Info->insertRows) {
if
(
pThreadInfo
->
counter
>=
g_args
.
num_of_RPR
)
{
pThreadInfo
->
start_table_from
++
;
pThreadInfo
->
counter
=
0
;
...
...
@@ -6871,15 +7238,15 @@ static void callBack(void *param, TAOS_RES *res, int code) {
for
(
int
i
=
0
;
i
<
g_args
.
num_of_RPR
;
i
++
)
{
int
rand_num
=
taosRandom
()
%
100
;
if
(
0
!=
pThreadInfo
->
s
uperTbl
Info
->
disorderRatio
&&
rand_num
<
pThreadInfo
->
s
uperTbl
Info
->
disorderRatio
)
{
if
(
0
!=
pThreadInfo
->
s
tb
Info
->
disorderRatio
&&
rand_num
<
pThreadInfo
->
s
tb
Info
->
disorderRatio
)
{
int64_t
d
=
pThreadInfo
->
lastTs
-
(
taosRandom
()
%
pThreadInfo
->
s
uperTbl
Info
->
disorderRange
+
1
);
generateStbRowData
(
pThreadInfo
->
s
uperTbl
Info
,
data
,
-
(
taosRandom
()
%
pThreadInfo
->
s
tb
Info
->
disorderRange
+
1
);
generateStbRowData
(
pThreadInfo
->
s
tb
Info
,
data
,
MAX_DATA_SIZE
,
d
);
}
else
{
generateStbRowData
(
pThreadInfo
->
s
uperTbl
Info
,
generateStbRowData
(
pThreadInfo
->
s
tb
Info
,
data
,
MAX_DATA_SIZE
,
pThreadInfo
->
lastTs
+=
1000
);
...
...
@@ -6887,7 +7254,7 @@ static void callBack(void *param, TAOS_RES *res, int code) {
pstr
+=
sprintf
(
pstr
,
"%s"
,
data
);
pThreadInfo
->
counter
++
;
if
(
pThreadInfo
->
counter
>=
pThreadInfo
->
s
uperTbl
Info
->
insertRows
)
{
if
(
pThreadInfo
->
counter
>=
pThreadInfo
->
s
tb
Info
->
insertRows
)
{
break
;
}
}
...
...
@@ -6903,7 +7270,7 @@ static void callBack(void *param, TAOS_RES *res, int code) {
static
void
*
asyncWrite
(
void
*
sarg
)
{
threadInfo
*
pThreadInfo
=
(
threadInfo
*
)
sarg
;
SSuperTable
*
s
uperTblInfo
=
pThreadInfo
->
superTbl
Info
;
SSuperTable
*
s
tbInfo
=
pThreadInfo
->
stb
Info
;
setThreadName
(
"asyncWrite"
);
...
...
@@ -6912,7 +7279,7 @@ static void *asyncWrite(void *sarg) {
pThreadInfo
->
lastTs
=
pThreadInfo
->
start_time
;
int
insert_interval
=
s
uperTblInfo
?
superTbl
Info
->
insertInterval
:
g_args
.
insert_interval
;
s
tbInfo
?
stb
Info
->
insertInterval
:
g_args
.
insert_interval
;
if
(
insert_interval
)
{
pThreadInfo
->
st
=
taosGetTimestampMs
();
}
...
...
@@ -6949,8 +7316,81 @@ static int convertHostToServAddr(char *host, uint16_t port, struct sockaddr_in *
return
0
;
}
#if STMT_IFACE_ENABLED == 1
static
int
parseSampleFileToStmt
(
SSuperTable
*
stbInfo
,
uint32_t
timePrec
)
{
stbInfo
->
sampleBindArray
=
calloc
(
1
,
sizeof
(
char
*
)
*
MAX_SAMPLES_ONCE_FROM_FILE
);
if
(
stbInfo
->
sampleBindArray
==
NULL
)
{
errorPrint
(
"%s() LN%d, Failed to allocate %"
PRIu64
" bind array buffer
\n
"
,
__func__
,
__LINE__
,
(
uint64_t
)
sizeof
(
char
*
)
*
MAX_SAMPLES_ONCE_FROM_FILE
);
return
-
1
;
}
for
(
int
i
=
0
;
i
<
MAX_SAMPLES_ONCE_FROM_FILE
;
i
++
)
{
char
*
bindArray
=
calloc
(
1
,
sizeof
(
TAOS_BIND
)
*
(
stbInfo
->
columnCount
+
1
));
if
(
bindArray
==
NULL
)
{
errorPrint
(
"%s() LN%d, Failed to allocate %d bind params
\n
"
,
__func__
,
__LINE__
,
(
stbInfo
->
columnCount
+
1
));
return
-
1
;
}
TAOS_BIND
*
bind
;
int
cursor
=
0
;
for
(
int
c
=
0
;
c
<
stbInfo
->
columnCount
+
1
;
c
++
)
{
bind
=
(
TAOS_BIND
*
)((
char
*
)
bindArray
+
(
sizeof
(
TAOS_BIND
)
*
c
));
if
(
c
==
0
)
{
bind
->
buffer_type
=
TSDB_DATA_TYPE_TIMESTAMP
;
bind
->
buffer_length
=
sizeof
(
int64_t
);
bind
->
buffer
=
NULL
;
//bind_ts;
bind
->
length
=
&
bind
->
buffer_length
;
bind
->
is_null
=
NULL
;
}
else
{
char
*
restStr
=
stbInfo
->
sampleDataBuf
+
stbInfo
->
lenOfOneRow
*
i
+
cursor
;
int
lengthOfRest
=
strlen
(
restStr
);
int
index
=
0
;
for
(
index
=
0
;
index
<
lengthOfRest
;
index
++
)
{
if
(
restStr
[
index
]
==
','
)
{
break
;
}
}
char
*
bindBuffer
=
calloc
(
1
,
index
+
1
);
if
(
bindBuffer
==
NULL
)
{
errorPrint
(
"%s() LN%d, Failed to allocate %d bind buffer
\n
"
,
__func__
,
__LINE__
,
DOUBLE_BUFF_LEN
);
return
-
1
;
}
strncpy
(
bindBuffer
,
restStr
,
index
);
cursor
+=
index
+
1
;
// skip ',' too
if
(
-
1
==
prepareStmtBindArrayByType
(
bind
,
stbInfo
->
columns
[
c
-
1
].
dataType
,
stbInfo
->
columns
[
c
-
1
].
dataLen
,
timePrec
,
bindBuffer
))
{
free
(
bindBuffer
);
return
-
1
;
}
free
(
bindBuffer
);
}
}
*
((
uintptr_t
*
)(
stbInfo
->
sampleBindArray
+
(
sizeof
(
char
*
))
*
i
))
=
(
uintptr_t
)
bindArray
;
}
return
0
;
}
#endif
static
void
startMultiThreadInsertData
(
int
threads
,
char
*
db_name
,
char
*
precision
,
SSuperTable
*
s
uperTbl
Info
)
{
char
*
precision
,
SSuperTable
*
s
tb
Info
)
{
int32_t
timePrec
=
TSDB_TIME_PRECISION_MILLI
;
if
(
0
!=
precision
[
0
])
{
...
...
@@ -6964,19 +7404,19 @@ static void startMultiThreadInsertData(int threads, char* db_name,
#endif
}
else
{
errorPrint
(
"Not support precision: %s
\n
"
,
precision
);
exit
(
-
1
);
exit
(
EXIT_FAILURE
);
}
}
int64_t
start_time
;
if
(
s
uperTbl
Info
)
{
if
(
0
==
strncasecmp
(
s
uperTbl
Info
->
startTimestamp
,
"now"
,
3
))
{
if
(
s
tb
Info
)
{
if
(
0
==
strncasecmp
(
s
tb
Info
->
startTimestamp
,
"now"
,
3
))
{
start_time
=
taosGetTimestamp
(
timePrec
);
}
else
{
if
(
TSDB_CODE_SUCCESS
!=
taosParseTime
(
s
uperTbl
Info
->
startTimestamp
,
s
tb
Info
->
startTimestamp
,
&
start_time
,
strlen
(
s
uperTbl
Info
->
startTimestamp
),
strlen
(
s
tb
Info
->
startTimestamp
),
timePrec
,
0
))
{
ERROR_EXIT
(
"failed to parse time!
\n
"
);
}
...
...
@@ -6990,12 +7430,12 @@ static void startMultiThreadInsertData(int threads, char* db_name,
int64_t
start
=
taosGetTimestampMs
();
// read sample data from file first
if
((
s
uperTblInfo
)
&&
(
0
==
strncasecmp
(
superTbl
Info
->
dataSource
,
if
((
s
tbInfo
)
&&
(
0
==
strncasecmp
(
stb
Info
->
dataSource
,
"sample"
,
strlen
(
"sample"
))))
{
if
(
0
!=
prepareSampleDataForSTable
(
s
uperTbl
Info
))
{
if
(
0
!=
prepareSampleDataForSTable
(
s
tb
Info
))
{
errorPrint
(
"%s() LN%d, prepare sample data for stable failed!
\n
"
,
__func__
,
__LINE__
);
exit
(
-
1
);
exit
(
EXIT_FAILURE
);
}
}
...
...
@@ -7005,68 +7445,68 @@ static void startMultiThreadInsertData(int threads, char* db_name,
if
(
NULL
==
taos0
)
{
errorPrint
(
"%s() LN%d, connect to server fail , reason: %s
\n
"
,
__func__
,
__LINE__
,
taos_errstr
(
NULL
));
exit
(
-
1
);
exit
(
EXIT_FAILURE
);
}
int64_t
ntables
=
0
;
uint64_t
tableFrom
;
if
(
s
uperTbl
Info
)
{
if
(
s
tb
Info
)
{
int64_t
limit
;
uint64_t
offset
;
if
((
NULL
!=
g_args
.
sqlFile
)
&&
(
s
uperTbl
Info
->
childTblExists
==
TBL_NO_EXISTS
)
&&
((
s
uperTbl
Info
->
childTblOffset
!=
0
)
||
(
s
uperTbl
Info
->
childTblLimit
>=
0
)))
{
&&
(
s
tb
Info
->
childTblExists
==
TBL_NO_EXISTS
)
&&
((
s
tb
Info
->
childTblOffset
!=
0
)
||
(
s
tb
Info
->
childTblLimit
>=
0
)))
{
printf
(
"WARNING: offset and limit will not be used since the child tables not exists!
\n
"
);
}
if
(
s
uperTbl
Info
->
childTblExists
==
TBL_ALREADY_EXISTS
)
{
if
((
s
uperTbl
Info
->
childTblLimit
<
0
)
||
((
s
uperTbl
Info
->
childTblOffset
+
s
uperTbl
Info
->
childTblLimit
)
>
(
s
uperTbl
Info
->
childTblCount
)))
{
s
uperTbl
Info
->
childTblLimit
=
s
uperTblInfo
->
childTblCount
-
superTbl
Info
->
childTblOffset
;
if
(
s
tb
Info
->
childTblExists
==
TBL_ALREADY_EXISTS
)
{
if
((
s
tb
Info
->
childTblLimit
<
0
)
||
((
s
tb
Info
->
childTblOffset
+
s
tb
Info
->
childTblLimit
)
>
(
s
tb
Info
->
childTblCount
)))
{
s
tb
Info
->
childTblLimit
=
s
tbInfo
->
childTblCount
-
stb
Info
->
childTblOffset
;
}
offset
=
s
uperTbl
Info
->
childTblOffset
;
limit
=
s
uperTbl
Info
->
childTblLimit
;
offset
=
s
tb
Info
->
childTblOffset
;
limit
=
s
tb
Info
->
childTblLimit
;
}
else
{
limit
=
s
uperTbl
Info
->
childTblCount
;
limit
=
s
tb
Info
->
childTblCount
;
offset
=
0
;
}
ntables
=
limit
;
tableFrom
=
offset
;
if
((
s
uperTbl
Info
->
childTblExists
!=
TBL_NO_EXISTS
)
&&
((
s
uperTblInfo
->
childTblOffset
+
superTblInfo
->
childTblLimit
)
>
s
uperTbl
Info
->
childTblCount
))
{
if
((
s
tb
Info
->
childTblExists
!=
TBL_NO_EXISTS
)
&&
((
s
tbInfo
->
childTblOffset
+
stbInfo
->
childTblLimit
)
>
s
tb
Info
->
childTblCount
))
{
printf
(
"WARNING: specified offset + limit > child table count!
\n
"
);
prompt
();
}
if
((
s
uperTbl
Info
->
childTblExists
!=
TBL_NO_EXISTS
)
&&
(
0
==
s
uperTbl
Info
->
childTblLimit
))
{
if
((
s
tb
Info
->
childTblExists
!=
TBL_NO_EXISTS
)
&&
(
0
==
s
tb
Info
->
childTblLimit
))
{
printf
(
"WARNING: specified limit = 0, which cannot find table name to insert or query!
\n
"
);
prompt
();
}
s
uperTbl
Info
->
childTblName
=
(
char
*
)
calloc
(
1
,
s
tb
Info
->
childTblName
=
(
char
*
)
calloc
(
1
,
limit
*
TSDB_TABLE_NAME_LEN
);
if
(
superTblInfo
->
childTblName
==
NULL
)
{
errorPrint
(
"%s() LN%d, alloc memory failed!
\n
"
,
__func__
,
__LINE__
);
if
(
stbInfo
->
childTblName
==
NULL
)
{
taos_close
(
taos0
);
exit
(
-
1
);
errorPrint
(
"%s() LN%d, alloc memory failed!
\n
"
,
__func__
,
__LINE__
);
exit
(
EXIT_FAILURE
);
}
int64_t
childTblCount
;
getChildNameOfSuperTableWithLimitAndOffset
(
taos0
,
db_name
,
s
uperTbl
Info
->
sTblName
,
&
s
uperTbl
Info
->
childTblName
,
&
childTblCount
,
db_name
,
s
tb
Info
->
sTblName
,
&
s
tb
Info
->
childTblName
,
&
childTblCount
,
limit
,
offset
);
}
else
{
...
...
@@ -7087,11 +7527,11 @@ static void startMultiThreadInsertData(int threads, char* db_name,
b
=
ntables
%
threads
;
}
if
((
s
uperTbl
Info
)
&&
(
s
uperTbl
Info
->
iface
==
REST_IFACE
))
{
if
((
s
tb
Info
)
&&
(
s
tb
Info
->
iface
==
REST_IFACE
))
{
if
(
convertHostToServAddr
(
g_Dbs
.
host
,
g_Dbs
.
port
,
&
(
g_Dbs
.
serv_addr
))
!=
0
)
{
exit
(
-
1
);
ERROR_EXIT
(
"convert host to server address"
);
}
}
...
...
@@ -7104,98 +7544,110 @@ static void startMultiThreadInsertData(int threads, char* db_name,
memset
(
pids
,
0
,
threads
*
sizeof
(
pthread_t
));
memset
(
infos
,
0
,
threads
*
sizeof
(
threadInfo
));
#if STMT_IFACE_ENABLED == 1
char
*
stmtBuffer
=
calloc
(
1
,
BUFFER_SIZE
);
assert
(
stmtBuffer
);
if
((
g_args
.
iface
==
STMT_IFACE
)
||
((
stbInfo
)
&&
(
stbInfo
->
iface
==
STMT_IFACE
)))
{
char
*
pstr
=
stmtBuffer
;
if
((
stbInfo
)
&&
(
AUTO_CREATE_SUBTBL
==
stbInfo
->
autoCreateTable
))
{
pstr
+=
sprintf
(
pstr
,
"INSERT INTO ? USING %s TAGS(?"
,
stbInfo
->
sTblName
);
for
(
int
tag
=
0
;
tag
<
(
stbInfo
->
tagCount
-
1
);
tag
++
)
{
pstr
+=
sprintf
(
pstr
,
",?"
);
}
pstr
+=
sprintf
(
pstr
,
") VALUES(?"
);
}
else
{
pstr
+=
sprintf
(
pstr
,
"INSERT INTO ? VALUES(?"
);
}
int
columnCount
;
if
(
stbInfo
)
{
columnCount
=
stbInfo
->
columnCount
;
}
else
{
columnCount
=
g_args
.
num_of_CPR
;
}
for
(
int
col
=
0
;
col
<
columnCount
;
col
++
)
{
pstr
+=
sprintf
(
pstr
,
",?"
);
}
pstr
+=
sprintf
(
pstr
,
")"
);
debugPrint
(
"%s() LN%d, stmtBuffer: %s"
,
__func__
,
__LINE__
,
stmtBuffer
);
if
((
stbInfo
)
&&
(
0
==
strncasecmp
(
stbInfo
->
dataSource
,
"sample"
,
strlen
(
"sample"
))))
{
parseSampleFileToStmt
(
stbInfo
,
timePrec
);
}
}
#endif
for
(
int
i
=
0
;
i
<
threads
;
i
++
)
{
threadInfo
*
pThreadInfo
=
infos
+
i
;
pThreadInfo
->
threadID
=
i
;
tstrncpy
(
pThreadInfo
->
db_name
,
db_name
,
TSDB_DB_NAME_LEN
);
pThreadInfo
->
time_precision
=
timePrec
;
pThreadInfo
->
s
uperTblInfo
=
superTbl
Info
;
pThreadInfo
->
s
tbInfo
=
stb
Info
;
pThreadInfo
->
start_time
=
start_time
;
pThreadInfo
->
minDelay
=
UINT64_MAX
;
if
((
NULL
==
s
uperTbl
Info
)
||
(
s
uperTbl
Info
->
iface
!=
REST_IFACE
))
{
if
((
NULL
==
s
tb
Info
)
||
(
s
tb
Info
->
iface
!=
REST_IFACE
))
{
//t_info->taos = taos;
pThreadInfo
->
taos
=
taos_connect
(
g_Dbs
.
host
,
g_Dbs
.
user
,
g_Dbs
.
password
,
db_name
,
g_Dbs
.
port
);
if
(
NULL
==
pThreadInfo
->
taos
)
{
free
(
infos
);
errorPrint
(
"%s() LN%d, connect to server fail from insert sub thread, reason: %s
\n
"
,
__func__
,
__LINE__
,
taos_errstr
(
NULL
));
free
(
infos
);
exit
(
-
1
);
exit
(
EXIT_FAILURE
);
}
#if STMT_IFACE_ENABLED == 1
if
((
g_args
.
iface
==
STMT_IFACE
)
||
((
s
uperTbl
Info
)
&&
(
s
uperTbl
Info
->
iface
==
STMT_IFACE
)))
{
||
((
s
tb
Info
)
&&
(
s
tb
Info
->
iface
==
STMT_IFACE
)))
{
int
columnCount
;
if
(
superTblInfo
)
{
columnCount
=
superTblInfo
->
columnCount
;
}
else
{
columnCount
=
g_args
.
num_of_CPR
;
}
pThreadInfo
->
stmt
=
taos_stmt_init
(
pThreadInfo
->
taos
);
if
(
NULL
==
pThreadInfo
->
stmt
)
{
free
(
pids
);
free
(
infos
);
errorPrint
(
"%s() LN%d, failed init stmt, reason: %s
\n
"
,
__func__
,
__LINE__
,
taos_errstr
(
NULL
));
free
(
pids
);
free
(
infos
);
exit
(
-
1
);
}
char
*
buffer
=
calloc
(
1
,
BUFFER_SIZE
);
assert
(
buffer
);
char
*
pstr
=
buffer
;
if
((
superTblInfo
)
&&
(
AUTO_CREATE_SUBTBL
==
superTblInfo
->
autoCreateTable
))
{
pstr
+=
sprintf
(
pstr
,
"INSERT INTO ? USING %s TAGS(?"
,
superTblInfo
->
sTblName
);
for
(
int
tag
=
0
;
tag
<
(
superTblInfo
->
tagCount
-
1
);
tag
++
)
{
pstr
+=
sprintf
(
pstr
,
",?"
);
}
pstr
+=
sprintf
(
pstr
,
") VALUES(?"
);
}
else
{
pstr
+=
sprintf
(
pstr
,
"INSERT INTO ? VALUES(?"
);
}
for
(
int
col
=
0
;
col
<
columnCount
;
col
++
)
{
pstr
+=
sprintf
(
pstr
,
",?"
);
exit
(
EXIT_FAILURE
);
}
pstr
+=
sprintf
(
pstr
,
")"
);
debugPrint
(
"%s() LN%d, buffer: %s"
,
__func__
,
__LINE__
,
buffer
);
int
ret
=
taos_stmt_prepare
(
pThreadInfo
->
stmt
,
buffer
,
0
);
int
ret
=
taos_stmt_prepare
(
pThreadInfo
->
stmt
,
stmtBuffer
,
0
);
if
(
ret
!=
0
){
errorPrint
(
"failed to execute taos_stmt_prepare. return 0x%x. reason: %s
\n
"
,
ret
,
taos_stmt_errstr
(
pThreadInfo
->
stmt
));
free
(
pids
);
free
(
infos
);
free
(
buffer
);
exit
(
-
1
);
free
(
stmtBuffer
);
errorPrint
(
"failed to execute taos_stmt_prepare. return 0x%x. reason: %s
\n
"
,
ret
,
taos_stmt_errstr
(
pThreadInfo
->
stmt
));
exit
(
EXIT_FAILURE
);
}
free
(
buffer
);
pThreadInfo
->
bind_ts
=
malloc
(
sizeof
(
int64_t
));
}
#endif
}
else
{
pThreadInfo
->
taos
=
NULL
;
}
/* if ((NULL == s
uperTbl
Info)
|| (0 == s
uperTbl
Info->multiThreadWriteOneTbl)) {
/* if ((NULL == s
tb
Info)
|| (0 == s
tb
Info->multiThreadWriteOneTbl)) {
*/
pThreadInfo
->
start_table_from
=
tableFrom
;
pThreadInfo
->
ntables
=
i
<
b
?
a
+
1
:
a
;
...
...
@@ -7203,7 +7655,7 @@ static void startMultiThreadInsertData(int threads, char* db_name,
tableFrom
=
pThreadInfo
->
end_table_to
+
1
;
/* } else {
pThreadInfo->start_table_from = 0;
pThreadInfo->ntables = s
uperTbl
Info->childTblCount;
pThreadInfo->ntables = s
tb
Info->childTblCount;
pThreadInfo->start_time = pThreadInfo->start_time + rand_int() % 10000 - rand_tinyint();
}
*/
...
...
@@ -7215,6 +7667,10 @@ static void startMultiThreadInsertData(int threads, char* db_name,
}
}
#if STMT_IFACE_ENABLED == 1
free
(
stmtBuffer
);
#endif
for
(
int
i
=
0
;
i
<
threads
;
i
++
)
{
pthread_join
(
pids
[
i
],
NULL
);
}
...
...
@@ -7228,11 +7684,10 @@ static void startMultiThreadInsertData(int threads, char* db_name,
for
(
int
i
=
0
;
i
<
threads
;
i
++
)
{
threadInfo
*
pThreadInfo
=
infos
+
i
;
tsem_destroy
(
&
(
pThreadInfo
->
lock_sem
));
#if STMT_IFACE_ENABLED == 1
if
(
pThreadInfo
->
stmt
)
{
taos_stmt_close
(
pThreadInfo
->
stmt
);
tmfree
((
char
*
)
pThreadInfo
->
bind_ts
);
}
#endif
tsem_destroy
(
&
(
pThreadInfo
->
lock_sem
));
...
...
@@ -7242,9 +7697,9 @@ static void startMultiThreadInsertData(int threads, char* db_name,
__func__
,
__LINE__
,
pThreadInfo
->
threadID
,
pThreadInfo
->
totalInsertRows
,
pThreadInfo
->
totalAffectedRows
);
if
(
s
uperTbl
Info
)
{
s
uperTbl
Info
->
totalAffectedRows
+=
pThreadInfo
->
totalAffectedRows
;
s
uperTbl
Info
->
totalInsertRows
+=
pThreadInfo
->
totalInsertRows
;
if
(
s
tb
Info
)
{
s
tb
Info
->
totalAffectedRows
+=
pThreadInfo
->
totalAffectedRows
;
s
tb
Info
->
totalInsertRows
+=
pThreadInfo
->
totalInsertRows
;
}
else
{
g_args
.
totalAffectedRows
+=
pThreadInfo
->
totalAffectedRows
;
g_args
.
totalInsertRows
+=
pThreadInfo
->
totalInsertRows
;
...
...
@@ -7265,22 +7720,22 @@ static void startMultiThreadInsertData(int threads, char* db_name,
double
tInMs
=
t
/
1000
.
0
;
if
(
s
uperTbl
Info
)
{
if
(
s
tb
Info
)
{
fprintf
(
stderr
,
"Spent %.2f seconds to insert rows: %"
PRIu64
", affected rows: %"
PRIu64
" with %d thread(s) into %s.%s. %.2f records/second
\n\n
"
,
tInMs
,
s
uperTbl
Info
->
totalInsertRows
,
s
uperTbl
Info
->
totalAffectedRows
,
threads
,
db_name
,
s
uperTbl
Info
->
sTblName
,
tInMs
,
s
tb
Info
->
totalInsertRows
,
s
tb
Info
->
totalAffectedRows
,
threads
,
db_name
,
s
tb
Info
->
sTblName
,
(
tInMs
)
?
(
double
)(
s
uperTbl
Info
->
totalInsertRows
/
tInMs
)
:
FLT_MAX
);
(
double
)(
s
tb
Info
->
totalInsertRows
/
tInMs
)
:
FLT_MAX
);
if
(
g_fpOfInsertResult
)
{
fprintf
(
g_fpOfInsertResult
,
"Spent %.2f seconds to insert rows: %"
PRIu64
", affected rows: %"
PRIu64
" with %d thread(s) into %s.%s. %.2f records/second
\n\n
"
,
tInMs
,
s
uperTbl
Info
->
totalInsertRows
,
s
uperTbl
Info
->
totalAffectedRows
,
threads
,
db_name
,
s
uperTbl
Info
->
sTblName
,
tInMs
,
s
tb
Info
->
totalInsertRows
,
s
tb
Info
->
totalAffectedRows
,
threads
,
db_name
,
s
tb
Info
->
sTblName
,
(
tInMs
)
?
(
double
)(
s
uperTbl
Info
->
totalInsertRows
/
tInMs
)
:
FLT_MAX
);
(
double
)(
s
tb
Info
->
totalInsertRows
/
tInMs
)
:
FLT_MAX
);
}
}
else
{
fprintf
(
stderr
,
"Spent %.2f seconds to insert rows: %"
PRIu64
", affected rows: %"
PRIu64
" with %d thread(s) into %s %.2f records/second
\n\n
"
,
...
...
@@ -7335,8 +7790,8 @@ static void *readTable(void *sarg) {
}
int64_t
num_of_DPT
;
/* if (pThreadInfo->s
uperTbl
Info) {
num_of_DPT = pThreadInfo->s
uperTbl
Info->insertRows; // nrecords_per_table;
/* if (pThreadInfo->s
tb
Info) {
num_of_DPT = pThreadInfo->s
tb
Info->insertRows; // nrecords_per_table;
} else {
*/
num_of_DPT
=
g_args
.
num_of_DPT
;
...
...
@@ -7410,7 +7865,7 @@ static void *readMetric(void *sarg) {
return
NULL
;
}
int64_t
num_of_DPT
=
pThreadInfo
->
s
uperTbl
Info
->
insertRows
;
int64_t
num_of_DPT
=
pThreadInfo
->
s
tb
Info
->
insertRows
;
int64_t
num_of_tables
=
pThreadInfo
->
ntables
;
// rinfo->end_table_to - rinfo->start_table_from + 1;
int64_t
totalData
=
num_of_DPT
*
num_of_tables
;
bool
do_aggreFunc
=
g_Dbs
.
do_aggreFunc
;
...
...
@@ -7549,14 +8004,14 @@ static int insertTestProcess() {
if
(
g_Dbs
.
db
[
i
].
superTblCount
>
0
)
{
for
(
uint64_t
j
=
0
;
j
<
g_Dbs
.
db
[
i
].
superTblCount
;
j
++
)
{
SSuperTable
*
s
uperTbl
Info
=
&
g_Dbs
.
db
[
i
].
superTbls
[
j
];
SSuperTable
*
s
tb
Info
=
&
g_Dbs
.
db
[
i
].
superTbls
[
j
];
if
(
s
uperTblInfo
&&
(
superTbl
Info
->
insertRows
>
0
))
{
if
(
s
tbInfo
&&
(
stb
Info
->
insertRows
>
0
))
{
startMultiThreadInsertData
(
g_Dbs
.
threadCount
,
g_Dbs
.
db
[
i
].
dbName
,
g_Dbs
.
db
[
i
].
dbCfg
.
precision
,
s
uperTbl
Info
);
s
tb
Info
);
}
}
}
...
...
@@ -7776,7 +8231,7 @@ static int queryTestProcess() {
if
(
taos
==
NULL
)
{
errorPrint
(
"Failed to connect to TDengine, reason:%s
\n
"
,
taos_errstr
(
NULL
));
exit
(
-
1
);
exit
(
EXIT_FAILURE
);
}
if
(
0
!=
g_queryInfo
.
superQueryInfo
.
sqlCount
)
{
...
...
@@ -7796,7 +8251,7 @@ static int queryTestProcess() {
if
(
0
==
strncasecmp
(
g_queryInfo
.
queryMode
,
"rest"
,
strlen
(
"rest"
)))
{
if
(
convertHostToServAddr
(
g_queryInfo
.
host
,
g_queryInfo
.
port
,
&
g_queryInfo
.
serv_addr
)
!=
0
)
exit
(
-
1
);
ERROR_EXIT
(
"convert host to server address"
);
}
pthread_t
*
pids
=
NULL
;
...
...
@@ -8000,10 +8455,10 @@ static void *superSubscribe(void *sarg) {
setThreadName
(
"superSub"
);
if
(
pThreadInfo
->
ntables
>
MAX_QUERY_SQL_COUNT
)
{
free
(
subSqlStr
);
errorPrint
(
"The table number(%"
PRId64
") of the thread is more than max query sql count: %d
\n
"
,
pThreadInfo
->
ntables
,
MAX_QUERY_SQL_COUNT
);
free
(
subSqlStr
);
exit
(
-
1
);
exit
(
EXIT_FAILURE
);
}
if
(
pThreadInfo
->
taos
==
NULL
)
{
...
...
@@ -8269,7 +8724,7 @@ static int subscribeTestProcess() {
if
(
taos
==
NULL
)
{
errorPrint
(
"Failed to connect to TDengine, reason:%s
\n
"
,
taos_errstr
(
NULL
));
exit
(
-
1
);
exit
(
EXIT_FAILURE
);
}
if
(
0
!=
g_queryInfo
.
superQueryInfo
.
sqlCount
)
{
...
...
@@ -8298,7 +8753,7 @@ static int subscribeTestProcess() {
errorPrint
(
"%s() LN%d, sepcified query sqlCount %d.
\n
"
,
__func__
,
__LINE__
,
g_queryInfo
.
specifiedQueryInfo
.
sqlCount
);
exit
(
-
1
);
exit
(
EXIT_FAILURE
);
}
pids
=
calloc
(
...
...
@@ -8313,7 +8768,7 @@ static int subscribeTestProcess() {
sizeof
(
threadInfo
));
if
((
NULL
==
pids
)
||
(
NULL
==
infos
))
{
errorPrint
(
"%s() LN%d, malloc failed for create threads
\n
"
,
__func__
,
__LINE__
);
exit
(
-
1
);
exit
(
EXIT_FAILURE
);
}
for
(
int
i
=
0
;
i
<
g_queryInfo
.
specifiedQueryInfo
.
sqlCount
;
i
++
)
{
...
...
@@ -8350,7 +8805,7 @@ static int subscribeTestProcess() {
errorPrint
(
"%s() LN%d, malloc failed for create threads
\n
"
,
__func__
,
__LINE__
);
// taos_close(taos);
exit
(
-
1
);
exit
(
EXIT_FAILURE
);
}
int64_t
ntables
=
g_queryInfo
.
superQueryInfo
.
childTblCount
;
...
...
@@ -8553,8 +9008,7 @@ static int regexMatch(const char *s, const char *reg, int cflags) {
/* Compile regular expression */
if
(
regcomp
(
&
regex
,
reg
,
cflags
)
!=
0
)
{
printf
(
"Fail to compile regex
\n
"
);
exit
(
-
1
);
ERROR_EXIT
(
"Fail to compile regex
\n
"
);
}
/* Execute regular expression */
...
...
@@ -8567,9 +9021,9 @@ static int regexMatch(const char *s, const char *reg, int cflags) {
return
0
;
}
else
{
regerror
(
reti
,
&
regex
,
msgbuf
,
sizeof
(
msgbuf
));
printf
(
"Regex match failed: %s
\n
"
,
msgbuf
);
regfree
(
&
regex
);
exit
(
-
1
);
printf
(
"Regex match failed: %s
\n
"
,
msgbuf
);
exit
(
EXIT_FAILURE
);
}
return
0
;
...
...
@@ -8671,7 +9125,7 @@ static void queryResult() {
if
(
g_args
.
use_metric
)
{
pThreadInfo
->
ntables
=
g_Dbs
.
db
[
0
].
superTbls
[
0
].
childTblCount
;
pThreadInfo
->
end_table_to
=
g_Dbs
.
db
[
0
].
superTbls
[
0
].
childTblCount
-
1
;
pThreadInfo
->
s
uperTbl
Info
=
&
g_Dbs
.
db
[
0
].
superTbls
[
0
];
pThreadInfo
->
s
tb
Info
=
&
g_Dbs
.
db
[
0
].
superTbls
[
0
];
tstrncpy
(
pThreadInfo
->
tb_prefix
,
g_Dbs
.
db
[
0
].
superTbls
[
0
].
childTblPrefix
,
TBNAME_PREFIX_LEN
);
}
else
{
...
...
@@ -8687,10 +9141,10 @@ static void queryResult() {
g_Dbs
.
db
[
0
].
dbName
,
g_Dbs
.
port
);
if
(
pThreadInfo
->
taos
==
NULL
)
{
free
(
pThreadInfo
);
errorPrint
(
"Failed to connect to TDengine, reason:%s
\n
"
,
taos_errstr
(
NULL
));
free
(
pThreadInfo
);
exit
(
-
1
);
exit
(
EXIT_FAILURE
);
}
tstrncpy
(
pThreadInfo
->
filePath
,
g_Dbs
.
resultFile
,
MAX_FILE_NAME_LEN
);
...
...
src/kit/taospack/taospack.c
浏览文件 @
4c185833
...
...
@@ -149,7 +149,10 @@ float* read_float(const char* inFile, int* pcount){
//printf(" buff=%s float=%.50f \n ", buf, floats[fi]);
if
(
++
fi
==
malloc_cnt
)
{
malloc_cnt
+=
100000
;
floats
=
realloc
(
floats
,
malloc_cnt
*
sizeof
(
float
));
float
*
floats1
=
realloc
(
floats
,
malloc_cnt
*
sizeof
(
float
));
if
(
floats1
==
NULL
)
break
;
floats
=
floats1
;
}
memset
(
buf
,
0
,
sizeof
(
buf
));
}
...
...
src/mnode/src/mnodeTable.c
浏览文件 @
4c185833
...
...
@@ -2921,10 +2921,11 @@ static SMultiTableMeta* ensureMsgBufferSpace(SMultiTableMeta *pMultiMeta, SArray
(
*
totalMallocLen
)
*=
2
;
}
pMultiMeta
=
realloc
(
pMultiMeta
,
*
totalMallocLen
);
if
(
pMultiMeta
==
NULL
)
{
SMultiTableMeta
*
pMultiMeta1
=
realloc
(
pMultiMeta
,
*
totalMallocLen
);
if
(
pMultiMeta
1
==
NULL
)
{
return
NULL
;
}
pMultiMeta
=
pMultiMeta1
;
}
return
pMultiMeta
;
...
...
src/os/src/detail/osMemory.c
浏览文件 @
4c185833
...
...
@@ -504,8 +504,9 @@ void * taosTRealloc(void *ptr, size_t size) {
void
*
tptr
=
(
void
*
)((
char
*
)
ptr
-
sizeof
(
size_t
));
size_t
tsize
=
size
+
sizeof
(
size_t
);
tptr
=
realloc
(
tptr
,
tsize
);
if
(
tptr
==
NULL
)
return
NULL
;
void
*
tptr1
=
realloc
(
tptr
,
tsize
);
if
(
tptr1
==
NULL
)
return
NULL
;
tptr
=
tptr1
;
*
(
size_t
*
)
tptr
=
size
;
...
...
src/os/src/windows/wGetline.c
浏览文件 @
4c185833
...
...
@@ -81,11 +81,13 @@ int32_t getstr(char **lineptr, size_t *n, FILE *stream, char terminator, int32_t
*
n
+=
MIN_CHUNK
;
nchars_avail
=
(
int32_t
)(
*
n
+
*
lineptr
-
read_pos
);
*
lineptr
=
realloc
(
*
lineptr
,
*
n
);
if
(
!
*
lineptr
)
{
char
*
lineptr1
=
realloc
(
*
lineptr
,
*
n
);
if
(
!
lineptr1
)
{
errno
=
ENOMEM
;
return
-
1
;
}
*
lineptr
=
lineptr1
;
read_pos
=
*
n
-
nchars_avail
+
*
lineptr
;
assert
((
*
lineptr
+
*
n
)
==
(
read_pos
+
nchars_avail
));
}
...
...
src/query/src/qTsbuf.c
浏览文件 @
4c185833
...
...
@@ -223,8 +223,11 @@ static STSGroupBlockInfoEx* addOneGroupInfo(STSBuf* pTSBuf, int32_t id) {
static
void
shrinkBuffer
(
STSList
*
ptsData
)
{
// shrink tmp buffer size if it consumes too many memory compared to the pre-defined size
if
(
ptsData
->
allocSize
>=
ptsData
->
threshold
*
2
)
{
ptsData
->
rawBuf
=
realloc
(
ptsData
->
rawBuf
,
MEM_BUF_SIZE
);
ptsData
->
allocSize
=
MEM_BUF_SIZE
;
char
*
rawBuf
=
realloc
(
ptsData
->
rawBuf
,
MEM_BUF_SIZE
);
if
(
rawBuf
)
{
ptsData
->
rawBuf
=
rawBuf
;
ptsData
->
allocSize
=
MEM_BUF_SIZE
;
}
}
}
...
...
tests/script/general/parser/function.sim
浏览文件 @
4c185833
...
...
@@ -1149,9 +1149,11 @@ endi
sql select derivative(test_column_alias_name, 1s, 0) from (select avg(k) test_column_alias_name from t1 interval(1s));
sql create table smeters (ts timestamp, current float, voltage int);
sql insert into smeters values ('2021-08-08 10:10:10', 10, 1);
sql insert into smeters values ('2021-08-08 10:10:12', 10, 2);
sql create table smeters (ts timestamp, current float, voltage int) tags (t1 int);
sql create table smeter1 using smeters tags (1);
sql insert into smeter1 values ('2021-08-08 10:10:10', 10, 2);
sql insert into smeter1 values ('2021-08-08 10:10:12', 10, 2);
sql insert into smeter1 values ('2021-08-08 10:10:14', 20, 1);
sql select stddev(voltage) from smeters where ts>='2021-08-08 10:10:10.000' and ts < '2021-08-08 10:10:20.000' and current=10 interval(1000a);
if $rows != 2 then
...
...
@@ -1160,9 +1162,21 @@ endi
if $data00 != @21-08-08 10:10:10.000@ then
return -1
endi
if $data01 != 0.000000000 then
return -1
endi
if $data10 != @21-08-08 10:10:12.000@ then
return -1
endi
if $data11 != 0.000000000 then
return -1
endi
sql select stddev(voltage) from smeters where ts>='2021-08-08 10:10:10.000' and ts < '2021-08-08 10:10:20.000' and current=10;
if $rows != 1 then
return -1
endi
if $data00 != 0.000000000 then
return -1
endi
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录