Commit Graph

2244 Commits

Author SHA1 Message Date
Jean-Sébastien Pédron 414f9509e1
rabbitmq-run.mk: Start nodes in parallel in `start-{brokers,cluster}`
[Why]
For Mnesia, we don't really care. However, for the upcoming use of
Khepri, we need that because the cluster will require at least a quorum
number of nodes to start to become available.

[How]
We simply rely on the shell's job management and wait for them to
complete.

We do the same for `stop-{brokers,cluster}` mostly for consistency's
sake.

It also makes starting nodes slightly faster.
2023-09-05 17:30:57 +02:00
Karl Nilsson 119f034406
Message Containers (#5077)
This PR implements an approach for a "protocol (data format) agnostic core" where the format of the message isn't converted at point of reception.

Currently all non AMQP 0.9.1 originating messages are converted into a AMQP 0.9.1 flavoured basic_message record before sent to a queue. If the messages are then consumed by the originating protocol they are converted back from AMQP 0.9.1. For some protocols such as MQTT 3.1 this isn't too expensive as MQTT is mostly a fairly easily mapped subset of AMQP 0.9.1 but for others such as AMQP 1.0 the conversions are awkward and in some cases lossy even if consuming from the originating protocol.

This PR instead wraps all incoming messages in their originating form into a generic, extensible message container type (mc). The container module exposes an API to get common message details such as size and various properties (ttl, priority etc) directly from the source data type. Each protocol needs to implement the mc behaviour such that when a message originating form one protocol is consumed by another protocol we convert it to the target protocol at that point.

The message container also contains annotations, dead letter records and other meta data we need to record during the lifetime of a message. The original protocol message is never modified unless it is consumed.

This includes conversion modules to and from amqp, amqpl (AMQP 0.9.1) and mqtt.


COMMIT HISTORY:

* Refactor away from using the delivery{} record

In many places including exchange types. This should make it
easier to move towards using a message container type instead of
basic_message.

Add mc module and move direct replies outside of exchange

Lots of changes incl classic queues

Implement stream support incl amqp conversions

simplify mc state record

move mc.erl

mc dlx stuff

recent history exchange

Make tracking work

But doesn't take a protocol agnostic approach as we just convert
everything into AMQP legacy and back. Might be good enough for now.

Tracing as a whole may want a bit of a re-vamp at some point.

tidy

make quorum queue peek work by legacy conversion

dead lettering fixes

dead lettering fixes

CMQ fixes

rabbit_trace type fixes

fixes

fix

Fix classic queue props

test assertion fix

feature flag and backwards compat

Enable message_container feature flag in some SUITEs

Dialyzer fixes

fixes

fix

test fixes

Various

Manually update a gazelle generated file

until a gazelle enhancement can be made
https://github.com/rabbitmq/rules_erlang/issues/185

Add message_containers_SUITE to bazel

and regen bazel files with gazelle from rules_erlang@main

Simplify essential proprty access

Such as durable, ttl and priority by extracting them into annotations
at message container init time.

Move type

to remove dependenc on amqp10 stuff in mc.erl

mostly because I don't know how to make bazel do the right thing

add more stuff

Refine routing header stuff

wip

Cosmetics

Do not use "maybe" as type name as "maybe" is a keyword since OTP 25
which makes Erlang LS complain.

* Dedup death queue names

* Fix function clause crashes

Fix failing tests in the MQTT shared_SUITE:
A classic queue message ID can be undefined as set in
fbe79ff47b/deps/rabbit/src/rabbit_classic_queue_index_v2.erl (L1048)

Fix failing tests in the MQTT shared_SUITE-mixed:
When feature flag message_containers is disabled, the
message is not an #mc{} record, but a #basic_message{} record.

* Fix is_utf8_no_null crash

Prior to this commit, the function crashed if invalid UTF-8 was
provided, e.g.:
```
1> rabbit_misc:is_valid_shortstr(<<"😇"/utf16>>).
** exception error: no function clause matching rabbit_misc:is_utf8_no_null(<<216,61,222,7>>) (rabbit_misc.erl, line 1481)
```

* Implement mqtt mc behaviour

For now via amqp translation.

This is still work in progress, but the following SUITEs pass:
```
make -C deps/rabbitmq_mqtt ct-shared t=[mqtt,v5,cluster_size_1] FULL=1
make -C deps/rabbitmq_mqtt ct-v5 t=[mqtt,cluster_size_1] FULL=1
```

* Shorten mc file names

Module name length matters because for each persistent message the #mc{}
record is persisted to disk.

```
1> iolist_size(term_to_iovec({mc, rabbit_mc_amqp_legacy})).
30
2> iolist_size(term_to_iovec({mc, mc_amqpl})).
17
```

This commit renames the mc modules:
```
ag -l rabbit_mc_amqp_legacy | xargs sed -i 's/rabbit_mc_amqp_legacy/mc_amqpl/g'
ag -l rabbit_mc_amqp | xargs sed -i 's/rabbit_mc_amqp/mc_amqp/g'
ag -l rabbit_mqtt_mc | xargs sed -i 's/rabbit_mqtt_mc/mc_mqtt/g'
```

* mc: make deaths an annotation + fixes

* Fix mc_mqtt protocol_state callback

* Fix test will_delay_node_restart

```
make -C deps/rabbitmq_mqtt ct-v5 t=[mqtt,cluster_size_3]:will_delay_node_restart FULL=1
```

* Bazel run gazelle

* mix format rabbitmqctl.ex

* Ensure ttl annotation is refelected in amqp legacy protocol state

* Fix id access in message store

* Fix rabbit_message_interceptor_SUITE

* dializer fixes

* Fix rabbit:rabbit_message_interceptor_SUITE-mixed

set_annotation/3 should not result in duplicate keys

* Fix MQTT shared_SUITE-mixed

Up to 3.12 non-MQTT publishes were always QoS 1 regardless of delivery_mode.
75a953ce28/deps/rabbitmq_mqtt/src/rabbit_mqtt_processor.erl (L2075-L2076)
From now on, non-MQTT publishes are QoS 1 if durable.
This makes more sense.

The MQTT plugin must send a #basic_message{} to an old node that does
not understand message containers.

* Field content of 'v1_0.data' can be binary

Fix
```
bazel test //deps/rabbitmq_mqtt:shared_SUITE-mixed \
    --test_env FOCUS="-group [mqtt,v4,cluster_size_1] -case trace" \
    -t- --test_sharding_strategy=disabled
```

* Remove route/2 and implement route/3 for all exchange types.

This removes the route/2 callback from rabbit_exchange_type and
makes route/3 mandatory instead. This is a breaking change and
will require all implementations of exchange types to update their
code, however this is necessary anyway for them to correctly handle
the mc type.

stream filtering fixes

* Translate directly from MQTT to AMQP 0.9.1

* handle undecoded properties in mc_compat

amqpl: put clause in right order

recover death deatails from amqp data

* Replace callback init_amqp with convert_from

* Fix return value of lists:keyfind/3

* Translate directly from AMQP 0.9.1 to MQTT

* Fix MQTT payload size

MQTT payload can be a list when converted from AMQP 0.9.1 for example

First conversions tests

Plus some other conversion related fixes.

bazel

bazel

translate amqp 1.0 null to undefined

mc: property/2 and correlation_id/message_id return type tagged values.

To ensure we can support a variety of types better.

The type type tags are AMQP 1.0 flavoured.

fix death recovery

mc_mqtt: impl new api

Add callbacks to allow protocols to compact data before storage

And make readable if needing to query things repeatedly.

bazel fix

* more decoding

* tracking mixed versions compat

* mc: flip default of `durable` annotation to save some data.

Assuming most messages are durable and that in memory messages suffer less
from persistence overhead it makes sense for a non existent `durable`
annotation to mean durable=true.

* mc conversion tests and tidy up

* mc make x_header unstrict again

* amqpl: death record fixes

* bazel

* amqp -> amqpl conversion test

* Fix crash in mc_amqp:size/1

Body can be a single amqp-value section (instead of
being a list) as shown by test
```
make -C deps/rabbitmq_amqp1_0/ ct-system t=java
```
on branch native-amqp.

* Fix crash in lists:flatten/1

Data can be a single amqp-value section (instead of
being a list) as shown by test
```
make -C deps/rabbitmq_amqp1_0 ct-system t=dotnet:roundtrip_to_amqp_091
```
on branch native-amqp.

* Fix crash in rabbit_writer

Running test
```
make -C deps/rabbitmq_amqp1_0 ct-system t=dotnet:roundtrip_to_amqp_091
```
on branch native-amqp resulted in the following crash:
```
crasher:
  initial call: rabbit_writer:enter_mainloop/2
  pid: <0.711.0>
  registered_name: []
  exception error: bad argument
    in function  size/1
       called as size([<<0>>,<<"Sw">>,[<<160,2>>,<<"hi">>]])
       *** argument 1: not tuple or binary
    in call from rabbit_binary_generator:build_content_frames/7 (rabbit_binary_generator.erl, line 89)
    in call from rabbit_binary_generator:build_simple_content_frames/4 (rabbit_binary_generator.erl, line 61)
    in call from rabbit_writer:assemble_frames/5 (rabbit_writer.erl, line 334)
    in call from rabbit_writer:internal_send_command_async/3 (rabbit_writer.erl, line 365)
    in call from rabbit_writer:handle_message/2 (rabbit_writer.erl, line 265)
    in call from rabbit_writer:handle_message/3 (rabbit_writer.erl, line 232)
    in call from rabbit_writer:mainloop1/2 (rabbit_writer.erl, line 223)
```
because #content.payload_fragments_rev is currently supposed to
be a flat list of binaries instead of being an iolist.

This commit fixes this crash inefficiently by calling
iolist_to_binary/1. A better solution would be to allow AMQP legacy's #content.payload_fragments_rev
to be an iolist.

* Add accidentally deleted line back

* mc: optimise mc_amqp internal format

By removint the outer records for message and delivery annotations
as well as application properties and footers.

* mc: optimis mc_amqp map_add by using upsert

* mc: refactoring and bug fixes

* mc_SUITE routingheader assertions

* mc remove serialize/1 callback as only used by amqp

* mc_amqp: avoid returning a nested list from protocol_state

* test and bug fix

* move infer_type to mc_util

* mc fixes and additiona assertions

* Support headers exchange routing for MQTT messages

When a headers exchange is bound to the MQTT topic exchange, routing
will be performend based on both MQTT topic (by the topic exchange) and
MQTT User Property (by the headers exchange).

This combines the best worlds of both MQTT 5.0 and AMQP 0.9.1 and
enables powerful routing topologies.

When the User Property contains the same name multiple times, only the
last name (and value) will be considered by the headers exchange.

* Fix crash when sending from stream to amqpl

When publishing a message via the stream protocol and consuming it via
AMQP 0.9.1, the following crash occurred prior to this commit:
```
crasher:
  initial call: rabbit_channel:init/1
  pid: <0.818.0>
  registered_name: []
  exception exit: {{badmatch,undefined},
                   [{rabbit_channel,handle_deliver0,4,
                                    [{file,"rabbit_channel.erl"},
                                     {line,2728}]},
                    {lists,foldl,3,[{file,"lists.erl"},{line,1594}]},
                    {rabbit_channel,handle_cast,2,
                                    [{file,"rabbit_channel.erl"},
                                     {line,728}]},
                    {gen_server2,handle_msg,2,
                                 [{file,"gen_server2.erl"},{line,1056}]},
                    {proc_lib,wake_up,3,
                              [{file,"proc_lib.erl"},{line,251}]}]}
```

This commit first gives `mc:init/3` the chance to set exchange and
routing_keys annotations.
If not set, `rabbit_stream_queue` will set these annotations assuming
the message was originally published via the stream protocol.

* Support consistent hash exchange routing for MQTT 5.0

When a consistent hash exchange is bound to the MQTT topic exchange,
MQTT 5.0 messages can be routed to queues consistently based on the
Correlation-Data in the PUBLISH packet.

* Convert MQTT 5.0 User Property

* to AMQP 0.9.1 headers
* from AMQP 0.9.1 headers
* to AMQP 1.0 application properties and message annotations
* from AMQP 1.0 application properties and message annotations

* Make use of Annotations in mc_mqtt:protocol_state/2

mc_mqtt:protocol_state/2 includes Annotations as parameter.
It's cleaner to make use of these Annotations when computing the
protocol state instead of relying on the caller (rabbitmq_mqtt_processor)
to compute the protocol state.

* Enforce AMQP 0.9.1 field name length limit

The AMQP 0.9.1 spec prohibits field names longer than 128 characters.
Therefore, when converting AMQP 1.0 message annotations, application
properties or MQTT 5.0 User Property to AMQP 0.9.1 headers, drop any
names longer than 128 characters.

* Fix type specs

Apply feedback from Michael Davis

Co-authored-by: Michael Davis <mcarsondavis@gmail.com>

* Add mc_mqtt unit test suite

Implement mc_mqtt:x_header/2

* Translate indicator that payload is UTF-8 encoded

when converting between MQTT 5.0 and AMQP 1.0

* Translate single amqp-value section from AMQP 1.0 to MQTT

Convert to a text representation, if possible, and indicate to MQTT
client that the payload is UTF-8 encoded. This way, the MQTT client will
be able to parse the payload.

If conversion to text representation is not possible, encode the payload
using the AMQP 1.0 type system and indiate the encoding via Content-Type
message/vnd.rabbitmq.amqp.

This Content-Type is not registered.
Type "message" makes sense since it's a message.
Vendor tree "vnd.rabbitmq.amqp" makes sense since merely subtype "amqp" is not
registered.

* Fix payload conversion

* Translate Response Topic between MQTT and AMQP

Translate MQTT 5.0 Response Topic to AMQP 1.0 reply-to address and vice
versa.

The Response Topic must be a UTF-8 encoded string.

This commit re-uses the already defined RabbitMQ target addresses:
```
"/topic/"     RK        Publish to amq.topic with routing key RK
"/exchange/"  X "/" RK  Publish to exchange X with routing key RK
```

By default, the MQTT topic exchange is configure dto be amq.topic using
the 1st target address.

When an operator modifies the mqtt.exchange, the 2nd target address is
used.

* Apply PR feedback

and fix formatting

Co-authored-by: Michael Davis <mcarsondavis@gmail.com>

* tidy up

* Add MQTT message_containers test

* consistent hash exchange: avoid amqp legacy conversion

When hashing on a header value.

* Avoid converting to amqp legacy when using exchange federation

* Fix test flake

* test and dialyzer fixes

* dialyzer fix

* Add MQTT protocol interoperability tests

Test receiving from and sending to MQTT 5.0 and
* AMQP 0.9.1
* AMQP 1.0
* STOMP
* Streams

* Regenerate portions of deps/rabbit/app.bzl with gazelle

I'm not exactly sure how this happened, but gazell seems to have been
run with an older version of the rules_erlang gazelle extension at
some point. This caused generation of a structure that is no longer
used. This commit updates the structure to the current pattern.

* mc: refactoring

* mc_amqpl: handle delivery annotations

Just in case they are included.

Also use iolist_to_iovec to create flat list of binaries when
converting from amqp with amqp encoded payload.

---------

Co-authored-by: David Ansari <david.ansari@gmx.de>
Co-authored-by: Michael Davis <mcarsondavis@gmail.com>
Co-authored-by: Rin Kuryloski <kuryloskip@vmware.com>
2023-08-31 11:27:13 +01:00
Luke Bakken aefca26431
Fix `rabbitmq-env-conf.bat` parsing
Due to how the `echo` statement adds a space character, the output
marker was not found while parsing the output of
`rabbitmq-env-conf.bat`. This, in turn, resulted in _none_ of the
environment variables defined there being re-exported.

In addition, the parsing of the output did not succeed as the default is
to expect `sh`-style output.

It is rare for users to use this file on Windows which is how this
behavior has not been noticed in years.

Related to:
* https://pivotal-esc.atlassian.net/browse/VESC-1077
* https://vmware.slack.com/archives/C0RDGG81Z/p1689274725888439
* https://github.com/rabbitmq/rabbitmq-server/pull/5486 (tangentially related)

Add some simple win32 parsing tests
2023-07-19 08:50:55 -07:00
Michael Klishin 56967a537f
Merge branch 'main' into eval_membership_stand_alone_process 2023-07-13 19:27:23 +04:00
Lajos Gerecs 7d0c2854f2 Add the possibility of registering custom queue types 2023-07-12 14:07:12 +02:00
Simon Unge 559a83d45f See #7209. Evaluate quorum queue membership periodically. 2023-07-11 13:14:04 -07:00
Michael Klishin 1402183bc2 Introduce a way to disable FHC use in web_mqtt
Via `web_mqtt.enable_file_handle_cache`
2023-07-09 09:16:17 +04:00
Michael Klishin a6c522d207 Cosmetics (per review comments) 2023-07-09 09:16:17 +04:00
Michael Klishin d5d8689f54 FHC: use safe versions of ets update functions
Otherwise, if the FHC runs into an exception because of an ETS
write failure, most code paths begin failing.

This may help with the condition in #8784.
2023-07-09 09:16:17 +04:00
Jean-Sébastien Pédron 9c358dd9f3
rabbit_peer_discovery: Move peer discovery driving code from `rabbit_mnesia`
[Why]
Peer discovery is not Mnesia-specific and will be used once we introduce
Khepri.

[How]
The whole peer discovery driving code is moved from `rabbit_mnesia` to
`rabbit_peer_discovery`. When `rabbit_mnesia` calls that code, it simply
passes a callback for the Mnesia-specific cluster expansion code.
2023-07-07 09:42:32 +02:00
Jean-Sébastien Pédron 8bd656c4be
rabbit_mnesia: Only consider feature flags when testing node compatibility
[Why]
Up to RabbitMQ 3.7.x, versions were compared to determine if two nodes
were compatible. In 3.8.0, feature flags were introduced to fulfill this
check.

The current branch of RabbitMQ is no longer compatible with 3.7.x
because several feature flags are now required. This means the user must
upgrade to intermediate versions first before.

Therefore, we don't need to keep comparing versions.

[How]
The check is now simply calling the feature flags subsystem check.

We still keep versions comparison for plugins. However, we can get rid
of the special case for RabbitMQ 3.6.6.
2023-07-07 09:42:31 +02:00
Arnaud Cogoluègnes d8f77c5882
Settle unroutable message with released state
Currently it is not possible for an AMQP 1.0 to make find
out a message is unroutable as it is settled with the
accepted state. This is because the current implementation
relies only on the publish confirms AMQP 091 extension.

This commit changes this by settling the message with the
released state. It uses the mandatory flag mechanism from
AMQP 091 and "internally" extends it to provide not only
the message in the callback, but the publishing sequence
as well. This applies only for AMQP 1.0, not for other
cases. Publish confirms and the mandatory flag are used
in conjonction in this case.

References #7823
2023-06-30 15:01:26 +02:00
Loïc Hoguin 610af302c6
Add support for LOCAL proxy header
This is what the proxy uses for health checks. In those cases
we use the socket's IP/ports for the connection name as we
have nothing else we can use.
2023-06-23 12:12:58 +02:00
David Ansari 2fec1a22d9 Allow route/3 to return additional infos
Allow rabbitmq_exchange:route_return() to return infos in addition to
the matched binding keys.
For example, some exchange types read the full #amqqueue{} record from the database
and can in future return it from the route/3 function to avoid reading the full
record again in the channel.
2023-06-21 17:14:08 +01:00
David Ansari bb20618b13 Return matched binding keys faster
For MQTT 5.0 destination queues, the topic exchange does not only have
to return the destination queue names, but also the matched binding
keys.
This is needed to implement MQTT 5.0 subscription options No Local,
Retain As Published and Subscription Identifiers.

Prior to this commit, as the trie was walked down, we remembered the
edges being walked and assembled the final binding key with
list_to_binary/1.

list_to_binary/1 is very expensive with long lists (long topic names),
even in OTP 26.
The CPU flame graph showed ~3% of CPU usage was spent only in
list_to_binary/1.

Unfortunately and unnecessarily, the current topic exchange
implementation stores topic levels as lists.

It would be better to store topic levels as binaries:
split_topic_key/1 should ideally use binary:split/3 similar as follows:
```
1> P = binary:compile_pattern(<<".">>).
{bm,#Ref<0.1273071188.1488322568.63736>}
2> Bin = <<"aaa.bbb..ccc">>.
<<"aaa.bbb..ccc">>
3> binary:split(Bin, P, [global]).
[<<"aaa">>,<<"bbb">>,<<>>,<<"ccc">>]
```
The compiled pattern could be placed into persistent term.

This commit decided to avoid migrating Mnesia tables to use binaries
instead of lists. Mnesia migrations are non-trivial, especially with the
current feature flag subsystem.
Furthermore the Mnesia topic tables are already getting migrated to
their Khepri counterparts in 3.13.
Adding additional migration only for Mnesia does not make sense.

So, instead of assembling the binding key as we walk down the trie and
then calling list_to_binary/1 in the leaf, it
would be better to just fetch the binding key from the database in the leaf.

As we reach the leaf of the trie, we know both source and destination.
Unfortunately, we cannot fetch the binding key efficiently with the
current rabbit_route (sorted by source exchange) and
rabbit_reverse_route (sorted by destination) tables as the key is in
the middle between source and destination.
If there are a huge number of bindings for a given sourc exchange (very
realistic in MQTT use cases) or a large number of bindings for a given
destination (also realistic), it would require scanning these large
number of bindings.

Therefore this commit takes the simplest possible solution:
The solution leverages the fact that binding arguments are already part of
table rabbit_topic_trie_binding.
So, if we simply include the binding key into the binding arguments, we
can fetch and return it efficiently in the topic exchange
implementation.

The following patch omitting fetching the empty list binding argument
(the default) makes routing slower because function
`analyze_pattern.constprop.0` requires significantly more (~2.5%) CPU time
```
@@ -273,7 +273,11 @@ trie_bindings(X, Node) ->
                                    node_id       = Node,
                                    destination   = '$1',
                                    arguments     = '$2'}},
-    mnesia:select(?MNESIA_BINDING_TABLE, [{MatchHead, [], [{{'$1', '$2'}}]}]).
+    mnesia:select(
+      ?MNESIA_BINDING_TABLE,
+      [{MatchHead, [{'andalso', {'is_list', '$2'}, {'=/=', '$2', []}}], [{{'$1', '$2'}}]},
+       {MatchHead, [], ['$1']}
+      ]).
```
Hence, this commit always fetches the binding arguments.

All MQTT 5.0 destination queues will create a binding that
contains the binding key in the binding arguments.

Not only does this solution avoid expensive list_to_binay/1 calls, but
it also means that Erlang app rabbit (specifically the topic exchange
implementation) does not need to be aware of MQTT anymore:
It just returns the binding key when the binding args tell to do so.

In future, once the Khepri migration completed, we should be able to
relatively simply remove the binding key from the binding arguments
again to free up some storage space.

Note that one of the advantages of a trie data structue is its space
efficiency that you don't have to store the same prefixes multiple
times.
However, for RabbitMQ the binding key is already stored at least N times
in various routing tables, so storing it a few times more via the
binding arguments should be acceptable.
The speed improvements are favoured over a few more MBs ETS usage.
2023-06-21 17:14:08 +01:00
David Ansari fb7af48df6 Support Will Delay Interval
Previously, the Will Message could be kept in memory in the MQTT
connection process state. Upon termination, the Will Message is sent.

The new MQTT 5.0 feature Will Delay Interval requires storing the Will
Message outside of the MQTT connection process state.

The Will Message should not be stored node local because the client
could reconnect to a different node.

Storing the Will Message in Mnesia is not an option because we want to
get rid of Mnesia. Storing the Will Message in a Ra cluster or in Khepri
is only an option if the Will Payload is small as there is currently no
way in Ra to **efficiently** snapshot large binary data (Note that these
Will Messages are not consumed in a FIFO style workload like messages in
quorum queues. A Will Message needs to be stored for as long as the
Session lasts - up to 1 day by default, but could also be much longer if
RabbitMQ is configured with a higher maximum session expiry interval.)
Usually Will Payloads are small: They are just a notification that its
MQTT session ended abnormally. However, we don't know how users leverage
the Will Message feature. The MQTT protocol allows for large Will Payloads.

Therefore, the solution implemented in this commit - which should work
good enough - is storing the Will Message in a queue.
Each MQTT session which has a Session Expiry Interval and Will Delay
Interval of > 0 seconds will create a queue if the current Network
Connection ends where it stores its Will Message. The Will Message has a
message TTL set (corresponds to the Will Delay Interval) and the queue
has a queue TTL set (corresponds to the Session Expiry Interval).
If the client does not reconnect within the Will Delay Interval, the
message is dead lettered to the configured MQTT topic exchange
(amq.topic by default).

The Will Delay Interval can be set by both publishers and subscribers.
Therefore, the Will Message is the 1st session state that RabbitMQ keeps
for publish-only MQTT clients.

One current limitation of this commit is that a Will Message that is
delayed (i.e. Will Delay Interval is set) and retained (i.e. Will Retain
flag set) will not be retained.
One solution to retain delayed Will Messages is that the retainer
process consumes from a queue and the queue binds to the topic exchange
with a topic starting with `$`, for example `$retain/#`.
The AMQP 0.9.1 Will Message that is dead lettered could then be added a
CC header such that it won't not only be published with the Will Topic,
but also with `$retain` topic. For example, if the Will Topic is `a/b`,
it will publish with routing key `a/b` and CC header `$retain/a/b`.

The reason this is not implemented in this commit is that to keep the
currently broken retained message store behaviour, we would require
creating at least one queue per node and publishing only to that local
queue. In future, once we have a replicated retained message store based
on a Stream for example, we could just publish all retained messages to
the `$retain` topic and thefore into the Stream.
So, for now, we list "retained and delayed Will Messages" as a limitation
that they actually won't be retained.
2023-06-21 17:14:08 +01:00
David Ansari acd249cb0f Add a test for Session Expiry Interval 2023-06-21 17:14:08 +01:00
Michael Klishin 55442aa914 Replace @rabbitmq.com addresses with rabbitmq-core@groups.vmware.com
Don't ask why we have to do it. Because reasons!
2023-06-20 15:40:13 +04:00
Michal Kuratczyk b8d5d15cc1
revert d9d68e931c
A recent change in OTP made the unit_SUITE fail with a case clause.
cdd7200cbe

Reverting this old commit seems to fix the problem for OTP master
without breaking OTP25/26.

Co-authored-by: @lhoguin
2023-06-12 13:21:24 +02:00
Loïc Hoguin 32816c0a76
CQ: Improve reading from shared message store
This commit replaces file combining with single-file compaction
where data is moved near the beginning of the file before
updating the index entries. The file is then truncated when
all existing readers are gone. This allows removing the lock
that existed before and enables reading multiple messages at
once from the shared files. This also helps us avoid many
ets operations and simplify the code greatly.

This commit still has some issues: reading a single message
is currently slow due to the removal of FHC in the client
code. This will be resolved by implementing read buffering
in a similar way as FHC but without keeping files open
more than necessary.

The dirty recovery code also likely has a number of issues
because of the compaction changes.
2023-05-30 11:19:45 +02:00
Luke Bakken 9e170e990b
Remove unused rabbit_http_util functions (#8303)
The associated eunit tests were failing on Windows and OTP 26. Since they are unused, there is no reason to keep them around.

https://app.buildbuddy.io/invocation/2d08b45f-41e1-464b-8e82-11da0334207b?target=%2F%2Fdeps%2Frabbit_common%3Aeunit#@17
2023-05-23 20:20:59 +02:00
Luke Bakken 349e0a5040
Move dep_credentials_obfuscation to rabbitmq-components.mk
Potential fix for publishing to hex.pm
2023-05-22 13:10:30 -07:00
Rin Kuryloski 0be657ee14 Fix offline `make dist`
See #7869. #7875 resulted in elixir apps (besides the cli) in the deps
dir. This triggered dormant makefile logic to compile such deps. It
turns out that it's unnecessary to pre-compile them, given the cli's
mix.exs file.
2023-05-16 12:05:25 +02:00
Rin Kuryloski eb94a58bc9 Add a workflow to compare the bazel/erlang.mk output
To catch any drift between the builds
2023-05-15 13:54:14 +02:00
Rin Kuryloski a944439fba Replace globs in bazel with explicit lists of files
As this is preferred in rules_erlang 3.9.14
2023-04-25 17:29:12 +02:00
Luke Bakken 6c39f6812a Make dialyzer happy by ensuring `rabbit_data_coercion:to_list/1` can handle `inet:ip_address()` 2023-04-24 11:39:16 -07:00
Michael Klishin c094bbb828
Merge pull request #7927 from rabbitmq/otp-26-tcp-send
Make tcp send OTP 26 compatible
2023-04-24 14:49:12 +04:00
Rin Kuryloski 854d01d9a5 Restore the original -include_lib statements from before #6466
since this broke erlang_ls

requires rules_erlang 3.9.13
2023-04-20 12:40:45 +02:00
Michael Klishin c0ed80c625
Merge pull request #6466 from rabbitmq/gazelle
Use gazelle for some maintenance of bazel BUILD files
2023-04-19 09:33:44 +04:00
David Ansari 6b4d881403 Make tcp send OTP 26 compatible
Follow up of https://github.com/rabbitmq/rabbitmq-server/pull/7913
and https://github.com/rabbitmq/rabbitmq-server/pull/7921

This commit uses the approach explained in https://github.com/erlang/otp/issues/7130#issuecomment-1512808759

We cannot use the macro `?OTP_RELEASE` since macros are evaluated at
compile time. RabbitMQ can be compiled with OTP 25 and executed with OTP
26. Therefore, we use `erlang:system_info(otp_release)` instead.
As `erlang:system_info/1` might be costly, we store the send function in
persistent_term.

For OTP 25, we use the "old tcp send workaround" (i.e.
`erlang:port_command/2`) which avoids expensive selective receives.
For OTP 26, we use `gen_tcp:send/2` which uses the optimised selective
receive.

Once the minimum required version becomes OTP 26, we can just switch to
`gen_tcp:send/2` and delete the `inet_reply` handling code in the various
RabbitMQ reader and writer processes.

Note that `rabbit_net:port_command/2` is not only used by RabbitMQ server,
but also by the AMQP 0.9.1 client.
Therefore, instead of putting the OTP version (or send function) into
persistent_term within the rabbit app, we just do it the first time
`rabbit_net:port_command/2` is invoked.
(`rabbit_common` is just a library without supervision hierarchy.)
2023-04-18 15:51:00 +00:00
David Ansari 81d21f59cd Revert erlang:port_command/2 to gen_tcp:send/2 change
Revert the change introduced in https://github.com/rabbitmq/rabbitmq-server/pull/7900

RabbitMQ 3.12 will require OTP 25 (not yet OTP 26).

The use of macro `OTP_RELEASE` was wrong because RabbitMQ can be
compiled with OTP 25, but run with OTP 26. Macros are evaluated at
compile time.

An alternative runtime equivalent would have been
```
1> erlang:system_info(otp_release).
"26"
```
2023-04-18 10:27:11 +00:00
Rin Kuryloski 8de8f59d47 Use gazelle generated bazel files
Bazel build files are now maintained primarily with `bazel run
gazelle`. This will analyze and merge changes into the build files as
necessitated by certain code changes (e.g. the introduction of new
modules).

In some cases there hints to gazelle in the build files, such as `#
gazelle:erlang...` or `# keep` comments. xref checks on plugins that
depend on the cli are a good example.
2023-04-17 18:13:18 +02:00
David Ansari 485512f23c Avoid costly selective receive in OTP 25
In OTP 25, gen_tcp:send/2 has poor performance when the Erlang mailbox
is large because the selective receive is not optimised.

https://erlang.org/download/otp_src_26.0-rc3.readme

OTP-18520    Application(s): erts
               Related Id(s): GH-6455

               gen_tcp:send/*, gen_udp:send/* and gen_sctp:send/* have
               been optimized to use the infamous receive reference
               optimization, so now sending should not have bad
               performance when the calling process has a large
               message queue.
2023-04-17 16:09:04 +00:00
Michael Klishin 0f8a5899de
Merge branch 'main' into otp26-compatibility 2023-04-17 14:23:21 +04:00
Rin Kuryloski 8a7eee6a86 Ignore warnings when building plt files for dependencies
As we don't generally care if a dependency has warnings, only the
target
2023-04-17 10:09:24 +02:00
Loïc Hoguin e33c008789
Don't use erlang:port_command to send TCP data
This no longer works with OTP-26 and will not work moving
forward. So we do like ssl and simulate a real port command.
2023-04-13 14:37:19 +02:00
Michal Kuratczyk 3c2917b871
Don't rely on implict list ordering
While at it, refactor `rabbit_misc:plmerge/2` to use the same precedence
as maps:merge and lists:merge (the second argument supersedes the first
one)
2023-04-13 14:37:18 +02:00
Michal Kuratczyk 8652403d2b
Exclude shake128/256 from a test 2023-04-13 14:37:18 +02:00
Michal Kuratczyk 1f01a85c9b
Don't rely on implict list ordering 2023-04-13 14:37:18 +02: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
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
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 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
Alex Valiushko db99c252a0 Add setting to disable op policy edit via API 2023-02-06 14:36:10 -08: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
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
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
Diana Parra Corbacho f2443f6d10 Move mnesia queries from rabbit_misc to rabbit_mnesia 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 d0ac99df5e Move queue/exchange/binding/policy Mnesia-specific code to rabbit_db_* modules 2023-01-31 10:23:16 +01:00
Luke Bakken b70af46b2e
Ensure that a timeout closes exe port on win32
Fixes #7038
2023-01-26 11:51:52 -08:00
Chunyi Lyu 6cc65ecceb Export opaque types for event and mqtt_packet state 2023-01-24 17:32:59 +00:00
David Ansari 15636fdb90 Rename frame to packet
The MQTT protocol specs define the term "MQTT Control Packet".
The MQTT specs never talk about "frame".

Let's reflect this naming in the source code since things get confusing
otherwise:
Packets belong to MQTT.
Frames belong to AMQP 0.9.1 or web sockets.
2023-01-24 17:30:10 +00:00
David Ansari 816fedf080 Enable flow control to target classic queue 2023-01-24 17:29:07 +00:00
David Ansari af68fb4484 Decrease memory usage of queue_type state
Prior to this commit, 1 MQTT publisher publishing to 1 Million target
classic queues requires around 680 MB of process memory.

After this commit, it requires around 290 MB of process memory.

This commit requires feature flag classic_queue_type_delivery_support
and introduces a new one called no_queue_name_in_classic_queue_client.

Instead of storing the binary queue name 4 times, this commit now stores
it only 1 time.

The monitor_registry is removed since only classic queue clients monitor
their classic queue server processes.

The classic queue client does not store the queue name anymore. Instead
the queue name is included in messages handled by the classic queue
client.

Storing the queue name in the record ctx was unnecessary.

More potential future memory optimisations:
* When routing to destination queues, looking up the queue record,
  delivering to queue: Use streaming / batching instead of fetching all
  at once
* Only fetch ETS columns that are necessary instead of whole queue
  records
* Do not hold the same vhost binary in memory many times. Instead,
  maintain a mapping.
* Remove unnecessary tuple fields.
2023-01-24 17:29:07 +00:00
David Ansari ab8957ba9c Use best-effort client ID tracking
"Each Client connecting to the Server has a unique ClientId"

"If the ClientId represents a Client already connected to
the Server then the Server MUST disconnect the existing
Client [MQTT-3.1.4-2]."

Instead of tracking client IDs via Raft, we use local ETS tables in this
commit.

Previous tracking of client IDs via Raft:
(+) consistency (does the right thing)
(-) state of Ra process becomes large > 1GB with many (> 1 Million) MQTT clients
(-) Ra process becomes a bottleneck when many MQTT clients (e.g. 300k)
    disconnect at the same time because monitor (DOWN) Ra commands get
    written resulting in Ra machine timeout.
(-) if we need consistency, we ideally want a single source of truth,
    e.g. only Mnesia, or only Khepri (but not Mnesia + MQTT ra process)

While above downsides could be fixed (e.g. avoiding DOWN commands by
instead doing periodic cleanups of client ID entries using session interval
in MQTT 5 or using subscription_ttl parameter in current RabbitMQ MQTT config),
in this case we do not necessarily need the consistency guarantees Raft provides.

In this commit, we try to comply with [MQTT-3.1.4-2] on a best-effort
basis: If there are no network failures and no messages get lost,
existing clients with duplicate client IDs get disconnected.

In the presence of network failures / lost messages, two clients with
the same client ID can end up publishing or receiving from the same
queue. Arguably, that's acceptable and less worse than the scaling
issues we experience when we want stronger consistency.

Note that it is also the responsibility of the client to not connect
twice with the same client ID.

This commit also ensures that the client ID is a binary to save memory.

A new feature flag is introduced, which when enabled, deletes the Ra
cluster named 'mqtt_node'.

Independent of that feature flag, client IDs are tracked locally in ETS
tables.
If that feature flag is disabled, client IDs are additionally tracked in
Ra.

The feature flag is required such that clients can continue to connect
to all nodes except for the node being udpated in a rolling update.

This commit also fixes a bug where previously all MQTT connections were
cluster-wide closed when one RabbitMQ node was put into maintenance
mode.
2023-01-24 17:29:07 +00:00
David Ansari f4d1f68212 Move authn / authz into rabbitmq_mqtt 2023-01-24 17:29:07 +00:00
Michael Klishin 8e9f0f7627
Merge pull request #7021 from rabbitmq/dialyzer-warnings-rabbit
Fix all dialyzer warnings in `rabbit`
2023-01-24 10:51:44 -06:00
Alexey Lebedeff 7c0f04067f Fix all dialyzer warnings in `rabbit` 2023-01-24 17:26:58 +01:00
Alexey Lebedeff 183a260290 Fix all dialyzer warnings in peer discovery plugins 2023-01-23 22:32:06 +00:00
Rin Kuryloski a317b30807 Use improved assert_suites2 macro from rules_erlang 3.9.0 2023-01-18 15:07:06 +01:00
Jean-Sébastien Pédron 8788e65bc7
Declare logging domain for database-related messages
Here is an example:

    ?LOG_DEBUG(
      "DB: initialization successeful",
      #{domain => ?RMQLOG_DOMAIN_DB}),
2023-01-13 11:37:13 +01:00
Michael Klishin ec4f1dba7d
(c) year bump: 2022 => 2023 2023-01-01 23:17:36 -05:00
Luke Bakken cedf909270
Update mix_task_archve_deps to 1.0.0
Also update with SHA512 so that the download and install via `mix archive.install` works.

Related to: https://groups.google.com/g/rabbitmq-users/c/mSJMjyE20Nk
2022-12-12 16:43:32 -08:00
Luke Bakken 10fcc64b74
Use win32_cmd/2 to run handle.exe because it is great. 2022-12-10 14:20:02 -08:00
Luke Bakken f7b65abc15
Execute powershell directly 2022-12-10 13:19:45 -08:00
Péter Gömöri 6a6f29cbea Report flow/blocked shovel status in Mgmt UI 2022-12-08 23:37:40 +01:00
Rin Kuryloski cf3fa10c98 Turn strict dialyzer back on for some deps 2022-12-02 09:51:27 +01:00
Rin Kuryloski bef2756b5f Fixes for various dialyzer warnings 2022-12-02 09:14:08 +01:00
Rin Kuryloski 57d7f7f8b5 Fix dialyzer warnings in rabbit_common 2022-12-02 09:13:56 +01:00
Rin Kuryloski 344e4553ba Fix rabbit_misc:hexify/1 when called with a list 2022-12-02 09:13:47 +01:00
Jean-Sébastien Pédron ae06f79c10
rabbit: Introduce `rabbit:data_dir/0`
This function returns the data directory where all subsystems should
store their files.

Historically, this was the Mnesia directory. But semantically, this
should be the reverse: RabbitMQ owns the data directory and Mnesia is
configured to put its files there too.

`rabbit_mnesia:dir/0` now calls `rabbit:data_dir/0`.

Other subsystems will be modified in a follow-up commit to call
`rabbit:data_dir/0` instead of `rabbit_mnesia:dir/0`.
2022-11-30 14:41:28 +01:00
Jean-Sébastien Pédron 99b14fd0fa
rabbit_env: Rename `mnesia_*dir` to `data_*dir`
The location and name of this directory remains the same for
compatibility reasons. Therefore, it sill contains "mnesia" in its name.
However, semantically, we want this directory to be unrelated to Mnesia.

In the end, many subsystems write files and directories there, including
Mnesia, all Ra systems and in the future, Khepri.
2022-11-30 13:00:49 +01:00
Jean-Sébastien Pédron e0b4bce4f4
rabbit_env: Rename `data_dir` to `home_dir`
This value is used internally by `rabbit_env` and usually not read by
RabbitMQ otherwise.

This patch prepares the rename of `mnesia_dir` to `data_dir`, in order
to not semantically rely on Mnesia configuration or use to locate data,
whether it is stored in Mnesia or not.
2022-11-30 13:00:45 +01:00
Michal Kuratczyk 05ec5e488f
Remove unnecessary call to priority_queue:len/1
Seems like we are not using it anywhere in our code base.
It's unlikely that it's used somewhere else and even if it is,
the API is backwards compatible - we just pass 0, as if the priority_queue
was empty.
2022-11-24 13:02:43 +01:00
Michael Klishin 8ad1c8be5c
Bump credentials_obfuscation to 3.2.0 2022-11-08 03:35:33 +04:00
Michael Klishin fb2b219522
Merge pull request #6126 from rabbitmq/partially-revert-delegate-opt-3865
Partially revert delegate optimisation
2022-10-17 21:05:58 +04:00
Karl Nilsson 8804434a01 Partially revert delegate optimisation
That was done in PR #3865.

The changes introduced in #3865 can cause message arrival ordering guarantees
between two logical erlang process (sending messages via delegate) to
be violated as a message sent to a single destination can overtake a prior
message sent as part of a fan-out. This is due to the fact that the fan-out
take a different route via the delegate process than the direct delivery that
bypasses it.

This commit only reverses it for the `invoke_no_result/2|3` API and leaves the
optimisation in for the synchronous `invoke/` API. This means that the message
send ordering you expect between erlang processes still can be violated when
mixing invoke and invoke_no_result invocations. As far as I can see there are
no places where the code relies on this and there are uses of invoke (mgmt db)
that very well could benefit from avoiding the additional copying.
2022-10-17 15:15:22 +01:00
Michael Klishin 08d804786c Handle a rare case with multiple dist ports
See rabbitmq/rabbitmq-server#6097 for background
2022-10-17 15:37:33 +04:00
Luke Bakken 7fe159edef
Yolo-replace format strings
Replaces `~s` and `~p` with their unicode-friendly counterparts.

```
git ls-files *.erl | xargs sed -i.ORIG -e s/~s>/~ts/g -e s/~p>/~tp/g
```
2022-10-10 10:32:03 +04:00
Jean-Sébastien Pédron 4b132daaba
Remove upgrade-specific log file
This category should be unused with the decommissioning of the old
upgrade subsystem (in favor of the feature flags subsystem). It means:
1. The upgrade log file will not be created by default anymore.
2. The `$RABBITMQ_UPGRADE_LOG` environment variable is now unsupported.

The configuration variables remain to avoid breaking an existing and
working configuration.
2022-10-06 21:28:50 +02:00
Luke Bakken 74cddc29ab
Update from `master` to `main`
Fixes #5980

Reference rabbitmq/rabbitmq-metronome#16
2022-10-03 12:32:04 -07:00
Michael Klishin 69b06d30f1
Merge pull request #4522 from rabbitmq/loic-cq-dont-reduce-memory-usage
CQ: Merge lazy/default behavior into a unified mode
2022-10-01 20:11:41 +04:00
Luke Bakken 553aab51c9
Update branch names and links
Fix publish of libs to hex.pm

@lhoguin noticed that the hex packages for the amqp_client, amqp10_client and related project do not currently work with erlang.mk. This PR fixes this issue.

Tested using this project: https://github.com/lukebakken/amqp-clients-test.git
2022-09-29 13:58:56 -07:00
Michal Kuratczyk 2855278034
Migrate from supervisor2 to supervisor 2022-09-27 13:53:06 +02:00
Loïc Hoguin 3683ab9a6e
CQ: Use v2 sets instead of gb_sets for confirms
For the following flags I see an improvement of
30k/s to 34k/s on my machine:

-x 1 -y 1 -A 1000 -q 1000 -c 1000 -s 1000 -f persistent
-u cqv2 --queue-args=x-queue-version=2
2022-09-27 12:00:08 +02:00
Luke Bakken 3c1c7ada58
Log errors from unicode:characters_to_list 2022-09-24 11:37:29 -07:00
Luke Bakken 755ac7176b
Follow-up to #5486
Discovered by @dumbbell

Ensure externally read strings are saved as utf-8 encoded binaries. This
is necessary since `cmd.exe` on Windows uses ISO-8859-1 encoding and
directories can have latin1 characters, like `RabbitMQ Sérvér`.

The `é` is represented by decimal `233` in the ISO-8859-1 encoding. The
unicode code point is the same decimal value, `233`, so you will see
this in the charlist data. However, when encoded using utf-8, this
becomes the two-byte sequence `C3 A9` (hexidecimal).

When reading strings from env variables and configuration, they will be
unicode charlists, with each list item representing a unicode code
point. All of Erlang string functions can handle strings in this form.
Once these strings are written to ETS or Mnesia, they will be converted
to utf-8 encoded binaries. Prior to these changes just
`list_to_binary/1` was used.

Fix xref error

re:replace requires an iodata, which is not a list of unicode code points

Correctly parse unicode vhost tags

Fix many format strings to account for utf8 input. Try again to fix unicode vhost tags

More format string fixes, try to get the CONFIG_FILE var correct

Be sure to use the `unicode` option for re:replace when necessary

More unicode format strings, add unicode option to re:split

More format strings updated

Change ~s to ~ts for vhost format strings

Change ~s to ~ts for more vhost format strings

Change ~s to ~ts for more vhost format strings

Add unicode format chars to disk monitor

Quote the directory on unix

Finally figure out the correct way to pass unicode to the port
2022-09-24 11:19:59 -07:00
David Ansari d4a25f9092 Use maps:get/3
instead of maps:find/2.
This creates less garbage.
2022-09-09 10:52:38 +00:00
David Ansari b6952540a3 Remove rabbit_misc:atom_to_binary/1
Nowadays, we have erlang:atom_to_binary/1.
2022-09-09 10:52:38 +00:00
David Ansari b953b0f10e Stop sending stats to rabbit_event
Stop sending connection_stats from protocol readers to rabbit_event.
Stop sending queue_stats from queues to rabbit_event.
Sending these stats every 5 seconds to the event manager process is
superfluous because noone handles these events.

They seem to be a relict from before rabbit_core_metrics ETS tables got
introduced in 2016.

Delete test head_message_timestamp_statistics because it tests that
head_message_timestamp is set correctly in queue_stats events
although queue_stats events are used nowhere.
The functionality of head_message_timestamp itself is still tested in
deps/rabbit/test/priority_queue_SUITE.erl and
deps/rabbit/test/temp/head_message_timestamp_tests.py
2022-09-09 10:52:38 +00:00
Michael Klishin ab5eeb745c
Merge pull request #5659 from Ayanda-D/allow-ignoring-supervisor2-error-reports
Controllable way to ignore supervisor2 error reports
2022-08-29 02:13:57 +04:00
Ayanda Dube 55526755ec Ensure clean shutdown of rabbit_event manager in supervisor2_SUITE to avoid noisy test terminations 2022-08-28 22:45:52 +01:00
Ayanda Dube f10f81bf90 Rename TRACE_SUP2 to TRACE_SUPERVISOR2 and add to Makefile 2022-08-28 22:41:54 +01:00
Ayanda Dube daf1a52e99 Inlcude test_event_handler in rabbit_common supervisor2_SUITE bazel 2022-08-28 22:37:34 +01:00
Ayanda Dube 80f2116935 Use local include to reference rabbit.hrl in test_event_handler 2022-08-28 19:52:44 +01:00
Michael Klishin cb7d840700 Basic unit tests for rabbit_date_time 2022-08-28 14:43:35 +04:00
Michael Klishin 2153acf8e1 Introduce a concept of release series EOL date
into the code as well as application environment default. This way
this value can be checked and every branch can use a value that makes
sense to it.
2022-08-27 17:33:35 +04:00
Ayanda Dube bd70cb1b9c Use SupPID provided in ?TRACE_SUPERVISOR2_ERROR_LOG macro through
SupName.
2022-08-26 19:43:56 +01:00
Ayanda Dube be6c188d64 Implement tests for controlling supervisor2 error reports.
Tests behaviour controlled at compile time through, macro.
2022-08-26 18:35:47 +01:00
Ayanda Dube fa508aca99 Add a test_event_handler for rabbit_common event based tests 2022-08-26 18:30:37 +01:00
Ayanda Dube 2f78330d35 Control supervisor2 error reports with application variable to be set
in e.g. the `advanced.config` file, or manually in runtime.

This also adds tracing through use of `rabbit_event`, controllable by
use of compile time flag, e.g. TRACE_SUP2.
2022-08-26 18:27:01 +01:00
Johan Rhodin 70c2fb78dc
Fix typo 2022-08-23 16:02:48 -05:00
Péter Gömöri e979b2fad6 Fix a typo in a comment in rabbit_env 2022-08-23 00:54:35 +02:00
Michal Kuratczyk b6006aa207 Remove an old check
It returns true in all supported OTP version.
2022-08-19 17:00:48 +02:00
Michael Klishin b378483a1e
Merge pull request #5486 from rabbitmq/rabbitmq-server-5471-2
Run rabbitmq-env-conf.bat on win32 taking spaces into account
2022-08-16 23:43:09 +04:00
Luke Bakken 032afd8dbc
Fix `badmatch` by taking edge case into account
A couple users reported `badmatch` crashes due to scenarios where
`inet:peername/1` does not return the expected value, most likely due to
the port closing between the time they are listed and when
`inet:peername/1` is called.

Fixes #5496

Discussion in #5490
2022-08-16 09:26:15 -07:00
Rin Kuryloski 575c5f9975 Remove all of the .travis.yml files
since we no longer use them
2022-08-16 09:46:31 +02:00
Luke Bakken fae769458c
Ensure CONF_ENV_FILE is run correctly on win32
Fixes #5471
2022-08-11 10:40:41 -07:00
Michael Klishin 0639f3ecd2
rabbit_json:decode/2: raise a two-tuple error 2022-07-30 04:26:13 +04:00
Michael Klishin 2bd585dd64
rabbit_json:decode/1: use erlang:error/1 like the JSX version did 2022-07-29 10:34:52 +04:00
Michael Klishin bad6e394b2
Swap JSX for Thoas in more places
and adapt rabbit_json for Thoas in the process.

Pair: @pjk25
2022-07-29 10:34:51 +04:00
Michael Klishin 9c99f76579
Replace JSX with Thoas for JSON operations
Thoas is more efficient both in terms of encoding
time and peak memory footprint.

In the process we have discovered an issue:
https://github.com/lpil/thoas/issues/15

Pair: @pjk25
2022-07-29 10:34:47 +04:00
Gabriele Santomaggio 72d522a8ce
change timeout to 5 seconds
Signed-off-by: Gabriele Santomaggio <G.santomaggio@gmail.com>
2022-07-26 14:48:06 +02:00
dcorbacho 40b05357d0 Move mirrored_supervisor to rabbit application
where it belongs
2022-07-21 12:08:35 +02:00
Rin Kuryloski e80c17c56b Be less noisy when sysctl cannot be used for vm_memory_monitor
This avoids printing the full stacktrace when the error comes from the
sysctl invocation, the error message itself is sufficient

In practice, when testing with bazel with macos, sysctl is blocked by
the sandbox, so logging the stacktrace is rather noisy for tests
2022-07-18 12:43:39 +00:00
Luke Bakken f56c84489f
Continuously run powershell to get disk free space
Much faster than starting it every time.

Fixes #4140

Take noeol into account
2022-07-13 07:42:39 -07:00
Jean-Sébastien Pédron bcb8733880
rabbit_feature_flags: Add a feature flags controller process
This gen_statem-based process is responsible for handling concurrency
when feature flags are enabled and synchronized when a cluster is
expanded.

This clarifies and stabilizes the behavior of the feature flag subsystem
w.r.t. situations where e.g. a feature flag migration function takes
time to update data and a new node joins a cluster and synchronizes its
feature flag states with the cluster. There was a chance that the
feature flag was marked as enabled on the joining node, even though the
migration function didn't take care of that node.

With this new feature flags controller, enabling or synchronizing
feature flags blocks and delays any concurrent operations which try to
modify feature flags states too.

This change also clarifies where and when the migration function is
called: it is called at least once on each node who knows the feature
flag and when the state goes from "disabled" to "enabled" on that node.

Note that even if the feature flag is being enabled on a subset of the
nodes (because other nodes already have it enabled), it is marked as
"state_changing" everywhere during the migration. This is to prevent
that a node where it is enabled assumes it is enabled on all nodes who
know the feature flag.

There is a new feature as well: just after a feature flag is enabled,
the migration function is called a second time for any post-enable
actions. The feature flag is marked as enabled between these "enable"
and "post-enable" steps. The success or failure of this "post-enable"
run does not affect the state of the feature flag (i.e. it is ignored).

A new migration function API is introduced to allow more advanced
things. The new API is:

    my_migration_function(
      #ffcommand{name = ...,
                 props = ...,
		 command = enable | post_enable,
		 extra = #{...}})

The record is defined in `include/feature_flags.hrl`. Here is the
meaning of each field:

* `name` and `props` are the equivalent of the `FeatureName` and
  `FeatureProps` arguments of the previous migration function API.

* `command` is basically the same as the previous `Arg` arguments.

* `extra` is map containing context-specific information. For instance, it
  contains the list of nodes where the feature flag state changes.

This whole new behavior is behind a new feature flag called
`feature_flags_v2`. If a feature flag uses the new migration function
API, `feature_flags_v2` will be automatically enabled.

If many feature flags are enabled at once (like when a fresh RabbitMQ
node is started for the first time), `feature_flags_v2` will be enabled
first if it is in the list.
2022-06-28 10:13:19 +02:00
Michael Klishin b8718c736e
Merge pull request #5020 from rabbitmq/stream-max-segment-size-limit
Limit stream max segment size to 3 GB
2022-06-10 18:53:15 +04:00
Michael Klishin aa8b0dc778
Merge pull request #4985 from rabbitmq/rabbitmq-server-4981
Fix cluster links statistic
2022-06-10 13:50:03 +04:00
Arnaud Cogoluègnes e44b65957d
Limit stream max segment size to 3 GB
Values too large can overflow the stream position field
in the index (32 bit int).
2022-06-10 11:45:57 +02:00
Philip Kuryloski 15a79466b1 Use the new xref2 macro from rules_erlang
That adopts the modern erlang.mk xref behaviour
2022-06-09 23:18:28 +02:00
Luke Bakken 86a509df80
Fix cluster links statistic
Use the `sys_dist` ets table to get distribution port information.

Fixes #4981

Get cluster links stats for TLS dist

Use code from prometheus.erl to get dist links info
2022-06-09 07:20:45 -07:00
Philip Kuryloski 327f075d57 Make rabbitmq-server work with rules_erlang 3
Also rework elixir dependency handling, so we no longer rely on mix to
fetch the rabbitmq_cli deps

Also:

- Specify ra version with a commit rather than a branch
- Fixup compilation options for erlang 23
- Add missing ra reference in MODULE.bazel
- Add missing flag in oci.yaml
- Reduce bazel rbe jobs to try to save memory
- Use bazel built erlang for erlang git master tests
- Use the same cache for all the workflows but windows
- Avoid using `mix local.hex --force` in elixir rules
  - Fetching seems blocked in CI, and this should reduce hex api usage in
    all builds, which is always nice
- Remove xref and dialyze tags since rules_erlang 3 includes them in
  the defaults
2022-06-08 14:04:53 +02:00
Luke Bakken b172bca19b
Add rabbit_consult module
This will be used to fix rabbitmq/osiris#78

If a RabbitMQ `advanced.config` file contains the following:

```
{customize_hostname_check, [
    {match_fun, public_key:pkix_verify_hostname_match_fun(https)}
]}
```

...`file:consult/1` will fail because it does not evaluate terms in the
file.

The code in `rabbit_consult` was copied from this OTP module:

https://github.com/erlang/otp/blob/master/lib/ssl/src/ssl_dist_sup.erl

...and then modified for our use.

Add Bazel suite

Use the same license as Erlang/OTP, add link to source cc @dumbbell

Add test and ensure value returned matches file:consult/1

Add test data file

Ensure that Funs are converted to binaries before jsx:encode is called

Add a check that customize_hostname_check can be JSON encoded

Ensure that customize_hostname_check and match_fun are filtered out from listener data
2022-06-05 06:13:49 -07:00
Michael Klishin 5777dc9d44
Merge pull request #4955 from rabbitmq/switch-from-python-to-python3 2022-06-02 13:37:15 +04:00
Philip Kuryloski b24ab46a1a Switch the default python binary for codegen scripts to python3 2022-06-02 10:58:42 +02:00
Loïc Hoguin dc70cbf281
Update Erlang.mk and switch to new xref code 2022-05-31 13:51:12 +02:00
David Ansari 2d14403dad Reduce expiry limit from 100 to 10 years 2022-05-18 12:11:57 +00:00
David Ansari de4eeb678e Set maximum expiration
When applications accidentally set an unreasonable high value for
the message TTL expiration field, e.g. 6779303336614035452,
before this commit quorum queue and classic queue processes crashed:

```
2022-05-17 13:35:26.488670+00:00 [notice] <0.1000.0> queue 'test' in vhost '/': candidate -> leader in term: 2 machine version: 2
2022-05-17 13:35:26.489492+00:00 [error] <0.1000.0>   crasher:
2022-05-17 13:35:26.489492+00:00 [error] <0.1000.0>     initial call: ra_server_proc:init/1
2022-05-17 13:35:26.489492+00:00 [error] <0.1000.0>     pid: <0.1000.0>
2022-05-17 13:35:26.489492+00:00 [error] <0.1000.0>     registered_name: '%2F_test'
2022-05-17 13:35:26.489492+00:00 [error] <0.1000.0>     exception error: bad argument
2022-05-17 13:35:26.489492+00:00 [error] <0.1000.0>       in function  erlang:start_timer/4
2022-05-17 13:35:26.489492+00:00 [error] <0.1000.0>          called as erlang:start_timer(6779303336614035351,<0.1000.0>,
2022-05-17 13:35:26.489492+00:00 [error] <0.1000.0>                                       {timeout,expire_msgs},
2022-05-17 13:35:26.489492+00:00 [error] <0.1000.0>                                       [])
2022-05-17 13:35:26.489492+00:00 [error] <0.1000.0>          *** argument 1: exceeds the maximum supported time value
2022-05-17 13:35:26.489492+00:00 [error] <0.1000.0>       in call from gen_statem:loop_timeouts_start/16 (gen_statem.erl, line 2108)
2022-05-17 13:35:26.489492+00:00 [error] <0.1000.0>     ancestors: [<0.999.0>,ra_server_sup_sup,<0.250.0>,ra_systems_sup,ra_sup,
2022-05-17 13:35:26.489492+00:00 [error] <0.1000.0>                   <0.186.0>]
```

In this commit, we disallow expiry fields higher than 100 years.
This causes the channel to be closed which is better than crashing the
queue process.

This new validation applies to message TTLs and queue expiry.

From the docs of erlang:start_timer:
"The absolute point in time, the timer is set to expire on, must be in the interval
[erlang:convert_time_unit(erlang:system_info(start_time), native, millisecond),
 erlang:convert_time_unit(erlang:system_info(end_time), native, millisecond)].
If a relative time is specified, the Time value is not allowed to be negative.

end_time:
The last Erlang monotonic time in native time unit that can be represented
internally in the current Erlang runtime system instance.
The time between the start time and the end time is at least a quarter of a millennium."
2022-05-18 11:01:17 +00:00
Michael Klishin 949f7e37db
Bump credentials_obfuscation to 3.1.0 2022-05-16 23:54:32 +04:00
Michael Klishin 5cf3a43523
Revert "Make master depend on credentials_obfuscation main branch"
This reverts commit 62819f3bcc.

This commit has served its QA purpose.

Will either update Bazel dependency to use git or pin to
a new release instead.
2022-05-14 02:58:07 +04:00
Michael Klishin 62819f3bcc
Make master depend on credentials_obfuscation main branch 2022-05-14 01:42:09 +04:00
David Ansari 84ff7e6dea Increase routing throughput for direct exchange 2022-05-11 15:25:15 +00:00
Philip Kuryloski 2e62cae69e Use rabbitmqctl await_startup instead if erl eval
when starting background nodes for tests
2022-05-04 13:33:03 +02:00
Michael Klishin a66ac8c347
Bump credentials_obfuscation to 3.0.0 2022-05-02 11:57:55 +04:00
Michael Klishin 1d9ef20adb
Drop -Wrace_conditions from Dialyzer opts in more places
for Erlang 25 compatibility
2022-04-30 01:49:09 +04:00
Michael Klishin 7cb439cda6
Merge pull request #4665 from rabbitmq/rabbitmq-server-4588-follow-up
OAuth 2: expand all scope aliases provided
2022-04-27 22:04:32 +04:00
Michael Klishin ca290f1116
OAuth 2: expand all scope aliases provided
Per discussion with @MarcialRosales.

In follow-up to #4588.
2022-04-27 21:21:40 +04:00
Philip Kuryloski a4da3bb332 Add a MODULE.bazel file and enable bzlmod 2022-04-27 16:07:52 +02:00
Michael Klishin f69fe93136
Correct a double quote introduced in #4603 2022-04-20 16:06:36 +04:00
Michael Klishin 7c47d0925a
Revert "Correct a double quote introduced in #4603"
This reverts commit 6a44e0e2ef.

That wiped a lot of files unintentionally
2022-04-20 16:05:56 +04:00
Michael Klishin 6a44e0e2ef
Correct a double quote introduced in #4603 2022-04-20 16:01:29 +04:00
Michael Klishin cfb1d44920
Correct GitHub repo links in Hex metadata 2022-04-20 11:14:12 +04:00
Luke Bakken fb5068a80e
Begin work migrating to native hex publishing
Use hex for credentials_obfuscation dep
2022-04-19 13:21:52 -07:00
Luke Bakken dba25f6462
Replace files with symlinks
This prevents duplicated and out-of-date instructions.
2022-04-15 06:04:29 -07:00
Philip Kuryloski 2dd9bde891 Bring over PROJECT_APP_EXTRA_KEYS values from make to bazel 2022-04-07 17:39:33 +02:00
Philip Kuryloski a22234f6eb Updates for rules_erlang 2.5.0
rabbitmq_cli uses some private rules_erlang apis that have changed in
the upcoming release

Additionally:
- Avoid including both standard and test versions of amqp_client in
integration test suites
- Eliminate most of the compilation order hints (explicit first_srcs)
in the bazel build
- Fix an include statement - in bazel, an app is not available to
itself as a library at compilation time
2022-04-07 14:54:37 +02:00
Loïc Hoguin 499e0b9197
Remove the CQv1 disabled stats from management/Prometheus 2022-04-05 12:37:54 +02:00
Loïc Hoguin 81c0fa7cc1
CQv1: Disable expensive stats killing v1 performance
In particular:

 - io_file_handle_open_attempt
 - queue_index_journal_write

Neither have proven to be very useful in recent years
and with the move to FHC-less and journal-less v2 index
they will slowly become irrelevant. This should be a
good compromise until we can switch to v2 permanently
or rework the stats module to use counters.
2022-04-05 12:37:49 +02:00
Luke Bakken 9799fc6674
Add necessary items for hex-publish to work for amqp10_client 2022-03-29 10:25:45 -07:00
Michael Klishin c5c730c371
Merge pull request #4324 from felixhuettner/fhcs_write_concurrency
Enable write_concurrency for file handle cache stats
2022-03-22 12:20:08 +04:00
Michael Klishin c38a3d697d
Bump (c) year 2022-03-21 01:21:56 +04:00
Felix Huettner fab514f643 Enable write_concurrency for file handle cache stats
During most of the time the file_handle_cache_stats ets table is
used for writing only.
By enabeling `write_concurrency` on the table we allow different values
to be written concurrently without taking a global lock.

There the only codepath reading from the ets table is run on the
`collect_statistics_interval` interval and reads the whole table.
So we can assume we are not blocking any large amount of concurrent reads.
2022-03-14 14:58:36 +01:00
Karl Nilsson 4b193608bb
Merge pull request #3121 from rabbitmq/quorum-queues-v2
QQ: introduce new machine version (2)
2022-03-08 16:19:04 +00:00
Michael Klishin 8ff862f0f6
Merge pull request #4233 from ansd/nxdomain
Wait between retries if nxdomain
2022-03-04 22:05:41 +06:00
David Ansari 1c17773c91 Add at-least once dead-lettering for quorum queues
and message TTL
2022-02-28 16:27:56 +01:00
Philip Kuryloski d8201726ae Ignore dialyzer warnings for most apps 2022-02-21 09:19:56 +01:00
Michael Klishin 127f39a090
Squash a compilation warning 2022-01-28 23:01:19 +03:00
Michael Klishin 057e033431
Introduce definition hashing during import
as an opt-in feature. The goal is to avoid re-importing the definition
from the definition file/directory/source if we know the content
has not changed. Since this feature won't be appropriate for
every environment (sometimes unconditional reimporting is expected),
the feature is opt-in.

This is still a WIP.
2022-01-28 22:52:00 +03:00
Philip Kuryloski efcd881658 Use rules_erlang v2
bazel-erlang has been renamed rules_erlang. v2 is a substantial
refactor that brings Windows support. While this alone isn't enough to
run all rabbitmq-server suites on windows, one can at least now start
the broker (bazel run broker) and run the tests that do not start a
background broker process
2022-01-18 13:43:46 +01:00
Luke Bakken 95a60fc3be
Replace one use of filelib:is_regular/1
This specific case is called multiple times by the Prometheus plugin. It eventually calls `file:read_file_info/1` which leaks on Windows

See #3936
2022-01-11 09:08:34 -08:00
Michael Klishin d2e0fae1aa
Bump (c) year in node startup banner 2022-01-05 09:03:46 +04:00
Luke Bakken 7f0285834e
Fix all uses of file:read_file/1
This is to address another memory leak on win32 reported here:

https://groups.google.com/g/rabbitmq-users/c/UE-wxXerJl8

"RabbitMQ constant memory increase (binary_alloc) in idle state"

The root cause is the Prometheus plugin making repeated calls to `rabbit_misc:otp_version/0` which then calls `file:read_file/1` and leaks memory on win32.

See https://github.com/erlang/otp/issues/5527 for the report to the Erlang team.

Turn `badmatch` into actual error
2022-01-03 11:33:36 -08:00
Michael Klishin 394ee4880a
delegate: documentation edits 2021-12-26 03:19:33 +03:00
tomyouyou 40db6563b8
Optimisation for 'delegate'
This is copied from https://github.com/rabbitmq/rabbitmq-common/pull/349


If a message is sent to only one queue(in most application scenarios), passing through the 'delegate' is meaningless. Otherwise, it increases the delay of the message and the possibility of 'delegate' congestion.

Here are some test data:
node1: Pentium(R) Dual-Core CPU E5300 @ 2.60GHz
node2: Pentium(R) Dual-Core CPU E5300 @ 2.60GHz

Join node1 and node2 to a cluster. Create 100 queues on node2, and start 100 consumers to receive messages from these queues.
Start 100 publishers on node1 to send messages to the queues of node2. Each publisher will send 10k messages at the rate of 100/s(10k/s theoretically in total), and all the messages for all publishers is 1 million.

Before optimisation:
{1,[{msg_time,812312(=<1ms),177922(=<5ms),9507(=<50ms),221(=<500ms),38(=<1000ms),0,0,0,0,1061,1069,0,0}]}

After optimisation:
{1,[{msg_time,902854(=< 1ms),93993(=<5ms),3038(=<50ms),96(=<500ms),19(=<1000ms),0,0,0,0,1049,1060,0,0}]}

Additional information:

Time counted here is the stay time of a message in the cluster, that is, Time(leaving from node2 at) - Time(reaching node1 at).
"812312(=<1ms)" is the number of messages with time consumption less than or equal to 1ms.
Overall, the optimisation is effective.
2021-12-07 17:58:42 +08:00
Sagi Sarussi eff5c063cb
Grammar 2021-11-10 15:31:06 +02:00
Arnaud Cogoluègnes 75b2a53f52
Merge pull request #3503 from rabbitmq/super-stream-cli
Add functions to create/delete super stream in manager
2021-10-14 11:01:58 +02:00
Alexey Lebedeff 23be565a38 Allow having multiple `make run-broker` simulatneously
It was automatically happening for e.g. `make start-cluster`.

But some plugins were not covered by default generated config, and
running rabbit from 2 different worktrees was a bit complicated.
2021-10-13 10:52:02 +02:00
Arnaud Cogoluègnes 6b9589bae4
Handle stream arguments in add_super_stream command
max-age, leader-locator, etc.
2021-10-11 16:50:03 +02:00
Michael Klishin 798be7dcaf
Peer discovery AWS, K8S: more Dialyzer fixes 2021-10-07 03:42:44 +03:00
Michal Kuratczyk 1a2126676d Update CLA URL 2021-09-23 14:29:36 +02:00
Michael Klishin 5fb118e8ef
Merge pull request #3409 from rabbitmq/lh-increase-queue-shutdown-timeout
Increase classic queue shutdown timeout
2021-09-21 16:46:21 +03:00
Philip Kuryloski bcd565f2cb Use the +deterministic compiler flag when building with Make 2021-09-17 09:34:50 +02:00
Loïc Hoguin 09c8cd4f98
Increase classic queue shutdown timeout
A value that is too low will prevent the index from shutting
down in time when there are many queues. This leads to the
process being killed and on the next RabbitMQ restart a
(potentially very long) dirty recovery is needed.

The value of 10 minutes was chosen to mirror the shutdown
timeout of the message store. Since both queues and message
store need to have shut down gracefully in order to have
a clean restart it makes sense to use the same value.

Related: c40c2628a9
2021-09-13 10:59:30 +02:00
Philip Kuryloski 5fd9d1f638 Use Ranch 2.1.0 in bazel build
Matches 063d32626d
2021-09-10 14:46:36 +02:00
Loïc Hoguin 0a2bde4ab1
Use the new function ranch_proxy_header:to_connection_info/1 2021-09-09 13:15:08 +02:00
Paweł Chmielowski 6af41527f1 Fix some edge cases in handling ssl information from PROXY protocol
When we fail to parse name of cipher suite from PROXY protocol
just say that no ssl is used, instead of trying to fill that
with data from connection between proxy and our server.
2021-09-06 19:36:42 +02:00
Jean-Sébastien Pédron 689c56cb04
Logging: Add `single_line` flag support to $RABBITMQ_LOG
A user could already enable single-line logging (the `single_line`
option of `logger_formatter` or RabbitMQ internal formatters) from the
configuration file. For example:

    log.console.formatter.single_line = on

With this patch, the option can be enabled from the `$RABBITMQ_LOG`
environment variable as well:

    make run-broker RABBITMQ_LOG=+single_line
2021-09-01 09:31:54 +02:00
Jean-Sébastien Pédron 33c6cbf239
rabbit_env: Add $RABBITMQ_DEFAULT_{USER,PASS,VHOST} and $RABBITMQ_ERLANG_COOKIE vars
Those environment variables are unset by default. The default values are
set in the `rabbit` application environment and can be configured in the
configuration file. However, the environment variables will take
precedence over them respectively if they are set.
2021-08-11 15:50:36 +02:00
Alexey Lebedeff 87532c4af4 Make test/development related makefile vars lazy
They were trying to run `hostname` and `which`, which produced a bunch
of error messages in a hermetic build environment.

And performance of those `shell` calls is not very important, as they
are caled just a few times during script runtime anyway (there is a
hack to make these lazy, but evaluating only once - but it's hardly
worth it).
2021-08-06 17:32:04 +02:00
Michael Klishin c84115f102
Warn when lock could not be acquired successfully 2021-08-05 11:31:35 +03:00
Michael Klishin 22add3c8ca
Acquire locks when starting mirrored supervisor children
Unlike pg2, pg in Erlang 24 is eventually consistent. So this
reintroduces some of the same kind of locking mirrored_supervisor
used to rely on implicitly via pg2.

Per discussion with @lhoguin.

Closes #3260.

References #3132, #3154.
2021-08-05 00:39:16 +03:00
Michael Klishin 9a0f4b17cd
More mirrored supervisor logging 2021-08-04 16:58:44 +03:00
Michael Klishin 4f3d5e5e13
Mirrored supervisor: more logging at debug level 2021-08-04 15:56:45 +03:00
Philip Kuryloski c9e016d545 Remove duplicate compilation options in rabbit_common 2021-08-03 14:31:05 +02:00
Michael Klishin 0617419e75
This *is* a Unicode character, U+060E 2021-07-28 19:04:16 +03:00
Ilya Khaprov 854f26ac18
Do not crash on badarg when env file has an 'unusual' unicode character
closes #3212
2021-07-28 16:39:17 +02:00
Jean-Sébastien Pédron ac7df333b6
Revert "rabbitmq-dist.mk: Install CLI scripts as part of the build"
This has the unfortunate side effect of causing a rebuild of all
applications every time. I need to figure out another place to build and
install the CLI during build time (instead of as part of the dist
target).

This reverts commit 4322cca66e.
2021-07-23 10:46:56 +02:00
Philip Kuryloski ae955d44c6 Avoid building the cli scripts in rabbitmq_stream_common
This isn't an issue in the monorepo, but causes problems externally
projects using rabbitmq-components.mk
2021-07-23 10:40:20 +02:00
Jean-Sébastien Pédron 80b428d5d3
rabbit_runtime: Find erl(1) in the ERTS bin directory
erl(1) might not be in the directory pointed by init's root argument.
This is the case with Erlang releases built with relx for instance.
2021-07-22 10:21:37 +02:00
Jean-Sébastien Pédron 4322cca66e
rabbitmq-dist.mk: Install CLI scripts as part of the build
... instead of the `dist` target. This way, the Erlang release can use
them.
2021-07-22 10:21:33 +02:00
Michael Klishin 29bb9c5b0c
Merge pull request #3175 from processone/proxy_protocol_tls_info
Extract TLS informations that are delivered in PROXY protocol frame
2021-07-13 15:08:40 +03:00
Philip Kuryloski 8f9de08de7 Also assert no missing suites for all other deps 2021-07-12 18:05:55 +02:00
Paweł Chmielowski d5daf7598b Extract TLS informations that are delivered in PROXY protocol frame 2021-07-05 13:29:59 +02:00
Michael Klishin 65ccf7ce42
Mirrored supervisor: make it easier to keep track of group membership changes
in the logs.

Referenes #3148.
2021-07-05 14:02:37 +03:00
Michael Klishin 4f01d450e0
Make sure not to wait for epmd-starter subprocess forever
Per discussion in #3162
2021-06-30 15:20:09 +03:00
Michael Klishin 62e7785a48
Canonicalize a few more paths in the startup banner
References #3149
2021-06-28 13:48:13 +03:00
Pavel Heimlich 020b22f9ea fix hostname(1) calls on Solaris 2021-06-17 13:23:05 +02:00