Skip to content

Commit

Permalink
Disable routepref filter_prefixes for large filter sets
Browse files Browse the repository at this point in the history
When using filter_prefixes, we run one SQL query per prefix,
which has overhead for large sets. This ignored it when there
are >5000.
  • Loading branch information
mxsasha committed Apr 11, 2023
1 parent 555c327 commit 97cbd22
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
4 changes: 4 additions & 0 deletions irrd/routepref/routepref.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from .status import RoutePreferenceStatus

logger = logging.getLogger(__name__)
MAX_FILTER_PREFIX_LEN = 5000


class RoutePreferenceValidator:
Expand Down Expand Up @@ -137,6 +138,9 @@ def update_route_preference_status(
and an optional set of prefixes to limit the evaluation.
Results are saved to the database and counters are logged.
"""
if filter_prefixes and len(filter_prefixes) > MAX_FILTER_PREFIX_LEN:
filter_prefixes = None

validator = build_validator(database_handler, filter_prefixes)
pks_to_be_visible, pks_to_be_suppressed = validator.validate_known_routes()
pks_to_become_visible = pks_to_be_visible + validator.excluded_currently_suppressed
Expand Down
31 changes: 30 additions & 1 deletion irrd/routepref/tests/test_routepref.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import itertools

from IPy import IP

from irrd.storage.queries import RPSLDatabaseQuery
Expand Down Expand Up @@ -99,7 +101,7 @@ def test_route_preference_validator(config_override):
assert to_be_suppressed == []


def test_update_route_preference_status(config_override):
def test_update_route_preference_status(config_override, monkeypatch):
config_override(
{
"sources": {
Expand Down Expand Up @@ -189,3 +191,30 @@ def test_update_route_preference_status(config_override):
{"rpsl_objs_now_visible": [], "rpsl_objs_now_suppressed": []},
)
]

# Finally, test with a "large" set of prefixes
monkeypatch.setattr("irrd.routepref.routepref.MAX_FILTER_PREFIX_LEN", 5)
mock_dh.reset_mock()
mock_dh.query_responses[RPSLDatabaseQuery] = iter(route_objects)
ip = IP("192.0.0.0/23")
filter_prefixes = list(itertools.chain.from_iterable(itertools.repeat(ip, 10)))
update_route_preference_status(mock_dh, filter_prefixes)
assert mock_dh.queries == [
RPSLDatabaseQuery(column_names=expected_columns, ordered_by_sources=False).object_classes(
object_classes
),
RPSLDatabaseQuery(
enrich_columns,
enable_ordering=False,
).pks(["route-A"]),
RPSLDatabaseQuery(
enrich_columns,
enable_ordering=False,
).pks(["route-D"]),
]
assert mock_dh.other_calls == [
(
"update_route_preference_status",
{"rpsl_objs_now_visible": [], "rpsl_objs_now_suppressed": []},
)
]

0 comments on commit 97cbd22

Please sign in to comment.