Commit dd30872
authored
Preserve module load order in CONFIG REWRITE (valkey-io#3769)
## Why
`CONFIG REWRITE` did not preserve module load order because the module
registry was stored in a hash table with unspecified iteration order.
This could write dependent modules before their dependencies, causing
the next restart to fail. Runtime `MODULE LOAD` and `MODULE UNLOAD`
operations could also change the resulting order.
## Fix
Use a single ordered list as the module registry instead of maintaining
a module dictionary and a separate load-order structure.
- Register modules at the tail of the list.
- Perform name lookups by scanning the list case-insensitively.
- Remove modules directly from the list when unloaded.
- Iterate the same list when writing `loadmodule` directives during
`CONFIG REWRITE`.
- Unload modules in reverse load order so dependents are unloaded before
their dependencies.
Module counts are normally small, so linear lookup keeps the
implementation simple while preserving load order as a single source of
truth.
Reloading a module moves it to the tail, reflecting its new load time.
## Tests
The module API tests verify that:
1. `CONFIG REWRITE` preserves module load order.
2. Static modules such as `lua` are not written to the configuration.
3. A rejected unload does not change the rewritten module order.
4. Unloading and reloading a module moves it to the tail.
5. The server can restart from the rewritten configuration.
Fixes valkey-io#3119
---------
Signed-off-by: Taeknology <20297177+Taeknology@users.noreply.github.com>1 parent f4dc3ca commit dd30872
5 files changed
Lines changed: 160 additions & 112 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1662 | 1662 | | |
1663 | 1663 | | |
1664 | 1664 | | |
1665 | | - | |
| 1665 | + | |
1666 | 1666 | | |
1667 | 1667 | | |
1668 | 1668 | | |
1669 | 1669 | | |
1670 | 1670 | | |
| 1671 | + | |
| 1672 | + | |
1671 | 1673 | | |
1672 | | - | |
1673 | | - | |
1674 | | - | |
1675 | | - | |
| 1674 | + | |
| 1675 | + | |
| 1676 | + | |
1676 | 1677 | | |
1677 | 1678 | | |
1678 | 1679 | | |
1679 | 1680 | | |
1680 | | - | |
1681 | | - | |
| 1681 | + | |
1682 | 1682 | | |
1683 | 1683 | | |
1684 | 1684 | | |
| |||
0 commit comments