André
André

Reputation: 172

Concurrent API LayoutLocalService.addLayout throws StaleObjectStateException in LayoutSetLocalService

UPDATE

Liferay ticket accepted , solution in dev : https://issues.liferay.com/browse/LPS-82954

Situation

My context is a parallel import of liferay layouts through a liferay portlet; build with spring. When i´m executing it in Liferay dxp; the api call to add a Layout throws a StaleObjectStateException. (https://github.com/liferay/liferay-portal/blob/d969e0e839db9ea64267f7bff0a76be93cd26fa0/portal-impl/src/com/liferay/portal/service/impl/LayoutLocalServiceImpl.java)

This exception occurs when the api internally does an update on the corresponding LayoutSet (updating the PageCount for that Group, where the layout has been added to, just a single moment ago).

This does not happen in a single threaded execution!

Actions

  1. Firstly i synchronized that call .. without any better results
  2. meanwhile i read something about, that only synchronizing the threading won´t help, because the transaction itself may not be inside the synchronized execution block. therefore i also added a transactional annotation. .. without better results

so far i gained the following insight:

Code Excerpts

-> Test Project Available: https://github.com/andrebiegel/liferay-layout-issue.git

private static final Object layoutCreationLock = new Object();
            synchronized (layoutCreationLock) {
                newLayout = addLayoutApiCall(pageContext, serviceContext, typeSettings, friendlyURLMap);
            }





    @Transactional(propagation = Propagation.REQUIRES_NEW)
public Layout addLayoutApiCall(IPageContext pageContext, ServiceContext serviceContext, String typeSettings,
        Map<Locale, String> friendlyURLMap) throws PortalException {
    Layout newLayout;
    newLayout = LayoutLocalServiceUtil.addLayout( pageContext.getProjectConfiguration().getUserId(), pageContext.getProjectConfiguration()
                                                  .getSiteId(), pageContext.isPrivatePage(), pageContext.getParentLayoutId(), pageContext
                                                  .getNamesMap(), pageContext.getTitleMap(), pageContext.getDescriptionMap(), pageContext
                                                  .getKeywordsMap(), pageContext.getRobotsMap(), pageContext.getPageType(), typeSettings,
                                                  pageContext.isHiddenPage(), friendlyURLMap, serviceContext );
    return newLayout;
}

Upvotes: 1

Views: 240

Answers (1)

Andr&#233;
Andr&#233;

Reputation: 172

Unfortunately Liferay will not fix this. Ticket has been closed; declared as not a Use Case. The reason is that the solution produced negativ consequences in other use case. So Liferay seems to have an issue in their transaction management. by the way , i have also seen such Exceptions when concurrently adding Expandos.

Upvotes: 0

Related Questions