feng-tao commented on a change in pull request #4396: [AIRFLOW-3585] - Add 
edges to database
URL: https://github.com/apache/airflow/pull/4396#discussion_r259596086
 
 

 ##########
 File path: airflow/models/__init__.py
 ##########
 @@ -4019,17 +4073,50 @@ def create_dagrun(self,
             conf=conf,
             state=state
         )
+
+        dag_model = DagModel.get_dagmodel(self.dag_id)
+
+        tis = self.create_tis(execution_date)
+        # Setting graph_id temparary on -1, will set set later.
+        edges = self.create_edges(graph_id=-1)
+
+        last_dagrun = 
dag_model.get_last_dagrun(include_externally_triggered=True)
+        if last_dagrun is None:
+            is_dag_unchanged = False
+        else:
+            last_edges = DagEdge.fetch_edges(self.dag_id, last_dagrun.graph_id)
+
+            # Compare edges from last run
+            prev_edges = [(edge.task_from, edge.task_to) for edge in 
last_edges]
+            current_edges = [(edge.task_from, edge.task_to) for edge in edges]
+            is_dag_unchanged = len(current_edges) == len(prev_edges)
+            is_dag_unchanged &= set(current_edges) == set(prev_edges)
+
+        if is_dag_unchanged:
+            # graph is not changed, keep last graph_id
+            graph_id = last_dagrun.graph_id
+        elif last_dagrun is None or last_dagrun.graph_id is None:
+            # no graph known yet, beginning at 1
+            graph_id = 1
+        else:
+            # graph is changed
+            graph_id = last_dagrun.graph_id + 1
 
 Review comment:
   the new graph_id always increments by 1. The backfill and scheduled DAGRun 
is shared in the same table. Assuming the latest schedule_dagrun execute date 
is 2/20/2019 with graph id 10, if we choose to backfill 1/20/2019, the graph id 
for 1/20/2019 dagrun will be 11, then if we backfill another date 1/21/2019, 
the graph id for 1/21/2019 will be 11 as well. In this case both DAGRun will 
have the same graph id. Is it ok?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to