Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
杠杠峰
TDengine
提交
d7a16a5b
TDengine
项目概览
杠杠峰
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
d7a16a5b
编写于
9月 29, 2021
作者:
dengyihao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-6217]<feauture> merge develop
上级
6f541853
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
162 addition
and
0 deletion
+162
-0
tests/examples/c/connect_two_cluster.c
tests/examples/c/connect_two_cluster.c
+162
-0
未找到文件。
tests/examples/c/connect_two_cluster.c
0 → 100644
浏览文件 @
d7a16a5b
#include <stdio.h>
#include <pthread.h>
#include <stdlib.h>
#include <unistd.h>
#include "taos.h"
int
numOfThreads
=
1
;
void
*
connectClusterAndDeal
(
void
*
arg
)
{
int
port
=
*
(
int
*
)
arg
;
const
char
*
host
=
"127.0.0.1"
;
const
char
*
user
=
"root"
;
const
char
*
passwd
=
"taosdata"
;
TAOS
*
taos1
=
taos_connect
(
host
,
user
,
passwd
,
""
,
port
);
TAOS
*
taos2
=
taos_connect
(
host
,
user
,
passwd
,
""
,
port
+
1000
);
if
(
NULL
==
taos1
||
NULL
==
taos2
)
{
printf
(
"connect to (%d/%d) failed
\n
"
,
port
,
port
+
1000
);
return
NULL
;
}
TAOS_RES
*
result
=
NULL
;
result
=
taos_query
(
taos1
,
"drop database if exists db"
);
if
(
0
!=
taos_errno
(
result
))
{
printf
(
"failed %s
\n
"
,
taos_errstr
(
result
));
}
taos_free_result
(
result
);
taos_query
(
taos2
,
"drop database if exists db"
);
if
(
0
!=
taos_errno
(
result
))
{
printf
(
"failed %s
\n
"
,
taos_errstr
(
result
));
}
taos_free_result
(
result
);
// ========= build database
{
result
=
taos_query
(
taos1
,
"create database db"
);
if
(
0
!=
taos_errno
(
result
))
{
printf
(
"failed %s
\n
"
,
taos_errstr
(
result
));
}
taos_free_result
(
result
);
}
{
result
=
taos_query
(
taos2
,
"create database db"
);
if
(
0
!=
taos_errno
(
result
))
{
printf
(
"failed %s
\n
"
,
taos_errstr
(
result
));
}
taos_free_result
(
result
);
}
//======== create table
{
result
=
taos_query
(
taos1
,
"create stable db.stest (ts timestamp, port int) tags(tport int)"
);
if
(
0
!=
taos_errno
(
result
))
{
printf
(
"failed %s
\n
"
,
taos_errstr
(
result
));
}
taos_free_result
(
result
);
}
{
result
=
taos_query
(
taos2
,
"create stable db.stest (ts timestamp, port int) tags(tport int)"
);
if
(
0
!=
taos_errno
(
result
))
{
printf
(
"failed %s
\n
"
,
taos_errstr
(
result
));
}
taos_free_result
(
result
);
}
//======== create table
{
result
=
taos_query
(
taos1
,
"use db"
);
if
(
0
!=
taos_errno
(
result
))
{
printf
(
"failed %s
\n
"
,
taos_errstr
(
result
));
}
taos_free_result
(
result
);
}
{
result
=
taos_query
(
taos2
,
"use db"
);
if
(
0
!=
taos_errno
(
result
))
{
printf
(
"failed %s
\n
"
,
taos_errstr
(
result
));
}
taos_free_result
(
result
);
}
{
char
buf
[
1024
]
=
{
0
};
sprintf
(
buf
,
"insert into db.t1 using stest tags(%d) values(now, %d)"
,
port
,
port
);
for
(
int
i
=
0
;
i
<
100000
;
i
++
)
{
//printf("error here\t");
result
=
taos_query
(
taos1
,
buf
);
if
(
0
!=
taos_errno
(
result
))
{
printf
(
"failed %s
\n
"
,
taos_errstr
(
result
));
}
taos_free_result
(
result
);
//sleep(1);
}
}
{
char
buf
[
1024
]
=
{
0
};
sprintf
(
buf
,
"insert into db.t1 using stest tags(%d) values(now, %d)"
,
port
+
1000
,
port
+
1000
);
for
(
int
i
=
0
;
i
<
100000
;
i
++
)
{
result
=
taos_query
(
taos2
,
buf
);
if
(
0
!=
taos_errno
(
result
))
{
printf
(
"failed %s
\n
"
,
taos_errstr
(
result
));
}
taos_free_result
(
result
);
//sleep(1);
}
}
// query result
{
result
=
taos_query
(
taos1
,
"select * from stest"
);
if
(
result
==
NULL
||
taos_errno
(
result
)
!=
0
)
{
printf
(
"query failed %s
\n
"
,
taos_errstr
(
result
));
taos_free_result
(
result
);
}
TAOS_ROW
row
;
int
rows
=
0
;
int
num_fields
=
taos_field_count
(
result
);
TAOS_FIELD
*
fields
=
taos_fetch_fields
(
result
);
while
((
row
=
taos_fetch_row
(
result
)))
{
char
temp
[
1024
]
=
{
0
};
rows
++
;
taos_print_row
(
temp
,
row
,
fields
,
num_fields
);
printf
(
"%s
\n
"
,
temp
);
}
taos_free_result
(
result
);
}
// query result
{
result
=
taos_query
(
taos2
,
"select * from stest"
);
if
(
result
==
NULL
||
taos_errno
(
result
)
!=
0
)
{
printf
(
"query failed %s
\n
"
,
taos_errstr
(
result
));
taos_free_result
(
result
);
}
TAOS_ROW
row
;
int
rows
=
0
;
int
num_fields
=
taos_field_count
(
result
);
TAOS_FIELD
*
fields
=
taos_fetch_fields
(
result
);
while
((
row
=
taos_fetch_row
(
result
)))
{
char
temp
[
1024
]
=
{
0
};
rows
++
;
taos_print_row
(
temp
,
row
,
fields
,
num_fields
);
printf
(
"%s
\n
"
,
temp
);
}
taos_free_result
(
result
);
}
taos_close
(
taos1
);
taos_close
(
taos2
);
return
NULL
;
}
int
main
(
int
argc
,
char
*
argv
[])
{
pthread_t
*
pthreads
=
malloc
(
sizeof
(
pthread_t
)
*
numOfThreads
);
int
*
port
=
malloc
(
sizeof
(
int
)
*
numOfThreads
);
port
[
0
]
=
6030
;
for
(
int
i
=
0
;
i
<
numOfThreads
;
i
++
)
{
pthread_create
(
&
pthreads
[
i
],
NULL
,
connectClusterAndDeal
,
(
void
*
)
&
port
[
i
]);
}
for
(
int
i
=
0
;
i
<
numOfThreads
;
i
++
)
{
pthread_join
(
pthreads
[
i
],
NULL
);
}
free
(
port
);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录