From b9700c1298e86dfa7a7e7c05da5d53b22dfc3199 Mon Sep 17 00:00:00 2001 From: Vinicius Arcanjo Date: Mon, 7 Aug 2023 12:17:16 -0300 Subject: [PATCH 1/5] chore: updated flow.priority index and compound index to be DESCENDING --- controllers/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/controllers/__init__.py b/controllers/__init__.py index 3fcb146..323ec10 100644 --- a/controllers/__init__.py +++ b/controllers/__init__.py @@ -46,15 +46,15 @@ def bootstrap_indexes(self) -> None: index_tuples = [ ("flows", [("flow_id", pymongo.ASCENDING)], {"unique": True}), ("flows", [("flow.cookie", pymongo.ASCENDING)], {}), - ("flows", [("flow.priority", pymongo.ASCENDING)], {}), + ("flows", [("flow.priority", pymongo.DESCENDING)], {}), ("flows", [("state", pymongo.ASCENDING)], {}), ( "flows", [ ("switch", pymongo.ASCENDING), ("flow.cookie", pymongo.ASCENDING), - ("flow.priority", pymongo.ASCENDING), ("state", pymongo.ASCENDING), + ("flow.priority", pymongo.DESCENDING), ("inserted_at", pymongo.ASCENDING), ("updated_at", pymongo.ASCENDING), ], From 2e3c0f4005d0a97e2ca07b103358b709d1651294 Mon Sep 17 00:00:00 2001 From: Vinicius Arcanjo Date: Mon, 7 Aug 2023 12:27:59 -0300 Subject: [PATCH 2/5] chore: added scripts/drop_compound_index.py --- scripts/README.md | 8 +++++++ scripts/drop_compound_index.py | 40 ++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 scripts/drop_compound_index.py diff --git a/scripts/README.md b/scripts/README.md index 9c07e7c..9a4edd9 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -62,3 +62,11 @@ Run the script to upgrade all flows from `mef_eline`, `of_lldp` and `coloring` w ``` python3 pipeline_related.py ``` + +### Drop compound index + +On version `2023.1`, this `flows` compound index `switch_1_flow.cookie_1_state_1_inserted_at_1_updated_at_1` has changed. If you're upgrading to `2023.1` froma previous version, you should run the `drop_compound_index.py` script to drop it: + +``` +CMD=drop_index python3 drop_compound_index.py +``` diff --git a/scripts/drop_compound_index.py b/scripts/drop_compound_index.py new file mode 100644 index 0000000..bcfe8d8 --- /dev/null +++ b/scripts/drop_compound_index.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +import sys +import os +import pymongo + +from napps.kytos.flow_manager.controllers import FlowController + + +flow_controller = FlowController() + + +def drop_index(index_name=None, flow_controller=flow_controller) -> dict: + """drop_index.""" + index_name = index_name or os.environ.get( + "INDEX_NAME", "switch_1_flow.cookie_1_state_1_inserted_at_1_updated_at_1" + ) + return flow_controller.db.flows.drop_index(index_name) + + +if __name__ == "__main__": + cmds = { + "drop_index": drop_index, + } + try: + cmd = os.environ["CMD"] + except KeyError: + print("Please set the 'CMD' env var.") + sys.exit(1) + try: + for command in cmd.split(","): + print(cmds[command]()) + except KeyError as e: + print( + f"Unknown cmd: {str(e)}. 'CMD' env var has to be one of these {list(cmds.keys())}." + ) + sys.exit(1) + except pymongo.errors.PyMongoError as e: + print(f"pymongo error: {str(e)}") + sys.exit(1) From 3c96a4e95551ce6763beee80ba7234c2967b2b7c Mon Sep 17 00:00:00 2001 From: Vinicius Arcanjo Date: Mon, 7 Aug 2023 12:29:27 -0300 Subject: [PATCH 3/5] Updated CHANGELOG.rst --- CHANGELOG.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 6185555..7f906a0 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -23,6 +23,7 @@ Changed General Information =================== - ``@rest`` endpoints are now run by ``starlette/uvicorn`` instead of ``flask/werkzeug``. +- ``scripts/drop_compound_index.py`` can be used to drop a compound index that has changed. Fixed ===== From cc6ac8565aedffe8f6f32ae920383dd8f29d4698 Mon Sep 17 00:00:00 2001 From: Vinicius Arcanjo Date: Mon, 7 Aug 2023 13:02:38 -0300 Subject: [PATCH 4/5] chore: fixed unit test --- tests/unit/test_flow_controller.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/test_flow_controller.py b/tests/unit/test_flow_controller.py index 622553f..b9a6593 100644 --- a/tests/unit/test_flow_controller.py +++ b/tests/unit/test_flow_controller.py @@ -35,15 +35,15 @@ def test_boostrap_indexes(self) -> None: expected_indexes = [ ("flows", [("flow_id", 1)]), ("flows", [("flow.cookie", 1)]), - ("flows", [("flow.priority", 1)]), + ("flows", [("flow.priority", -1)]), ("flows", [("state", 1)]), ( "flows", [ ("switch", 1), ("flow.cookie", 1), - ("flow.priority", 1), ("state", 1), + ("flow.priority", -1), ("inserted_at", 1), ("updated_at", 1), ], From 76d071d265d79c1520a0e6fe8f6e52a6accdcda9 Mon Sep 17 00:00:00 2001 From: Vinicius Arcanjo Date: Mon, 7 Aug 2023 13:34:21 -0300 Subject: [PATCH 5/5] chore: added extra information in the changelog --- CHANGELOG.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 7f906a0..9833b29 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -23,7 +23,7 @@ Changed General Information =================== - ``@rest`` endpoints are now run by ``starlette/uvicorn`` instead of ``flask/werkzeug``. -- ``scripts/drop_compound_index.py`` can be used to drop a compound index that has changed. +- ``scripts/drop_compound_index.py`` can be used to drop a compound index that has changed. If you tried to upgrade to ``2022.3.2`` before and it ended up creating ``'flow.priority_1'`` index, then you also want to delete it by running ``CMD=drop_index INDEX_NAME=flow.priority_1 python3 drop_compound_index.py`` Fixed =====