33
33
import java .util .concurrent .TimeUnit ;
34
34
import java .util .concurrent .atomic .AtomicLong ;
35
35
36
+ import static com .dtstack .flink .sql .dirtyManager .manager .DirtyKeys .DEFAULT_BLOCKING_INTERVAL ;
37
+ import static com .dtstack .flink .sql .dirtyManager .manager .DirtyKeys .DEFAULT_ERROR_LIMIT_RATE ;
38
+ import static com .dtstack .flink .sql .dirtyManager .manager .DirtyKeys .DEFAULT_PRINT_LIMIT ;
39
+ import static com .dtstack .flink .sql .dirtyManager .manager .DirtyKeys .DEFAULT_TYPE ;
40
+ import static com .dtstack .flink .sql .dirtyManager .manager .DirtyKeys .DIRTY_BLOCK_STR ;
41
+ import static com .dtstack .flink .sql .dirtyManager .manager .DirtyKeys .DIRTY_LIMIT_RATE_STR ;
42
+ import static com .dtstack .flink .sql .dirtyManager .manager .DirtyKeys .PLUGIN_LOAD_MODE_STR ;
43
+ import static com .dtstack .flink .sql .dirtyManager .manager .DirtyKeys .PLUGIN_PATH_STR ;
44
+ import static com .dtstack .flink .sql .dirtyManager .manager .DirtyKeys .PLUGIN_TYPE_STR ;
45
+ import static com .dtstack .flink .sql .dirtyManager .manager .DirtyKeys .PRINT_LIMIT_STR ;
46
+
36
47
/**
37
48
* @author tiezhu
38
49
* Company dtstack
@@ -43,11 +54,7 @@ public class DirtyDataManager implements Serializable {
43
54
public final static int MAX_POOL_SIZE_LIMIT = 5 ;
44
55
private static final long serialVersionUID = 7190970299538893497L ;
45
56
private static final Logger LOG = LoggerFactory .getLogger (DirtyDataManager .class );
46
- private static final String DIRTY_BLOCK_STR = "blockingInterval" ;
47
- private static final String DIRTY_LIMIT_RATE_STR = "errorLimitRate" ;
48
57
private final static int MAX_TASK_QUEUE_SIZE = 100 ;
49
- private final static String DEFAULT_ERROR_LIMIT_RATE = "0.8" ;
50
- private final static String DEFAULT_BLOCKING_INTERVAL = "60" ;
51
58
public static AbstractDirtyDataConsumer consumer ;
52
59
53
60
private static ThreadPoolExecutor dirtyDataConsumer ;
@@ -77,14 +84,14 @@ public static DirtyDataManager newInstance(Properties properties) {
77
84
manager .blockingInterval = Long .parseLong (String .valueOf (properties .getOrDefault (DIRTY_BLOCK_STR , DEFAULT_BLOCKING_INTERVAL )));
78
85
manager .errorLimitRate = Double .parseDouble (String .valueOf (properties .getOrDefault (DIRTY_LIMIT_RATE_STR , DEFAULT_ERROR_LIMIT_RATE )));
79
86
consumer = DirtyConsumerFactory .getDirtyConsumer (
80
- properties .getProperty ("type" )
81
- , properties .getProperty ("pluginPath" )
82
- , properties .getProperty ("pluginLoadMode" )
87
+ properties .getProperty (PLUGIN_TYPE_STR , DEFAULT_TYPE )
88
+ , properties .getProperty (PLUGIN_PATH_STR )
89
+ , properties .getProperty (PLUGIN_LOAD_MODE_STR )
83
90
);
84
91
consumer .init (properties );
85
92
consumer .setQueue (new LinkedBlockingQueue <>());
86
93
dirtyDataConsumer = new ThreadPoolExecutor (MAX_POOL_SIZE_LIMIT , MAX_POOL_SIZE_LIMIT , 0 , TimeUnit .MILLISECONDS ,
87
- new LinkedBlockingQueue <>(MAX_TASK_QUEUE_SIZE ), new DTThreadFactory ("dirtyDataConsumer" ), new ThreadPoolExecutor .CallerRunsPolicy ());
94
+ new LinkedBlockingQueue <>(MAX_TASK_QUEUE_SIZE ), new DTThreadFactory ("dirtyDataConsumer" , true ), new ThreadPoolExecutor .CallerRunsPolicy ());
88
95
dirtyDataConsumer .execute (consumer );
89
96
return manager ;
90
97
} catch (Exception e ) {
@@ -99,8 +106,8 @@ public static DirtyDataManager newInstance(Properties properties) {
99
106
*/
100
107
public static String buildDefaultDirty () {
101
108
JSONObject jsonObject = new JSONObject ();
102
- jsonObject .put ("type" , "console" );
103
- jsonObject .put ("printLimit" , "1000" );
109
+ jsonObject .put (PLUGIN_TYPE_STR , DEFAULT_TYPE );
110
+ jsonObject .put (PRINT_LIMIT_STR , DEFAULT_PRINT_LIMIT );
104
111
return jsonObject .toJSONString ();
105
112
}
106
113
@@ -128,6 +135,8 @@ public void collectDirtyData(String dataInfo, String cause) {
128
135
LOG .warn ("dirty Data insert error ... Failed number: " + errorCount .incrementAndGet ());
129
136
LOG .warn ("error dirty data:" + dirtyDataEntity .toString ());
130
137
if (errorCount .get () > Math .ceil (count .longValue () * errorLimitRate )) {
138
+ // close consumer and manager
139
+ close ();
131
140
throw new RuntimeException (String .format ("The number of failed number 【%s】 reaches the limit, manager fails" , errorCount .get ()));
132
141
}
133
142
}
0 commit comments