Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Cristian Petrula
Sharding 6.1.2 not working correct
September 6, 2013 12:43 AM
Answer

Cristian Petrula

Rank: Junior Member

Posts: 29

Join Date: August 26, 2013

Recent Posts

Hello I am using Liferay 6.1.2 GA3, Java 7 and JBoss eap 6.1 and I have problems with shards. I made all the configurations for 3 shards: default and two others, all db-s are created, tables are created but I noticed that in shards company table and shard table are empty. When I create a new portal instance and specify his shard it is created but stored in company table from default shard. The same for the date from shard table. What can I check to see what is wrong.
Cristian Petrula
RE: Sharding 6.1.2 not working correct
September 12, 2013 11:55 PM
Answer

Cristian Petrula

Rank: Junior Member

Posts: 29

Join Date: August 26, 2013

Recent Posts

I have solved my issue. Sharding works fine I just had to specify from the code what shard to use. Only on shard_default company and shard tables have data.

if (ShardUtil.isEnabled()) {
CompanyThreadLocal.setCompanyId(companyId);
LOG.info("Set shard for company " + companyId);
}

this code makes sure that you are using the correct shard
Alberto Chaparro
RE: Sharding 6.1.2 not working correct
September 13, 2013 1:18 AM
Answer

Alberto Chaparro

LIFERAY STAFF

Rank: Regular Member

Posts: 100

Join Date: April 25, 2011

Recent Posts

Hi Cristian,

That's right, there are several entities that only contain data in the shard by default, they are the following one:
- ClassName
- Company
- CounterFinder
- Counter
- PortalPreferences
- Release
- ResourceAction
- ServiceComponent
- Shard
- VirtualHostPersistence

You can consult this information for each version in the file:
portal-impl/src/com/liferay/portal/dao/shard/advice/ShardPersistenceAdvice.java

Cheers.
Vilmos Papp
RE: Sharding 6.1.2 not working correct
September 13, 2013 1:23 AM
Answer

Vilmos Papp

LIFERAY STAFF

Rank: Expert

Posts: 463

Join Date: October 21, 2010

Recent Posts

Hi Cristian,

I would suggest you to use the following pattern if you want to specify the shard to use:

 1
 2try {
 3    ShardUtil.pushCompanyService(companyIdToUse);
 4
 5    /* call your methods here */
 6
 7}
 8finally {
 9    ShardUtil.popCompanyService();
10}


This way you will have the proper shard for your services/methods but you will not break the other functions which should use the default shard for example.