使用 JTA 工作的分布式 Ehcache
我正在尝试使用 Terracotta Ehcache (开源)对分布式事务内存进行一些基准测试。我在理解它与 JTA 的配合时遇到一些问题。在代码中,我发现对分布式事务感兴趣的缓存将自身登记为 JTA 的资源,JTA 稍后在该资源上执行两阶段提交。
我的问题是,如果只有一个缓存被列为资源,JTA 如何能够在分布式设置中自动更新所有其他缓存?我们不会将其他缓存引用传递给 JTA,因此不会对它们进行原子更新。我觉得,我在这里缺少一些字符串,有人能解释它是如何工作的吗?我也是 J2EE 新手,我是否缺少一些允许将其他缓存自动引用传递到 JTA 的 J2EE 概念?
I am trying to do some bench-marking of Distributed transaction memory using Terracotta Ehcache (Open Source). I am having some problem understanding its working with JTA. In code I have found that cache interested in a Distributed Transaction enlist itself as a resource with JTA on which JTA later executes the two phase commit.
My question is if only one cache is enlisted as a resource, how JTA will be able to update all other caches atomically in distributed settings? We are not passing other caches reference to JTA, so atomically update will not be done on them. I feel, I am missing some string here, can anyone explain how it works? I am new to J2EE too, am I missing some J2EE concept which allow automatic reference passing of other caches to JTA?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Ehcache,如果以这种方式配置(
transactionalMode="xa"
或transactionalMode="xa_strict"
),可以作为完整的 XAResource 参与 JTA 事务(全局事务),它由事务管理器(来自您的应用程序服务器或某些独立产品)控制。在这种情况下,Ehcache 本身负责在事务管理器中注册。此外,作为完整的 XAResource,可以注册多个缓存并且可以成为事务的一部分。集群范围内的强一致性是相当昂贵的(天下没有免费的午餐)。它归结为使用锁和涉及等待、确认等的同步(网络)操作。
有关更详细的阅读,我建议您查阅 Ehcache 文档:Ehcache 中的事务
Ehcache, if configured that way (
transactionalMode="xa"
ortransactionalMode="xa_strict"
), can work as a full XAResource to participate in JTA transactions (global transactions), which is controlled by a Transaction Manager (from your application server or some standalone product). Ehcache itself takes care of registering at the Transaction Manager in this case. Also, as a full XAResource, multiple caches can be registered and can be part of a transaction.Strong, cluster-wide consistency is quite expensive (there is no free lunch). It boils down using locks and synchronous (network) operations involving waits, acknowledging etc.
For a more detailed read, I'd suggest you to consult Ehcache docs: Transactions in Ehcache
每个配置有
transactionalMode="xa_strict"
并在 JTA 事务中更新的缓存都会将自身注册为事务管理器的 XAResource。这对于最终用户来说都是自动化且透明的,您无需执行任何特殊操作即可启动此机制,您只需在 JTA 内使用缓存即可,如果您还碰巧访问其他非JTA 事务上下文中的事务缓存,这些缓存不会成为事务的一部分,并且会在您修改它们后立即更新。
Each cache configured with
transactionalMode="xa_strict"
and updated within a JTA transaction will register itself as an XAResource to the transaction manager. This is all automated and transparent to the end user, you don't have anything special at all to do for this mechanism to kick in, you just have to use your cache inside a JTA begIf you also happen to access other, non-transactional caches in the JTA transaction context, those won't be part of the transaction and will simply be updated as soon as you modify them.
尝试过 xa_strict 但似乎没有自动征用 XAResource?不过,切换到纯 xa 可以...
Tried xa_strict but there seems to be no automatic enlistment of the XAResource? Switching to plain xa works though...