GemFire 中的全局事务

Global Transaction in GemFire

我在内存中使用 GemFire,在内存中使用 Cassandra 作为事实来源,发现很难为以下场景实施全局事务管理器。

使用CacheWriter insert/update Cassandra 和 GemFire Repository 中的数据,用于 GemFire 中的 inserting/updating 记录。如果 GemFire 或 Cassandra 出现任何故障,我需要回滚数据。

这似乎是我以前回答过的问题(最近也是)。反正我没找到。

我使用 Pivotal GemFire 结合使用 SD JPA 的 HSQLDB DataSource 构建了 Global Transaction example

NOTE: This example is part of my Contacts Application Reference implementation (RI) for both Spring Data Geode (for Apache Geode) and Spring Data GemFire (for Pivotal GemFire) showcasing the many capabilities features of Pivotal GemFire/Apache Geode, Spring Data GemFire/Geode and Spring in general. This repository-example focuses on using Spring Data Commons's Repository Infrastructure and extensions to apply the Repository Data Access patterns from SD Commons to Pivotal GemFire/Apache Geode in a Spring context. Of the many things this example shows (e.g. CRUD, Querying, custom Repository methods, etc) both Local (Cache) and Global (JTA) based transaction are part of the repository-example. Unfortunately, the documentation is still largely a WIP. But I do plan to keep this RI and examples up-to-date as I also use the code as a basis for my conference talks. Anyway...

虽然此示例将 Pivotal GemFire 与 RDBMS(即 HSQLDB)相结合,但可以将 HSQLDB 换成 Apache Cassandra。所需要的只是数据 source/store 符合 JTA。

此 example/test 的配置是 here, and relies rather extensively on Spring Boot "auto-configuration" support. That is, when Atomikos (open source JTA Transaction Manager) is on the CLASSPATH (or any JTA Transaction Manager supported by Spring Boot), Spring Boot will auto-configure 基于 JTA 的事务。当然,您可以使用其他不受支持的 JTA 事务管理器提供程序,但您只能自己手动配置它们。如果愿意,您甚至可以手动配置 Atomikos,但是 Spring Boot 的 auto-configuration 支持非常方便,推荐使用。

唯一需要做的就是让每个数据源都知道 JTA 事务。

对于 Pivotal GemFire,这需要 setting up a Naming context (i.e javax.naming.InitialContext) that GemFire itself uses in order to "lookup" (by name) and find the existing JTA Transaction. Essentially, this bean definition associates the JTA "TransactionManager" used with the proper "name" 正如 GemFire 在其查找过程中所预期的那样。

NOTE: the artificial Naming context would not be required if you were in a managed environment, such as an application server, or even Tomcat, since it provides a Naming context service for your applications. Of course, then you would need to register the JTA Transaction with that environment instead. However, since this is a standalone (Spring Boot) app not in a app container, I used Spring's mock/test Naming context support in my NamingContextBuilderFactoryBean class.

剩下的就是让您查看 Apache Cassandra/DataStax 关于让 Apache Cassandra 参与 JTA 事务的文档。那么您不需要任何 Pivotal GemFire 特定的 类(例如 CacheWriter)来从 GemFire 更新 Cassandra。使用 JTA,所有符合 JTA 的数据存储要么正确持久,要么不持久。

可以找到有关 Pivotal GemFire 的全局 JTA 事务支持的更多信息 here, and specifically, related material here

here 开始可以找到有关 Cassandra Transactions 的更多信息。希望这会有所帮助。

干杯, 约翰