Last published item not loaded from DB

Hi:

I’m working on a project that uses pep service for event notifications, the thing is that I found an issue with the lastPublished property (LeafNode class). Seems that this property is set in memory when the item is published (also is stored in db by another thread), so after a while the PEPService is removed from cache (full or lifetime) and the next time that is loaded from DB it doesn’t populate lastPublished property (from DB), so later when a client performs a login against openfire it doesn’t receive the lastPublished property cause is null. What I did is to modify the getLastPublishedItem (LeafNode.class) method and add some code to grab the last published property from DB whether is not already in memory, I used an already existing method from PubSubPersistenceManager class called getLastPublishedItem (BTW this method is running a query that blow up due to a missing column in the select statement which is the id column, should be added first). Please let me know if I’m missing something or if it is not the right approach!

Code that I modified in the LeafNode java class

@Override

public synchronized PublishedItem getLastPublishedItem() {

// added by JMM to force last published item load from db

// whether is not already in memory, made it synchronized

if (lastPublished == null) {

lastPublished = PubSubPersistenceManager.getLastPublishedItem(this);

}

return lastPublished;

}

Thanks in advance!

Added OF-596 to Jira for this bug.

BTW, related to the sql query that PubSubPersistenceManager.getLastPublishedItem method executes for getting the last published item (LOAD_LAST_ITEM), it is really slow and makes db engine to consume a lot of CPU, so I switched it to:

private static final String LOAD_LAST_ITEM =

"SELECT id,jid,creationDate,payload FROM ofPubsubItem " +

“WHERE serviceID=? AND nodeID=? ORDER BY creationDate DESC”;

and then in the PreparedStatement you can do:

pstmt.setFetchSize(1);

pstmt.setMaxRows(1);

So now no inner select is executed so the query is really fast.

Thanks, I added another issue (OF-597) for that one. Could you supply it as a patch so I can attach it to the Jira task?

Sorry for the delay, I’ve beeing busy, but here is the patch, you can address it to Jira ticket.

Greetings!
PubSubPersistenceManager.zip (675 Bytes)