-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The good: * Added better comments and more thorough testing. The bad: The bugfix had bugs. * We're supposed to SELECT FROM public.omicron.ipv4_nat_entry, but I wrote SELECT FROM ipv4_nat_entry. @dap explained a little while back that the fully qualified path needs to be present when the db is being initialized because we're instantiating the tables from a different namespace. This is what is breaking CI. * In the view I wrote version_added AS version twice, when the second statement should be version_removed AS version. It actually works correctly during initial dendrite startup, but will probably have issues with subsequent NAT updates. The more thorough testing catches these cases now.
- Loading branch information
1 parent
c6b68ae
commit f408ba3
Showing
5 changed files
with
145 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DROP VIEW IF EXISTS omicron.public.ipv4_nat_changes; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* A view of the ipv4 nat change history | ||
* used to summarize changes for external viewing | ||
*/ | ||
CREATE VIEW IF NOT EXISTS omicron.public.ipv4_nat_changes | ||
AS | ||
-- Subquery: | ||
-- We need to be able to order partial changesets. ORDER BY on separate columns | ||
-- will not accomplish this, so we'll do this by interleaving version_added | ||
-- and version_removed (version_removed taking priority if NOT NULL) and then sorting | ||
-- on the appropriate version numbers at call time. | ||
WITH interleaved_versions AS ( | ||
-- fetch all active NAT entries (entries that have not been soft deleted) | ||
SELECT | ||
external_address, | ||
first_port, | ||
last_port, | ||
sled_address, | ||
vni, | ||
mac, | ||
-- rename version_added to version | ||
version_added AS version, | ||
-- create a new virtual column, boolean value representing whether or not | ||
-- the record has been soft deleted | ||
(version_removed IS NOT NULL) as deleted | ||
FROM omicron.public.ipv4_nat_entry | ||
WHERE version_removed IS NULL | ||
|
||
-- combine the datasets, unifying the version_added and version_removed | ||
-- columns to a single `version` column so we can interleave and sort the entries | ||
UNION | ||
|
||
-- fetch all inactive NAT entries (entries that have been soft deleted) | ||
SELECT | ||
external_address, | ||
first_port, | ||
last_port, | ||
sled_address, | ||
vni, | ||
mac, | ||
-- rename version_removed to version | ||
version_removed AS version, | ||
-- create a new virtual column, boolean value representing whether or not | ||
-- the record has been soft deleted | ||
(version_removed IS NOT NULL) as deleted | ||
FROM omicron.public.ipv4_nat_entry | ||
WHERE version_removed IS NOT NULL | ||
) | ||
-- this is our new "table" | ||
-- here we select the columns from the subquery defined above | ||
SELECT | ||
external_address, | ||
first_port, | ||
last_port, | ||
sled_address, | ||
vni, | ||
mac, | ||
version, | ||
deleted | ||
FROM interleaved_versions; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters