Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
7c133359
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
7c133359
编写于
10月 20, 2022
作者:
D
dapan1121
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: add retrieve db and table route info api
上级
723110c4
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
249 addition
and
5 deletion
+249
-5
include/client/taos.h
include/client/taos.h
+1
-1
include/libs/catalog/catalog.h
include/libs/catalog/catalog.h
+2
-0
source/client/src/clientMain.c
source/client/src/clientMain.c
+49
-1
source/libs/catalog/src/catalog.c
source/libs/catalog/src/catalog.c
+1
-3
tests/script/api/dbTableRoute.c
tests/script/api/dbTableRoute.c
+195
-0
tests/script/api/makefile
tests/script/api/makefile
+1
-0
未找到文件。
include/client/taos.h
浏览文件 @
7c133359
...
...
@@ -213,7 +213,7 @@ DLL_EXPORT void taos_fetch_raw_block_a(TAOS_RES *res, __taos_async_fn_t f
DLL_EXPORT
const
void
*
taos_get_raw_block
(
TAOS_RES
*
res
);
DLL_EXPORT
int
taos_get_db_route_info
(
TAOS
*
taos
,
const
char
*
db
,
TAOS_DB_ROUTE_INFO
*
dbInfo
);
DLL_EXPORT
int
taos_get_table_vgId
(
TAOS
*
taos
,
const
char
*
table
,
TAOS_DB_ROUTE_INFO
*
dbInfo
,
int
*
vgId
);
DLL_EXPORT
int
taos_get_table_vgId
(
TAOS
*
taos
,
const
char
*
db
,
const
char
*
table
,
int
*
vgId
);
DLL_EXPORT
int
taos_load_table_info
(
TAOS
*
taos
,
const
char
*
tableNameList
);
DLL_EXPORT
TAOS_RES
*
taos_schemaless_insert
(
TAOS
*
taos
,
char
*
lines
[],
int
numLines
,
int
protocol
,
int
precision
);
...
...
include/libs/catalog/catalog.h
浏览文件 @
7c133359
...
...
@@ -165,6 +165,8 @@ int32_t catalogGetDBVgVersion(SCatalog* pCtg, const char* dbFName, int32_t* vers
*/
int32_t
catalogGetDBVgList
(
SCatalog
*
pCatalog
,
SRequestConnInfo
*
pConn
,
const
char
*
pDBName
,
SArray
**
pVgroupList
);
int32_t
catalogGetDBVgInfo
(
SCatalog
*
pCtg
,
SRequestConnInfo
*
pConn
,
const
char
*
dbFName
,
TAOS_DB_ROUTE_INFO
*
pInfo
);
int32_t
catalogUpdateDBVgInfo
(
SCatalog
*
pCatalog
,
const
char
*
dbName
,
uint64_t
dbId
,
SDBVgInfo
*
dbInfo
);
int32_t
catalogRemoveDB
(
SCatalog
*
pCatalog
,
const
char
*
dbName
,
uint64_t
dbId
);
...
...
source/client/src/clientMain.c
浏览文件 @
7c133359
...
...
@@ -1006,6 +1006,7 @@ int taos_get_db_route_info(TAOS* taos, const char* db, TAOS_DB_ROUTE_INFO* dbInf
char
*
sql
=
"taos_get_db_route_info"
;
int32_t
code
=
buildRequest
(
connId
,
sql
,
strlen
(
sql
),
NULL
,
false
,
&
pRequest
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
terrno
=
code
;
return
terrno
;
}
...
...
@@ -1037,8 +1038,55 @@ _return:
return
code
;
}
int
taos_get_table_vgId
(
TAOS
*
taos
,
const
char
*
table
,
TAOS_DB_ROUTE_INFO
*
dbInfo
,
int
*
vgId
)
{
int
taos_get_table_vgId
(
TAOS
*
taos
,
const
char
*
db
,
const
char
*
table
,
int
*
vgId
)
{
if
(
NULL
==
taos
)
{
terrno
=
TSDB_CODE_TSC_DISCONNECTED
;
return
terrno
;
}
if
(
NULL
==
db
||
NULL
==
table
||
NULL
==
vgId
)
{
tscError
(
"invalid input param, db:%p, table:%p, vgId:%p"
,
db
,
table
,
vgId
);
terrno
=
TSDB_CODE_TSC_INVALID_INPUT
;
return
terrno
;
}
int64_t
connId
=
*
(
int64_t
*
)
taos
;
SRequestObj
*
pRequest
=
NULL
;
char
*
sql
=
"taos_get_table_vgId"
;
int32_t
code
=
buildRequest
(
connId
,
sql
,
strlen
(
sql
),
NULL
,
false
,
&
pRequest
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
terrno
;
}
STscObj
*
pTscObj
=
pRequest
->
pTscObj
;
SCatalog
*
pCtg
=
NULL
;
code
=
catalogGetHandle
(
pTscObj
->
pAppInfo
->
clusterId
,
&
pCtg
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
goto
_return
;
}
SRequestConnInfo
conn
=
{
.
pTrans
=
pTscObj
->
pAppInfo
->
pTransporter
,
.
requestId
=
pRequest
->
requestId
,
.
requestObjRefId
=
pRequest
->
self
};
conn
.
mgmtEps
=
getEpSet_s
(
&
pTscObj
->
pAppInfo
->
mgmtEp
);
SName
tableName
;
toName
(
pTscObj
->
acctId
,
db
,
table
,
&
tableName
);
SVgroupInfo
vgInfo
;
code
=
catalogGetTableHashVgroup
(
pCtg
,
&
conn
,
&
tableName
,
&
vgInfo
);
if
(
code
)
{
goto
_return
;
}
*
vgId
=
vgInfo
.
vgId
;
_return:
terrno
=
code
;
destroyRequest
(
pRequest
);
return
code
;
}
int
taos_load_table_info
(
TAOS
*
taos
,
const
char
*
tableNameList
)
{
...
...
source/libs/catalog/src/catalog.c
浏览文件 @
7c133359
...
...
@@ -814,9 +814,7 @@ _return:
if
(
dbCache
)
{
ctgRUnlockVgInfo
(
dbCache
);
ctgReleaseDBCache
(
pCtg
,
dbCache
);
}
if
(
dbInfo
)
{
}
else
if
(
dbInfo
)
{
taosHashCleanup
(
dbInfo
->
vgHash
);
taosMemoryFreeClear
(
dbInfo
);
}
...
...
tests/script/api/dbTableRoute.c
0 → 100644
浏览文件 @
7c133359
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// TAOS asynchronous API example
// this example opens multiple tables, insert/retrieve multiple tables
// it is used by TAOS internally for one performance testing
// to compiple: gcc -o asyncdemo asyncdemo.c -ltaos
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <unistd.h>
#include <string.h>
#include <pthread.h>
#include "taos.h"
int
rtTables
=
20
;
char
hostName
[
128
];
static
void
rtExecSQL
(
TAOS
*
taos
,
char
*
command
)
{
int
i
;
int32_t
code
=
-
1
;
TAOS_RES
*
pSql
=
taos_query
(
taos
,
command
);
code
=
taos_errno
(
pSql
);
if
(
code
!=
0
)
{
fprintf
(
stderr
,
"Failed to run %s, reason: %s
\n
"
,
command
,
taos_errstr
(
pSql
));
taos_free_result
(
pSql
);
taos_close
(
taos
);
taos_cleanup
();
exit
(
EXIT_FAILURE
);
}
taos_free_result
(
pSql
);
}
static
void
rtFetchVgId
(
TAOS
*
taos
,
char
*
sql
,
int
*
vgId
)
{
int
i
;
int32_t
code
=
-
1
;
TAOS_RES
*
pSql
=
taos_query
(
taos
,
sql
);
code
=
taos_errno
(
pSql
);
if
(
code
!=
0
)
{
fprintf
(
stderr
,
"Failed to run %s, reason: %s
\n
"
,
sql
,
taos_errstr
(
pSql
));
taos_free_result
(
pSql
);
taos_close
(
taos
);
taos_cleanup
();
exit
(
EXIT_FAILURE
);
}
TAOS_ROW
row
=
taos_fetch_row
(
pSql
);
*
vgId
=
*
(
int
*
)
row
[
0
];
taos_free_result
(
pSql
);
}
void
rtError
(
char
*
prefix
,
const
char
*
errMsg
)
{
fprintf
(
stderr
,
"%s error: %s
\n
"
,
prefix
,
errMsg
);
}
void
rtExit
(
char
*
prefix
,
const
char
*
errMsg
)
{
rtError
(
prefix
,
errMsg
);
exit
(
1
);
}
int
rtPrepare
(
TAOS
**
p
,
int
prefix
,
int
suffix
)
{
char
sql
[
1024
]
=
{
0
};
int32_t
code
=
0
;
TAOS
*
taos
=
taos_connect
(
hostName
,
"root"
,
"taosdata"
,
NULL
,
0
);
if
(
taos
==
NULL
)
rtExit
(
"taos_connect"
,
taos_errstr
(
NULL
));
strcpy
(
sql
,
"drop database if exists db1"
);
rtExecSQL
(
taos
,
sql
);
sprintf
(
sql
,
"create database db1 vgroups 10 table_prefix %d table_suffix %d"
,
prefix
,
suffix
);
rtExecSQL
(
taos
,
sql
);
strcpy
(
sql
,
"use db1"
);
rtExecSQL
(
taos
,
sql
);
for
(
int32_t
i
=
0
;
i
<
rtTables
;
++
i
)
{
sprintf
(
sql
,
"create table tb%d (ts timestamp, f1 int)"
,
i
);
rtExecSQL
(
taos
,
sql
);
}
*
p
=
taos
;
return
0
;
}
int
rtGetDbRouteInfo
(
TAOS
*
taos
)
{
TAOS_DB_ROUTE_INFO
dbInfo
;
int
code
=
taos_get_db_route_info
(
taos
,
"db1"
,
&
dbInfo
);
if
(
code
)
{
rtExit
(
"taos_get_db_route_info"
,
taos_errstr
(
NULL
));
}
printf
(
"db db1 routeVersion:%d hashPrefix:%d hashSuffix:%d hashMethod:%d vgNum %d
\n
"
,
dbInfo
.
routeVersion
,
dbInfo
.
hashPrefix
,
dbInfo
.
hashSuffix
,
dbInfo
.
hashMethod
,
dbInfo
.
vgNum
);
for
(
int32_t
i
=
0
;
i
<
dbInfo
.
vgNum
;
++
i
)
{
printf
(
"%dth vg, id:%d hashBegin:%u hashEnd:%u
\n
"
,
i
,
dbInfo
.
vgHash
[
i
].
vgId
,
dbInfo
.
vgHash
[
i
].
hashBegin
,
dbInfo
.
vgHash
[
i
].
hashEnd
);
}
return
0
;
}
int
rtGetTableRouteInfo
(
TAOS
*
taos
)
{
char
table
[
64
]
=
{
0
};
int
vgId1
=
0
;
int
vgId2
=
0
;
char
sql
[
1024
]
=
{
0
};
for
(
int32_t
i
=
0
;
i
<
rtTables
;
++
i
)
{
sprintf
(
table
,
"tb%d"
,
i
);
int
code
=
taos_get_table_vgId
(
taos
,
"db1"
,
table
,
&
vgId1
);
if
(
code
)
{
rtExit
(
"taos_get_table_vgId"
,
taos_errstr
(
NULL
));
}
sprintf
(
sql
,
"select vgroup_id from information_schema.ins_tables where table_name=
\"
tb%d
\"
"
,
i
);
rtFetchVgId
(
taos
,
sql
,
&
vgId2
);
if
(
vgId1
!=
vgId2
)
{
fprintf
(
stderr
,
"!!!! table tb%d vgId mis-match, vgId(api):%d, vgId(sys):%d
\n
"
,
i
,
vgId1
,
vgId2
);
exit
(
1
);
}
else
{
printf
(
"table tb%d vgId %d
\n
"
,
i
,
vgId1
);
}
}
return
0
;
}
void
rtClose
(
TAOS
*
taos
)
{
taos_close
(
taos
);
}
int
rtRunCase1
(
void
)
{
TAOS
*
taos
=
NULL
;
rtPrepare
(
&
taos
,
0
,
0
);
rtGetDbRouteInfo
(
taos
);
rtGetTableRouteInfo
(
taos
);
rtClose
(
taos
);
return
0
;
}
int
rtRunCase2
(
void
)
{
TAOS
*
taos
=
NULL
;
rtPrepare
(
&
taos
,
2
,
0
);
rtGetTableRouteInfo
(
taos
);
rtGetDbRouteInfo
(
taos
);
rtClose
(
taos
);
return
0
;
}
int
main
(
int
argc
,
char
*
argv
[])
{
if
(
argc
!=
2
)
{
printf
(
"usage: %s server-ip
\n
"
,
argv
[
0
]);
exit
(
0
);
}
srand
((
unsigned
int
)
time
(
NULL
));
strcpy
(
hostName
,
argv
[
1
]);
rtRunCase1
();
rtRunCase2
();
int32_t
l
=
5
;
while
(
l
)
{
printf
(
"%d
\n
"
,
l
--
);
sleep
(
1
);
}
return
0
;
}
tests/script/api/makefile
浏览文件 @
7c133359
...
...
@@ -13,6 +13,7 @@ all: $(TARGET)
exe
:
gcc
$(CFLAGS)
./batchprepare.c
-o
$(ROOT)
batchprepare
$(LFLAGS)
gcc
$(CFLAGS)
./stopquery.c
-o
$(ROOT)
stopquery
$(LFLAGS)
gcc
$(CFLAGS)
./dbTableRoute.c
-o
$(ROOT)
dbTableRoute
$(LFLAGS)
clean
:
rm
$(ROOT)
batchprepare
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录