03 October 2015

Database sherd in liferay with JNDI


Sharding is a type of database partitioning that separates very large databases the into smaller, faster, more easily managed parts called datashards. The word shard means a small part of a whole

Steps for liferay sharding :
1)     Initially add JNDI entries in portal-ext.properties and root.xml file as follows
portal-ext.properties jdbc.default.jndi.name=jdbc/LiferayPool
root.xml:
 <Resource
       name="jdbc/LiferayPool"
       auth="Container"
       type="javax.sql.DataSource"
       driverClassName="com.mysql.jdbc.Driver"
       url="jdbc:mysql://localhost/lportal80?useUnicode=true&amp;characterEncoding=UTF-8&amp;useFastDateParsing=false"
       username="root"
       password="root"
       maxActive="150"
       maxIdle="30"
       maxWait="10000"
        />
Start the liferay server .
2)     Add the site , users , pages ,webcontent , documents form admin console .
3)     Now stop the sever .
4)     Enable instance specific properties  
                         we need to add -Dcompany-id-properties=true in your java arguments . set them to JAVA_OPS in bin/setevn.bat. 
                     Add the  below property in portal-ext.properties file
                      include-and-override=portal-<web-id>.properties
5)     Add JNDI entries for shard in portal-ext.properties and root.xml
Portal-ext.properties: jdbc.one.jndi.name=jdbc/LiferayPoolSherd
Root.xml :
<Resource
       name="jdbc/LiferayPoolSherd"
       auth="Container"
       type="javax.sql.DataSource"
       driverClassName="com.mysql.jdbc.Driver"
       url="jdbc:mysql://localhost/lportal81?useUnicode=true&amp;characterEncoding=UTF-8&amp;useFastDateParsing=false"
       username="root"
       password="root"
       maxActive="150"
       maxIdle="30"
       maxWait="10000"
        />

6)     Add spring specific properties for supporting shard.
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/document-library-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,\
       #META-INF/memcached-spring.xml,\
        \
        classpath*:META-INF/ext-spring.xml

7)     Create the file  by name  portal-<web-id>.properties and place in the same folder as of portal-ext.properties .
8)     By using this sharding works properly, but  there is some issues
Like for some portlet like custom or calender the table is not created on both instance DB.
So, for this we need to add following property at once:
        Add the below entries in portal-<web-id>.properties
verify.frequency=-1
verify.processes=com.liferay.portal.verify.VerifyDocumentLibrary
                    

9)     Finally root.xml should look as below .
<Context path="" crossContext="true">
        <Resource
       name="jdbc/LiferayPool"
       auth="Container"
       type="javax.sql.DataSource"
       driverClassName="com.mysql.jdbc.Driver"
       url="jdbc:mysql://localhost/lportal80?useUnicode=true&amp;characterEncoding=UTF-8&amp;useFastDateParsing=false"
       username="root"
       password="root"
       maxActive="150"
       maxIdle="30"
       maxWait="10000"
        />
        <Resource
       name="jdbc/LiferayPoolSherd"
       auth="Container"
       type="javax.sql.DataSource"
       driverClassName="com.mysql.jdbc.Driver"
       url="jdbc:mysql://localhost/lportal81?useUnicode=true&amp;characterEncoding=UTF-8&amp;useFastDateParsing=false"
       username="root"
       password="root"
       maxActive="150"
       maxIdle="30"
       maxWait="10000"
        />
</Context>


And portal-ext.properties file should look like below


jdbc.default.jndi.name=jdbc/LiferayPool
jdbc.one.jndi.name=jdbc/LiferayPoolSherd
shard.selector=com.liferay.portal.dao.shard.ManualShardSelector
include-and-override=portal-domain2.com.properties

#
    # Input a list of comma delimited Spring configurations. These will be
    # loaded after the bean definitions specified in the contextConfigLocation
    # parameter in web.xml.
    #
    # Note that there is a special case for hibernate-spring.xml and
    # jpa-spring.xml. Even though both files are specified, only one will
    # actually load at runtime based on the property "persistence.provider".
    #
    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/document-library-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,\
       #META-INF/memcached-spring.xml,\
        \
        classpath*:META-INF/ext-spring.xml



Start the server.

Login with as admin .
Go to control-panel , then go to server administration .
Execute the button with lable

“Verify database tables of all plugins. “

Create the new instance with name domain2.com.

Now go to url

Domain2.com:8080/
Use the default user email id  test@domain2.com and test is the password




No comments: