Description
When using jgroups to run multiple instances of xwiki that use the same database delete/rename events cannot be properly updated between them.
Procedure:
- start two instances using a single database and connected with jgroups, enable logging for jgroups.
- Create a new page in one version. You will see the creation events sent from the current instance and received
by the other. The page is updated and appears both places. - Now edit the page again and save it so that the version is incremented. It must be
on a version other than 1.1 for the error to occur. - Do a rename of your new page on one instance. This creates the new page with the new
name, and then deletes the old version. It then sends these same events to the other instance. - The second instance attempts to implement these same changes. It correctly creates the
new page but the old one is not properly removed unless the most recent version of the page is 1.1.
The problem occurs in AbstractXwikiEventConverter.class on line 159.
https://github.com/xwiki/xwiki-platform/blob/0f5b636ea0eb6e761bc613bd8bc8995bd200f2d9/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/internal/observation/remote/converter/AbstractXWikiEventConverter.java
When the second instance of XWiki attempts to delete the old page it gets to getDocument here. On line 170
it compares the version number of the old document (which has been deleted and is no longer in the database)
to the version number passed to the method (version of the document when rename was called).
The old document version returns null because it has been deleted. It then goes inside the if loop and attempts
to get the version matching the one that was passed in. This fails and throws an exception
because it cannot find the given version for a nonexisting document. The only way that this works is if the
renamed document was at version 1.1. On line 170 the getVersion() method that is called on the old
document returns 1.1 as the version if the documents version is null. Therefore when the version passed in
is 1.1 the version of the now deleted doc is set to 1.1 and it never tries to get the version, avoiding
the failure. The document is gone from the database but it remains in the cache of that instance of XWiki
and can be viewed. It will be removed if the instance is restarted and the cache is refreshed.
See also line 955 in XWikiDocument.class. This is the method that replaces all null versions with 1.1.
https://github.com/xwiki/xwiki-platform/blob/8fcdaa169059654cb7450a72e855011e3e513720/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/doc/XWikiDocument.java