Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
oceanbase
oblogclient
提交
eb199f78
O
oblogclient
项目概览
oceanbase
/
oblogclient
1 年多 前同步成功
通知
5
Star
15
Fork
11
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
oblogclient
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
未验证
提交
eb199f78
编写于
5月 20, 2022
作者:
H
He Wang
提交者:
GitHub
5月 20, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix & optimize ClientStream process (#37)
* optimize process thread * revert checkpoint update
上级
aa5a0783
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
25 addition
and
43 deletion
+25
-43
logproxy-client/src/main/java/com/oceanbase/clogproxy/client/connection/ClientStream.java
...m/oceanbase/clogproxy/client/connection/ClientStream.java
+23
-35
logproxy-client/src/test/java/com/oceanbase/clogproxy/client/LogProxyClientTest.java
...va/com/oceanbase/clogproxy/client/LogProxyClientTest.java
+2
-8
未找到文件。
logproxy-client/src/main/java/com/oceanbase/clogproxy/client/connection/ClientStream.java
浏览文件 @
eb199f78
...
...
@@ -32,11 +32,12 @@ public class ClientStream {
/** Flag of whether the stream is started. */
private
final
AtomicBoolean
started
=
new
AtomicBoolean
(
false
);
/** The process thread. */
private
Thread
thread
=
null
;
/** Context of stream. */
private
StreamContext
context
;
private
final
StreamContext
context
;
/** Checkpoint string used to resume writing into the queue. */
private
String
checkpointString
;
...
...
@@ -79,10 +80,10 @@ public class ClientStream {
this
.
context
=
new
StreamContext
(
this
,
clientConf
,
connectionParams
);
}
/** Close
and wait the connection
. */
/** Close
the connection and wait the process thread
. */
public
void
stop
()
{
if
(
!
started
.
compareAndSet
(
true
,
false
))
{
logger
.
info
(
"
stopping LogProxy Client....
"
);
if
(
started
.
compareAndSet
(
true
,
false
))
{
logger
.
info
(
"
Try to stop this client
"
);
if
(
connection
!=
null
)
{
connection
.
close
();
...
...
@@ -91,8 +92,8 @@ public class ClientStream {
join
();
thread
=
null
;
logger
.
info
(
"Client stopped successfully"
);
}
logger
.
info
(
"stopped LogProxy Client"
);
}
/** Call {@link Thread#join()} method of process thread. */
...
...
@@ -101,8 +102,8 @@ public class ClientStream {
try
{
thread
.
join
();
}
catch
(
InterruptedException
e
)
{
logger
.
warn
(
"
ClientStream thread is interrupted: "
+
e
.
getMessage
());
s
top
();
logger
.
warn
(
"
Waits for process thread failed : {}"
,
e
.
getMessage
());
triggerS
top
();
}
}
}
...
...
@@ -140,11 +141,10 @@ public class ClientStream {
while
(
isRunning
())
{
ReconnectState
state
=
reconnect
();
if
(
state
==
ReconnectState
.
EXIT
)
{
logger
.
error
(
"read thread to exit"
);
triggerException
(
new
LogProxyClientException
(
ErrorCode
.
E_MAX_RECONNECT
,
"
exceed max reconnect retry
"
));
"
Exceed max retry times
"
));
break
;
}
if
(
state
==
ReconnectState
.
RETRY
)
{
...
...
@@ -157,8 +157,8 @@ public class ClientStream {
continue
;
}
StreamContext
.
TransferPacket
packet
;
while
(
true
)
{
StreamContext
.
TransferPacket
packet
=
null
;
while
(
isRunning
()
)
{
try
{
packet
=
context
.
recordQueue
()
...
...
@@ -193,33 +193,24 @@ public class ClientStream {
+
packet
.
getType
());
}
}
catch
(
LogProxyClientException
e
)
{
triggerStop
();
triggerException
(
e
);
return
;
break
;
}
catch
(
Exception
e
)
{
// if exception occurred, we exit
triggerStop
();
triggerException
(
new
LogProxyClientException
(
ErrorCode
.
E_USER
,
e
));
return
;
break
;
}
}
started
.
set
(
false
);
if
(
connection
!=
null
)
{
connection
.
close
();
}
thread
=
null
;
// TODO... if exception occurred, run handler callback
logger
.
warn
(
"!!! read thread exit !!!"
);
triggerStop
();
logger
.
info
(
"Client process thread exit"
);
});
thread
.
setDaemon
(
false
);
thread
.
start
();
}
// add a shutdown hook to trigger the stop the process
Runtime
.
getRuntime
().
addShutdownHook
(
new
Thread
(
this
::
stop
));
}
/**
...
...
@@ -239,15 +230,14 @@ public class ClientStream {
private
ReconnectState
reconnect
()
{
// reconnect flag mark, tiny load for checking
if
(
reconnect
.
compareAndSet
(
true
,
false
))
{
logger
.
warn
(
"start to reconnect...
"
);
logger
.
info
(
"Try to reconnect
"
);
try
{
if
(
context
.
config
().
getMaxReconnectTimes
()
!=
-
1
&&
retryTimes
>=
context
.
config
().
getMaxReconnectTimes
())
{
logger
.
error
(
"
f
ailed to reconnect, exceed max reconnect retry time: {}"
,
"
F
ailed to reconnect, exceed max reconnect retry time: {}"
,
context
.
config
().
getMaxReconnectTimes
());
reconnect
.
set
(
true
);
return
ReconnectState
.
EXIT
;
}
...
...
@@ -261,32 +251,30 @@ public class ClientStream {
logger
.
warn
(
"reconnect set checkpoint: {}"
,
checkpointString
);
context
.
params
().
updateCheckpoint
(
checkpointString
);
}
connection
=
ConnectionFactory
.
instance
().
createConnection
(
context
);
if
(
connection
!=
null
)
{
logger
.
warn
(
"reconnect SUCC
"
);
logger
.
info
(
"Reconnect successfully
"
);
retryTimes
=
0
;
reconnect
.
compareAndSet
(
true
,
false
);
return
ReconnectState
.
SUCCESS
;
}
logger
.
error
(
"
f
ailed to reconnect, retry count: {}, max: {}"
,
"
F
ailed to reconnect, retry count: {}, max: {}"
,
++
retryTimes
,
context
.
config
().
getMaxReconnectTimes
());
// not success, retry next time
reconnect
.
set
(
true
);
return
ReconnectState
.
RETRY
;
}
catch
(
Exception
e
)
{
logger
.
error
(
"
f
ailed to reconnect, retry count: {}, max: {}, message: {}"
,
"
F
ailed to reconnect, retry count: {}, max: {}, message: {}"
,
++
retryTimes
,
context
.
config
().
getMaxReconnectTimes
(),
e
);
// not success, retry next time
reconnect
.
set
(
true
);
return
ReconnectState
.
RETRY
;
}
finally
{
reconnecting
.
set
(
false
);
}
...
...
logproxy-client/src/test/java/com/oceanbase/clogproxy/client/LogProxyClientTest.java
浏览文件 @
eb199f78
...
...
@@ -50,10 +50,7 @@ public class LogProxyClientTest {
@Override
public
void
onException
(
LogProxyClientException
e
)
{
if
(
e
.
needStop
())
{
logger
.
error
(
e
.
getMessage
());
client
.
stop
();
}
logger
.
error
(
e
.
getMessage
());
}
});
client
.
start
();
...
...
@@ -83,10 +80,7 @@ public class LogProxyClientTest {
@Override
public
void
onException
(
LogProxyClientException
e
)
{
if
(
e
.
needStop
())
{
logger
.
error
(
e
.
getMessage
());
client
.
stop
();
}
logger
.
error
(
e
.
getMessage
());
}
});
client
.
start
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录