|
360 | 360 | inventory/0, |
361 | 361 | cluster_inventory/0]). |
362 | 362 |
|
363 | | --on_load(on_load/0). |
364 | | - |
365 | 363 | -spec list() -> feature_flags(). |
366 | 364 | %% @doc |
367 | 365 | %% Lists all supported feature flags. |
@@ -1243,63 +1241,3 @@ sync_feature_flags_with_cluster(_Nodes, _NodeIsVirgin) -> |
1243 | 1241 |
|
1244 | 1242 | refresh_feature_flags_after_app_load() -> |
1245 | 1243 | rabbit_ff_controller:refresh_after_app_load(). |
1246 | | - |
1247 | | -on_load() -> |
1248 | | - %% The goal of this `on_load()` code server hook is to prevent this |
1249 | | - %% module from being loaded in an already running RabbitMQ node if |
1250 | | - %% the running version does not have the feature flags subsystem. |
1251 | | - %% |
1252 | | - %% This situation happens when an upgrade overwrites RabbitMQ files |
1253 | | - %% with the node still running. This is the case with many packages: |
1254 | | - %% files are updated on disk, then a post-install step takes care of |
1255 | | - %% restarting the service. |
1256 | | - %% |
1257 | | - %% The problem is that if many nodes in a cluster are updated at the |
1258 | | - %% same time, one node running the newer version might query feature |
1259 | | - %% flags on an old node where this module is already available |
1260 | | - %% (because files were already overwritten). This causes the query |
1261 | | - %% to report an unexpected answer and the newer node to refuse to |
1262 | | - %% start. |
1263 | | - %% |
1264 | | - %% However, when the module is executed outside of RabbitMQ (for |
1265 | | - %% debugging purpose or in the context of EUnit for instance), we |
1266 | | - %% want to allow the load. That's why we first check if RabbitMQ is |
1267 | | - %% actually running. |
1268 | | - case rabbit:is_running() of |
1269 | | - true -> |
1270 | | - %% RabbitMQ is running. |
1271 | | - %% |
1272 | | - %% Now we want to differentiate a pre-feature-flags node |
1273 | | - %% from one having the subsystem. |
1274 | | - %% |
1275 | | - %% To do that, we verify if the `feature_flags_file` |
1276 | | - %% application environment variable is defined. With a |
1277 | | - %% feature-flags-enabled node, this application environment |
1278 | | - %% variable is defined by rabbitmq-server(8). |
1279 | | - case application:get_env(rabbit, feature_flags_file) of |
1280 | | - {ok, _} -> |
1281 | | - %% This is a feature-flags-enabled version. Loading |
1282 | | - %% the module is permitted. |
1283 | | - ok; |
1284 | | - _ -> |
1285 | | - %% This is a pre-feature-flags version. We deny the |
1286 | | - %% load and report why, possibly specifying the |
1287 | | - %% version of RabbitMQ. |
1288 | | - Vsn = case application:get_key(rabbit, vsn) of |
1289 | | - {ok, V} -> V; |
1290 | | - undefined -> "unknown version" |
1291 | | - end, |
1292 | | - "Refusing to load '" ?MODULE_STRING "' on this " |
1293 | | - "node. It appears to be running a pre-feature-flags " |
1294 | | - "version of RabbitMQ (" ++ Vsn ++ "). This is fine: " |
1295 | | - "a newer version of RabbitMQ was deployed on this " |
1296 | | - "node, but it was not restarted yet. This warning " |
1297 | | - "is probably caused by a remote node querying this " |
1298 | | - "node for its feature flags." |
1299 | | - end; |
1300 | | - false -> |
1301 | | - %% RabbitMQ is not running. Loading the module is permitted |
1302 | | - %% because this Erlang node will never be queried for its |
1303 | | - %% feature flags. |
1304 | | - ok |
1305 | | - end. |
0 commit comments