Commit 6971ed6
Fix routing for empty binding key to topic exchange (#16271)
* Fix routing for empty binding key to topic exchange
Fixes #16221
## What?
Fix a bug in the Khepri v4 topic trie projection where
messages published with an empty routing key to a topic exchange
were incorrectly routed to queues bound to other topic exchanges
with an empty binding key.
## Why?
The MQTT 5.0 spec states:
> All Topic Names and Topic Filters MUST be at least one character long
In contrast, the AMQP 0.9.1 spec state:
> The routing key used for a topic exchange MUST consist of **zero** or more words
delimited by dots. Each word may contain the letters A-Z and a-z and digits 0-9.
The routing pattern follows the same rules as the routing key with the addition
that * matches a single word, and # matches zero or more words
Hence zero words, i.e. empty routing keys and empty binding keys, are expliclity
allowed for the topic exchange type.
In the Khepri v4 projection, the topic trie used a global `root` atom
as the initial node ID for all topic exchanges. When a binding was
created with an empty binding key (`<<>>`), `split_topic_key_binary/1`
returned an empty list (`[]`). The trie traversal stopped immediately
at the root, meaning the binding was inserted into the
`rabbit_khepri_topic_binding_v4` ETS table with the global `root` atom
as the `LeafNodeId`.
Because the `LeafNodeId` lacked any exchange-specific context, all
empty bindings across all topic exchanges were
attached to the exact same global `root` node. Consequently, when a
message was published with an empty routing key to any topic exchange,
the routing logic (`trie_bindings/3`) would scan the ETS table starting
at the global `root` node and incorrectly match bindings belonging to
completely unrelated topic exchanges.
## How?
To fix this and ensure exchange isolation, the conceptual root of the
trie was changed from the global `root` atom to an exchange-specific
tuple: `{root, XSrc}` (where `XSrc` is `{VHost, ExchangeName}`).
- `rabbit_khepri:trie_follow_down_create/3` and `trie_follow_down_get_path/3`
now initialize their trie traversal with `{root, XSrc}`.
- `rabbit_db_topic_exchange:trie_match/5` now initiates routing from
`{root, {VHost, XName}}`.
This structural change guarantees that empty bindings are isolated per
exchange in the bindings ETS table, completely resolving the cross-exchange
leakage while fully supporting AMQP 0-9-1's allowance for empty binding
keys without breaking backward compatibility.
* Add new v5 projection for topic exchange routing
This commit introduces a new feature flag, `topic_binding_projection_v5`,
and a corresponding Khepri projection version (v5) to deploy the
exchange isolation fix for empty binding keys.
* Fix style
* Add 4.3.1 release notes
* Exercise one more code path #16271 #16221
---------
Co-authored-by: Michael Klishin <michaelklishin@icloud.com>1 parent e56c164 commit 6971ed6
6 files changed
Lines changed: 234 additions & 66 deletions
File tree
- deps/rabbit
- src
- test
- release-notes
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
255 | 255 | | |
256 | 256 | | |
257 | 257 | | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | 19 | | |
23 | 20 | | |
24 | 21 | | |
| |||
39 | 36 | | |
40 | 37 | | |
41 | 38 | | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
42 | 45 | | |
43 | | - | |
| 46 | + | |
44 | 47 | | |
45 | 48 | | |
46 | 49 | | |
| |||
87 | 90 | | |
88 | 91 | | |
89 | 92 | | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
94 | 97 | | |
95 | | - | |
96 | | - | |
97 | | - | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
98 | 101 | | |
99 | | - | |
100 | | - | |
| 102 | + | |
| 103 | + | |
101 | 104 | | |
102 | | - | |
103 | | - | |
| 105 | + | |
| 106 | + | |
104 | 107 | | |
105 | 108 | | |
106 | | - | |
107 | | - | |
108 | | - | |
| 109 | + | |
| 110 | + | |
109 | 111 | | |
110 | 112 | | |
111 | 113 | | |
112 | | - | |
| 114 | + | |
113 | 115 | | |
114 | 116 | | |
115 | | - | |
116 | | - | |
117 | | - | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
118 | 120 | | |
119 | | - | |
120 | | - | |
| 121 | + | |
| 122 | + | |
121 | 123 | | |
122 | 124 | | |
123 | 125 | | |
| |||
129 | 131 | | |
130 | 132 | | |
131 | 133 | | |
132 | | - | |
| 134 | + | |
133 | 135 | | |
134 | | - | |
| 136 | + | |
135 | 137 | | |
136 | | - | |
| 138 | + | |
137 | 139 | | |
138 | | - | |
| 140 | + | |
139 | 141 | | |
140 | | - | |
| 142 | + | |
141 | 143 | | |
142 | 144 | | |
143 | 145 | | |
| |||
154 | 156 | | |
155 | 157 | | |
156 | 158 | | |
157 | | - | |
158 | | - | |
| 159 | + | |
| 160 | + | |
159 | 161 | | |
160 | 162 | | |
161 | | - | |
162 | | - | |
| 163 | + | |
| 164 | + | |
163 | 165 | | |
164 | 166 | | |
165 | 167 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
182 | 182 | | |
183 | 183 | | |
184 | 184 | | |
185 | | - | |
| 185 | + | |
| 186 | + | |
186 | 187 | | |
187 | 188 | | |
188 | 189 | | |
189 | 190 | | |
| 191 | + | |
| 192 | + | |
190 | 193 | | |
191 | 194 | | |
192 | 195 | | |
| |||
1564 | 1567 | | |
1565 | 1568 | | |
1566 | 1569 | | |
1567 | | - | |
1568 | | - | |
| 1570 | + | |
| 1571 | + | |
1569 | 1572 | | |
1570 | 1573 | | |
1571 | 1574 | | |
| |||
1648 | 1651 | | |
1649 | 1652 | | |
1650 | 1653 | | |
1651 | | - | |
| 1654 | + | |
1652 | 1655 | | |
1653 | 1656 | | |
1654 | 1657 | | |
| |||
1658 | 1661 | | |
1659 | 1662 | | |
1660 | 1663 | | |
1661 | | - | |
| 1664 | + | |
1662 | 1665 | | |
1663 | 1666 | | |
1664 | 1667 | | |
1665 | | - | |
1666 | | - | |
1667 | | - | |
1668 | | - | |
| 1668 | + | |
1669 | 1669 | | |
1670 | 1670 | | |
1671 | 1671 | | |
| |||
1681 | 1681 | | |
1682 | 1682 | | |
1683 | 1683 | | |
1684 | | - | |
1685 | | - | |
1686 | | - | |
1687 | | - | |
| 1684 | + | |
| 1685 | + | |
| 1686 | + | |
1688 | 1687 | | |
1689 | 1688 | | |
1690 | 1689 | | |
1691 | 1690 | | |
1692 | | - | |
1693 | | - | |
| 1691 | + | |
| 1692 | + | |
1694 | 1693 | | |
1695 | 1694 | | |
1696 | 1695 | | |
1697 | 1696 | | |
1698 | 1697 | | |
| 1698 | + | |
| 1699 | + | |
| 1700 | + | |
| 1701 | + | |
1699 | 1702 | | |
1700 | 1703 | | |
1701 | | - | |
| 1704 | + | |
1702 | 1705 | | |
1703 | 1706 | | |
1704 | | - | |
| 1707 | + | |
1705 | 1708 | | |
1706 | 1709 | | |
1707 | 1710 | | |
| |||
1712 | 1715 | | |
1713 | 1716 | | |
1714 | 1717 | | |
1715 | | - | |
| 1718 | + | |
1716 | 1719 | | |
1717 | 1720 | | |
1718 | 1721 | | |
| |||
1732 | 1735 | | |
1733 | 1736 | | |
1734 | 1737 | | |
1735 | | - | |
1736 | | - | |
| 1738 | + | |
| 1739 | + | |
1737 | 1740 | | |
1738 | 1741 | | |
1739 | 1742 | | |
| |||
1756 | 1759 | | |
1757 | 1760 | | |
1758 | 1761 | | |
1759 | | - | |
1760 | | - | |
| 1762 | + | |
| 1763 | + | |
1761 | 1764 | | |
1762 | 1765 | | |
1763 | 1766 | | |
| |||
1811 | 1814 | | |
1812 | 1815 | | |
1813 | 1816 | | |
1814 | | - | |
| 1817 | + | |
| 1818 | + | |
| 1819 | + | |
| 1820 | + | |
| 1821 | + | |
| 1822 | + | |
| 1823 | + | |
| 1824 | + | |
| 1825 | + | |
1815 | 1826 | | |
1816 | 1827 | | |
1817 | | - | |
1818 | | - | |
1819 | | - | |
1820 | | - | |
1821 | | - | |
| 1828 | + | |
| 1829 | + | |
| 1830 | + | |
| 1831 | + | |
| 1832 | + | |
| 1833 | + | |
| 1834 | + | |
| 1835 | + | |
| 1836 | + | |
| 1837 | + | |
| 1838 | + | |
| 1839 | + | |
| 1840 | + | |
| 1841 | + | |
| 1842 | + | |
| 1843 | + | |
| 1844 | + | |
| 1845 | + | |
| 1846 | + | |
| 1847 | + | |
| 1848 | + | |
| 1849 | + | |
| 1850 | + | |
| 1851 | + | |
| 1852 | + | |
| 1853 | + | |
| 1854 | + | |
| 1855 | + | |
| 1856 | + | |
1822 | 1857 | | |
1823 | 1858 | | |
1824 | 1859 | | |
| |||
1827 | 1862 | | |
1828 | 1863 | | |
1829 | 1864 | | |
1830 | | - | |
| 1865 | + | |
1831 | 1866 | | |
1832 | 1867 | | |
1833 | 1868 | | |
| |||
1836 | 1871 | | |
1837 | 1872 | | |
1838 | 1873 | | |
| 1874 | + | |
| 1875 | + | |
| 1876 | + | |
| 1877 | + | |
| 1878 | + | |
| 1879 | + | |
| 1880 | + | |
| 1881 | + | |
| 1882 | + | |
1839 | 1883 | | |
1840 | 1884 | | |
1841 | 1885 | | |
| |||
1849 | 1893 | | |
1850 | 1894 | | |
1851 | 1895 | | |
1852 | | - | |
| 1896 | + | |
| 1897 | + | |
| 1898 | + | |
| 1899 | + | |
| 1900 | + | |
1853 | 1901 | | |
1854 | 1902 | | |
1855 | 1903 | | |
| |||
0 commit comments