Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
d4bd1906
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
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看板
未验证
提交
d4bd1906
编写于
5月 30, 2023
作者:
W
wade zhang
提交者:
GitHub
5月 30, 2023
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #21279 from taosdata/feat/TD-24012
feat(driver): jdbc add tmq seek function
上级
94d4de61
2e5ac6b0
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
137 addition
and
5 deletion
+137
-5
source/client/jni/com_taosdata_jdbc_tmq_TMQConnector.h
source/client/jni/com_taosdata_jdbc_tmq_TMQConnector.h
+13
-0
source/client/src/clientTmqConnector.c
source/client/src/clientTmqConnector.c
+124
-5
未找到文件。
source/client/jni/com_taosdata_jdbc_tmq_TMQConnector.h
浏览文件 @
d4bd1906
...
...
@@ -158,6 +158,13 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_tmq_TMQConnector_tmqGetVgroupId(JN
*/
JNIEXPORT
jstring
JNICALL
Java_com_taosdata_jdbc_tmq_TMQConnector_tmqGetTableName
(
JNIEnv
*
,
jobject
,
jlong
);
/*
* Class: com_taosdata_jdbc_tmq_TMQConnector
* Method: tmqGetOffset
* Signature: (J)Ljava/lang/String;
*/
JNIEXPORT
jlong
JNICALL
Java_com_taosdata_jdbc_tmq_TMQConnector_tmqGetOffset
(
JNIEnv
*
,
jobject
,
jlong
);
/*
* Class: com_taosdata_jdbc_tmq_TMQConnector
* Method: fetchBlockImp
...
...
@@ -166,6 +173,12 @@ JNIEXPORT jstring JNICALL Java_com_taosdata_jdbc_tmq_TMQConnector_tmqGetTableNam
JNIEXPORT
jint
JNICALL
Java_com_taosdata_jdbc_tmq_TMQConnector_fetchRawBlockImp
(
JNIEnv
*
,
jobject
,
jlong
,
jlong
,
jobject
,
jobject
);
JNIEXPORT
jint
JNICALL
Java_com_taosdata_jdbc_tmq_TMQConnector_tmqSeekImp
(
JNIEnv
*
,
jobject
,
jlong
,
jstring
,
jint
,
jlong
);
JNIEXPORT
jint
JNICALL
Java_com_taosdata_jdbc_tmq_TMQConnector_tmqGetTopicAssignmentImp
(
JNIEnv
*
,
jobject
,
jlong
,
jstring
,
jobject
);
#ifdef __cplusplus
}
#endif
...
...
source/client/src/clientTmqConnector.c
浏览文件 @
d4bd1906
...
...
@@ -17,9 +17,16 @@
#include "jniCommon.h"
#include "taos.h"
int
__init_tmq
=
0
;
int
__init_tmq
=
0
;
jmethodID
g_offsetCallback
;
jclass
g_assignmentClass
;
jmethodID
g_assignmentConstructor
;
jmethodID
g_assignmentSetVgId
;
jmethodID
g_assignmentSetCurrentOffset
;
jmethodID
g_assignmentSetBegin
;
jmethodID
g_assignmentSetEnd
;
void
tmqGlobalMethod
(
JNIEnv
*
env
)
{
// make sure init function executed once
switch
(
atomic_val_compare_exchange_32
(
&
__init_tmq
,
0
,
1
))
{
...
...
@@ -46,6 +53,38 @@ void tmqGlobalMethod(JNIEnv *env) {
jniDebug
(
"tmq method register finished"
);
}
int
__init_assignment
=
0
;
void
tmqAssignmentMethod
(
JNIEnv
*
env
)
{
// make sure init function executed once
switch
(
atomic_val_compare_exchange_32
(
&
__init_assignment
,
0
,
1
))
{
case
0
:
break
;
case
1
:
do
{
taosMsleep
(
0
);
}
while
(
atomic_load_32
(
&
__init_assignment
)
==
1
);
case
2
:
return
;
}
if
(
g_vm
==
NULL
)
{
(
*
env
)
->
GetJavaVM
(
env
,
&
g_vm
);
}
jclass
assignment
=
(
*
env
)
->
FindClass
(
env
,
"com/taosdata/jdbc/tmq/Assignment"
);
g_assignmentClass
=
(
*
env
)
->
NewGlobalRef
(
env
,
assignment
);
g_assignmentConstructor
=
(
*
env
)
->
GetMethodID
(
env
,
g_assignmentClass
,
"<init>"
,
"()V"
);
g_assignmentSetVgId
=
(
*
env
)
->
GetMethodID
(
env
,
g_assignmentClass
,
"setVgId"
,
"(I)V"
);
// int
g_assignmentSetCurrentOffset
=
(
*
env
)
->
GetMethodID
(
env
,
g_assignmentClass
,
"setCurrentOffset"
,
"(J)V"
);
// long
g_assignmentSetBegin
=
(
*
env
)
->
GetMethodID
(
env
,
g_assignmentClass
,
"setBegin"
,
"(J)V"
);
// long
g_assignmentSetEnd
=
(
*
env
)
->
GetMethodID
(
env
,
g_assignmentClass
,
"setEnd"
,
"(J)V"
);
// long
(
*
env
)
->
DeleteLocalRef
(
env
,
assignment
);
atomic_store_32
(
&
__init_assignment
,
2
);
jniDebug
(
"tmq method assignment finished"
);
}
// deprecated
void
commit_cb
(
tmq_t
*
tmq
,
int32_t
code
,
void
*
param
)
{
JNIEnv
*
env
=
NULL
;
...
...
@@ -266,8 +305,9 @@ JNIEXPORT void JNICALL Java_com_taosdata_jdbc_tmq_TMQConnector_tmqCommitAsync(JN
tmq_commit_async
(
tmq
,
res
,
commit_cb
,
consumer
);
}
JNIEXPORT
void
JNICALL
Java_com_taosdata_jdbc_tmq_TMQConnector_consumerCommitAsync
(
JNIEnv
*
env
,
jobject
jobj
,
jlong
jtmq
,
jlong
jres
,
jobject
offset
)
{
JNIEXPORT
void
JNICALL
Java_com_taosdata_jdbc_tmq_TMQConnector_consumerCommitAsync
(
JNIEnv
*
env
,
jobject
jobj
,
jlong
jtmq
,
jlong
jres
,
jobject
offset
)
{
tmqGlobalMethod
(
env
);
tmq_t
*
tmq
=
(
tmq_t
*
)
jtmq
;
if
(
tmq
==
NULL
)
{
...
...
@@ -335,7 +375,7 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_tmq_TMQConnector_tmqGetVgroupId(JN
TAOS_RES
*
res
=
(
TAOS_RES
*
)
jres
;
if
(
res
==
NULL
)
{
jniDebug
(
"jobj:%p, invalid res handle"
,
jobj
);
return
-
1
;
return
JNI_RESULT_SET_NULL
;
}
return
tmq_get_vgroup_id
(
res
);
}
...
...
@@ -350,6 +390,15 @@ JNIEXPORT jstring JNICALL Java_com_taosdata_jdbc_tmq_TMQConnector_tmqGetTableNam
return
(
*
env
)
->
NewStringUTF
(
env
,
tmq_get_table_name
(
res
));
}
JNIEXPORT
jlong
JNICALL
Java_com_taosdata_jdbc_tmq_TMQConnector_tmqGetOffset
(
JNIEnv
*
env
,
jobject
jobj
,
jlong
jres
)
{
TAOS_RES
*
res
=
(
TAOS_RES
*
)
jres
;
if
(
res
==
NULL
)
{
jniDebug
(
"jobj:%p, invalid res handle"
,
jobj
);
return
JNI_RESULT_SET_NULL
;
}
return
tmq_get_vgroup_offset
(
res
);
}
JNIEXPORT
jint
JNICALL
Java_com_taosdata_jdbc_tmq_TMQConnector_fetchRawBlockImp
(
JNIEnv
*
env
,
jobject
jobj
,
jlong
con
,
jlong
res
,
jobject
rowobj
,
jobject
arrayListObj
)
{
...
...
@@ -369,7 +418,8 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_tmq_TMQConnector_fetchRawBlockImp(
jniDebug
(
"jobj:%p, conn:%p, resultset:%p, no data to retrieve"
,
jobj
,
tscon
,
(
void
*
)
res
);
return
JNI_FETCH_END
;
}
else
{
jniError
(
"jobj:%p, conn:%p, query interrupted, tmq fetch block error code:%d, msg:%s"
,
jobj
,
tscon
,
error_code
,
taos_errstr
(
tres
));
jniError
(
"jobj:%p, conn:%p, query interrupted, tmq fetch block error code:%d, msg:%s"
,
jobj
,
tscon
,
error_code
,
taos_errstr
(
tres
));
return
JNI_RESULT_SET_NULL
;
}
}
...
...
@@ -399,3 +449,72 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_tmq_TMQConnector_fetchRawBlockImp(
(
*
env
)
->
CallVoidMethod
(
env
,
rowobj
,
g_blockdataSetByteArrayFp
,
jniFromNCharToByteArray
(
env
,
(
char
*
)
data
,
len
));
return
JNI_SUCCESS
;
}
JNIEXPORT
jint
JNICALL
Java_com_taosdata_jdbc_tmq_TMQConnector_tmqSeekImp
(
JNIEnv
*
env
,
jobject
jobj
,
jlong
jtmq
,
jstring
jtopic
,
jint
partition
,
jlong
offset
)
{
tmq_t
*
tmq
=
(
tmq_t
*
)
jtmq
;
if
(
tmq
==
NULL
)
{
jniDebug
(
"jobj:%p, tmq is closed"
,
jobj
);
return
TMQ_CONSUMER_NULL
;
}
if
(
jtopic
==
NULL
)
{
jniDebug
(
"jobj:%p, topic is null"
,
jobj
);
return
TMQ_TOPIC_NULL
;
}
const
char
*
topicName
=
(
*
env
)
->
GetStringUTFChars
(
env
,
jtopic
,
NULL
);
int32_t
res
=
tmq_offset_seek
(
tmq
,
topicName
,
partition
,
offset
);
if
(
res
!=
TSDB_CODE_SUCCESS
)
{
jniError
(
"jobj:%p, tmq seek error, code:%d, msg:%s"
,
jobj
,
res
,
tmq_err2str
(
res
));
}
(
*
env
)
->
ReleaseStringUTFChars
(
env
,
jtopic
,
topicName
);
return
(
jint
)
res
;
}
JNIEXPORT
jint
JNICALL
Java_com_taosdata_jdbc_tmq_TMQConnector_tmqGetTopicAssignmentImp
(
JNIEnv
*
env
,
jobject
jobj
,
jlong
jtmq
,
jstring
jtopic
,
jobject
jarrayList
)
{
tmqAssignmentMethod
(
env
);
tmq_t
*
tmq
=
(
tmq_t
*
)
jtmq
;
if
(
tmq
==
NULL
)
{
jniDebug
(
"jobj:%p, tmq is closed"
,
jobj
);
return
TMQ_CONSUMER_NULL
;
}
if
(
jtopic
==
NULL
)
{
jniDebug
(
"jobj:%p, topic is null"
,
jobj
);
return
TMQ_TOPIC_NULL
;
}
const
char
*
topicName
=
(
*
env
)
->
GetStringUTFChars
(
env
,
jtopic
,
NULL
);
tmq_topic_assignment
*
pAssign
=
NULL
;
int32_t
numOfAssignment
=
0
;
int32_t
res
=
tmq_get_topic_assignment
(
tmq
,
topicName
,
&
pAssign
,
&
numOfAssignment
);
if
(
res
!=
TSDB_CODE_SUCCESS
)
{
(
*
env
)
->
ReleaseStringUTFChars
(
env
,
jtopic
,
topicName
);
jniError
(
"jobj:%p, tmq get topic assignment error, topic:%s, code:%d, msg:%s"
,
jobj
,
topicName
,
res
,
tmq_err2str
(
res
));
tmq_free_assignment
(
pAssign
);
return
(
jint
)
res
;
}
(
*
env
)
->
ReleaseStringUTFChars
(
env
,
jtopic
,
topicName
);
for
(
int
i
=
0
;
i
<
numOfAssignment
;
++
i
)
{
tmq_topic_assignment
assignment
=
pAssign
[
i
];
jobject
jassignment
=
(
*
env
)
->
NewObject
(
env
,
g_assignmentClass
,
g_assignmentConstructor
);
(
*
env
)
->
CallVoidMethod
(
env
,
jassignment
,
g_assignmentSetVgId
,
assignment
.
vgId
);
(
*
env
)
->
CallVoidMethod
(
env
,
jassignment
,
g_assignmentSetCurrentOffset
,
assignment
.
currentOffset
);
(
*
env
)
->
CallVoidMethod
(
env
,
jassignment
,
g_assignmentSetBegin
,
assignment
.
begin
);
(
*
env
)
->
CallVoidMethod
(
env
,
jassignment
,
g_assignmentSetEnd
,
assignment
.
end
);
(
*
env
)
->
CallBooleanMethod
(
env
,
jarrayList
,
g_arrayListAddFp
,
jassignment
);
}
tmq_free_assignment
(
pAssign
);
return
JNI_SUCCESS
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录