-
Notifications
You must be signed in to change notification settings - Fork 16.5k
Hard limit priority weight total by int32 value #38125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,11 @@ Priority Weights | |
| bumped to any integer. Moreover, each task has a true ``priority_weight`` that is calculated based on its | ||
| ``weight_rule`` which defines the weighting method used for the effective total priority weight of the task. | ||
|
|
||
| .. versionadded:: 2.9.0 | ||
|
|
||
| Total priority weight should be in range between **-2,147,483,648** and **2,147,483,647**. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we support negative value for weight?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The value doesn’t have any semantic meanings, things are simply ordered by it in the scheduler. A negative value works as well as positive, or zero.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thinking about this though, I wonder if we should just change the database field to a float instead. We don’t really care about the precise value here, and a float can be ordered as well as an int.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's an interesting thought. might be indeed simple to implement - just migration - and does not require any code changes
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah this is also applicable. It still required to change a code: Models + Migration Just one nit this change might invoke internally recreate Task Instance table (delete old records, create new records). In user perspective it might required some time on huge TI table.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With current implementation it is hard to overflow even But it might changed in case of #36029, some custom user defined WeightRules could easily overflow any values in case of progressive and exponential progressive implementations.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Anyway, I will try to this approach, and we could decide which one is better suits for current and potential future implementations
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
We recommand to clean old records periodicly and before upgrade.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Even if we recommended it doesn't mean that it does not impact someone who even uses this recommendation. This one only changes validation in one place and someone who does not use priorities probably does not even notice about this change but it introduces hard limits which already exist, but rather that crash scheduler it changed values to suitable. The other one is required to change type, find which type better suits, write migrations and change types from int to float. |
||
| In case of overflow it fallback to the boundaries of allowed range. | ||
|
|
||
| Below are the weighting methods. By default, Airflow's weighting method is ``downstream``. | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
| from __future__ import annotations | ||
|
|
||
| import contextlib | ||
| import warnings | ||
|
|
||
| import pytest | ||
|
|
||
| from airflow.models.baseoperator import BaseOperator | ||
| from airflow.operators.empty import EmptyOperator | ||
| from tests.test_utils.db import clear_db_dags, clear_db_serialized_dags | ||
|
|
||
| INT32_MAX = 2147483647 | ||
| INT32_MIN = -2147483648 | ||
|
|
||
|
|
||
| @contextlib.contextmanager | ||
| def _warning_not_expected(): | ||
| with warnings.catch_warnings(): | ||
| warnings.filterwarnings( | ||
| "error", message=".*exceeds allowed priority weight range.*", category=UserWarning | ||
| ) | ||
| yield | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def _clear_dags(): | ||
| clear_db_dags() | ||
| clear_db_serialized_dags() | ||
| yield | ||
| clear_db_dags() | ||
| clear_db_serialized_dags() | ||
|
|
||
|
|
||
| class TestDagTaskParameterOverflow: | ||
| @_warning_not_expected() | ||
| def test_priority_weight_default(self): | ||
| assert EmptyOperator(task_id="empty").priority_weight_total | ||
|
|
||
| @pytest.mark.parametrize( | ||
| "priority_weight", | ||
| [ | ||
| 42, | ||
| pytest.param(INT32_MIN, id="lower-bound"), | ||
| pytest.param(INT32_MAX, id="upper-bound"), | ||
| ], | ||
| ) | ||
| @_warning_not_expected() | ||
| def test_priority_weight_absolute(self, priority_weight): | ||
| EmptyOperator(task_id="empty", priority_weight=priority_weight) | ||
|
|
||
| @pytest.mark.parametrize( | ||
| "priority_weight, priority_weight_total", | ||
| [ | ||
| pytest.param(INT32_MIN - 1, INT32_MIN, id="less-than-lower-bound"), | ||
| pytest.param(INT32_MAX + 1, INT32_MAX, id="greater-than-upper-bound"), | ||
| ], | ||
| ) | ||
| def test_priority_weight_absolute_overflow(self, priority_weight, priority_weight_total): | ||
| op = EmptyOperator(task_id="empty", priority_weight=priority_weight) | ||
| with pytest.warns(UserWarning, match="exceeds allowed priority weight range"): | ||
| assert op.priority_weight_total == priority_weight_total | ||
|
|
||
| @pytest.mark.db_test | ||
| @pytest.mark.parametrize( | ||
| "priority, bound_priority", | ||
| [ | ||
| pytest.param(-10, INT32_MIN, id="less-than-lower-bound"), | ||
| pytest.param(10, INT32_MAX, id="greater-than-upper-bound"), | ||
| ], | ||
| ) | ||
| def test_priority_weight_sum_up_overflow( | ||
| self, priority: int, bound_priority: int, dag_maker, _clear_dags | ||
| ): | ||
| class TestOp(BaseOperator): | ||
| def __init__(self, value, **kwargs): | ||
| super().__init__(**kwargs) | ||
| self.value = value | ||
|
|
||
| with dag_maker(dag_id="test_priority_weight_sum_up_overflow"): | ||
| op1 = EmptyOperator(task_id="op1", priority_weight=priority) | ||
| op2 = TestOp.partial(task_id="op2", priority_weight=bound_priority).expand(value=[1, 2, 3]) | ||
| op3 = EmptyOperator(task_id="op3", priority_weight=priority) | ||
| op1 >> op2 >> op3 | ||
|
|
||
| with pytest.warns(UserWarning, match="exceeds allowed priority weight range"): | ||
| dr = dag_maker.create_dagrun() | ||
|
|
||
| tis_priorities = {ti.task_id: ti.priority_weight for ti in dr.task_instances} | ||
| assert tis_priorities["op3"] == priority | ||
| assert tis_priorities["op2"] == bound_priority | ||
| assert tis_priorities["op1"] == bound_priority |
Uh oh!
There was an error while loading. Please reload this page.