Skip to content
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

chore: release 2022.3.3: added scripts/drop_compound_index.py #163

Merged
merged 7 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ file.
[UNRELEASED] - Under development
********************************

[2022.3.3] - 2023-08-07
***********************

General Information
===================
- ``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``

[2022.3.2] - 2023-07-20
***********************

Expand Down
4 changes: 2 additions & 2 deletions controllers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
],
Expand Down
2 changes: 1 addition & 1 deletion kytos.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"username": "kytos",
"name": "flow_manager",
"description": "Manage switches' flows through a REST API.",
"version": "2022.3.2",
"version": "2022.3.3",
"napp_dependencies": ["kytos/of_core"],
"license": "MIT",
"url": "https://github.com/kytos/flow_manager.git",
Expand Down
8 changes: 8 additions & 0 deletions scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,11 @@ And then, to insert (or update) the flows:
```
CMD=insert_flows python3 scripts/storehouse_to_mongo.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` from a previous version, you should run the `drop_compound_index.py` script to drop it:

```
CMD=drop_index python3 drop_compound_index.py
```
40 changes: 40 additions & 0 deletions scripts/drop_compound_index.py
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 2 additions & 2 deletions tests/unit/test_flow_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
],
Expand Down