[jboss-user] [JBossCache] - JBossCache on JBoss 4.2.1.GA - Two Nodes not replicating
burakbayramli
do-not-reply at jboss.com
Mon Nov 12 05:27:27 EST 2007
Hi all,
I wrote a simple Hibernate example and deployed this on two nodes in a cluster. I start the cluster using run.sh -c all method. I wrote a stress test that would randomly choose an object ID and a node, and do persist() on one node and then find() on another.
I see no SELECT statements on Hibernate log, which is good, however after test ends, the same ID on two nodes returns different values which tells me replication did not take place. Any thoughts?
My settings are
persistence.xml:
<persistence>
| <persistence-unit name="GGLocal">
| <provider>org.hibernate.ejb.HibernatePersistence</provider>
| <jta-data-source>java:/GGLocalDataSource</jta-data-source>
| <properties>
| <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
| <property name="hibernate.show_sql" value="true"/>
| <property name="hibernate.use_sql_comments" value="true"/>
| <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
|
| <property name="hibernate.cache.use_second_level_cache" value="true"/>
| <property name="hibernate.transaction.manager_lookup_class"
| value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
| <property name="hibernate.cache.use_query_cache" value="true"/>
| <property name="hibernate.cache.provider_class"
| value="org.jboss.ejb3.entity.TreeCacheProviderHook"/>
| <property name="hibernate.treecache.mbean.object_name"
| value="jboss.cache:service=EJB3EntityTreeCache"/>
|
| </properties>
| </persistence-unit>
|
| </persistence>
|
POJO:
@Entity
| @Table(name="car")
| @Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL)
| public class Car implements Serializable {
|
| @Id
| @Column(name="license_plate")
| String licensePlate;
|
| public String getLicensePlate() {
| return licensePlate;
| }
|
| public void setLicensePlate(String newLicensePlate) {
| this.licensePlate = newLicensePlate;
| }
|
| String description;
|
| public String getDescription() {
| return description;
| }
|
| public void setDescription(String newDescription) {
| this.description = newDescription;
| }
|
| @ManyToOne()
| @JoinColumn(name="garage_id")
| Garage garage;
|
| public Garage getGarage() {
| return garage;
| }
|
| public void setGarage(Garage newGarage) {
| this.garage = newGarage;
| }
|
| }
|
Session Bean:
@Stateful
| public class CarService implements CarInterface, Serializable
| {
|
| private Logger log = Logger.getLogger("appLogger");
|
| @PersistenceContext(unitName="GGLocal")
| EntityManager entityManager;
|
| @TransactionAttribute(TransactionAttributeType.REQUIRED)
| public void updateCar(String id) {
| UUID uuid = java.util.UUID.randomUUID();
| Car car = entityManager.find(Car.class, id);
| car.setDescription(uuid.toString());
| entityManager.persist(car);
| }
|
| @TransactionAttribute(TransactionAttributeType.REQUIRED)
| public String readCarDescription(String id) {
| Car car = entityManager.find(Car.class, id);
| return car.getDescription();
| }
|
| @TransactionAttribute(TransactionAttributeType.REQUIRED)
| public void makeQuery() {
| Query q = entityManager.createQuery("from Car");
| q.setHint("org.hibernate.cacheable", true);
| System.out.println("size=" + q.getResultList().size());
| }
|
|
| }
|
Test:
| public class TerraTest {
|
| /**
| * Describe <code>main</code> method here.
| *
| * @param args a <code>String[]</code> value
| */
| public static void main(String[] args) {
| multiUpdateTest();
| }
|
| // ============================================================
|
| /**
| * Describe <code>multiUpdateTest</code> method here.
| *
| */
| public static void multiUpdateTest() {
|
| System.out.println("-------- started ----------");
|
| CarInterface refs[] = new CarInterface[2];
| refs[0] = getServiceRef("p1","1099");
| refs[1] = getServiceRef("p2","1099");
|
| System.out.println("------------ Refs received -----------");
|
| String plates[] =
| {"34 TTD 2202",
| "32 TF 22",
| "33 TD 202",
| "31 TGG 102",
| "30 TD 212"};
|
| Random nr = new Random();
| Random np = new Random();
|
| for (int i=0;i<400;i++) {
| // pick a random host and car for udpate
| int h = nr.nextInt(2);
| System.out.println("Updating car on node " + h);
| refs[h].updateCar(plates[np.nextInt(plates.length)]);
|
| // pick a random host and car for read
| h = nr.nextInt(2);
| String s = refs[h].readCarDescription(plates[np.nextInt(plates.length)]);
|
| }
|
| String s1 = refs[0].readCarDescription(plates[0]);
| String s2 = refs[1].readCarDescription(plates[0]);
|
| System.out.println("s1=" + s1);
| System.out.println("s2=" + s2);
|
| if (s1.equals(s2)) {
| System.out.println("------------ GOOD -----------");
| }
| }
|
Sample data:
| insert into car(license_plate, garage_id, description) values('34 TTD 2202',1, 'ornek description 1')
| insert into car(license_plate, garage_id, description) values('32 TF 22',1,'ornek description 2')
| insert into car(license_plate, garage_id, description) values('33 TD 202',1,'ornek description 3')
| insert into car(license_plate, garage_id, description) values('31 TGG 102',2,'ornek description 4')
| insert into car(license_plate, garage_id, description) values('30 TD 212',2,'ornek description 5')
|
The logs are attached below:
http://www.bilgidata.com/downloads/jc-logs.zip
Thanks in advance,
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4103595#4103595
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4103595
More information about the jboss-user
mailing list