Search code examples
javafailoverhigh-availabilityterracotta

How does Terracotta work in this situation?


So lets say I have an N sized server array set up like so:

alt text http://www.terracotta.org/web/download/attachments/43909161/ServerArrayMirrorGroup.png

I have a simple JavaBean/POJO:

package example;

public class Person {
  private OtherObject obj;

  public void setObj(OtherObject theObj) {
    synchronized (this) {
      obj = theObj;
    }
  }

  public OtherObject getObj() {
    synchronized (this) {
      return obj;
    }
  }
}

Now if one of the Clients calls Person.setObj(OtherObject) on a Person Object in the TC root (data structure), is the synchronized block (in Person.setObj(OtherObject)) on that client held:

1) Until all N of the Servers in the N sized server array have been synchronized/updated with that Person.obj attribute?

or

2) Until the "active" server has been synchronized with that updated Person.obj attribute? Then the other (N-1) servers in the array are synchronized as possible?

or

3) Some other method that I am over looking?


Solution

  • The answer is not really 1 or 2. Objects are striped across the server mirror groups. The first time this field is set, a transaction is created and that mirror group chosen for that first transaction will "own" the object after that.

    With respect to both 1 and 2, not all active server groups need to be updated so there is no need to to wait for either of those conditions.

    You can find more info at the Terracotta documentation about configuring the Terracotta server array:

    From a locking point of view, the clustered lock on this Person object would be held (mutual exclusion across the cluster) while performing the object modification. The scope of the synchronized block forms the transaction mentioned above. In the getObj() method, you could configure this as a read lock which would allow multiple concurrent readers across the cluster.