@@ -77,18 +77,20 @@ public class MysqlDagStateStoreWithDagNodes implements DagStateStoreWithDagNodes
77
77
protected final GsonSerDe <List <JobExecutionPlan >> serDe ;
78
78
private final JobExecutionPlanDagFactory jobExecPlanDagFactory ;
79
79
80
- protected static final String CREATE_TABLE_STATEMENT = "CREATE TABLE IF NOT EXISTS %s ("
81
- + "dag_node_id VARCHAR(" + ServiceConfigKeys .MAX_DAG_NODE_ID_LENGTH
82
- + ") CHARACTER SET latin1 COLLATE latin1_bin NOT NULL, " + "parent_dag_id VARCHAR("
83
- + ServiceConfigKeys .MAX_DAG_ID_LENGTH + ") NOT NULL, " + "dag_node JSON NOT NULL, "
84
- + "modified_time timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, "
85
- + "is_failed_dag INT NOT NULL DEFAULT 0, " + "PRIMARY KEY (dag_node_id), "
86
- + "UNIQUE INDEX dag_node_index (dag_node_id), " + "INDEX dag_index (parent_dag_id))" ;
87
-
88
- protected static final String INSERT_STATEMENT = "INSERT INTO %s (dag_node_id, parent_dag_id, dag_node, is_failed_dag) "
89
- + "VALUES (?, ?, ?, ?) AS new ON DUPLICATE KEY UPDATE dag_node = new.dag_node, is_failed_dag = new.is_failed_dag" ;
90
- protected static final String GET_DAG_NODES_STATEMENT = "SELECT dag_node,is_failed_dag FROM %s WHERE parent_dag_id = ?" ;
91
- protected static final String GET_DAG_NODE_STATEMENT = "SELECT dag_node,is_failed_dag FROM %s WHERE dag_node_id = ?" ;
80
+ protected static final String CREATE_TABLE_STATEMENT =
81
+ "CREATE TABLE IF NOT EXISTS %s (" + "dag_node_id VARCHAR(" + ServiceConfigKeys .MAX_DAG_NODE_ID_LENGTH
82
+ + ") CHARACTER SET latin1 COLLATE latin1_bin NOT NULL, " + "parent_dag_id VARCHAR("
83
+ + ServiceConfigKeys .MAX_DAG_ID_LENGTH + ") NOT NULL, " + "dag_node JSON NOT NULL, "
84
+ + "modified_time timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, "
85
+ + "is_failed_dag TINYINT(1) DEFAULT 0, " + "PRIMARY KEY (dag_node_id), "
86
+ + "UNIQUE INDEX dag_node_index (dag_node_id), " + "INDEX dag_index (parent_dag_id))" ;
87
+
88
+ protected static final String INSERT_STATEMENT =
89
+ "INSERT INTO %s (dag_node_id, parent_dag_id, dag_node, is_failed_dag) "
90
+ + "VALUES (?, ?, ?, ?) AS new ON DUPLICATE KEY UPDATE dag_node = new.dag_node, is_failed_dag = new.is_failed_dag" ;
91
+ protected static final String GET_DAG_NODES_STATEMENT =
92
+ "SELECT dag_node FROM %s WHERE parent_dag_id = ?" ;
93
+ protected static final String GET_DAG_NODE_STATEMENT = "SELECT dag_node FROM %s WHERE dag_node_id = ?" ;
92
94
protected static final String DELETE_DAG_STATEMENT = "DELETE FROM %s WHERE parent_dag_id = ?" ;
93
95
private final ContextAwareCounter totalDagCount ;
94
96
@@ -103,7 +105,8 @@ public MysqlDagStateStoreWithDagNodes(Config config, Map<URI, TopologySpec> topo
103
105
DataSource dataSource = MysqlDataSourceFactory .get (config , SharedResourcesBrokerFactory .getImplicitBroker ());
104
106
105
107
try (Connection connection = dataSource .getConnection ();
106
- PreparedStatement createStatement = connection .prepareStatement (String .format (CREATE_TABLE_STATEMENT , tableName ))) {
108
+ PreparedStatement createStatement = connection .prepareStatement (
109
+ String .format (CREATE_TABLE_STATEMENT , tableName ))) {
107
110
createStatement .executeUpdate ();
108
111
connection .commit ();
109
112
} catch (SQLException e ) {
@@ -150,8 +153,7 @@ public boolean cleanUp(DagManager.DagId dagId) throws IOException {
150
153
return deleteStatement .executeUpdate () != 0 ;
151
154
} catch (SQLException e ) {
152
155
throw new IOException (String .format ("Failure deleting dag for %s" , dagId ), e );
153
- }
154
- }, true );
156
+ }}, true );
155
157
this .totalDagCount .dec ();
156
158
return true ;
157
159
}
@@ -165,7 +167,7 @@ public void cleanUp(String dagId) throws IOException {
165
167
@ Override
166
168
public List <Dag <JobExecutionPlan >> getDags () throws IOException {
167
169
throw new NotSupportedException (getClass ().getSimpleName () + " does not need this legacy API that originated with "
168
- + "the DagManager that is replaced by DagProcessingEngine" ); }
170
+ + "the DagManager that is replaced by DagProcessingEngine" );}
169
171
170
172
@ Override
171
173
public Dag <JobExecutionPlan > getDag (DagManager .DagId dagId ) throws IOException {
@@ -189,19 +191,11 @@ private Dag<JobExecutionPlan> convertDagNodesIntoDag(Set<Dag.DagNode<JobExecutio
189
191
if (dagNodes .isEmpty ()) {
190
192
return null ;
191
193
}
192
- Dag <JobExecutionPlan > dag = jobExecPlanDagFactory .createDag (dagNodes .stream ().map (Dag .DagNode ::getValue ).collect (Collectors .toList ()));
193
-
194
- // if any node of the dag is failed it means that the dag has been marked as failed, update the is_failed_dag field of the dag and it's nodes as true
195
- if (dag .getNodes ().stream ().anyMatch (Dag .DagNode ::isFailedDag )) {
196
- dag .setFailedDag (true );
197
- dag .getNodes ().forEach (node -> node .setFailedDag (true ));
198
- }
199
- return dag ;
194
+ return jobExecPlanDagFactory .createDag (dagNodes .stream ().map (Dag .DagNode ::getValue ).collect (Collectors .toList ()));
200
195
}
201
196
202
197
@ Override
203
- public int updateDagNode (DagManager .DagId parentDagId , Dag .DagNode <JobExecutionPlan > dagNode , boolean isFailedDag )
204
- throws IOException {
198
+ public int updateDagNode (DagManager .DagId parentDagId , Dag .DagNode <JobExecutionPlan > dagNode , boolean isFailedDag ) throws IOException {
205
199
String dagNodeId = dagNode .getValue ().getId ().toString ();
206
200
return dbStatementExecutor .withPreparedStatement (String .format (INSERT_STATEMENT , tableName ), insertStatement -> {
207
201
try {
@@ -212,25 +206,23 @@ public int updateDagNode(DagManager.DagId parentDagId, Dag.DagNode<JobExecutionP
212
206
return insertStatement .executeUpdate ();
213
207
} catch (SQLException e ) {
214
208
throw new IOException (String .format ("Failure adding dag node for %s" , dagNodeId ), e );
215
- }
216
- }, true );
209
+ }}, true );
217
210
}
218
211
219
212
@ Override
220
213
public Set <Dag .DagNode <JobExecutionPlan >> getDagNodes (DagManager .DagId parentDagId ) throws IOException {
221
- return dbStatementExecutor .withPreparedStatement (String .format (GET_DAG_NODES_STATEMENT , tableName ),
222
- getStatement -> {
223
- getStatement .setString (1 , parentDagId .toString ());
224
- HashSet <Dag .DagNode <JobExecutionPlan >> dagNodes = new HashSet <>();
225
- try (ResultSet rs = getStatement .executeQuery ()) {
226
- while (rs .next ()) {
227
- dagNodes .add (new Dag .DagNode <>(this .serDe .deserialize (rs .getString (1 )).get (0 ), rs .getBoolean (2 )));
228
- }
229
- return dagNodes ;
230
- } catch (SQLException e ) {
231
- throw new IOException (String .format ("Failure get dag nodes for dag %s" , parentDagId ), e );
232
- }
233
- }, true );
214
+ return dbStatementExecutor .withPreparedStatement (String .format (GET_DAG_NODES_STATEMENT , tableName ), getStatement -> {
215
+ getStatement .setString (1 , parentDagId .toString ());
216
+ HashSet <Dag .DagNode <JobExecutionPlan >> dagNodes = new HashSet <>();
217
+ try (ResultSet rs = getStatement .executeQuery ()) {
218
+ while (rs .next ()) {
219
+ dagNodes .add (new Dag .DagNode <>(this .serDe .deserialize (rs .getString (1 )).get (0 )));
220
+ }
221
+ return dagNodes ;
222
+ } catch (SQLException e ) {
223
+ throw new IOException (String .format ("Failure get dag nodes for dag %s" , parentDagId ), e );
224
+ }
225
+ }, true );
234
226
}
235
227
236
228
@ Override
@@ -239,7 +231,7 @@ public Optional<Dag.DagNode<JobExecutionPlan>> getDagNode(DagNodeId dagNodeId) t
239
231
getStatement .setString (1 , dagNodeId .toString ());
240
232
try (ResultSet rs = getStatement .executeQuery ()) {
241
233
if (rs .next ()) {
242
- return Optional .of (new Dag .DagNode <>(this .serDe .deserialize (rs .getString (1 )).get (0 ), rs . getBoolean ( 2 ) ));
234
+ return Optional .of (new Dag .DagNode <>(this .serDe .deserialize (rs .getString (1 )).get (0 )));
243
235
}
244
236
return Optional .empty ();
245
237
} catch (SQLException e ) {
0 commit comments