Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
D
dsk-dsc-flink
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
shezaixing
dsk-dsc-flink
Commits
0a0fd085
Commit
0a0fd085
authored
Feb 20, 2025
by
liaowenwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加日志
parent
fc995aee
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
6 deletions
+8
-6
MysqlDataTransferSinkBatch.java
...dsk/flink/dsc/common/sink/MysqlDataTransferSinkBatch.java
+8
-6
No files found.
src/main/java/com/dsk/flink/dsc/common/sink/MysqlDataTransferSinkBatch.java
View file @
0a0fd085
...
...
@@ -30,8 +30,9 @@ public class MysqlDataTransferSinkBatch extends RichSinkFunction<String> {
EnvProperties
envProps
;
private
static
transient
ExecutorService
executorService
;
private
static
transient
DruidDataSource
dataSource
;
private
static
final
int
BATCH_SIZE
=
1
000
;
private
static
final
int
BATCH_SIZE
=
2
000
;
private
static
final
int
FLUSH_INTERVAL
=
500
;
private
static
final
int
INIT_CAPACITY
=
(
int
)(
BATCH_SIZE
/
0.75
+
1
);
private
ArrayBlockingQueue
<
String
>
sqlBatch
=
new
ArrayBlockingQueue
<>(
BATCH_SIZE
*
2
);
private
static
transient
ScheduledExecutorService
scheduledExecutorService
;
private
AtomicBoolean
flushing
=
new
AtomicBoolean
(
false
);
...
...
@@ -42,7 +43,7 @@ public class MysqlDataTransferSinkBatch extends RichSinkFunction<String> {
@Override
public
void
open
(
Configuration
parameters
)
throws
Exception
{
executorService
=
new
ThreadPoolExecutor
(
1
0
,
1
0
,
20
,
TimeUnit
.
MINUTES
,
new
ArrayBlockingQueue
<>(
1000
));
executorService
=
new
ThreadPoolExecutor
(
1
5
,
2
0
,
20
,
TimeUnit
.
MINUTES
,
new
ArrayBlockingQueue
<>(
1000
));
// 初始化获取配置
String
configTidbUrl
=
String
.
format
(
envProps
.
getDb_url
(),
envProps
.
getDb_host
(),
envProps
.
getDb_port
(),
envProps
.
getDb_database
());
dataSource
=
new
DruidDataSource
();
...
...
@@ -50,8 +51,8 @@ public class MysqlDataTransferSinkBatch extends RichSinkFunction<String> {
dataSource
.
setUsername
(
envProps
.
getDb_username
());
dataSource
.
setPassword
(
envProps
.
getDb_password
());
dataSource
.
setUrl
(
configTidbUrl
);
dataSource
.
setMaxActive
(
3
0
);
dataSource
.
setInitialSize
(
2
0
);
dataSource
.
setMaxActive
(
5
0
);
dataSource
.
setInitialSize
(
3
0
);
dataSource
.
setTestWhileIdle
(
true
);
dataSource
.
setMaxWait
(
20000
);
dataSource
.
setValidationQuery
(
"select 1"
);
...
...
@@ -81,7 +82,7 @@ public class MysqlDataTransferSinkBatch extends RichSinkFunction<String> {
flushing
.
set
(
false
);
return
;
}
List
<
String
>
batch
=
new
ArrayList
<>(
1334
);
List
<
String
>
batch
=
new
ArrayList
<>(
INIT_CAPACITY
);
sqlBatch
.
drainTo
(
batch
,
BATCH_SIZE
);
if
(
batch
.
isEmpty
())
{
flushing
.
set
(
false
);
...
...
@@ -103,7 +104,8 @@ public class MysqlDataTransferSinkBatch extends RichSinkFunction<String> {
logger
.
error
(
"事务回滚异常"
,
ex
);
}
logger
.
error
(
"------错误时间:{}-------------异常:"
,
new
Date
(),
e
);
SqlErrorLog
errorLog
=
new
SqlErrorLog
(
new
Date
(),
String
.
join
(
";"
,
batch
),
e
.
getMessage
());
//SqlErrorLog errorLog = new SqlErrorLog(new Date(), String.join(";", batch), e.getMessage());
SqlErrorLog
errorLog
=
new
SqlErrorLog
(
new
Date
(),
batch
.
get
(
0
),
e
.
getMessage
());
writeErrLogDb
(
errorLog
);
}
}
catch
(
Exception
e
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment