Skip to content

Commit a7f3f4c

Browse files
committed
Forbid running with persistence true and a plugin at the same time.
1 parent efb0962 commit a7f3f4c

4 files changed

Lines changed: 64 additions & 19 deletions

File tree

ChangeLog.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
2.1.2 - 2026-02-xx
22
==================
33

4+
Broker:
5+
- Forbid running with `persistence true` and with a persistence plugin at the
6+
same time.
7+
48
Build:
59
- Build fixes for OpenBSD. Closes #3474.
610
- Add missing libedit to docker builds. Closes #3476.

man/mosquitto.conf.5.xml

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -419,13 +419,15 @@
419419
<varlistentry>
420420
<term><option>autosave_interval</option> <replaceable>seconds</replaceable></term>
421421
<listitem>
422-
<para>The number of seconds that mosquitto will wait
422+
<para>
423+
The number of seconds that mosquitto will wait
423424
between each time it saves the in-memory database to
424425
disk. If set to 0, the in-memory database will only be
425426
saved when mosquitto exits or when receiving the
426427
SIGUSR1 signal. Note that this setting only has an
427-
effect if persistence is enabled. Defaults to 1800
428-
seconds (30 minutes).</para>
428+
effect if the built-in persistence is enabled. Defaults
429+
to 1800 seconds (30 minutes).
430+
</para>
429431

430432
<para>This option applies globally.</para>
431433

@@ -445,6 +447,7 @@
445447
<option>autosave_interval</option> as a time in
446448
seconds.</para>
447449

450+
<para>Applies to built-in persistence only.</para>
448451
<para>This option applies globally.</para>
449452

450453
<para>Reloaded on reload signal.</para>
@@ -1003,18 +1006,25 @@ log_timestamp_format %Y-%m-%dT%H:%M:%S
10031006
<varlistentry>
10041007
<term><option>persistence</option> [ true | false ]</term>
10051008
<listitem>
1006-
<para>If <replaceable>true</replaceable>, connection,
1007-
subscription and message data will be written to the
1008-
disk in mosquitto.db at the location dictated by
1009-
persistence_location. When mosquitto is restarted, it
1010-
will reload the information stored in mosquitto.db. The
1011-
data will be written to disk when mosquitto closes and
1012-
also at periodic intervals as defined by
1013-
autosave_interval. Writing of the persistence database
1014-
may also be forced by sending mosquitto the SIGUSR1
1015-
signal. If <replaceable>false</replaceable>, the data
1016-
will be stored in memory only. Defaults to
1017-
<replaceable>false</replaceable>.</para>
1009+
<para>
1010+
If <replaceable>true</replaceable>, then built-in persistence
1011+
is enabled. It is recommended that a plugin based persistence
1012+
is used instead.
1013+
</para>
1014+
1015+
<para>
1016+
If enabled, connection, subscription and message data
1017+
will be written to disk in mosquitto.db at the location
1018+
dictated by persistence_location. When mosquitto is
1019+
restarted, it will reload the information stored in
1020+
mosquitto.db. The data will be written to disk when
1021+
mosquitto closes and also at periodic intervals as
1022+
defined by autosave_interval. Writing of the persistence
1023+
database may also be forced by sending mosquitto the
1024+
SIGUSR1 signal. If <replaceable>false</replaceable>,
1025+
the data will be stored in memory only. Defaults to
1026+
<replaceable>false</replaceable>.
1027+
</para>
10181028
<para>The persistence file may change its format in a new
10191029
version. The broker can currently read all old formats,
10201030
but will only save in the latest format. It should always
@@ -1031,8 +1041,10 @@ log_timestamp_format %Y-%m-%dT%H:%M:%S
10311041
<varlistentry>
10321042
<term><option>persistence_file</option> <replaceable>file name</replaceable></term>
10331043
<listitem>
1034-
<para>The filename to use for the persistent database.
1035-
Defaults to mosquitto.db.</para>
1044+
<para>
1045+
The filename to use for the built-in persistent database.
1046+
Defaults to mosquitto.db.
1047+
</para>
10361048

10371049
<para>This option applies globally.</para>
10381050

@@ -1042,8 +1054,12 @@ log_timestamp_format %Y-%m-%dT%H:%M:%S
10421054
<varlistentry>
10431055
<term><option>persistence_location</option> <replaceable>path</replaceable></term>
10441056
<listitem>
1045-
<para>The path where the persistence database should be
1046-
stored. If not given, then the current directory is used.</para>
1057+
<para>
1058+
The path where plugins should store any persistence
1059+
data, and the path where the built-in persistence will
1060+
store its data. If not given, then the current directory
1061+
is used.
1062+
</para>
10471063

10481064
<para>This option applies globally.</para>
10491065

src/plugin_callbacks.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,26 @@ BROKER_EXPORT int mosquitto_callback_register(
216216
return MOSQ_ERR_INVAL;
217217
}
218218

219+
if(db.config->persistence && (event == MOSQ_EVT_PERSIST_RESTORE
220+
|| event == MOSQ_EVT_PERSIST_BASE_MSG_ADD
221+
|| event == MOSQ_EVT_PERSIST_BASE_MSG_DELETE
222+
|| event == MOSQ_EVT_PERSIST_RETAIN_MSG_SET
223+
|| event == MOSQ_EVT_PERSIST_RETAIN_MSG_DELETE
224+
|| event == MOSQ_EVT_PERSIST_CLIENT_ADD
225+
|| event == MOSQ_EVT_PERSIST_CLIENT_DELETE
226+
|| event == MOSQ_EVT_PERSIST_CLIENT_UPDATE
227+
|| event == MOSQ_EVT_PERSIST_SUBSCRIPTION_ADD
228+
|| event == MOSQ_EVT_PERSIST_SUBSCRIPTION_DELETE
229+
|| event == MOSQ_EVT_PERSIST_CLIENT_MSG_ADD
230+
|| event == MOSQ_EVT_PERSIST_CLIENT_MSG_DELETE
231+
|| event == MOSQ_EVT_PERSIST_CLIENT_MSG_UPDATE
232+
|| event == MOSQ_EVT_PERSIST_WILL_ADD
233+
|| event == MOSQ_EVT_PERSIST_WILL_DELETE
234+
)){
235+
log__printf(NULL, MOSQ_LOG_ERR, "Error: `persistence true` cannot be used with a persistence plugin.");
236+
return MOSQ_ERR_INVAL;
237+
}
238+
219239
if(event == MOSQ_EVT_CONTROL){
220240
return control__register_callback(identifier, cb_func, event_data, userdata);
221241
}

src/retain.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,11 @@ int retain__store(const char *topic, struct mosquitto__base_msg *base_msg, char
181181
#endif
182182

183183
if(retainhier->retained){
184+
if(retainhier->retained == base_msg){
185+
/* This may occur if multiple persistence providers are used */
186+
return MOSQ_ERR_SUCCESS;
187+
}
188+
184189
if(persist && retainhier->retained->data.topic[0] != '$' && base_msg->data.payloadlen == 0){
185190
/* Only delete if another retained message isn't replacing this one */
186191
plugin_persist__handle_retain_msg_delete(retainhier->retained);

0 commit comments

Comments
 (0)