Uploaded image for project: 'PUBLIC - Liferay Portal Community Edition'
  1. PUBLIC - Liferay Portal Community Edition
  2. LPS-44425

Persistence sharding feature execute CRUD operations in the default database only.

    Details

      Description

      Steps to reproduce it:
      1- Configure Portal 6.1GA2 for using sharding
      2- Startup the portal server (with marketplace porlet desployed)
      3- Create a new instance from control panel
      4- Shutdown the portal
      5- Startup 6.1GA2 again to create the proper records in the ExpandoTable database for MarketPlace
      6- Shutdown the portal
      7- Configure master for using sharding pointing out to the previous databases
      8- Startup master server (deploying the new version of marketplace porlet)

      The exception described in LPS-44346 will be displayed during the upgrade process.

      Documentation
      After crete a hook to replace themeIds in 4 different portal instances configure in sharding I figured out that Liferay was only executing CRUD operations in the default database. The problem is a bug in the com.liferay.portal.dao.shard.advice.ShardPersistenceAdvice class around this if statement:

      if (_shardAdvice.getGlobalCall() == null) {
      	String shardName = _shardAdvice.setShardNameByCompany();
      
      	ShardUtil.setTargetSource(shardName);
      
      	if (_log.isInfoEnabled()) {
      		_log.info(
      			"Using shard name " + shardName + " for " +
      				methodInvocation.toString());
      	}
      
      	return methodInvocation.proceed();
      }
      

      The correct code would be:

      if (_shardAdvice.getGlobalCall() == null) {
      	String shardName = _shardAdvice.setShardNameByCompany();
      
      	String currentShardName = ShardUtil.setTargetSource(shardName);
      
      	if (_log.isInfoEnabled()) {
      		_log.info(
      				"Using shard name " + shardName + " for " +
      						methodInvocation.toString());
      	}
      
      	_shardAdvice.pushCompanyService(shardName);
      
      	try {
      		return methodInvocation.proceed();
      	}
      	finally {
      		_shardAdvice.popCompanyService();
      
      		ShardUtil.setTargetSource(currentShardName);
      	}
      }
      

      This way you push and pop the current sharding configuration around the execution of the real method.

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                1 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Days since last comment:
                  5 years, 29 weeks, 1 day ago

                  Packages

                  Version Package
                  6.2.2 CE GA3
                  6.2.X EE
                  7.0.0 M3