Wednesday, December 29, 2010

HAJDBC with Liferay

Integrate HAJDBC and Liferay

1. Create portal-ext.properties as below and place it in the root folder of the liferay
# HAJDBC
#
jdbc.default.driverClassName=net.sf.hajdbc.sql.Driver
jdbc.default.url=jdbc:ha-jdbc:cluster1
jdbc.default.username=lportal
jdbc.default.password=lportal
2. Create ha-jdbc-cluster1.xml as below and place it in the folder C:\Liferay-Portal\Tomcat\webapps\ROOT\WEB-INF\classes
<ha-jdbc>
<!--<distributable config="" 
stack="sequencer" /> -->
<sync id="diff" class="net.sf.hajdbc.sync.DifferentialSynchronizationStrategy" >
<property name="fetchSize">1000</property>
<property name="maxBatchSize">100</property>
</sync>
<cluster default-sync="diff" balancer="load" meta-data-cache="none"
dialect="net.sf.hajdbc.dialect.MySQLDialect" transaction-mode="parallel"
auto-activate-schedule="0 * * ? * *" failure-detectschedule="0 * * ? * *">
<database id="database1">
<driver>com.mysql.jdbc.Driver</driver>
<url>jdbc:mysql://localhost:3306/lportal1</url>
<user>lportal</user>
<password>lportal</password>
</database>

<database id="database2">
<driver>com.mysql.jdbc.Driver</driver>
<url>jdbc:mysql://localhost:3306/lportal</url>
<user>lportal</user>
<password>lportal</password>
</database> 
</cluster>
</ha-jdbc>
3. Create stacks.xml as below and place it in the location C:\Liferay-Portal\Tomcat\webapps\ROOT\WEB-INF\classes

<!--
Sample file that defines a number of stacks, used by multiplexer
JGroups channel Author: Bela Ban Version: $Id: stacks.xml,v 1.1
2006/02/16 09:08:53 belaban Exp $
-->
<protocol_stacks>
<stack name="fc-fast-minimalthreads" description="Flow control, no up or
down threads">
<config>
<UDP mcast_port="45566" mcast_addr="228.10.10.10" tos="16"
ucast_recv_buf_size="20000000" ucast_send_buf_size="640000"
mcast_recv_buf_size="25000000" mcast_send_buf_size="640000"
loopback="false" discard_incompatible_packets="true"
max_bundle_size="64000" max_bundle_timeout="30"
use_incoming_packet_handler="true" use_outgoing_packet_handler="false"
ip_ttl="2" down_thread="false" up_thread="false" enable_bundling="true" />
<PING timeout="2000" down_thread="false" up_thread="false"
num_initial_members="3" />
<MERGE2 max_interval="100000" down_thread="false" up_thread="false"
min_interval="20000" />
<FD_SOCK down_thread="false" up_thread="false" />
<VERIFY_SUSPECT timeout="1500" down_thread="false" />
<pbcast.NAKACK max_xmit_size="60000" use_mcast_xmit="false"
gc_lag="0" retransmit_timeout="100,200,300,600,1200,2400,4800"
down_thread="false" up_thread="false" discard_delivered_msgs="true" />
<UNICAST timeout="300,600,1200,2400,3600" down_thread="false"
up_thread="false" />
<pbcast.STABLE stability_delay="1000"
desired_avg_gossip="50000" down_thread="false" up_thread="false"
max_bytes="400000" />
<VIEW_SYNC avg_send_interval="60000" down_thread="false"
up_thread="false" />
<pbcast.GMS print_local_addr="true" join_timeout="3000"
down_thread="false" up_thread="false" join_retry_timeout="2000"
shun="true" />
<FC max_credits="2000000" down_thread="false" up_thread="false"
min_threshold="0.10" />
<FRAG2 frag_size="60000" down_thread="false" up_thread="true" />
<pbcast.STATE_TRANSFER down_thread="false"
up_thread="false" />
</config>
</stack>

