32
32
import com .dtstack .flink .sql .util .RowDataComplete ;
33
33
import com .google .common .collect .Lists ;
34
34
import com .google .common .collect .Maps ;
35
- import io .vertx .core .DeploymentOptions ;
36
35
import io .vertx .core .Vertx ;
37
36
import io .vertx .core .VertxOptions ;
38
37
import io .vertx .core .json .JsonArray ;
@@ -95,13 +94,9 @@ public class RdbAsyncReqRow extends BaseAsyncReqRow {
95
94
96
95
private transient Vertx vertx ;
97
96
98
- private transient VertxOptions vertxOptions ;
99
-
100
- private transient JsonObject jdbcConfig ;
101
-
102
97
private int asyncPoolSize = 1 ;
103
98
104
- private int errorLogPrintNum = 3 ;
99
+ private final int errorLogPrintNum = 3 ;
105
100
106
101
private final AtomicBoolean connectionStatus = new AtomicBoolean (true );
107
102
@@ -114,9 +109,9 @@ public class RdbAsyncReqRow extends BaseAsyncReqRow {
114
109
public void open (Configuration parameters ) throws Exception {
115
110
super .open (parameters );
116
111
117
- vertxOptions = new VertxOptions ();
112
+ VertxOptions vertxOptions = new VertxOptions ();
118
113
119
- jdbcConfig = buildJdbcConfig ();
114
+ JsonObject jdbcConfig = buildJdbcConfig ();
120
115
System .setProperty ("vertx.disableFileCPResolving" , "true" );
121
116
vertxOptions
122
117
.setEventLoopPoolSize (DEFAULT_VERTX_EVENT_LOOP_POOL_SIZE )
@@ -131,6 +126,9 @@ public void open(Configuration parameters) throws Exception {
131
126
new LinkedBlockingQueue <>(MAX_TASK_QUEUE_SIZE ),
132
127
new DTThreadFactory ("rdbAsyncExec" ),
133
128
new ThreadPoolExecutor .CallerRunsPolicy ());
129
+
130
+ vertx = Vertx .vertx (vertxOptions );
131
+ rdbSqlClient = JDBCClient .createNonShared (vertx , jdbcConfig );
134
132
}
135
133
136
134
public RdbAsyncReqRow (BaseSideInfo sideInfo ) {
@@ -153,8 +151,6 @@ public JsonObject buildJdbcConfig() {
153
151
154
152
@ Override
155
153
protected void preInvoke (BaseRow input , ResultFuture <BaseRow > resultFuture ) {
156
- vertx = Vertx .vertx (vertxOptions );
157
- rdbSqlClient = JDBCClient .createNonShared (vertx , jdbcConfig );
158
154
}
159
155
160
156
@ Override
@@ -163,7 +159,7 @@ public void handleAsyncInvoke(Map<String, Object> inputParams, BaseRow input, Re
163
159
//network is unhealthy
164
160
while (!connectionStatus .get ()) {
165
161
if (networkLogCounter .getAndIncrement () % 1000 == 0 ) {
166
- LOG .info ("network unhealth to block task" );
162
+ LOG .info ("network unhealthy to block task" );
167
163
}
168
164
Thread .sleep (100 );
169
165
}
@@ -178,12 +174,14 @@ protected void asyncQueryData(Map<String, Object> inputParams,
178
174
AtomicLong failCounter ,
179
175
AtomicBoolean finishFlag ,
180
176
CountDownLatch latch ) {
181
- doAsyncQueryData (inputParams ,
182
- input , resultFuture ,
183
- rdbSqlClient ,
184
- failCounter ,
185
- finishFlag ,
186
- latch );
177
+ doAsyncQueryData (
178
+ inputParams ,
179
+ input ,
180
+ resultFuture ,
181
+ rdbSqlClient ,
182
+ failCounter ,
183
+ finishFlag ,
184
+ latch );
187
185
}
188
186
189
187
final protected void doAsyncQueryData (
@@ -198,18 +196,23 @@ final protected void doAsyncQueryData(
198
196
try {
199
197
String errorMsg ;
200
198
Integer retryMaxNum = sideInfo .getSideTableInfo ().getConnectRetryMaxNum (3 );
199
+ int logPrintTime = retryMaxNum / errorLogPrintNum == 0 ?
200
+ retryMaxNum : retryMaxNum / errorLogPrintNum ;
201
201
if (conn .failed ()) {
202
202
connectionStatus .set (false );
203
203
errorMsg = ExceptionTrace .traceOriginalCause (conn .cause ());
204
- if (failCounter .getAndIncrement () %
205
- (retryMaxNum / 3 == 0 ? retryMaxNum : retryMaxNum / 3 ) == 0 ) {
204
+ if (failCounter .getAndIncrement () % logPrintTime == 0 ) {
206
205
LOG .error ("getConnection error. cause by " + errorMsg );
207
206
}
208
207
LOG .error (String .format ("retry ... current time [%s]" , failCounter .get ()));
209
208
if (failCounter .get () >= retryMaxNum ) {
210
209
resultFuture .completeExceptionally (
211
210
new SuppressRestartsException (
212
- new Throwable (ExceptionTrace .traceOriginalCause (conn .cause ()))));
211
+ new Throwable (
212
+ ExceptionTrace .traceOriginalCause (conn .cause ())
213
+ )
214
+ )
215
+ );
213
216
finishFlag .set (true );
214
217
}
215
218
return ;
@@ -233,12 +236,14 @@ private void connectWithRetry(Map<String, Object> inputParams, BaseRow input, Re
233
236
while (!finishFlag .get ()) {
234
237
try {
235
238
CountDownLatch latch = new CountDownLatch (1 );
236
- asyncQueryData (inputParams ,
237
- input , resultFuture ,
238
- rdbSqlClient ,
239
- failCounter ,
240
- finishFlag ,
241
- latch );
239
+ asyncQueryData (
240
+ inputParams ,
241
+ input ,
242
+ resultFuture ,
243
+ rdbSqlClient ,
244
+ failCounter ,
245
+ finishFlag ,
246
+ latch );
242
247
try {
243
248
latch .await ();
244
249
} catch (InterruptedException e ) {
@@ -331,7 +336,9 @@ public void close() throws Exception {
331
336
if (rdbSqlClient != null ) {
332
337
rdbSqlClient .close (done -> {
333
338
if (done .failed ()) {
334
- LOG .error ("sql client close failed! " , done .cause ());
339
+ LOG .error ("sql client close failed! " +
340
+ ExceptionTrace .traceOriginalCause (done .cause ())
341
+ );
335
342
}
336
343
337
344
if (done .succeeded ()) {
@@ -348,7 +355,9 @@ public void close() throws Exception {
348
355
if (Objects .nonNull (vertx )) {
349
356
vertx .close (done -> {
350
357
if (done .failed ()) {
351
- LOG .error ("vert.x close error. cause by " + done .cause ().getMessage ());
358
+ LOG .error ("vert.x close error. cause by " +
359
+ ExceptionTrace .traceOriginalCause (done .cause ())
360
+ );
352
361
}
353
362
});
354
363
}
@@ -363,7 +372,9 @@ private void handleQuery(SQLConnection connection, Map<String, Object> inputPara
363
372
LOG .error (
364
373
String .format ("\n get data with sql [%s] failed! \n cause: [%s]" ,
365
374
sideInfo .getSqlCondition (),
366
- rs .cause ().getMessage ()));
375
+ rs .cause ().getMessage ()
376
+ )
377
+ );
367
378
dealFillDataError (input , resultFuture , rs .cause ());
368
379
return ;
369
380
}
@@ -397,7 +408,10 @@ private void handleQuery(SQLConnection connection, Map<String, Object> inputPara
397
408
connection .close (done -> {
398
409
if (done .failed ()) {
399
410
throw new SuppressRestartsException (
400
- new Throwable (ExceptionTrace .traceOriginalCause (done .cause ())));
411
+ new Throwable (
412
+ ExceptionTrace .traceOriginalCause (done .cause ())
413
+ )
414
+ );
401
415
}
402
416
});
403
417
}
@@ -411,8 +425,4 @@ private Map<String, Object> formatInputParam(Map<String, Object> inputParam) {
411
425
});
412
426
return result ;
413
427
}
414
-
415
- protected int getAsyncPoolSize () {
416
- return asyncPoolSize ;
417
- }
418
428
}
0 commit comments