Hello Dennis.
Thanks for your comment, it is indeed an interesting idea. As you say,
Terracotta is already doing a lot of the work behind the scenes needed
to implement something like STM.
There is an internal API that provides some support for the primitives
that you would need to implement something like STM. I don't think it is
complete, but it could give you a starting point.
I started to play around with the idea of impl STM on top of TC about a
year ago. I didn't get very far due to lack of time, and I can't find
the code now, but conceptually it would look something like this.
// AspectJ aspect that is using the internal TC API
import com.tc.object.bytecode.Manager;
import com.tc.object.bytecode.ManagerUtil;
public aspect STMAspect issingleton() {
Object around(Object target) :
execution(@Atomic * *.*(..)) && this(target) {
try {
ManagerUtil.optimisticBegin();
ManagerUtil.monitorEnter(target, Manager.LOCK_TYPE_WRITE);
Object clone = (Target) ManagerUtil.deepCopy(target);
Object result = proceed(clone);
ManagerUtil.monitorExit(target);
ManagerUtil.optimisticCommit();
return result;
} catch (Throwable e) { // catch a specific exception
ManagerUtil.monitorExit(target);
ManagerUtil.optimisticRollback(); // throw away the clone with
the changes
... // retry
}
}
}
This aspect would (if fully implemented) provide atomicity (e.g
commit/rollback of change set within the method) For all methods that
are annotated with the @Atomic annotation. E.g. something like this:
@Atomic
void updateSomePOJO(....) {
...
} // commit or rollback
Note: in order for this to work you also need a Terracotta configuration
file that includes all classes that might be updated in a transaction
(however, no declarative locking or other stuff in the configuration file).
However, the optimisticCommit/optimisticRollback/deepCopy API is very
much prototype and is currently not used in Terracotta at all. But
please start playing with it and give us feedback. I will be very
interested in hearing more about your ideas and/or progress.
/Jonas
Dennis Thrysøe wrote:
> Hi,
>
> I was just wondering how to best implement transactional memory in
> conjunction with terracotta.
>
> Obviously it could be implemented "on top", with for instance some
> bytecode instrumentation to intercept field read and write operations.
>
> But, as I understand it, Terracotta DSO more or less does this already.
>
> So I'm imagining something like a plugin on the client side that can
> queue up changes in a transaction log over time, and then either commit
> or roolback these changes.
>
> Any thoughts on this?
>
>
> Thanks,
>
> -dennis
> ---------------------------------------------------------------------------
> The information in this email is confidential and may be legally protected.
>
> _______________________________________________
> tc-dev mailing list
> [email protected]
> http://lists.terracotta.org/mailman/listinfo/tc-dev
--
Jonas Bonér
http://jonasboner.com
_______________________________________________
tc-dev mailing list
[email protected]
http://lists.terracotta.org/mailman/listinfo/tc-dev