Skip to content

Commit dcfebda

Browse files
committed
OF-3153: Introduce option to configure failfast behavior of room loading
This introduces a new SystemProperty `xmpp.muc.loading.failfast` that controls if an exception while loading a room causes an error to be thrown (fail-fast), or will allow all other rooms to be loaded (resilient). Note that this applies to non-SQL exceptions only, as SQL exceptions are logged but otherwise ignored by the `loadFromDB` method.
1 parent f8f0294 commit dcfebda

3 files changed

Lines changed: 24 additions & 5 deletions

File tree

i18n/src/main/resources/openfire_i18n.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,6 +1369,7 @@ system_property.xmpp.muc.muclumbus.v1-0.enabled=Determine if the multi-user chat
13691369
system_property.xmpp.muc.join.presence=Setting the presence send of participants joining in MUC rooms.
13701370
system_property.xmpp.muc.join.self-presence-timeout=Maximum duration to wait for presence to be broadcast while joining a MUC room.
13711371
system_property.xmpp.muc.bulkretraction=Enable or disable the bulk retraction of messages in MUC rooms.
1372+
system_property.xmpp.muc.loading.failfast=If true, room loading aborts on the first failure (fail-fast); if false, all rooms are attempted (resilient).
13721373
system_property.xmpp.muc.loading.timeout=Defines the maximum duration to wait for loading MUC rooms from the database at service startup. If the loading process exceeds this timeout, it will be aborted. A value of zero indicates that no timeout is configured, and the process may run indefinitely.
13731374
system_property.xmpp.muc.loading.workers=Controls the number of parallel workers used when loading MUC rooms from the database at service startup. A value of 1 loads rooms sequentially. Values 2-5 enable parallel loading which can improve startup time for services with many rooms, but increases database load. Consider your database's connection pool size and capacity before increasing this value.
13741375
system_property.ldap.authorizeField=Name of attribute in user's LDAP object used by the LDAP authorization policy.

i18n/src/main/resources/openfire_i18n_nl.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,6 +1278,7 @@ system_property.xmpp.muc.muclumbus.v1-0.enabled=Definieert of de multi-user chat
12781278
system_property.xmpp.muc.join.presence=Wissel statusinformatie uit als een nieuwe participant een MUC ruimte binnentreedt.
12791279
system_property.xmpp.muc.join.self-presence-timeout=Maximale wachttijd voor omgeroepen status informatie tijdens het binnentreden van een MUC ruimte.
12801280
system_property.xmpp.muc.bulkretraction=Het in bulk intrekken van berichten in MUC-ruimtes in- of uitschakelen.
1281+
system_property.xmpp.muc.loading.failfast=Als true, stopt het laden van MUC-ruimtes bij de eerste fout (fail-fast); als false, worden alle MUC-ruimtes geprobeerd (resilient).
12811282
system_property.xmpp.muc.loading.timeout=Definieert de maximale duur om te wachten op het laden van MUC-rooms uit de database bij het opstarten van de service. Als het laadproces deze time-out overschrijdt, wordt het afgebroken. Een waarde van nul geeft aan dat er geen time-out is ingesteld en het proces mogelijk onbeperkt kan doorgaan.
12821283
system_property.xmpp.muc.loading.workers=Stelt het aantal parallelle werkers in dat wordt gebruikt bij het laden van MUC-ruimtes uit de database tijdens het opstarten van de service. Een waarde van 1 laadt de ruimtes achtereenvolgens. Waarden van 2 tot 5 maken parallel laden mogelijk, wat de opstarttijd kan verbeteren voor services met veel ruimtes, maar de belasting van de database verhoogt. Houd rekening met de grootte en capaciteit van de connectiepool van uw database voordat u deze waarde verhoogt.
12831284
system_property.ldap.authorizeField=Naam van kenmerk in het LDAP-object van de gebruiker dat door het LDAP-autorisatiebeleid wordt gebruikt.

xmppserver/src/main/java/org/jivesoftware/openfire/muc/spi/MUCPersistenceManager.java

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,9 @@
3737
import java.time.temporal.ChronoUnit;
3838
import java.util.Date;
3939
import java.util.*;
40-
import java.util.concurrent.ConcurrentHashMap;
41-
import java.util.concurrent.ExecutorService;
42-
import java.util.concurrent.Executors;
43-
import java.util.concurrent.ThreadFactory;
44-
import java.util.concurrent.TimeUnit;
40+
import java.util.concurrent.*;
4541
import java.util.concurrent.atomic.AtomicInteger;
42+
import java.util.concurrent.atomic.AtomicReference;
4643
import java.util.stream.Collectors;
4744
import java.util.stream.Stream;
4845

@@ -93,6 +90,15 @@ public class MUCPersistenceManager {
9390
.setDefaultValue(Duration.ZERO)
9491
.build();
9592

93+
/**
94+
* If true, room loading aborts on the first failure (fail-fast); if false, all rooms are attempted (resilient).
95+
*/
96+
public static final SystemProperty<Boolean> ROOM_LOADING_FAILFAST = SystemProperty.Builder.ofType(Boolean.class)
97+
.setKey("xmpp.muc.loading.failfast")
98+
.setDynamic(false)
99+
.setDefaultValue(true)
100+
.build();
101+
96102
private static final String GET_RESERVED_NAME =
97103
"SELECT nickname FROM ofMucMember WHERE roomID=? AND jid=?";
98104
private static final String LOAD_ROOM =
@@ -730,14 +736,22 @@ public static Collection<MUCRoom> loadRoomsFromDB(MultiUserChatService chatserve
730736
"MUC-RoomLoad-", Executors.defaultThreadFactory(), false, Thread.NORM_PRIORITY);
731737
final ExecutorService executor = Executors.newFixedThreadPool(workers, threadFactory);
732738
final AtomicInteger failedCount = new AtomicInteger(0);
739+
final AtomicReference<Exception> firstFailure = new AtomicReference<>();
740+
final boolean failFast = ROOM_LOADING_FAILFAST.getValue();
733741

734742
for (MUCRoom room : rooms.values()) {
735743
executor.submit(() -> {
744+
// Skip loading if fail-fast and a failure has already occurred
745+
if (failFast && failedCount.get() > 0) {
746+
return;
747+
}
748+
736749
try {
737750
loadFromDB(room);
738751
} catch (Exception e) {
739752
Log.error("Failed to load room '{}' from database.", room.getName(), e);
740753
failedCount.incrementAndGet();
754+
firstFailure.compareAndSet(null, e);
741755
}
742756
});
743757
}
@@ -756,6 +770,9 @@ public static Collection<MUCRoom> loadRoomsFromDB(MultiUserChatService chatserve
756770
}
757771

758772
if (failedCount.get() > 0) {
773+
if (failFast) {
774+
throw new RuntimeException("Failed to load a room for chat service " + chatserver.getServiceName(), firstFailure.get());
775+
}
759776
Log.warn("Failed to load {} room(s) for chat service {}. See previous error messages for details.",
760777
failedCount.get(), chatserver.getServiceName());
761778
}

0 commit comments

Comments
 (0)