2020package com .dtstack .flink .sql .side .rdb .async ;
2121
2222import com .dtstack .flink .sql .enums .ECacheContentType ;
23- import com .dtstack .flink .sql .metric .MetricConstant ;
2423import com .dtstack .flink .sql .side .BaseAsyncReqRow ;
2524import com .dtstack .flink .sql .side .BaseSideInfo ;
2625import com .dtstack .flink .sql .side .CacheMissVal ;
3029import io .vertx .core .json .JsonArray ;
3130import io .vertx .ext .sql .SQLClient ;
3231import io .vertx .ext .sql .SQLConnection ;
33- import org .apache .calcite .sql .JoinType ;
3432import org .apache .commons .lang3 .StringUtils ;
35- import org .apache .flink .metrics .Counter ;
3633import org .apache .flink .streaming .api .functions .async .ResultFuture ;
3734import org .apache .flink .table .runtime .types .CRow ;
3835import org .apache .flink .table .typeutils .TimeIndicatorTypeInfo ;
@@ -79,12 +76,8 @@ public class RdbAsyncReqRow extends BaseAsyncReqRow {
7976
8077 private final static AtomicBoolean CONN_STATUS = new AtomicBoolean (true );
8178
82- private final static AtomicLong FAIL_NUM = new AtomicLong (0 );
83-
8479 private Logger logger = LoggerFactory .getLogger (getClass ());
8580
86- private Counter counter = getRuntimeContext ().getMetricGroup ().counter (MetricConstant .DT_NUM_SIDE_PARSE_ERROR_RECORDS );
87-
8881 public RdbAsyncReqRow (BaseSideInfo sideInfo ) {
8982 super (sideInfo );
9083 }
@@ -98,7 +91,12 @@ protected void preInvoke(CRow input, ResultFuture<CRow> resultFuture){
9891 @ Override
9992 public void handleAsyncInvoke (Map <String , Object > inputParams , CRow input , ResultFuture <CRow > resultFuture ) throws Exception {
10093
94+ AtomicLong networkLogCounter = new AtomicLong (0L );
10195 while (!CONN_STATUS .get ()){//network is unhealth
96+ //todo:统一计数
97+ if (networkLogCounter .getAndIncrement () % 1000 == 0 ){
98+ LOG .info ("network unhealth to block task" );
99+ }
102100 Thread .sleep (100 );
103101 }
104102 rdbSqlClient .getConnection (conn -> {
@@ -127,12 +125,7 @@ private void connectWithRetry(Map<String, Object> inputParams, CRow input, Resul
127125 logger .error ("getConnection error" , conn .cause ());
128126 }
129127 if (failCounter .get () >= sideInfo .getSideTableInfo ().getAsyncFailMaxNum (3L )){
130- if (FAIL_NUM .incrementAndGet () > sideInfo .getSideTableInfo ().getAsyncFailMaxNum (Long .MAX_VALUE )){
131- counter .inc ();
132- resultFuture .completeExceptionally (conn .cause ());
133- } else {
134- dealMissKey (input , resultFuture );
135- }
128+ dealFillDataError (input , resultFuture , conn .cause ());
136129 finishFlag .set (true );
137130 }
138131 conn .result ().close ();
@@ -144,8 +137,7 @@ private void connectWithRetry(Map<String, Object> inputParams, CRow input, Resul
144137 handleQuery (conn .result (), inputParams , input , resultFuture );
145138 finishFlag .set (true );
146139 } catch (Exception e ) {
147- dealFillDataError (resultFuture , e , null );
148- logger .error ("" , e );
140+ dealFillDataError (input , resultFuture , e );
149141 } finally {
150142 latch .countDown ();
151143 }
@@ -210,13 +202,7 @@ private void handleQuery(SQLConnection connection,Map<String, Object> inputParam
210202 JsonArray params = new JsonArray (Lists .newArrayList (inputParams .values ()));
211203 connection .queryWithParams (sideInfo .getSqlCondition (), params , rs -> {
212204 if (rs .failed ()) {
213- if (FAIL_NUM .incrementAndGet () > sideInfo .getSideTableInfo ().getAsyncFailMaxNum (Long .MAX_VALUE )){
214- LOG .error ("Cannot retrieve the data from the database" , rs .cause ());
215- counter .inc ();
216- resultFuture .completeExceptionally (rs .cause ());
217- } else {
218- dealMissKey (input , resultFuture );
219- }
205+ dealFillDataError (input , resultFuture , rs .cause ());
220206 return ;
221207 }
222208
0 commit comments