hhuijser/liferay-portal — pull request #1734 by yuhai (2014-02-16 10:43:37+00:00)
Title: LPS-43772 fix LPS-41388

Firstly I rollback the LPS-41388 from liferay-plunigs. As for LPS-41388, the issue was caused by portal's data non-existed in Solr server. The reason is that after solr server shutdown, we deleted some data of portlet but these data were not deleted by solr so that Solr server index data count larger than the reality data of portal.

My fix logic refers to reindex the logic of one detailed portlet, please refer to the below code fragment in EditServerAction.reindex method

if (Validator.isNull(portletId)) {
// the code fragment is excuted when click reindex all portlets.
}
else {
...
for (String searchEngineId : searchEngineIds) {
for (long companyId : companyIds) {
SearchEngineUtil.deletePortletDocuments(
searchEngineId, companyId, portletId);
}
}
// refer to the code fragment logic. Before reindex the detailed portlet, we firstly delete all index data of this portlet from slor.

for (Indexer indexer : indexers) {
....
indexer.reindex(new String[] {String.valueOf(companyId)});
....
}
}

In fact, when we reindex all portlet, we index data using one portlet by one portlet to do. So before index every portlet, we may firstly execute deleting all index data of this portlet from slor.

As for sherry's fix logic, please refer to the below code:
the pull request https://github.com/yuhai/liferay-plugins/pull/2 and also add the following code.
###
List portletIdList = _portletIdListThreadLocal.get();

if (!portletIdList.contains(portletId)) {
deletePortletDocuments(searchContext, portletId);
portletIdList.add(portletId);
_portletIdListThreadLocal.set(portletIdList); // added
}
###

From my understanding, the logic is when index data by batches and we only delete all index data of the detailed portlet from slor one time by keep different portlet value in "private static _portletIdListThreadLocal". I suppose this can work. However, it can not really solve the LPS-41388. The reason is the followings:

After reindex all portlet successfully, the portletIdList should keep all portlets value. In this time, if LPS-41388 occurs again, we execute reindex all and it won't execute the "deletePortletDocuments(searchContext, portletId);" because portletIdList = "all portlets value".

Maybe we can clear _portletIdListThreadLocal (portletIdList) for null after reindex all portlet successfully in the frist time, and the above situation will be fixed.

However, after clearing, it also can't really solve the LPS-41388. Please see the example.
If the portlet(125:User) data is different from solr (LPS-41388 occurs), I may only reindex the portlet "Users and Org" to solve the issue. In this time, portletIdList includes "125".
If the portlet(125:User) data is different from solr (LPS-41388 occurs again), we execute reindex all portlet and it won't execute "deletePortletDocuments(searchContext, "125")" because
portletIdList includes "125".

That is to say, we can't judge when to clear _portletIdListThreadLocal (or portletIdList). So I think the logic might be not enough. But I also don't make sure whether my understanding is correctly regarding the sherry's fix logic.

Please help check it.

Thanks,
Hai