3030import io .vertx .ext .sql .SQLClient ;
3131import io .vertx .ext .sql .SQLConnection ;
3232import com .google .common .collect .Lists ;
33+ import org .apache .calcite .sql .JoinType ;
3334import org .apache .commons .lang .exception .ExceptionUtils ;
3435import org .apache .commons .lang3 .StringUtils ;
3536import org .apache .flink .streaming .api .functions .async .ResultFuture ;
3839import org .apache .flink .types .Row ;
3940import org .slf4j .Logger ;
4041import org .slf4j .LoggerFactory ;
42+ import scala .Int ;
4143
4244import java .sql .Timestamp ;
4345import java .util .Collection ;
4446import java .util .List ;
4547import java .util .Map ;
4648import java .util .concurrent .CountDownLatch ;
49+ import java .util .concurrent .ExecutionException ;
4750import java .util .concurrent .Future ;
4851import java .util .concurrent .ScheduledFuture ;
4952import java .util .concurrent .atomic .AtomicBoolean ;
5053import java .util .concurrent .atomic .AtomicInteger ;
54+ import java .util .concurrent .atomic .AtomicLong ;
5155import java .util .concurrent .atomic .AtomicReference ;
5256
5357/**
@@ -81,6 +85,8 @@ public class RdbAsyncReqRow extends BaseAsyncReqRow {
8185
8286 private final static AtomicBoolean CONN_STATUS = new AtomicBoolean (true );
8387
88+ private final static AtomicLong TIMOUT_NUM = new AtomicLong (0 );
89+
8490 private Logger logger = LoggerFactory .getLogger (getClass ());
8591
8692 public RdbAsyncReqRow (BaseSideInfo sideInfo ) {
@@ -114,7 +120,7 @@ public void handleAsyncInvoke(Map<String, Object> inputParams, CRow input, Resul
114120 }
115121
116122 private void connectWithRetry (Map <String , Object > inputParams , CRow input , ResultFuture <CRow > resultFuture , SQLClient rdbSqlClient ) {
117- AtomicInteger failCounter = new AtomicInteger (0 );
123+ AtomicLong failCounter = new AtomicLong (0 );
118124 AtomicBoolean finishFlag = new AtomicBoolean (false );
119125 while (!finishFlag .get ()){
120126 CountDownLatch latch = new CountDownLatch (1 );
@@ -124,8 +130,8 @@ private void connectWithRetry(Map<String, Object> inputParams, CRow input, Resul
124130 if (failCounter .getAndIncrement () % 1000 == 0 ){
125131 logger .error ("getConnection error" , conn .cause ());
126132 }
127- if (failCounter .get () >= sideInfo .getSideTableInfo ().getAsyncFailMaxNum (3 )){
128- resultFuture . completeExceptionally ( conn .cause ());
133+ if (failCounter .get () >= sideInfo .getSideTableInfo ().getAsyncFailMaxNum (3L )){
134+ outByJoinType ( resultFuture , conn .cause ());
129135 finishFlag .set (true );
130136 }
131137 conn .result ().close ();
@@ -202,8 +208,12 @@ private void handleQuery(SQLConnection connection,Map<String, Object> inputParam
202208 JsonArray params = new JsonArray (Lists .newArrayList (inputParams .values ()));
203209 connection .queryWithParams (sideInfo .getSqlCondition (), params , rs -> {
204210 if (rs .failed ()) {
211+ if (TIMOUT_NUM .incrementAndGet () > sideInfo .getSideTableInfo ().getAsyncFailMaxNum (Long .MAX_VALUE )){
212+ outByJoinType (resultFuture , rs .cause ());
213+ return ;
214+ }
205215 LOG .error ("Cannot retrieve the data from the database" , rs .cause ());
206- resultFuture .completeExceptionally ( rs . cause () );
216+ resultFuture .complete ( null );
207217 return ;
208218 }
209219
@@ -242,4 +252,12 @@ private void handleQuery(SQLConnection connection,Map<String, Object> inputParam
242252 });
243253 }
244254
255+ private void outByJoinType (ResultFuture <CRow > resultFuture , Throwable e ){
256+ if (sideInfo .getJoinType () == JoinType .LEFT ){
257+ resultFuture .complete (null );
258+ return ;
259+ }
260+ resultFuture .completeExceptionally (e );
261+ }
262+
245263}
0 commit comments