<stack name="sequencer" description="Totally ordered multicast using a
sequencer">
<config>
<UDP bind_addr="192.168.5.1" mcast_port="45566" mcast_addr="228.10.10.10"
tos="16" ucast_recv_buf_size="20000000" ucast_send_buf_size="640000"
mcast_recv_buf_size="25000000" mcast_send_buf_size="640000"
loopback="false" discard_incompatible_packets="true"
max_bundle_size="64000" max_bundle_timeout="30"
use_incoming_packet_handler="true" use_outgoing_packet_handler="false"
ip_ttl="2" down_thread="false" up_thread="false" enable_bundling="true" />
<PING timeout="2000" down_thread="false" up_thread="false"
num_initial_members="3" />
<MERGE2 max_interval="10000" down_thread="false" up_thread="false"
min_interval="5000" />
<FD_SOCK down_thread="false" up_thread="false" />
<VERIFY_SUSPECT timeout="1500" down_thread="false" />
<pbcast.NAKACK max_xmit_size="60000" use_mcast_xmit="false"
gc_lag="0" retransmit_timeout="100,200,300,600,1200,2400,4800"
down_thread="false" up_thread="false" discard_delivered_msgs="true" />
<UNICAST timeout="300,600,1200,2400,3600" down_thread="false"
up_thread="false" />
<pbcast.STABLE stability_delay="1000"
desired_avg_gossip="50000" down_thread="false" up_thread="false"
max_bytes="400000" />
<VIEW_SYNC avg_send_interval="60000" down_thread="false"
up_thread="false" />
<pbcast.GMS print_local_addr="true" join_timeout="3000"
down_thread="false" up_thread="false" join_retry_timeout="2000"
shun="true" handle_concurrent_startup="true" />
<SEQUENCER down_thread="false" up_thread="false" />
<FC max_credits="2000000" down_thread="false" up_thread="false"
min_threshold="0.10" />
<FRAG2 frag_size="60000" down_thread="false" up_thread="true" />
<pbcast.STATE_TRANSFER down_thread="false"
up_thread="false" />

</config>
</stack>


<stack name="tcp" description="Using TCP as transport">
<config>
<TCP start_port="7800" loopback="true" send_buf_size="100000"
recv_buf_size="200000" />
<TCPPING timeout="3000" initial_hosts="localhost[7800]"
port_range="3" num_initial_members="3" />
<FD timeout="2000" max_tries="4" />
<VERIFY_SUSPECT timeout="1500" down_thread="false"
up_thread="false" />
<pbcast.NAKACK gc_lag="100" retransmit_timeout="600,1200,2400,4800" />
<pbcast.STABLE stability_delay="1000"
desired_avg_gossip="20000" down_thread="false" max_bytes="0"
up_thread="false" />
<VIEW_SYNC avg_send_interval="60000" down_thread="false"
up_thread="false" />
<pbcast.GMS print_local_addr="true" join_timeout="5000"
join_retry_timeout="2000" shun="true" />
</config>
</stack>

</protocol_stacks>
4. Add the following jars in the location C:\Liferay-Portal\Tomcat\webapps\ROOT\WEB-INF\lib
a. ha-jdbc-2.0.16-rc-1-jdk1.6.jar
b. jcl-over-slf4j-1.5.7.jar
c. jgroups-2.6.10.jar
d. jibx-run-1.2.1.jar
e. log4j-1.2.15.jar
5. In tomcat server.xml add the below just before the last </> tag location: C:\Liferay-Portal\Tomcat\conf
<Context>
<!-- ... -->
<Resource name="jdbc/cluster" type="javax.sql.DataSource"
username="lportal" password="lportal" driverClassName="net.sf.hajdbc.sql.Driver"
url="jdbc:ha-jdbc:cluster1"/>
<!-- ... -->
</Context>
6. In tomcat web.xml add the below just before the last </webapp> tag location : C:\Liferay-Portal\Tomcat\conf
<resource-env-ref>
<resource-env-ref-name>jdbc/cluster</resource-env-ref-name>
<resource-env-ref-type>javax.sql.DataSource</resource-env-ref-type>
</resource-env-ref>
<!-- ... -->
7. Now the configuration is done go to mysql root and create a database lportal1 with following commands
a. mysql> create database lportal1 character set utf8;
b. mysql> grant all on lportal1.* to 'lportal'@'localhost' identified by 'lportal'
with grant option;
c. mysql> grant all on lportal1.* to 'lportal'@'localhost' identified by 'lportal'
with grant option;
8. Now start tomcat..

Trouble shooting : If tomcat throws exception that the lportal1…table does not exits.
Then reverse the database location ie 
Use this ha-jdbc-cluster1.xml in step 2
<ha-jdbc>
<!--<distributable config="" 
stack="sequencer" /> -->
<sync id="diff" class="net.sf.hajdbc.sync.DifferentialSynchronizationStrategy" >
<property name="fetchSize">1000</property>
<property name="maxBatchSize">100</property>
</sync>
<cluster default-sync="diff" balancer="load" meta-data-cache="none"
dialect="net.sf.hajdbc.dialect.MySQLDialect" transaction-mode="parallel"
auto-activate-schedule="0 * * ? * *" failure-detectschedule="0 * * ? * *">
<database id="database1">
<driver>com.mysql.jdbc.Driver</driver>
<url>jdbc:mysql://localhost:3306/lportal</url>
<user>lportal</user>
<password>lportal</password>
</database>

<database id="database2">
<driver>com.mysql.jdbc.Driver</driver>
<url>jdbc:mysql://localhost:3306/lportal1</url>
<user>lportal</user>
<password>lportal</password>
</database> 
</cluster>
</ha-jdbc>
We have changed the position highlighted in red.

No comments:

Post a Comment