Commit 85632a09 authored by Guus der Kinderen's avatar Guus der Kinderen

OF-1200: Work in progress

This is a very basic (and inefficient, and prone to cause thread starvation) change that causes
MAM queries to be responded to only after all relevant data has become available in the database.
parent 68d5e49e
...@@ -48,6 +48,7 @@ Monitoring Plugin Changelog ...@@ -48,6 +48,7 @@ Monitoring Plugin Changelog
<ul> <ul>
<li>[<a href='https://issues.igniterealtime.org/browse/OF-1486'>OF-1486</a>] - MAM RSM queries for MUC should allow for 'backwards-paging'.</li> <li>[<a href='https://issues.igniterealtime.org/browse/OF-1486'>OF-1486</a>] - MAM RSM queries for MUC should allow for 'backwards-paging'.</li>
<li>[<a href='https://issues.igniterealtime.org/browse/OF-1487'>OF-1487</a>] - Archived messages should become available in the database instantly.</li> <li>[<a href='https://issues.igniterealtime.org/browse/OF-1487'>OF-1487</a>] - Archived messages should become available in the database instantly.</li>
<li>[<a href='https://issues.igniterealtime.org/browse/OF-1200'>OF-1200</a>] - Don't answer MAM queries before relevant archives have been stored.</li>
</ul> </ul>
<p><b>1.5.9</b> -- Feb 13, 2018</p> <p><b>1.5.9</b> -- Feb 13, 2018</p>
......
...@@ -8,6 +8,8 @@ import java.util.Iterator; ...@@ -8,6 +8,8 @@ import java.util.Iterator;
import org.dom4j.*; import org.dom4j.*;
import org.jivesoftware.openfire.XMPPServer; import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.archive.ConversationManager;
import org.jivesoftware.openfire.archive.MonitoringConstants;
import org.jivesoftware.openfire.auth.UnauthorizedException; import org.jivesoftware.openfire.auth.UnauthorizedException;
import org.jivesoftware.openfire.disco.ServerFeaturesProvider; import org.jivesoftware.openfire.disco.ServerFeaturesProvider;
import org.jivesoftware.openfire.forward.Forwarded; import org.jivesoftware.openfire.forward.Forwarded;
...@@ -15,6 +17,7 @@ import org.jivesoftware.openfire.handler.IQHandler; ...@@ -15,6 +17,7 @@ import org.jivesoftware.openfire.handler.IQHandler;
import org.jivesoftware.openfire.muc.MUCRole; import org.jivesoftware.openfire.muc.MUCRole;
import org.jivesoftware.openfire.muc.MUCRoom; import org.jivesoftware.openfire.muc.MUCRoom;
import org.jivesoftware.openfire.muc.MultiUserChatService; import org.jivesoftware.openfire.muc.MultiUserChatService;
import org.jivesoftware.openfire.plugin.MonitoringPlugin;
import org.jivesoftware.openfire.session.Session; import org.jivesoftware.openfire.session.Session;
import org.jivesoftware.util.XMPPDateTimeFormat; import org.jivesoftware.util.XMPPDateTimeFormat;
import org.slf4j.Logger; import org.slf4j.Logger;
...@@ -121,8 +124,35 @@ abstract class IQQueryHandler extends AbstractIQHandler implements ...@@ -121,8 +124,35 @@ abstract class IQQueryHandler extends AbstractIQHandler implements
sendMidQuery(packet, session); sendMidQuery(packet, session);
Log.debug("Retrieving messages from archive...");
final QueryRequest queryRequest = new QueryRequest(packet.getChildElement(), archiveJid); final QueryRequest queryRequest = new QueryRequest(packet.getChildElement(), archiveJid);
// OF-1200: make sure that data is flushed to the database before retrieving it.
MonitoringPlugin plugin = (MonitoringPlugin) XMPPServer.getInstance().getPluginManager().getPlugin(MonitoringConstants.NAME);
ConversationManager conversationManager = (ConversationManager)plugin.getModule( ConversationManager.class);
final Date targetEndDate = new Date(); // TODO or, the 'before' date from RSM, if that's set and in the past.
while ( System.currentTimeMillis() < targetEndDate.getTime() + 2000 ) // TODO Use the value in org.jivesoftware.openfire.archive.ConversationManager.ArchivingRunnable.maxPurgeInterval but also add time to allow for query execution time.
{
if ( conversationManager.hasWrittenAllDataBefore( targetEndDate ) )
{
break;
}
try
{
// FIXME let's not block the thread, but use a callback of sorts instead.
Log.debug( "Not all data that is being requested has been written to the database yet. Delaying request processing. " );
Thread.sleep( 100 );
}
catch ( InterruptedException e )
{
break;
}
}
if ( !conversationManager.hasWrittenAllDataBefore( targetEndDate ) ) {
Log.warn( "Retrieving data from the database to formulate a response to a MAM query, while data is still waiting to be written there. The response might be incomplete." );
}
Log.debug("Retrieving messages from archive...");
Collection<ArchivedMessage> archivedMessages = retrieveMessages(queryRequest); Collection<ArchivedMessage> archivedMessages = retrieveMessages(queryRequest);
Log.debug("Retrieved {} messages from archive.", archivedMessages.size()); Log.debug("Retrieved {} messages from archive.", archivedMessages.size());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment