users@glassfish.java.net

Re: Stateful bean clustering

From: <Mahesh.Kannan_at_Oracle.Com>
Date: Mon, 18 Jul 2011 09:34:51 -0700

On 7/14/11 8:18 AM, Zlatko Josic wrote:
> Hi,
>
> I have question about stateful session beans clustering. GlassFish
> server uses checkpoint method to replicate bean state to replica node.
> Suppose we have two nodes. Node A and node b. Node B is replica for
> node A.
>
> Now suppose we have stateful session bean TestBean with method
> increment.Bean uses a local transaction. Bean has field named counter
> of long type and initial value is 1. Calling increment method of bean
> increments field counter by 1 and write new value to a database.
>
> What will happend in the case when the server A goes down immediately
> after commit transaction (node commits transactino successfuly but has
> not replicate bean state to replica node) ? Client's ejb proxy will
> detected the instance A goes down and will redirect call to node B
> where counter value of Bean A is less then the value in the database.
> Who will synchronize Test bean state with the value from database?
Hi Zlaja,

That needs to be handled by the application.

Note that you have to do this anyway if the transaction rolls back! Even
if node A and node B are up and running properly, if the write to the db
failed (but after incrementBean() method succeeded), the app must be
coded to call decrementBean() to be in sync with the db value. You can
do that if the your bean implements the SessionSynchronization interface.

In GlassFish, the state of the Stateful Session bean gets replicated
irrespective of the outcome of the transaction in which it participated.
So, if the Session bean's state was not synchronized (by the
application) after the transaction rolls back, the (unsynchronized)
state gets replicated.

Thanks,
--Mahesh

>
> Thanks
>
> Zlaja
>
>
> Thanks
> Zlaja