Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
32b1566d
T
TDengine
项目概览
taosdata
/
TDengine
接近 2 年 前同步成功
通知
1192
Star
22018
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
32b1566d
编写于
12月 17, 2021
作者:
S
shenglian zhou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix invalid table id during insert data points with taos_query through sql
上级
664b2a46
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
82 addition
and
42 deletion
+82
-42
src/client/src/tscParseLineProtocol.c
src/client/src/tscParseLineProtocol.c
+82
-42
未找到文件。
src/client/src/tscParseLineProtocol.c
浏览文件 @
32b1566d
...
...
@@ -387,7 +387,7 @@ static int32_t applySchemaAction(TAOS* taos, SSchemaAction* action, SSmlLinesInf
tscError
(
"SML:0x%"
PRIx64
" apply schema action. reset query cache. error: %s"
,
info
->
id
,
taos_errstr
(
res2
));
}
taos_free_result
(
res2
);
taosMsleep
(
500
);
taosMsleep
(
500
0
);
}
break
;
}
...
...
@@ -412,7 +412,7 @@ static int32_t applySchemaAction(TAOS* taos, SSchemaAction* action, SSmlLinesInf
tscError
(
"SML:0x%"
PRIx64
" apply schema action. reset query cache. error: %s"
,
info
->
id
,
taos_errstr
(
res2
));
}
taos_free_result
(
res2
);
taosMsleep
(
500
);
taosMsleep
(
500
0
);
}
break
;
}
...
...
@@ -434,7 +434,7 @@ static int32_t applySchemaAction(TAOS* taos, SSchemaAction* action, SSmlLinesInf
tscError
(
"SML:0x%"
PRIx64
" apply schema action. reset query cache. error: %s"
,
info
->
id
,
taos_errstr
(
res2
));
}
taos_free_result
(
res2
);
taosMsleep
(
500
);
taosMsleep
(
500
0
);
}
break
;
}
...
...
@@ -456,7 +456,7 @@ static int32_t applySchemaAction(TAOS* taos, SSchemaAction* action, SSmlLinesInf
tscError
(
"SML:0x%"
PRIx64
" apply schema action. reset query cache. error: %s"
,
info
->
id
,
taos_errstr
(
res2
));
}
taos_free_result
(
res2
);
taosMsleep
(
500
);
taosMsleep
(
500
0
);
}
break
;
}
...
...
@@ -498,7 +498,7 @@ static int32_t applySchemaAction(TAOS* taos, SSchemaAction* action, SSmlLinesInf
tscError
(
"SML:0x%"
PRIx64
" apply schema action. reset query cache. error: %s"
,
info
->
id
,
taos_errstr
(
res2
));
}
taos_free_result
(
res2
);
taosMsleep
(
500
);
taosMsleep
(
500
0
);
}
break
;
}
...
...
@@ -795,69 +795,69 @@ static int32_t arrangePointsByChildTableName(TAOS_SML_DATA_POINT* points, int nu
static
int32_t
applyChildTableDataPointsWithInsertSQL
(
TAOS
*
taos
,
char
*
cTableName
,
char
*
sTableName
,
SSmlSTableSchema
*
sTableSchema
,
SArray
*
cTablePoints
,
size_t
rowSize
,
SSmlLinesInfo
*
info
)
{
int32_t
code
=
TSDB_CODE_SUCCESS
;
size_t
numTags
=
taosArrayGetSize
(
sTableSchema
->
tags
);
size_t
numCols
=
taosArrayGetSize
(
sTableSchema
->
fields
);
size_t
rows
=
taosArrayGetSize
(
cTablePoints
);
size_t
numTags
=
taosArrayGetSize
(
sTableSchema
->
tags
);
size_t
numCols
=
taosArrayGetSize
(
sTableSchema
->
fields
);
size_t
rows
=
taosArrayGetSize
(
cTablePoints
);
SArray
*
tagsSchema
=
sTableSchema
->
tags
;
SArray
*
colsSchema
=
sTableSchema
->
fields
;
TAOS_SML_KV
*
tagKVs
[
TSDB_MAX_TAGS
]
=
{
0
};
for
(
int
i
=
0
;
i
<
rows
;
++
i
)
{
TAOS_SML_DATA_POINT
*
pDataPoint
=
taosArrayGetP
(
cTablePoints
,
i
);
for
(
int
i
=
0
;
i
<
rows
;
++
i
)
{
TAOS_SML_DATA_POINT
*
pDataPoint
=
taosArrayGetP
(
cTablePoints
,
i
);
for
(
int
j
=
0
;
j
<
pDataPoint
->
tagNum
;
++
j
)
{
TAOS_SML_KV
*
kv
=
pDataPoint
->
tags
+
j
;
tagKVs
[
kv
->
fieldSchemaIdx
]
=
kv
;
}
}
char
*
sql
=
malloc
(
tsMaxSQLStringLen
+
1
);
char
*
sql
=
malloc
(
tsMaxSQLStringLen
+
1
);
if
(
sql
==
NULL
)
{
tscError
(
"malloc sql memory error"
);
return
TSDB_CODE_TSC_OUT_OF_MEMORY
;
}
int32_t
freeBytes
=
tsMaxSQLStringLen
+
1
;
int32_t
freeBytes
=
tsMaxSQLStringLen
+
1
;
int32_t
totalLen
=
0
;
totalLen
+=
sprintf
(
sql
,
"insert into %s using %s ("
,
cTableName
,
sTableName
);
for
(
int
i
=
0
;
i
<
numTags
;
++
i
)
{
SSchema
*
tagSchema
=
taosArrayGet
(
tagsSchema
,
i
);
totalLen
+=
snprintf
(
sql
+
totalLen
,
freeBytes
-
totalLen
,
"%s,"
,
tagSchema
->
name
);
totalLen
+=
snprintf
(
sql
+
totalLen
,
freeBytes
-
totalLen
,
"%s,"
,
tagSchema
->
name
);
}
--
totalLen
;
totalLen
+=
snprintf
(
sql
+
totalLen
,
freeBytes
-
totalLen
,
")"
);
totalLen
+=
snprintf
(
sql
+
totalLen
,
freeBytes
-
totalLen
,
")"
);
totalLen
+=
snprintf
(
sql
+
totalLen
,
freeBytes
-
totalLen
,
" tags ("
);
totalLen
+=
snprintf
(
sql
+
totalLen
,
freeBytes
-
totalLen
,
" tags ("
);
// for (int i = 0; i < numTags; ++i) {
// snprintf(sql+strlen(sql), freeBytes-strlen(sql), "?,");
// }
// for (int i = 0; i < numTags; ++i) {
// snprintf(sql+strlen(sql), freeBytes-strlen(sql), "?,");
// }
for
(
int
i
=
0
;
i
<
numTags
;
++
i
)
{
if
(
tagKVs
[
i
]
==
NULL
)
{
totalLen
+=
snprintf
(
sql
+
totalLen
,
freeBytes
-
totalLen
,
"NULL,"
);
totalLen
+=
snprintf
(
sql
+
totalLen
,
freeBytes
-
totalLen
,
"NULL,"
);
}
else
{
TAOS_SML_KV
*
kv
=
tagKVs
[
i
];
size_t
beforeLen
=
totalLen
;
int32_t
len
=
0
;
converToStr
(
sql
+
beforeLen
,
kv
->
type
,
kv
->
value
,
kv
->
length
,
&
len
);
TAOS_SML_KV
*
kv
=
tagKVs
[
i
];
size_t
beforeLen
=
totalLen
;
int32_t
len
=
0
;
converToStr
(
sql
+
beforeLen
,
kv
->
type
,
kv
->
value
,
kv
->
length
,
&
len
);
totalLen
+=
len
;
totalLen
+=
snprintf
(
sql
+
totalLen
,
freeBytes
-
totalLen
,
","
);
totalLen
+=
snprintf
(
sql
+
totalLen
,
freeBytes
-
totalLen
,
","
);
}
}
--
totalLen
;
totalLen
+=
snprintf
(
sql
+
totalLen
,
freeBytes
-
totalLen
,
") ("
);
totalLen
+=
snprintf
(
sql
+
totalLen
,
freeBytes
-
totalLen
,
") ("
);
for
(
int
i
=
0
;
i
<
numCols
;
++
i
)
{
SSchema
*
colSchema
=
taosArrayGet
(
colsSchema
,
i
);
totalLen
+=
snprintf
(
sql
+
totalLen
,
freeBytes
-
totalLen
,
"%s,"
,
colSchema
->
name
);
totalLen
+=
snprintf
(
sql
+
totalLen
,
freeBytes
-
totalLen
,
"%s,"
,
colSchema
->
name
);
}
--
totalLen
;
totalLen
+=
snprintf
(
sql
+
totalLen
,
freeBytes
-
totalLen
,
") values "
);
totalLen
+=
snprintf
(
sql
+
totalLen
,
freeBytes
-
totalLen
,
") values "
);
TAOS_SML_KV
**
colKVs
=
malloc
(
numCols
*
sizeof
(
TAOS_SML_KV
*
));
TAOS_SML_KV
**
colKVs
=
malloc
(
numCols
*
sizeof
(
TAOS_SML_KV
*
));
for
(
int
r
=
0
;
r
<
rows
;
++
r
)
{
totalLen
+=
snprintf
(
sql
+
totalLen
,
freeBytes
-
totalLen
,
"("
);
totalLen
+=
snprintf
(
sql
+
totalLen
,
freeBytes
-
totalLen
,
"("
);
memset
(
colKVs
,
0
,
numCols
*
sizeof
(
TAOS_SML_KV
*
));
memset
(
colKVs
,
0
,
numCols
*
sizeof
(
TAOS_SML_KV
*
));
TAOS_SML_DATA_POINT
*
point
=
taosArrayGetP
(
cTablePoints
,
r
);
for
(
int
i
=
0
;
i
<
point
->
fieldNum
;
++
i
)
{
...
...
@@ -867,28 +867,68 @@ static int32_t applyChildTableDataPointsWithInsertSQL(TAOS* taos, char* cTableNa
for
(
int
i
=
0
;
i
<
numCols
;
++
i
)
{
if
(
colKVs
[
i
]
==
NULL
)
{
totalLen
+=
snprintf
(
sql
+
totalLen
,
freeBytes
-
totalLen
,
"NULL,"
);
totalLen
+=
snprintf
(
sql
+
totalLen
,
freeBytes
-
totalLen
,
"NULL,"
);
}
else
{
TAOS_SML_KV
*
kv
=
colKVs
[
i
];
size_t
beforeLen
=
totalLen
;
int32_t
len
=
0
;
converToStr
(
sql
+
beforeLen
,
kv
->
type
,
kv
->
value
,
kv
->
length
,
&
len
);
TAOS_SML_KV
*
kv
=
colKVs
[
i
];
size_t
beforeLen
=
totalLen
;
int32_t
len
=
0
;
converToStr
(
sql
+
beforeLen
,
kv
->
type
,
kv
->
value
,
kv
->
length
,
&
len
);
totalLen
+=
len
;
totalLen
+=
snprintf
(
sql
+
totalLen
,
freeBytes
-
totalLen
,
","
);
totalLen
+=
snprintf
(
sql
+
totalLen
,
freeBytes
-
totalLen
,
","
);
}
}
--
totalLen
;
totalLen
+=
snprintf
(
sql
+
totalLen
,
freeBytes
-
totalLen
,
")"
);
totalLen
+=
snprintf
(
sql
+
totalLen
,
freeBytes
-
totalLen
,
")"
);
}
free
(
colKVs
);
sql
[
totalLen
]
=
'\0'
;
tscDebug
(
"SML:0x%"
PRIx64
" insert child table table %s of super table %s sql: %s"
,
info
->
id
,
cTableName
,
sTableName
,
sql
);
TAOS_RES
*
res
=
taos_query
(
taos
,
sql
);
tscDebug
(
"SML:0x%"
PRIx64
" insert child table table %s of super table %s sql: %s"
,
info
->
id
,
cTableName
,
sTableName
,
sql
);
bool
tryAgain
=
false
;
int32_t
try
=
0
;
do
{
TAOS_RES
*
res
=
taos_query
(
taos
,
sql
);
code
=
taos_errno
(
res
);
if
(
code
!=
0
)
{
tscError
(
"SML:0x%"
PRIx64
" taos_query return %d:%s"
,
info
->
id
,
code
,
taos_errstr
(
res
));
}
tscDebug
(
"SML:0x%"
PRIx64
" taos_query inserted %d rows"
,
info
->
id
,
taos_affected_rows
(
res
));
info
->
affectedRows
+=
taos_affected_rows
(
res
);
taos_free_result
(
res
);
tryAgain
=
false
;
if
((
code
==
TSDB_CODE_TDB_INVALID_TABLE_ID
||
code
==
TSDB_CODE_VND_INVALID_VGROUP_ID
||
code
==
TSDB_CODE_TDB_TABLE_RECONFIGURE
||
code
==
TSDB_CODE_APP_NOT_READY
||
code
==
TSDB_CODE_RPC_NETWORK_UNAVAIL
)
&&
try
++
<
TSDB_MAX_REPLICA
)
{
tryAgain
=
true
;
}
if
(
code
==
TSDB_CODE_TDB_INVALID_TABLE_ID
||
code
==
TSDB_CODE_VND_INVALID_VGROUP_ID
)
{
TAOS_RES
*
res2
=
taos_query
(
taos
,
"RESET QUERY CACHE"
);
int32_t
code2
=
taos_errno
(
res2
);
if
(
code2
!=
TSDB_CODE_SUCCESS
)
{
tscError
(
"SML:0x%"
PRIx64
" insert child table by sql. reset query cache. error: %s"
,
info
->
id
,
taos_errstr
(
res2
));
}
taos_free_result
(
res2
);
if
(
tryAgain
)
{
taosMsleep
(
100
*
(
2
<<
try
));
}
}
if
(
code
==
TSDB_CODE_APP_NOT_READY
||
code
==
TSDB_CODE_RPC_NETWORK_UNAVAIL
)
{
if
(
tryAgain
)
{
taosMsleep
(
100
*
(
2
<<
try
));
}
}
}
while
(
tryAgain
);
free
(
sql
);
code
=
taos_errno
(
res
);
info
->
affectedRows
+=
taos_affected_rows
(
res
);
taos_free_result
(
res
);
return
code
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录