Commit Graph

26977 Commits

Author SHA1 Message Date
Michal Kuratczyk 4da170fbf9
Faster node start with many classic queues v2 (#7676)
* Faster all_queue_directory_names/1
* Optimise writing stub files

Combined, this reduces node startup time by half with many empty classic queues v2
2023-03-21 13:12:00 +01:00
Marcial Rosales 67b952c28c Refactor selenium tests 2023-03-21 12:39:28 +01:00
David Ansari b4871e2b83
Update PROTOCOL.adoc 2023-03-21 11:58:50 +01:00
Rin Kuryloski f2dfd6c89f Revert "Merge pull request #7672 from rabbitmq/mk-switch-cq-version-to-2-by-default"
This reverts commit f6e1a6e74b, reversing
changes made to c4d6503cad.
2023-03-21 09:55:52 +01:00
David Ansari 557c23b753 Do not restart DLX worker if leader is non-local
The rabbit_fifo_dlx_worker should be co-located with the quorum
queue leader.

If a new leader on a different node gets elected before the
rabbit_fifo_dlx_worker initialises (i.e. registers itself as a
consumer), it should stop itself normally, such that it is not restarted
by rabbit_fifo_dlx_sup.

Another rabbit_fifo_dlx_worker should be created on the new quorum
queue leader node.
2023-03-20 17:54:06 +01:00
David Ansari 76db0b5bfa Make rabbit_fifo_dlx_sup more resilient
Previously, it used the default intensity:
"intensity defaults to 1 and period defaults to 5."

However, it's a bit low given there can be dozens or hundreds of DLX
workers: If only 2 fail within 5 seconds, the whole supervisor
terminates.

Even with the new values, there shouldn't be any infnite loop of the
supervisor terminating and restarting childs because the
rabbit_fifo_dlx_worker is terminated and started very quickly
given that the (the slow) consumer registration happens in
rabbit_fifo_dlx_worker:handle_continue/2.
2023-03-20 17:54:06 +01:00
David Ansari e3cf90a841 Terminate replaced rabbit_fifo_dlx_worker
[Jepsen dead lettering tests](5977f587e2/jepsen/scripts/qq-jepsen-test.sh (L108))
of job `qq-jepsen-test-3-12` of Concourse pipeline `jepsen-tests`
fail sometimes with following error:
```
{{:try_clause, [{:undefined, #PID<12128.3596.0>, :worker, [:rabbit_fifo_dlx_worker]}, {:undefined, #PID<12128.10212.0>, :worker, [:rabbit_fifo_dlx_worker]}]}, [{:erl_eval, :try_clauses, 10, [file: 'erl_eval.erl', line: 995]}, {:erl_eval, :exprs, 2, []}]}
```

At the end of the Jepsen test, there are 2 DLX workers on the same node.

Analysing the logs reveals the following:

Source quorum queue node becomes leader and starts its DLX worker:
```
2023-03-18 12:14:04.365295+00:00 [debug] <0.1645.0> started rabbit_fifo_dlx_worker <0.3596.0> for queue 'jepsen.queue' in vhost '/'
```
Less than 1 second later, Mnesia reports a network partition (introduced
by Jepsen).
The DLX worker does not succeed to register as consumer to its source quorum queue because the Ra command times out:
```
2023-03-18 12:15:04.365840+00:00 [warning] <0.3596.0> Failed to process command {dlx,{checkout,<0.3596.0>,32}} on quorum queue leader {'%2F_jepsen.queue',
2023-03-18 12:15:04.365840+00:00 [warning] <0.3596.0>                                                                                  'rabbit@concourse-qq-jepsen-312-3'}: {timeout,
2023-03-18 12:15:04.365840+00:00 [warning] <0.3596.0>                                                                                                                        {'%2F_jepsen.queue',
2023-03-18 12:15:04.365840+00:00 [warning] <0.3596.0>                                                                                                                         'rabbit@concourse-qq-jepsen-312-3'}}
2023-03-18 12:15:04.365840+00:00 [warning] <0.3596.0> Trying 5 more time(s)...
```
3 seconds after the DLX worker got created, the local source quorum queue node is not leader anymore:
```
2023-03-18 12:14:07.289213+00:00 [notice] <0.1645.0> queue 'jepsen.queue' in vhost '/': leader -> follower in term: 17 machine version: 3
```
But because the DLX worker at this point failed to register as consumer, it will not be terminated in
865d533863/deps/rabbit/src/rabbit_fifo_dlx.erl (L264-L275)

Eventually, when the local node becomes a leader again, that DLX worker succeeds to register
as consumer (due to retries in 865d533863/deps/rabbit/src/rabbit_fifo_dlx_client.erl (L41-L58)),
and stays alive. When that happens, there is a 2nd DLX worker active because the 2nd
got started when the local quorum queue node transitioned to become a leader.

This commit prevents this issue.
So, last consumer who does a `#checkout{}` wins and the “old one” has to terminate.
2023-03-20 17:54:06 +01:00
Péter Gömöri 4d21184a12 Fix return value of mgmt login handler on bad method
To match what cowboy_handler expects.
2023-03-20 11:13:12 +01:00
Michael Klishin 03bfe0a446 Make CQv2 the new default
CQv2 is significantly more efficient (x2-4 on some workloads),
has lower and more predictable memory footprint, and eliminates
the need to make classic queues lazy to achieve that predictability.

Per several discussions with the team.
2023-03-20 08:37:26 +04:00
Michael Klishin 170862c4be
Merge pull request #7659 from rabbitmq/rin/queue-deleted-events-include-queue-type
Include the queue type in the queue_deleted rabbit_event
2023-03-18 00:14:29 +04:00
David Ansari f5564da94a Fix flaky test rabbit_mqtt_qos0_queue_overflow
The test always succeeds on `main` branch.

The test also always succeeds on `mc` branch when running remotely:
```
bazel test //deps/rabbitmq_mqtt:reader_SUITE --test_env FOCUS="-group tests -case rabbit_mqtt_qos0_queue_overflow" --config=rbe-25 -t- --runs_per_test=50
```

However, the test flakes when running on `mc` branch locally on the MAC:
```
make -C deps/rabbitmq_mqtt ct-reader t=tests:rabbit_mqtt_qos0_queue_overflow FULL=1
```
with the following local changes:
```
~/workspace/rabbitmq-server/deps/rabbitmq_mqtt mc *6 !1 >                                                                                                                                                                                                                                                  3s direnv rb 2.7.2
diff --git a/deps/rabbitmq_mqtt/test/reader_SUITE.erl b/deps/rabbitmq_mqtt/test/reader_SUITE.erl
index fb71eae375..21377a2e73 100644
--- a/deps/rabbitmq_mqtt/test/reader_SUITE.erl
+++ b/deps/rabbitmq_mqtt/test/reader_SUITE.erl
@@ -27,7 +27,7 @@ all() ->

 groups() ->
     [
-     {tests, [],
+     {tests, [{repeat_until_any_fail, 30}],
       [
        block_connack_timeout,
        handle_invalid_packets,
@@ -43,7 +43,7 @@ groups() ->
     ].

 suite() ->
-    [{timetrap, {seconds, 60}}].
+    [{timetrap, {minutes, 60}}].

 %% -------------------------------------------------------------------
 %% Testsuite setup/teardown.
```
failes prior to this commit after the 2nd time and does not fail after
this commit.
2023-03-17 15:54:33 +00:00
Rin Kuryloski fd23782444 Also include the kind in queue_deleted events for transient queues
These will always be rabbit_classic_queue queues
2023-03-17 11:50:14 +01:00
Rin Kuryloski c61d16c971 Include the queue type in the queue_deleted rabbit_event
This is useful for understanding if a deleted queue was matching any
policies given the more selective policies introduced in #7601.

Does not apply to bulk deletion of transient queues on node down.
2023-03-17 11:50:14 +01:00
Rin Kuryloski f73145bd93
Fix rabbit_policy:match_all/2 (#7654)
When rabbit_policy:match_all/2 is called with a name of a queue

look up the queue type to correctly match the extra policy granularity
added in #7601
2023-03-16 17:24:28 +01:00
Arnaud Cogoluègnes e9f2fa41ce
Take credits for inactive stream subscription
Not taking the credits can starve the subscription,
making it permanently under its credit send limit.

The subscription then never dispatches messages when
it becomes active again.

This happens in an active-inactive-active cycle, especially
with slow consumers.
2023-03-16 11:59:58 +01:00
Rin Kuryloski 7acfc4ed98
Merge pull request #7619 from rabbitmq/rin/bazel-rabbitmqctl-skip-test-deps
Avoid fetching test deps when building rabbitmqctl with bazel
2023-03-16 10:02:48 +01:00
Michael Klishin aedd6cb6ff
Merge pull request #7620 from markus812498/add-cli-streams-help
added :streams to the help command scopes
2023-03-15 18:57:20 +04:00
Rin Kuryloski 8e7e891589 Avoid fetching test deps when building rabbitmqctl with bazel 2023-03-15 11:54:37 +01:00
Rin Kuryloski eba1d531c9 Fetch cli prod deps via bazel or erlang.mk instead of mix
In preparation for offline bazel builds
2023-03-14 23:11:36 +01:00
Michael Klishin bb78f77aa4
Merge pull request #7548 from cloudamqp/vm_memory_stream_coordinator
Fix rabbit_vm:memory returning stream_queue_coordinator_procs
2023-03-14 21:56:08 +04:00
Kjell Winblad 5d04d8357d
Remove missleading text
The text mentioned that instructions would follow which is not the case.
2023-03-14 18:03:36 +01:00
Arnaud Cogoluègnes 8f99839ff9
Use x-stream-max-segment-size-bytes in STOMP tests 2023-03-14 14:11:41 +01:00
Arnaud Cogoluègnes 889a63493d
Support x-stream-max-segment-size-bytes in STOMP plugin
To be able to set the max segment size of the created
stream when using a "/queue/<name>" destination.
2023-03-14 13:48:56 +01:00
Michael Klishin 9f6ea7bf1e
Merge pull request #7601 from rabbitmq/policy-by-queue-type
Allow applying policies to specific queue types
2023-03-14 12:51:59 +04:00
Michal Kuratczyk 0a3136a916
Allow applying policies to specific queue types
Rather than relying on queue name conventions, allow applying policies
based on the queue type. For example, this allows multiple policies that
apply to all queue names (".*") that specify different parameters for
different queue types.
2023-03-13 12:36:48 +01:00
David Ansari 64d4e4f63a MQTT: Fix 3.12-beta.1 cluster creation
Deploying a 5 node RabbitMQ cluster with rabbitmq_mqtt plugin enabled
using the cluster-operator with rabbitmq image
rabbitmq:3.12.0-beta.1-management often fails with the following
error:
```
Feature flags: failed to enable `delete_ra_cluster_mqtt_node`:
{error,
    {no_more_servers_to_try,
        [{error,
            noproc},
        {error,
            noproc},
        {timeout,
            {mqtt_node,
                'rabbit@mqtt-rabbit-3-12-server-2.mqtt-rabbit-3-12-nodes.default'}}]}}
```

During rabbitmq_mqtt plugin start, the plugin decides whether it should
create a Ra cluster:
If feature flag delete_ra_cluster_mqtt_node is enabled, no Ra cluster
gets created.
If this feature flag is disabled, a Ra cluster is created.

Even though all feature flags are enabled by default for a fresh
cluster, the feature flag subsystem cannot provide any promise when feature
flag migration functions run during the boot process:
The migration functions can run before plugins are started or many
seconds after plugins are started.
There is also no API that tells when feature flag initialisation on the
local node is completed.

Therefore, during a fresh 3.12 cluster start with rabbitmq_mqtt enabled,
some nodes decide to start a Ra cluster (because not all feature flags
are enabled yet when the rabbitmq_mqtt plugin is started).
Prior to this commit, when the feature flag delete_ra_cluster_mqtt_node
got enabled, Ra cluster deletion timed out because the Ra cluster never got
initialised successfully: Members never proceeded past the pre-vote
phase because their Ra peers already had feature flag delete_ra_cluster_mqtt_node
enabled and therefore don't participate.

One possible fix is to remove the feature flag delete_ra_cluster_mqtt_node
and have the newly upgraded 3.12 node delete its Ra membership during a
rolling update. However, this approach is too risky because during a
rolling update of a 3 node cluster A, B, and C the following issue
arises:
1. C upgrades successfully and deletes its Ra membership
2. B shuts down. At this point A and B are members of the Ra cluster
   while only A is online (i.e. not a majority). MQTT clients which try
   to re-connect to A fail because A times out registering the client in
   ad5cc7e250/deps/rabbitmq_mqtt/src/rabbit_mqtt_processor.erl (L174-L179)

Therefore this commit fixes 3.12 cluster creation as follows:
The Ra cluster deletion timeout is reduced from 60 seconds to 15 seconds,
and the Ra server is force deleted if Ra cluster deletion fails.
Force deleting the server will wipe the Ra cluster data on disk.
2023-03-11 14:23:51 +00:00
Michael Klishin f27fa063fc etcd: do not filter out node TTL
Closes #7554
2023-03-11 02:58:23 +04:00
Jean-Sébastien Pédron e31fe383a4
rabbit_feature_flags: Improve `feature_props_extended()` spec
The `provided_by` field is required. This permitted to discover a wrong
spec of `rabbit_ff_registry:get/1`.

While here, sort `feature_props_extended()` fields like
`feature_props()`.
2023-03-10 09:25:42 +01:00
Jean-Sébastien Pédron 091d756d97
rabbitmq_cli: Fix invalid feature flag definitions
`desc` was set to binaries instead of strings.
2023-03-10 09:25:42 +01:00
Jean-Sébastien Pédron 7a42c485f6
amqqueue: Fix spec of `#amqqueue{}`
`policy` and `operator_policy` store the policy properties, not the
policy name. Therefore, it is a proplist, not a binary.
2023-03-10 09:25:38 +01:00
Michael Klishin 9d72450f93
Merge pull request #7552 from rabbitmq/return-precondition-failed-on-exchange-deletion-if-unused 2023-03-10 10:14:22 +04:00
Luke Bakken 981b0740e7
Add two file rotation test cases
Related to #7415
2023-03-09 12:59:49 -08:00
Aitor Perez Cedres 9c198d3df4
Document set_permissions_globally CLI command
Signed-off-by: Aitor Perez Cedres <acedres@vmware.com>
2023-03-09 16:06:23 +00:00
Péter Gömöri 21e1d8655d Fix rabbit_vm:memory stream_queue_coordinator_procs always zero
The memory of rabbit_stream_coordinator process was reported as other,
because there was a mismatch in ancestors. It is not under
`ra_server_sup_sup` any more but:
`[_,ra_coordination_server_sup_sup,_,ra_systems_sup,ra_sup,_]`

Instead of ancestors use its registered name to categorize it.
2023-03-09 16:26:41 +01:00
Arnaud Cogoluègnes e8fbb09efc
Return "precondition failed" on exchange deletion if appropriate
If unused flag is set. This keeps the original behavior.
2023-03-09 09:51:55 +01:00
markus812498 e676ab7067 added :streams to the help command scopes 2023-03-09 15:01:05 +13:00
Michael Klishin dff78e1c9f
Merge pull request #7540 from rabbitmq/add-erlang-25.3-to-matrix 2023-03-08 21:35:43 +04:00
Rin Kuryloski ba9c43de16 Fix a dialyzer error revealed by otp 25.3 2023-03-08 17:41:38 +01:00
Jean-Sébastien Pédron 746373a50b
Merge pull request #7534 from rabbitmq/fix-rabbit_db_cluster-members-for-ram-nodes
rabbit_db_cluster: Figure out members list even if Mnesia is stopped
2023-03-08 16:26:29 +01:00
Diana Parra Corbacho 35465562aa Improve test assertions to include `rabbit_nodes` ouput 2023-03-08 15:12:08 +01:00
Michal Kuratczyk 87c688bc45
Fix reached_target_cluster_size() after recent changes 2023-03-08 12:11:34 +01:00
Jean-Sébastien Pédron f8b29ea772
rabbit_db_cluster: Figure out members list even if Mnesia is stopped
[Why]
If Mnesia is stopped and the local node is a disk-less member, the list
returned by `mnesia:system_info(db_nodes)` will be empty. This is
problematic for any users of this list of members obviously.

[How]
The `members_using_mnesia/0` function copies the logic of
`rabbit_mnesia:cluster_status/1` but simplifies it to only work with all
members (not running members or disk members). Therefore, if Mnesia is
not running, we look at the cluster status files stored on disk. If they
are missing, the code falls back to a list made of the local node name
only.
2023-03-08 11:21:40 +01:00
David Ansari 4c602b7698 Add validator for non negative integer
A value of 0 means overload protection is disabled.
A negative value doesn't really make sense.
2023-03-07 14:35:28 +01:00
David Ansari d72ff9248b Expose mqtt.mailbox_soft_limit via Cuttlefish 2023-03-07 14:35:28 +01:00
Loïc Hoguin 0dce848549
CQ: Confirm related optimisations (#7516)
* CQ: Optimise shared store remove when nothing to remove

The message(s) was/were already optimised out during write
when the client acked faster than we could process the
write message.

* Optimise sets:subtract in single-confirm case

This happens due to message store optimisations that tries
to confirm as fast as possible on write or ack, even if that
means processing a single confirm. The ack scenario is common
because clients tend to not be built for multi-ack.

The optimisation avoids calling an expensive sets:subtract/2
when there is a single new confirm and instead does a
sets:del_element/2 of the first set.
2023-03-06 14:22:18 +01:00
David Ansari 942c4ab542 Add missing BEAM file
to fix failing Bazel test
2023-03-02 10:25:07 +01:00
David Ansari dd372619f8 Add missing exchange write access check
when an MQTT will message is published.
2023-03-02 10:25:07 +01:00
Jean-Sébastien Pédron 3b6b8ef769
Merge pull request #7476 from rabbitmq/remove-dead-code-in-per_user_connection_channel_tracking_SUITE
per_user_connection_channel_tracking_SUITE: Remove dead code
2023-03-01 12:57:41 +01:00
David Ansari dfc2ee634b Use integer as will message correlation
Instead of using atom `undefined`, use an integer as correlation term
when sending the will message to destination queues.

Classic queue clients for example expect a non negative integer.
Quorum queues expect any term.
2023-03-01 12:52:44 +01:00
Jean-Sébastien Pédron 0fad97f5d5
per_user_connection_channel_tracking_SUITE: Remove dead code
This code became unused when the `tracking_records_in_ets` feature flag
was made required and its compatibility code was removed.

Seee #7270.
2023-03-01 12:16:16 +01:00
Rin Kuryloski e66e5ed62d Pin rabbitmq_cli non-test deps
- Use the same stdout_formatter copy for both erlang and rabbitmq_cli
- Use the same observer_cli copy for both erlang and rabbitmq_cli
2023-03-01 09:54:35 +01:00
Rin Kuryloski 043a8d8971
Merge pull request #7463 from rabbitmq/rin/mark-test-deps-as-such
Mark test deps as such
2023-03-01 09:23:05 +01:00
Rin Kuryloski ced6520dee Mark additional rules as testonly 2023-02-28 21:36:49 +01:00
Rin Kuryloski 5cefbef029 Mark rabbitmq_ct_helpers/rabbitmq_ct_client_helpers as testonly 2023-02-28 21:20:32 +01:00
Michael Klishin 203b5bda41
Merge pull request #7458 from rabbitmq/fix-2549
Fix 2549 - auth_oauth2.preferred_username_claims should accept multiple values
2023-02-28 20:19:06 +04:00
Jean-Sébastien Pédron e85ca4e096
rabbit_db*: Fix EDoc syntax errors
It's easy to mix `...` from Markdown and `...' from EDoc.

While here, wrap too long lines.
2023-02-28 14:45:44 +01:00
Marcial Rosales 42b821f0e9 Add missing pem file 2023-02-28 14:10:00 +01:00
Marcial Rosales efb1b5bd10 Fix 2549
Allow list of preferred_username_claims in cuttlefish
config style.
Use new config style on two selenium test suites
Test oauth2 backend's config schema and oauth2 management
config schema
2023-02-28 10:38:28 +01:00
David Ansari 0058380fbd Web MQTT: Send CONNACK error code before closing connection
"If the Client supplies a zero-byte ClientId with CleanSession set to 0,
the Server MUST respond to the CONNECT Packet with a CONNACK return code 0x02
(Identifier rejected) and then close the Network Connection" [MQTT-3.1.3-8].

In Web MQTT, the CONNACK was not sent to the client because the Web MQTT
connection process terminated before being sending the CONNACK to the
client.
2023-02-28 10:33:57 +01:00
aubbiali 64957b0251 Added documentation for decommission_mqtt_node 2023-02-28 08:25:26 +01:00
Michael Klishin 8abcc634a9
Merge pull request #7445 from rabbitmq/lukebakken/fix-remote_shell-win32
Fix remote_shell on win32
2023-02-27 22:17:00 +04:00
Luke Bakken 96c3560986
Fix remote_shell on win32
This command requires werl.exe. In OTP 26, this will still work because werl.exe is the same as erl.exe
2023-02-27 08:49:58 -08:00
Karl Nilsson cb3407564b
Chunk quorum queue deliveries (#7175)
This puts a limit to the amount of message data that is added
to the process heap at the same time to around 128KB.

Large prefetch values combined with large messages could cause
excessive garbage collection work.

Also similify the intermediate delivery message format to avoid
allocations that aren't necessary.
2023-02-27 15:30:20 +00:00
Loïc Hoguin 74ce1a4bcc
Fix rabbitmq-diagnostics remote_shell for 26.0 (#7441) 2023-02-27 15:27:32 +01:00
Michael Klishin dd90d64a77
rabbitmqctl(8): move hash_password next to clear_password 2023-02-27 16:19:56 +04:00
Luke Bakken f420487e5e
Add documentation for hashing passwords
Fixes #7432

Adds HTTP API documentation as well as `rabbitmqctl hash_password` docs.

Add `rabbitmqctl` docs
2023-02-26 15:16:38 -08:00
Michael Klishin 659f16b21b
Merge pull request #7433 from rabbitmq/amazon-mq-preset-users
Add users on vhost creation per default_users config (with naming changes)
2023-02-26 14:25:11 +04:00
Michael Klishin 5e9e2f2ba1
Naming 2023-02-26 13:27:35 +04:00
Michael Klishin c3c31a6ddb
Remove a duplicate mapping 2023-02-26 13:02:44 +04:00
David Dutkovský 74cdb21397
Fix typo 2023-02-25 23:30:23 +04:00
Luke Bakken a5b3d6357b
Add bazel thingie for unit_password_hashing_SUITE 2023-02-25 09:57:07 -08:00
Luke Bakken d9d6e1bef6
Move rabbit_password to rabbit_common
This allows `rabbitmqctl hash_password` to run without having RabbitMQ up.

Follow-up to:
* #5957
* #7003
2023-02-25 09:53:46 -08:00
Alex Valiushko 89582422f5 Add default_users per #7208 2023-02-24 15:41:25 -08:00
David Dutkovský c243737214
Fix typo 2023-02-24 22:07:03 +01:00
Rin Kuryloski ff7f2c279b Reduce the default number of attempts to start the broker in tests
With the containerized CI environment, port conflicts are much less
likely, so reducing the attempt count improves the feedback loop
2023-02-23 13:25:14 +01:00
Michael Klishin fbe83e4b9d
Merge branch 'main' into rabbitmq-server-7262 2023-02-23 12:33:35 +04:00
Luke Bakken b0d2f94eed
Remove RABBITMQ_ERLANG_COOKIE warning
Fixes #7262
2023-02-22 13:09:01 -08:00
Simon Unge d66b38d333 See #7323. Rename default policy for ha-* and add option to massage key/value for aggregate_props 2023-02-22 11:46:03 -08:00
Michael Klishin 232c7faece
Merge branch 'main' into ha-mode-operator-policy 2023-02-22 20:21:59 +04:00
Jean-Sébastien Pédron cd2b4c7585
Use `rabbit_nodes` to list nodes in two plugins
... instead of using an internal implementation.

The plugins are `rabbitmq_peer_discovery_common` and
`rabbitmq_sharding`.

References #7058.
2023-02-22 15:28:04 +01:00
Jean-Sébastien Pédron 42bcd94dce
rabbit_db_cluster: New module on top of databases clustering
This new module sits on top of `rabbit_mnesia` and provide an API with
all cluster-related functions.

`rabbit_mnesia` should be called directly inside Mnesia-specific code
only, `rabbit_mnesia_rename` or classic mirrored queues for instance.
Otherwise, `rabbit_db_cluster` must be used.

Several modules, in particular in `rabbitmq_cli`, continue to call
`rabbit_mnesia` as a fallback option if the `rabbit_db_cluster` module
unavailable. This will be the case when the CLI will interact with an
older RabbitMQ version.

This will help with the introduction of a new database backend.
2023-02-22 15:28:04 +01:00
Jean-Sébastien Pédron a826b5720c
rabbit_process: Move process liveness functions here from `rabbit_mnesia`
These functions extend the functionality of `erlang:is_process_alive/1`
to take into account the node a process is running on and its cluster
membership.

These functions are moved away from `rabbit_mnesia` because we don't
want `rabbit_mnesia` to be a central piece of RabbitMQ.

Classic-mirrored-queue-related modules continue to use `rabbit_mnesia`
functions, therefore relying on Mnesia, because they depend entirely on
Mnesia anyway. They will go away at the same time as our use of Mnesia.
So by keeping this code untouched, we avoid possible regressions.
2023-02-22 15:28:00 +01:00
Simon b55465bf70
Merge branch 'main' into ha-mode-operator-policy 2023-02-21 11:49:29 -08:00
Simon Unge 245a5e07b3 See #7323. Add ha-mode and ha-params to default_policies 2023-02-21 11:45:49 -08:00
Simon Unge 36a559da51 See #7323. Cleanup testcase. 2023-02-21 11:33:47 -08:00
David Ansari bf2a97a20a Bump emqx/emqtt to 1.8.2 2023-02-21 17:25:19 +01:00
Michael Klishin 04ec916d54
Merge branch 'main' into ha-mode-operator-policy 2023-02-21 18:41:06 +04:00
Marcial Rosales 20269bf222 Fix issue #7369
Depending on `disable_stats` value
search for detailed exchange details or
basic details
2023-02-21 13:11:45 +01:00
Marcial Rosales 89ee77e5ec Improve how to look for elements and wait for them 2023-02-21 13:07:37 +01:00
Jean-Sébastien Pédron a4e8cdda58
rabbit_feature_flags: Support required feature flags in plugins
[Why]
If a plugin was already enabled when RabbitMQ starts, its required
feature flags were correctly handled and thus enabled. However, this was
not the case for a plugin enabled at runtime.

Here is an example with the `drop_unroutable_metric` from the
rabbitmq_management_agent plugin:

    Feature flags: `drop_unroutable_metric`: required feature flag not
    enabled! It must be enabled before upgrading RabbitMQ.

Supporting required feature flags in plugin is trickier than in the
core broker. Indeed, with the broker, we know when this is the first
time the broker is started. Therefore we are sure that a required
feature flag can be enabled directly, there is no existing data/context
that could conflict with the code behind the required feature flag.

For plugins, this is different: a plugin can be enabled/disabled at
runtime and between broker restarts (and thus upgrades). So, when a
plugin is enabled and it has a required feature flag, we have no way to
make sure that there is no existing and conflicting data/context.

[How]
In this patch, if the required feature flag is provided by a plugin
(i.e. not `rabbit`), we always mark it as enabled.

The plugin is responsible for handling any existing data/context and
perform any cleanup/conversion.

Reported by: @ansd
2023-02-20 10:56:36 +01:00
David Ansari 2dc45e8084 Fix flaky MQTT Java test
Every ~30 runs, test case `sessionRedelivery` was failing with error:
```
[ERROR] sessionRedelivery{TestInfo}  Time elapsed: 1.298 s  <<< ERROR!
org.eclipse.paho.client.mqttv3.MqttException: Client is currently disconnecting
	at com.rabbitmq.mqtt.test.MqttTest.sessionRedelivery(MqttTest.java:535)
```

The problem was that the Java client was still in connection state
`DISCONNECTING` which throws a Java exception when `connect()`ing.

So, the problem was client side.

We already check for `isConnected()` to be `false` which internally
checks for
```
conState == CONNECTED
```
However, there is no public client API to check for other connection
states. Therefore just waiting for a few milliseconds fixes the flake.
2023-02-20 10:42:18 +01:00
Simon Unge a22486211a See #7323. Oper policy for ha-mode and ha-params 2023-02-17 12:13:56 -08:00
Michal Kuratczyk 1b9179805d
Faster node startup with many classic queues (#7326)
* Faster node startup with many classic queues

On my machines, in a test with 100k queues, node startup goes down from
4-5 minutes to roughly 1 minute. The difference will be even larger with
more queues as `lists:member` gets very expensive with a long list.
2023-02-17 08:51:09 +01:00
David Ansari b165adb958 Add timeout for test AMQP 0.9.1 connection to open
We see sporadic test failures where a test case hangs in the
receive until the Bazel suite timeout is reached.

There is no point in a test case to wait forever for an AMQP 0.9.1
connection to establish. Let's time out after 1 minute.

This will make the test case fail faster.
2023-02-16 19:25:06 +01:00
Michael Klishin 914810b923
Merge pull request #7328 from rabbitmq/rename-cli-tanzu-scope 2023-02-16 11:25:10 -03:00
Rin Kuryloski 609171ec70 Rename the tanzu cli scope to vmware
And update other references to commercial editions
2023-02-16 13:49:54 +01:00
Michael Klishin 634f9b602f
Merge pull request #7270 from rabbitmq/ff-tracking-records-in-ets
Remove compatibility for flag tracking_records_in_ets
2023-02-16 09:44:46 -03:00
Michael Klishin 108c31fc60
Merge pull request #7268 from rabbitmq/remove-unused-catch
Remove unused catch clauses
2023-02-16 09:41:38 -03:00
Rin Kuryloski b77435660f
Merge pull request #7315 from rabbitmq/rin/eetcd-dialyzer-update
Use the latest rules_erlang
2023-02-16 12:59:03 +01:00
Rin Kuryloski 1bef97af2e Add missing dep to //deps/rabbitmq_aws:eunit test 2023-02-16 12:31:40 +01:00
Diana Parra Corbacho cbb4efd893 Remove unnecessary boot step 2023-02-16 10:20:09 +01:00
Rin Kuryloski 60093eeb50 Adjust the size of //deps/rabbit:bindings_SUITE to medium
generally speaking, rabbitmq_integration_suite tests do not reliably
run in under the 60s timeout implied by "small", at least in CI
2023-02-15 21:04:14 +01:00
David Ansari 4d7403cb62 Delete rabbit_stream_SUITE setup steps
since these feature flags became required in 3.12.
2023-02-15 17:01:59 +00:00
Rin Kuryloski 185e910e0f Update the note about eetcd and dialyzer
now that the original issue has been resolved. We cannot bump gun just
yet, as eetcd is not yet compatible with gun 2.0.0

https://github.com/zhongwencool/eetcd/issues/28
https://github.com/zhongwencool/eetcd/pull/55
2023-02-15 16:39:27 +01:00
Marcial Rosales 9ab7dca650 Fix issue 7301 2023-02-15 14:29:55 +01:00
Loïc Hoguin c7845f8003
CQ: Remove compat code for classic_mirrored_queue_version 2023-02-15 12:37:21 +01:00
Diana Parra Corbacho 56e4ed5464 Remove compatibility for flag tracking_records_in_ets 2023-02-14 22:51:57 +01:00
Rin Kuryloski f827490171
Merge pull request #7286 from rabbitmq/rin/add-v3.12.x-references
Add additional v3.12.x references
2023-02-14 18:28:51 +01:00
Rin Kuryloski 93be82d09f Add 3.13.0 as an allowed version in the test plugin in cli tests 2023-02-14 18:11:23 +01:00
Michael Klishin 6128c851ab
Merge pull request #7281 from rabbitmq/ff-listener-records-in-ets
Remove compatibility for flag listener_records_in_ets
2023-02-14 13:41:40 -03:00
Michael Klishin 8ac0829c15
Merge pull request #7196 from rabbitmq/dialyzer-enable-Wunkown
Fix all dependencies for the dialyzer
2023-02-14 13:41:22 -03:00
Michael Klishin 12558a9900
Merge pull request #7283 from rabbitmq/rin/align-some-specs
Update the spec for rabbit_binding:new/4 to match rabbit_types
2023-02-14 13:27:40 -03:00
Diana Parra Corbacho dceb600136 Refactor 2023-02-14 16:28:34 +01:00
David Ansari 97634e9099 Add rabbit_queue_type:is_enabled/1
This commits partially reverts 575f4e78bc

Function `rabbit_queue_type:is_enabled/1` seems to be useful for future
queue types.

See https://github.com/rabbitmq/rabbitmq-server/pull/7269#issuecomment-1429838579
2023-02-14 14:51:11 +00:00
Rin Kuryloski b63a9de362 Update the spec for rabbit_binding:new/4 to match rabbit_types 2023-02-14 15:22:34 +01:00
Michael Klishin 5a8e74ed5d
Merge pull request #7280 from rabbitmq/rin/rabbit_vhost-update_tags-skip-notify-if-unchanged
rabbit_vhost:set_tags/2 avoids notifying if tags are unchanged
2023-02-14 06:46:05 -03:00
Rin Kuryloski 0476d105d1 Tighten some test assertions 2023-02-14 10:13:38 +01:00
Diana Parra Corbacho e4b04583ec Remove compatibility for flag listener_records_in_ets 2023-02-14 10:10:11 +01:00
Michael Klishin d0dc951343
Merge pull request #7058 from rabbitmq/add-node-lists-functions-to-clarify-intent
rabbit_nodes: Add list functions to clarify which nodes we are interested in
2023-02-13 23:06:50 -03:00
Michael Klishin 054381a99b
Merge pull request #7269 from rabbitmq/ff-stream_queue
Remove compatibility for feature flag stream_queue
2023-02-13 22:35:08 -03:00
Michael Klishin aec92b14d9
Merge pull request #7266 from rabbitmq/ff-direct_exchange_routing_v2
Remove compatibility for flag direct_exchange_routing_v2
2023-02-13 22:30:43 -03:00
Michael Klishin b670273cbc
Merge pull request #7265 from rabbitmq/ff-stream_single_active_consumer
Remove compatibility for flag stream_single_active_consumer
2023-02-13 22:26:39 -03:00
Michael Klishin 9beda74d86
Sort tags before comparing them in this test
now that the server sorts and deduplicates them
2023-02-13 22:16:21 -03:00
Rin Kuryloski f87a5512c1 Relax and assertion which may vary when run not in isolation 2023-02-13 21:28:28 +01:00
Rin Kuryloski 12ec3a55ff rabbit_vhost:set_tags/2 avoids notifying if tags are unchanged
Additionally, tags are now always sorted when set
2023-02-13 20:38:25 +01:00
Alexey Lebedeff 949b53543d Fix all dependencies for the dialyzer
This is the latest commit in the series, it fixes (almost) all the
problems with missing and circular dependencies for typing.

The only 2 unsolved problems are:

- `lg` dependency for `rabbit` - the problem is that it's the only
  dependency that contains NIF. And there is no way to make dialyzer
  ignore it - looks like unknown check is not suppressable by dialyzer
  directives. In the future making `lg` a proper dependency can be a
  good thing anyway.

- some missing elixir function in `rabbitmq_cli` (CSV, JSON and
  logging related).

- `eetcd` dependency for `rabbitmq_peer_discovery_etcd` - this one
  uses sub-directories in `src/`, which confuses dialyzer (or our bazel
  machinery is not able to properly handle it). I've tried the latest
  rules_erlang which flattens directory for .beam files, but it wasn't
  enough for dialyzer - it wasn't able to find core erlang files. This
  is a niche plugin and an unusual dependency, so probably not worth
  investigating further.
2023-02-13 17:37:44 +01:00
David Ansari 415b341b3a Fix dialyzer issue 2023-02-13 16:17:44 +00:00
David Ansari 575f4e78bc Remove compatibility for feature flag stream_queue
Remove compatibility code for feature flag `stream_queue`
because this feature flag is required in 3.12.

See #7219
2023-02-13 15:31:40 +00:00
Diana Parra Corbacho a521603a39 Remove unused catch clauses
Delete functions now do not check vhost or user existance, they just
return ok if the entry is no longer on the metadata store.
2023-02-13 15:48:01 +01:00
David Ansari efa56bf0cc Fix flaky test
Very rarely, the assertion failed with
```
=== Ended at 2023-02-13 13:25:52
=== Location: [{shared_SUITE,global_counters,590},
              {test_server,ts_tc,1782},
              {test_server,run_test_case_eval1,1291},
              {test_server,run_test_case_eval,1223}]
=== === Reason: {assertEqual,
                     [{module,shared_SUITE},
                      {line,590},
                      {expression,"get_global_counters ( Config , ProtoVer )"},
                      {expected,
                          #{consumers => 0,messages_confirmed_total => 2,
                            messages_received_confirm_total => 2,
                            messages_received_total => 5,
                            messages_routed_total => 3,
                            messages_unroutable_dropped_total => 1,
                            messages_unroutable_returned_total => 1,
                            publishers => 0}},
                      {value,
                          #{consumers => 1,messages_confirmed_total => 2,
                            messages_received_confirm_total => 2,
                            messages_received_total => 5,
                            messages_routed_total => 3,
                            messages_unroutable_dropped_total => 1,
                            messages_unroutable_returned_total => 1,
                            publishers => 1}}]}
  in function  shared_SUITE:global_counters/2 (shared_SUITE.erl, line 590)
  in call from test_server:ts_tc/3 (test_server.erl, line 1782)
  in call from test_server:run_test_case_eval1/6 (test_server.erl, line 1291)
  in call from test_server:run_test_case_eval/9 (test_server.erl, line 1223)
```

The DISCONNECT packet is sent one-way from client to server.
2023-02-13 14:14:14 +00:00
David Ansari e1b336ff70 Remove compatibility for flag direct_exchange_routing_v2
Remove compatibility code for feature flag direct_exchange_routing_v2
because this feature flag is required in 3.12.

See #7219
2023-02-13 13:20:29 +00:00
Jean-Sébastien Pédron d65637190a
rabbit_nodes: Add list functions to clarify which nodes we are interested in
So far, we had the following functions to list nodes in a RabbitMQ
cluster:
* `rabbit_mnesia:cluster_nodes/1` to get members of the Mnesia cluster;
  the argument was used to select members (all members or only those
  running Mnesia and participating in the cluster)
* `rabbit_nodes:all/0` to get all members of the Mnesia cluster
* `rabbit_nodes:all_running/0` to get all members who currently run
  Mnesia

Basically:
* `rabbit_nodes:all/0` calls `rabbit_mnesia:cluster_nodes(all)`
* `rabbit_nodes:all_running/0` calls `rabbit_mnesia:cluster_nodes(running)`

We also have:
* `rabbit_node_monitor:alive_nodes/1` which filters the given list of
  nodes to only select those currently running Mnesia
* `rabbit_node_monitor:alive_rabbit_nodes/1` which filters the given
  list of nodes to only select those currently running RabbitMQ

Most of the code uses `rabbit_mnesia:cluster_nodes/1` or the
`rabbit_nodes:all*/0` functions. `rabbit_mnesia:cluster_nodes(running)`
or `rabbit_nodes:all_running/0` is often used as a close approximation
of "all cluster members running RabbitMQ". This list might be incorrect
in times where a node is joining the clustered or is being worked on
(i.e. Mnesia is running but not RabbitMQ).

With Khepri, there won't be the same possible approximation because we
will try to keep Khepri/Ra running even if RabbitMQ is stopped to
expand/shrink the cluster.

So in order to clarify what we want when we query a list of nodes, this
patch introduces the following functions:
* `rabbit_nodes:list_members/0` to get all cluster members, regardless
  of their state
* `rabbit_nodes:list_reachable/0` to get all cluster members we can
  reach using Erlang distribution, regardless of the state of RabbitMQ
* `rabbit_nodes:list_running/0` to get all cluster members who run
  RabbitMQ, regardless of the maintenance state
* `rabbit_nodes:list_serving/0` to get all cluster members who run
  RabbitMQ and are accepting clients

In addition to the list functions, there are the corresponding
`rabbit_nodes:is_*(Node)` checks and `rabbit_nodes:filter_*(Nodes)`
filtering functions.

The code is modified to use these new functions. One possible
significant change is that the new list functions will perform RPC calls
to query the nodes' state, unlike `rabbit_mnesia:cluster_nodes(running)`.
2023-02-13 12:58:40 +01:00
David Ansari 2f76102603 Remove compatibility for flag stream_single_active_consumer
Remove compatibility code for feature flag `stream_single_active_consumer`
because this feature flag is `required` in 3.12.

See https://github.com/rabbitmq/rabbitmq-server/pull/7219
2023-02-13 11:52:25 +00:00
Ilia Kurenkov 051419e46b
Fix descriptions of auth metrics. 2023-02-11 23:36:21 +01:00
Michael Klishin 1480fb61fa
Merge pull request #7239 from rabbitmq/mk-ctl-add-vhost-help-typo-fix
ctl add_vhost: minor improvements to help output
2023-02-09 15:40:27 -05:00
Michael Klishin 7b5e8a9955
ctl add_vhost: minor improvements to help output 2023-02-09 15:12:51 -05:00
David Ansari 700c122f9e Add test that MQTT ingores configured default queue type
The queue type being created for MQTT connections is solely determined
by the rabbitmq_mqtt plugin, not by per vhost defaults.

If the per vhost default queue type is configured to be a quorum queue,
we still want to create classic queues for MQTT connections.
2023-02-09 19:18:34 +01:00
David Ansari bd50a41d67 Decrease MQTT mailbox_soft_limit
Let's decrease the mailbox_soft_limit from 1000 to 200.
Obviously, both values are a bit arbitrary.
However, MQTT workloads usually do not have high throughput patterns for
a single MQTT connection. The only valid scenario where an MQTT
connections' process mailbox could have many messages is in large fan-in
scenarios where many MQTT devices sending messages at once to a single MQTT
device - which is rather unusual.

It makes more sense to protect against cluster wide memory alarms by
decreasing the mailbox_soft_limit.
2023-02-09 19:18:34 +01:00
Jean-Sébastien Pédron ddc5b3ee0a
Merge pull request #7228 from rabbitmq/mqtt-ff
Remove mixed version check in MQTT tests
2023-02-09 17:36:58 +01:00
Jean-Sébastien Pédron 10d3242133
rabbit_feature_flags: Fix formatting of the logged list of feature flags
If we don't pass arguments, `?LOG_*()` don't consider the passed string
as a format string, but as the plain message. Therefore, `~n` was not
interpreted.

While here, use `io_lib:format/2` instead of `rabbit_misc:format/2` as
we do a `lists:flatten/1` in the end anyway.
2023-02-09 15:43:03 +01:00
David Ansari 3cd7d80d04 Enable feature flag in test case
Always enable feature flag rabbit_mqtt_qos0_queue
in test case rabbit_mqtt_qos0_queue_overflow because this test case does
not make sense without the mqtt_qos0 queue type.

Note that enabling the feature flag should always succeed because this
test case runs on a single node, and therefore on a new version in mixed
version tests.
2023-02-09 11:17:52 +00:00
David Ansari 91b56bd85d Remove mixed version check in MQTT tests
In the MQTT test assertions, instead of checking whether the test runs
in mixed version mode where all non-required feature flags are disabled
by default, check whether the given feature flag is enabled.

Prior to this commit, once feature flag rabbit_mqtt_qos0_queue becomes
required, the test cases would have failed.
2023-02-09 10:53:50 +00:00
David Ansari db107500c5 Remove compatibility code for management agent feature flags
Remove compatibility code for feature flags
* drop_unroutable_metric
* empty_basic_get_metric

since they are required in 3.12.0.

See https://github.com/rabbitmq/rabbitmq-server/pull/7219
2023-02-09 09:53:46 +00:00
Jean-Sébastien Pédron 869f86161b
Merge pull request #7219 from rabbitmq/require-feature-flags
Require all feature flags introduced before 3.11.1
2023-02-09 10:10:15 +01:00
David Ansari 5045fce6de Require all feature flags introduced before 3.11.1
RabbitMQ 3.12 requires feature flag `feature_flags_v2` which got
introduced in 3.11.0 (see
https://github.com/rabbitmq/rabbitmq-server/pull/6810).

Therefore, we can mark all feature flags that got introduced in 3.11.0
or before 3.11.0 as required because users will have to upgrade to
3.11.x first, before upgrading to 3.12.x

The advantage of marking these feature flags as required is that we can
start deleting any compatibliy code for these feature flags, similarly
as done in https://github.com/rabbitmq/rabbitmq-server/issues/5215

This list shows when a given feature flag was first introduced:

```
classic_mirrored_queue_version 3.11.0
stream_single_active_consumer 3.11.0
direct_exchange_routing_v2 3.11.0
listener_records_in_ets 3.11.0
tracking_records_in_ets 3.11.0

empty_basic_get_metric 3.8.10
drop_unroutable_metric 3.8.10
```

In this commit, we also force all required feature flags in Erlang
application `rabbit` to be enabled in mixed version cluster testing
and delete any tests that were about a feature flag starting as disabled.

Furthermore, this commit already deletes the callback (migration) functions
given they do not run anymore in 3.12.x.

All other clean up (i.e. branching depending on whether a feature flag
is enabled) will be done in separate commits.
2023-02-08 16:00:03 +00:00
Michal Kuratczyk e9f3d9ed49
Ignore stream data folder in rabbit_mnesia:is_virgin_node/0
A Node that hosted a stream replica, may start receiving data as soon as
it starts, in some cases before `rabbit_mnesia:is_virgin_node/0` is
called.

https://github.com/rabbitmq/rabbitmq-server/discussions/7139
2023-02-08 16:52:39 +01:00
David Ansari 327e3da8cb Run MQTT maintenance test in mixed version cluster
Nowadays, the old RabbitMQ nodes in mixed version cluster
tests on `main` branch run in version 3.11.7.

Since maintenance mode was wrongly closing cluster-wide MQTT connections
only in RabbitMQ <3.11.2 (and <3.10.10), we can re-enable this mixed
version test.
2023-02-08 16:26:10 +01:00
Jean-Sébastien Pédron b795d6139f
rabbit_feature_flags: Remove duplicated code
... in the `rabbit_feature_flags` module.

`rabbit_ff_controller` already provides functions to list nodes.
2023-02-08 10:50:13 +01:00
Jean-Sébastien Pédron 78e8c595b1
set_permissions_globally_command_test: Fix "invalid_regex patterns" test expectations
Testcases are executed in a random order. Unfortunately, this testcase
depended on side effects of other testcases. If this testcase was
executed first, then there were no permissions set and the testcase
would fail.

It now lists permissions before and after the actual test and compare
both.
2023-02-08 10:21:10 +01:00
Jean-Sébastien Pédron 271a7babdf
set_permissions_globally_command_test: Always set @user
Otherwise the command causes a `function_clause` exception in the broker
because a `nil` atom is passed as the username instead of a binary.
2023-02-08 10:18:24 +01:00
David Ansari 3432dcb161 Shard shared_SUITE
such that MQTT and WebMQTT tests of the shared_SUITE can run in parallel.
Before this commit, the shared_SUITE runs 14 minutes, after this commit
the shared_SUITE runs 4 minutes in GitHub actions.
2023-02-07 16:36:08 +01:00
David Ansari 146570df5e Delete AMQP 0.9.1 header x-mqtt-dup
AMQP 0.9.1 header x-mqtt-dup was determined by the incoming MQTT PUBLISH
packet's DUP flag. Its only use was to determine the outgoing MQTT
PUBLISH packet's DUP flag. However, that's wrong behaviour because
the MQTT 3.1.1 protocol spec mandates:
"The value of the DUP flag from an incoming PUBLISH packet is not
propagated when the PUBLISH Packet is sent to subscribers by the Server.
The DUP flag in the outgoing PUBLISH packet is set independently to the
incoming PUBLISH packet, its value MUST be determined solely by whether
the outgoing PUBLISH packet is a retransmission."
[MQTT-3.3.1-3]

Native MQTT fixes this wrong behaviour. Therefore, we can delete this
AMQP 0.9.1 header.
2023-02-07 16:36:08 +01:00
David Ansari 5f6a1f96ca Remove unused NodeId parameter 2023-02-07 16:36:08 +01:00
David Ansari bec8f9a21c Support topic variable expansion for vhost and username
Native MQTT introduced a regression where the "{username}" and "{vhost}"
variables were not expanded in permission patterns.

This regression was unnoticed because the java_SUITE's
topicAuthorisationVariableExpansion test was wrongfully passing because
its topic started with "test-topic" which matched another allow listed
topic (namely "test-topic") instead of the pattern
"{username}.{client_id}.a".
This other java_SUITE regression got introduced by commit
26a17e8530

This commit fixes both the buggy Java test and the actual regression
introduced in Native MQTT.
2023-02-07 16:36:08 +01:00
David Ansari 1ba4823495 Delete unused files 2023-02-07 16:36:08 +01:00
David Ansari d7900c127d Log consistently
Some logs already contained "user", others did not.
Let's always log "user" so it's clearer that the String being output is
a user.
2023-02-07 16:36:08 +01:00
David Ansari 804777f575 Explicitly match `maybe` return values 2023-02-07 16:36:08 +01:00
David Ansari 79c12b60bc Use maybe expression instead of messy patterns
This commit is pure refactoring making the code base more maintainable.

Replace rabbit_misc:pipeline/3 with the new OTP 25 experimental maybe
expression because
"Frequent ways in which people work with sequences of failable
operations include folds over lists of functions, and abusing list
comprehensions. Both patterns have heavy weaknesses that makes them less
than ideal."
https://www.erlang.org/eeps/eep-0049#obsoleting-messy-patterns

Additionally, this commit is more restrictive in the type spec of
rabbit_mqtt_processor state fields.
Specifically, many fields were defined to be `undefined | T` where
`undefined` was only temporarily until the first CONNECT packet was
processed by the processor.
It's better to initialise the MQTT processor upon first CONNECT packet
because there is no point in having a processor without having received
any packet.
This allows many type specs in the processor to change from `undefined |
T` to just `T`.
Additionally, memory is saved by removing the `received_connect_packet`
field from the `rabbit_mqtt_reader` and `rabbit_web_mqtt_handler`.
2023-02-07 16:36:08 +01:00
Michael Klishin 802ef318c6
Merge pull request #7176 from rabbitmq/handle-pwd-none-or-empty-authprops
Handle various credentials scenarios while authenticating in the internal backend
2023-02-07 09:44:21 -05:00
David Ansari 67a428a913 Add API functions to behaviour module
Include API functions to the rabbit_mqtt_retained_msg_store
behaviour module.

"There is a best practice to have the behaviour module include
the API also as it helps other parts of the code to be correct
and a bit more dialyzable."

This commit also fixes a bug where the retainer process had only
60 milliseconds shutdown time before being unconditionally killed.
60 milliseconds can be too short to dump a large ETS table containing
many retained messages to disk.
2023-02-07 15:42:16 +01:00
Marcial Rosales 4dee5953f0 Improve wording as per @michaelklishin suggestion 2023-02-07 10:00:07 +01:00
Marcial Rosales 65ffbbc7e8 Unify how SSL authentication is handled
Some modules do not pass empty credentials, i.e., []
other modules pass {password, none} credential
and others no password but {rabbit_auth_backend_internal, Impl}
when the user has already been authenticated by the internal
backend
2023-02-07 10:00:06 +01:00
Michael Klishin 2dfa762bbb
Merge pull request #7177 from rabbitmq/oauth-mqtt-test
Add OAuth 2.0 MQTT system test
2023-02-06 23:18:17 -05:00
Michael Klishin ee5fddc37f
Correct find-and-replace artifact 2023-02-06 22:39:54 -05:00
Michael Klishin 6c6f9c49ae
Naming, references #7165 2023-02-06 22:25:09 -05:00
Alex Valiushko db99c252a0 Add setting to disable op policy edit via API 2023-02-06 14:36:10 -08:00
Michael Klishin 2a9c345b66
Merge pull request #7197 from rabbitmq/rabbitmq-server-1000
Introduce a CLI command that grants permissions to all virtual hosts
2023-02-06 16:33:29 -05:00
Michael Klishin 69add44ce3
CLI: mix format 2023-02-06 15:54:09 -05:00
Michael Klishin ab99ccfa45
Introduce a CLI command that grants permissions to all virtual hosts
Closes #1000
2023-02-06 13:07:09 -05:00
Alexey Lebedeff c7da0da8b8 Cleanup dialyzer calls
- Use the same base .plt everywhere, so there is no need to list
standard apps everywhere
- Fix typespecs: some typos and the use of not-exported types
2023-02-06 17:05:30 +01:00
brunomedeirosdedalus bf2b11d7ba
Fixing the rabbitmq_auth_backend_oauth2 schema
Fixing reference to the old key 'additional_rabbitmq_scopes'. Removing redundant mapping
2023-02-04 11:41:26 +01:00
David Ansari 2d0826c335 Add OAuth 2.0 MQTT system test
Add a test that rabbitmq_auth_backend_oauth2 works with MQTT.

See https://github.com/rabbitmq/rabbitmq-oauth2-tutorial#mqtt-protocol
2023-02-03 14:08:51 +00:00
Rin Kuryloski 1c178a88ab
Merge pull request #7164 from rabbitmq/rin/rabbitmq_amqp1_0-system_SUITE-sharding
Use sharding on //deps/rabbitmq_amqp1_0:system_SUITE
2023-02-03 10:29:36 +01:00
Rin Kuryloski e9b753a598 Remove unused group
The streams case runs already in the dotnet group
2023-02-03 09:47:53 +01:00
Michael Klishin 171f5f8fab
Merge pull request #7159 from rabbitmq/dialyzer-warnings-rabbitmq_prelaunch
Fix all dialyzer warnings in rabbitmq_prelaunch
2023-02-02 22:24:00 -05:00
Michael Klishin 11ab5831a9
Merge pull request #7163 from rabbitmq/rabbitmq-server-7161
Remove extra dollar sign
2023-02-02 21:46:11 -05:00
Luke Bakken ae70ecb7df
Add test for #7161 2023-02-02 14:16:37 -08:00
Rin Kuryloski 44ee48372b Use sharding on //deps/rabbitmq_amqp1_0:system_SUITE
to help mitigate flakiness
2023-02-02 21:25:37 +01:00
Luke Bakken 907a7bebce
Remove extra dollar sign
Not needed with bazel

Fixes #7161
2023-02-02 11:51:07 -08:00
David Ansari 0706cad7a1 Fix pid tracking when decommissioning an MQTT node
Prior to this commit test `deps.rabbitmq_mqtt.cluster_SUITE`
`connection_id_tracking_with_decommissioned_node` was flaky and sometimes
failed with
```
{cluster_SUITE,connection_id_tracking_with_decommissioned_node,160}
{test_case_failed,failed to match connection count 0}
```
2023-02-02 19:33:29 +00:00
Jean-Sébastien Pédron 9a99480bc9
Merge pull request #6821 from rabbitmq/rabbit-db-modules
Move missing Mnesia-specific code to rabbit_db_* modules
2023-02-02 15:40:11 +01:00
Alexey Lebedeff 6b2e7903f8 Fix all dialyzer warnings in rabbitmq_prelaunch 2023-02-02 15:25:50 +01:00
Diana Parra Corbacho 9cf10ed8a7 Unit test rabbit_db_* modules, spec and API updates 2023-02-02 15:01:42 +01:00
Jean-Sébastien Pédron 55cb7ec5d5
rabbit_feature_flags: Fix spec and doc of `get_stability/1'
The return value was incorrectly specified and documented: it can return
`undefined` when a feature flag name is passed and that feature flag is
unknown.

So far, this function is always called with a feature flag properties
map, in which case it doesn't return `undefined`.
2023-02-02 12:25:44 +01:00
Jean-Sébastien Pédron 4d4421f919
rabbit_feature_flags: Fix logging of the list of feature flags
"~~" was ok when the final string was a format string, but it's not
anymore. We need a simple "~".
2023-02-02 12:16:33 +01:00
Jean-Sébastien Pédron aa78bad243
rabbit_feature_flags: Fix experimental feature flags inventory
When we collect feature flag properties from all nodes, we start with an
empty cluster inventory (a common Erlang recursion pattern). This means
that all feature flags are unknown at first.

In `merge_feature_flags()`, we must compute a global stability level for
each feature flag, in case all nodes are not on the same page (like one
nodes considers a feature flag experimental, but another one marks it as
stable). That's why we rank stability level: required > stable >
experimental.

This ranking had one issue: `rabbit_feature_flags:get_stability/1`
defaults to `stable` if a feature flag has not explicit stability set.
Therefore, with our empty starting inventory, the starting stability
would be `stable`. And it would superceed an experimental feature flag
stability level, even though all nodes agree on that.

Now, if a feature flag is missing from our inventory being collected, we
consider its stability level to be experimental. This is different from
a known feature flag with no explicit stability level. This way, we are
sure that feature flags marked as experimental everywhere will be
considered experimental globally.
2023-02-02 12:16:18 +01:00
Michael Klishin 70094e6c1f
Merge pull request #7141 from rabbitmq/send-drained-bug-fix
Fix channel crash when draining AMQP 1.0 credits from classic queue
2023-02-01 21:41:19 -05:00
Michael Klishin 535a0be564
Merge pull request #7149 from rabbitmq/rin/rabbitmq_cli-dialyzer
Forward-port dialyzer related rabbitmq_cli fixes from #7122
2023-02-01 21:35:56 -05:00
Michael Klishin a864cfe70e
Merge pull request #7144 from rabbitmq/fix-7142
Fix issue #7142
2023-02-01 20:46:03 -05:00
Rin Kuryloski 0ac62a4a3b Forward-port dialyzer related rabbitmq_cli fixes from #7122 2023-02-01 23:21:10 +01:00
Marcial Rosales 166faa3629 Test when there are zero limits 2023-02-01 18:13:57 +01:00
Marcial Rosales 5ad72497a3 Test display limits when there are none 2023-02-01 17:42:38 +01:00
Marcial Rosales 3fca42ed7a Fix issue #7142
The issue is that users retrieved with
the intention to list in the limits view
are not paged hence they are not wrapped
around a paging struct where users would be
under items attribute.

Pending selenium tests
2023-02-01 16:42:33 +01:00
Karl Nilsson 3bb32737ee Fix channel crash when draining AMQP 1.0 credits from classic queue
Classic queues used a different format for the `{send_drained, _}`
queue type action which was missed originally. This change handles both
formats in the channel for backwards compatibility
 as well as changes classic queues to conform to the same format when
sending the queue event.

Whilst adding tests for this in the amqp10 plugin another issue around
the amqp10_client and filters was discovered and this commit also includes
improvements in this area. Such as more leninet support of source filters.
2023-02-01 15:34:29 +00:00
Michal Kuratczyk 67c123f91f
Merge pull request #7115 from rabbitmq/cq-perf-regression-fix
CQ: Fix performance regression after moving to v2 sets
2023-02-01 14:40:54 +01:00
Michael Klishin 6fd7b983d8
Merge pull request #7135 from rabbitmq/mk-report-total-core-count-cluster-status
List CPU core count in 'rabbitmq-diagnostics cluster_status'
2023-02-01 06:45:41 -05:00
Arnaud Cogoluègnes 149f3e5d34
Merge pull request #7118 from rabbitmq/fix-stream-delivery-v2-command-enablement
Activate stream delivery v2 correctly
2023-02-01 09:51:22 +01:00
Michael Klishin 1f902fd016
mix format 2023-01-31 20:57:11 -05:00
Michael Klishin cee705b99f
List CPU core count in 'rabbitmq-diagnostics cluster_status'
Both to simplify troubleshooting in some cases and to make it
easier to spot licensing irregularities.
2023-01-31 20:37:44 -05:00
Michael Klishin 2cf2133a44
Fix one more issue reported by CLI tools Dialyzer
(cherry picked from commit 5d8ba2f32a)
2023-01-31 17:47:24 -05:00
Michael Klishin 9ba8052ea1
Merge pull request #6931 from rabbitmq/support-oauth2-in-amqp1_0
Support OAuth 2.0 authentication in AMQP 1.0 plugin
2023-01-31 12:17:06 -05:00
Michael Klishin fac991a266
Wording 2023-01-31 11:42:14 -05:00
Michael Klishin dea4c439a6
Naming 2023-01-31 11:37:19 -05:00
Arnaud Cogoluègnes f558d80e3d
Activate stream delivery v2 correctly
As soon as v2 is supported, whatever the min supported
version is.
2023-01-31 16:49:48 +01:00
Arnaud Cogoluègnes 1425e5cb02
Mark AMQP 1.0 properties chunk as binary (#7001)
* Mark AMQP 1.0 properties chunk as binary

It is marked as an UTF8 string, which is not, so
strict AMQP 1.0 codecs can fail.

* Re-use AMQP 1.0 binary chunks if available

Instead of converting from AMQP 091 back to AMQP 1.0.
This is for AMQP 1.0 properties, application properties,
and message annotations.

* Test AMQP 1.0 binary chunk reuse

* Support AMQP 1.0 multi-value body better

In the rabbit_msg_record module, mostly. Before this commit,
only one Data section was supported. Now multiple Data sections,
multiple Sequence sections, and an AMQP value section are supported.

* Add test for non-single-data-section AMQP 1.0 message

* Squash some Dialyzer warnings

* Silent dialyzer for a function for now

* Fix type declaration, use type, not atom

* Address review comments
2023-01-31 15:23:21 +00:00
Michael Klishin f7f46a9ae8
Merge pull request #7113 from rabbitmq/mqtt-debug-log 2023-01-31 10:09:21 -05:00
Loïc Hoguin e330f683b6
CQ: Fix performance regression after moving to v2 sets
sets:from_list also must be told to use v2 otherwise
it will use v1.
2023-01-31 15:37:47 +01:00
Rin Kuryloski bdb2046185
Add rabbitmq_cli dialyze to bazel (#7066)
* Add rabbitmq_cli dialyze to bazel

and fix a number of warnings

Because we stop mix from recompiling rabbit_common in bazel, many
unknown functions are reported, so this dialyzer analysis is somewhat
incomplete.

* Use erlang dialyzer for rabbitmq_cli rather than mix dialyzer

Since this resolves all of the rabbit functions, there are far fewer
unknown functions.

Requires yet to be released rules_erlang 3.9.2

* Temporarily use pre-release rules_erlang

So that checks can run on this PR without a release

* Fix additional dialyzer warnings in rabbitmq_cli

* rabbitmq_cli: mix format

* Additional fixes for ignored return values

* Revert "Temporarily use pre-release rules_erlang"

This reverts commit c16b5b6815.

* Use rules_erlang 3.9.2
2023-01-31 15:05:52 +01:00
Marcial Rosales 9339ad1114 Comment why we are propagating authz_backends
when opening an internal amqp connection
2023-01-31 11:45:59 +01:00
Marcial Rosales 51e27f8a3f Fix issue #6909
Use the outcome from first authentication
stored in the #user.authz_backends to authenticate
subsequent attempts which occur when a session is
opened.
In particular, during the first authentication attempt
which occurs during the sasl handshake, the amqp 1.0
plugins reads and validates JWT token present in the
password field.
When a new AMQP 1.0 session is opened, the plugin creates
an internal AMQP connection which triggers a second/nth
authentication. For this second/nth authentication, the
plugin propagates as Authentication Credentials the outcome
from the first authentication which is stored in the
`#user.authz_backends`.
The Oauth2 backend first attempts to authenticate using
the password credentials else it uses the credential with the
key `rabbit_auth_backend_oauth2` which has a function which
returns the decoded token
2023-01-31 11:45:59 +01:00
Chunyi Lyu 6205e5e5e3 MQTT print stacktrace/payload only at debug level 2023-01-31 10:36:08 +00:00
Diana Parra Corbacho 7a12cf840d Adapt plugins to new exchange and exchange decorator API 2023-01-31 10:23:16 +01:00
Diana Parra Corbacho c95ac0a9e6 Move maintenance mode Mnesia-specific code to rabbit_db_maintenance module 2023-01-31 10:23:16 +01:00
Diana Parra Corbacho f2443f6d10 Move mnesia queries from rabbit_misc to rabbit_mnesia 2023-01-31 10:23:16 +01:00
Diana Parra Corbacho 783996f53d Move consistent hash exchange Mnesia-specific code to rabbit_db_ch_exchange module 2023-01-31 10:23:16 +01:00
Diana Parra Corbacho 5b39e7e4ce Move jms topic exchange Mnesia-specific code to rabbit_db_* modules 2023-01-31 10:23:16 +01:00
Diana Parra Corbacho ba1670a95a Move recent history exchange Mnesia-specific code to rabbit_db_* modules 2023-01-31 10:23:16 +01:00
Diana Parra Corbacho 5cdb6e590a Move rabbit_exchange_type to rabbit 2023-01-31 10:23:16 +01:00
Diana Parra Corbacho 90aaf3a87d Adapt federation and shovel to changes in exchange behaviour and mirrored_supervisor 2023-01-31 10:23:16 +01:00
Diana Parra Corbacho 452152469d Move mirrored supervisor Mnesia-specific code to rabbit_db_* modules 2023-01-31 10:23:16 +01:00
Diana Parra Corbacho d0ac99df5e Move queue/exchange/binding/policy Mnesia-specific code to rabbit_db_* modules 2023-01-31 10:23:16 +01:00
Diana Parra Corbacho d8ae41119c Move missing Mnesia-specific code to rabbit_db_topic_exchange module 2023-01-31 10:23:16 +01:00
David Ansari cbb389bb2a Remove MQTT processor field peer_addr
as it seems to always match peer_host.

Commit 7e09b85426 adds peer address
provided by WebMQTT plugin.

However, this seems unnecessary since function rabbit_net:peername/1 on
the unwrapped socket provides the same address.

The peer address was the address of the proxy if the proxy protocol is
enabled.

This commit simplifies code and reduces memory consumption.
2023-01-30 12:17:19 +00:00
David Ansari 590fa68fdc Fix direct_exchange_routing_v2 migration
Multiple users reported the following error when starting RabbitMQ in
containers:
```
Feature flags: failed to enable `direct_exchange_routing_v2`: {error,
                                                                {badarg,
                                                                 [{ets,lookup,
                                                                   [rabbit_exchange,
                                                                    {resource,
                                                                     <<"/">>,
                                                                     exchange,
                                                                     <<"messages">>}],
                                                                   [{error_info,
                                                                     #{cause =>
                                                                        id,
                                                                       module =>
                                                                        erl_stdlib_errors}}]},
                                                                  {rabbit_misc,
                                                                   dirty_read,
                                                                   1,
                                                                   [{file,
                                                                     "rabbit_misc.erl"},
                                                                    {line,
                                                                     372}]},
                                                                  {rabbit_binding,
                                                                   '-populate_index_route_table/0-fun-0-',
                                                                   1,
                                                                   [{file,
                                                                     "rabbit_binding.erl"},
                                                                    {line,
                                                                     757}]},
                                                                    ...
```

Although Mnesia table rabbit_exchange is present when the migration
function for direct_exchange_routing_v2 runs, its ETS table is not yet
present because there is no table copy on the local node.
The table copy was added later after all feature flags were synced.

Fixes #7068.
2023-01-30 10:03:00 +00:00
David Ansari 02cf072ae4 Restrict MQTT CONNECT packet size
In MQTT 3.1.1, the CONNECT packet consists of
1. 10 bytes variable header
2. ClientId (up to 23 bytes must be supported)
3. Will Topic
4. Will Message (maximum length 2^16 bytes)
5. User Name
6. Password

Restricting the CONNECT packet size to 2^16 = 65,536 bytes
seems to be a reasonalbe default.

The value is configurable via the MQTT app parameter
`max_packet_size_unauthenticated`.

(Instead of being called `max_packet_size_connect`) the
name `max_packet_size_unauthenticated` is generic
because MQTT 5 introduces an AUTH packet type.
2023-01-29 15:00:19 +00:00
Chunyi Lyu 209f23fa2f
Revert "Format MQTT code with `erlfmt`" 2023-01-27 18:25:57 +00:00
Marcial Rosales 6806a9a45e
Fixes a memory leak in AMQP 1.0 plugin (#7015)
* Fixes #6969 by

 * tracking channels using a map rather than
process dictionary
 * modifying Program.cs so that it opens 5
simulatneous sessions to send messages before
closing them and repeat again

* Address PR feedback: formatting, code style
2023-01-27 13:00:08 -05:00
Michael Klishin 798bee4c81
Merge pull request #7067 from rabbitmq/fmt-mqtt
Format MQTT code with `erlfmt`
2023-01-27 06:56:04 -06:00
Chunyi Lyu 1de9fcf582 Format mqtt files with erlfmt 2023-01-27 11:06:41 +00:00
Michael Klishin 90bd720548
Merge pull request #7039 from rabbitmq/rabbitmq-server-7038
Ensure that a timeout closes exe port on win32
2023-01-26 15:09:39 -06:00
Luke Bakken b70af46b2e
Ensure that a timeout closes exe port on win32
Fixes #7038
2023-01-26 11:51:52 -08:00
Simon Unge 03617f681c See #5957. Accept empty arg and prompt for password 2023-01-26 11:46:24 -08:00
Iliia Khaprov e4f1486d7a Fix Users filtering in Management UI.
close #4908
2023-01-26 16:28:47 +01:00
Michael Klishin 85e38dc777
Merge pull request #5895 from rabbitmq/mqtt
Native MQTT
2023-01-26 05:39:43 -06:00
syuparn e3e6c97466 Fix empty channel detail format in management api
Signed-off-by: syuparn <s.hello.spagetti@gmail.com>
2023-01-26 07:20:53 +09:00
Chunyi Lyu 50e25778bb Adding missing function specs 2023-01-25 19:34:24 +00:00
David Ansari 1f106fcd98 Fix wrong and add missing type specs 2023-01-25 17:13:54 +00:00
David Ansari ec137bc783 Add nested config record for rarely changing fields
When a single field in a record is updated, all remaining
fields' pointers are copied. Hence, if the record is large,
a lot will be copied.

Therefore, put static or rarely changing fields into their own record.

The same was done for the state in rabbit_channel or rabbit_fifo
for example.

Also, merge #info{} record into the new #cfg{} record.
2023-01-25 15:59:35 +00:00
Alexey Lebedeff a9b44f017c Fix all dialyzer warnings in `rabbitmq_stomp` 2023-01-25 16:13:10 +01:00
David Ansari 9c2f5975ea Support tracing in Native MQTT 2023-01-24 17:32:59 +00:00
Chunyi Lyu 6cc65ecceb Export opaque types for event and mqtt_packet state 2023-01-24 17:32:59 +00:00
David Ansari 9db8626abf Re-enable dialyzer option Wunmatched_returns 2023-01-24 17:32:59 +00:00
David Ansari 8a2a82e19b Remove feature flag no_queue_name_in_classic_queue_client
as it was unnecessary to introduce it in the first place.

Remove the queue name from all queue type clients and pass the queue
name to the queue type callbacks that need it.

We have to leave feature flag classic_queue_type_delivery_support
required because we removed the monitor registry
1fd4a6d353/deps/rabbit/src/rabbit_queue_type.erl (L322-L325)

Implements review from Karl:
"rather than changing the message format we could amend the queue type
callbacks involved with the stateful operation to also take the queue
name record as an argument. This way we don't need to maintain the extra
queue name (which uses memory for known but obscurely technical reasons
with how maps work) in the queue type state (as it is used in the queue
type state map as the key)"
2023-01-24 17:32:59 +00:00
David Ansari cd8962b5fd Remove optional rabbit_queue_type callbacks
Instead of having optional rabbit_queue_type callbacks, add stub
implementations to rabbit_mqtt_qos0_queue throwing an exception.
The exception uses erlang:error/2 including stack trace and arguments
of the unsupported functions to ease debugging in case these functions
were ever to be called.

Dialyzer suppressions are added for these functions such that dialyzer
won't complain about:
```
rabbit_mqtt_qos0_queue.erl:244:1: Function init/1 only terminates with explicit exception
```
2023-01-24 17:32:59 +00:00
Chunyi Lyu d86ce70fd6 Add missing type definitions in mqtt records 2023-01-24 17:32:59 +00:00
David Ansari d4cfbddd35 Parse at most maximum packet length of 256MB
"This allows applications to send Control Packets of size up to
268,435,455 (256 MB)."
http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc398718023
2023-01-24 17:32:59 +00:00
David Ansari 3f85f8d904 Do not log message payload
because it might contain large output.
2023-01-24 17:32:59 +00:00
David Ansari 437cbb73be Use delegate for stateless deliveries
For example when at-most-once dead lettering does a fan out to many
target classic queues this commit will reduce inter-node data traffic by
using delegate.
2023-01-24 17:32:59 +00:00
David Ansari 63ccf3ea3b Reduce inter-node traffic for MQTT QoS 0 queue type
Use delegate.

For large fan-outs with medium to large message size,
this commit will reduce inter-node data traffic by
multiple orders of magnitude preventing busy distribution
ports.
2023-01-24 17:32:59 +00:00
David Ansari a4db85de0d Make pipeline fail when there are dialyzer warnings
We want the build to fail if there are any dialyzer warnings in
rabbitmq_mqtt or rabbitmq_web_mqtt. Otherwise we rely on people manually
executing and checking the results of dialyzer.

Also, we want any test to fail that is flaky.
Flaky tests can indicate subtle errors in either test or program execution.
Instead of marking them as flaky, we should understand and - if possible -
fix the underlying root cause.

Fix OTP 25.0 dialyzer warning

Type gen_server:format_status() is known in OTP 25.2, but not in 25.0
2023-01-24 17:32:59 +00:00