Liferay Sharding


Liferay Sharding

Liferay Sharding allows you to split up the database by portal instance only.Database sharding allows system more scalable.

What is Sharding?

Sharding is used to split up the database by filtering data. If database/table is loaded with huge data then system will get slow.
In such case, sharding technique is used to distribute the data to different database and select the data based on that
For example, some implementations of sharding a database split up the users: User names beginning with A to D go in one database;
E to I go in another database;

How Liferay implemented Sharding?

  • Liferay allows you to support sharding through different portal instances and we can create separate database for each portal instance
  • default algorithm use round robin shard selector.
  • As we are creating separate database for each portal instance and it makes system more scalable

 

Sharding Configuration

  • Create databases for each portal instance
  • Add database configuration
    1. jdbc.default.url=jdbc\:mysql\://localhost/lportal?useUnicode\=true&characterEncoding\=UTF-8&useFastDateParsing\=false
      jdbc.default.driverClassName=com.mysql.jdbc.Driver
      jdbc.default.username=root
      jdbc.default.password=root
      
      jdbc.one.url=jdbc\:mysql\://localhost/lportal_one?useUnicode\=true&characterEncoding\=UTF-8&useFastDateParsing\=false
      jdbc.one.driverClassName=com.mysql.jdbc.Driver
      jdbc.one.username=root
      jdbc.one.password=root
      
      
      jdbc.two.url=jdbc\:mysql\://localhost/lportal_two?useUnicode\=true&characterEncoding\=UTF-8&useFastDateParsing\=false
      jdbc.two.driverClassName=com.mysql.jdbc.Driver
      jdbc.two.username=root
      jdbc.two.password=root
  • update shard availbe names
    1. shard.available.names=default,one,two
      shard.selector=com.liferay.portal.dao.shard.ManualShardSelector
  • add spring.configs also in portal-ext
    1. spring.configs=\
       META-INF/base-spring.xml,\
       \
       META-INF/hibernate-spring.xml,\
       META-INF/infrastructure-spring.xml,\
       META-INF/management-spring.xml,\
       \
       META-INF/util-spring.xml,\
       \
       META-INF/jpa-spring.xml,\
       \
       META-INF/executor-spring.xml,\
       \
       META-INF/audit-spring.xml,\
       META-INF/cluster-spring.xml,\
       META-INF/editor-spring.xml,\
       META-INF/jcr-spring.xml,\
       META-INF/ldap-spring.xml,\
       META-INF/messaging-core-spring.xml,\
       META-INF/messaging-misc-spring.xml,\
       META-INF/mobile-device-spring.xml,\
       META-INF/notifications-spring.xml,\
       META-INF/poller-spring.xml,\
       META-INF/rules-spring.xml,\
       META-INF/scheduler-spring.xml,\
       META-INF/search-spring.xml,\
       META-INF/workflow-spring.xml,\
       \
       META-INF/counter-spring.xml,\
       META-INF/mail-spring.xml,\
       META-INF/portal-spring.xml,\
       META-INF/portlet-container-spring.xml,\
       META-INF/staging-spring.xml,\
       META-INF/virtual-layouts-spring.xml,\
       \
       META-INF/monitoring-spring.xml,\
       \
       META-INF/dynamic-data-source-spring.xml,\
       META-INF/shard-data-source-spring.xml,\
       \
       classpath*:META-INF/ext-spring.xml
  • Restart the server and now you will be able to see the Shard Name while creating portal instanceLiferay Sharding

 

Note : If you wont get the shard name then make sure the below properties are set:

  1. There is limitation the using of shard names and you must start the with one, two and corresponding jdbc config is jdbc.one etc.
  2. shard.selector
  3. spring.config