简体   繁体   English

从 Spring 引导应用程序写入转发的多区域 Aurora

[英]Multi-Region Aurora with write forwarding from Spring Boot Application

I have created a multi-region( eg two region ) Aurora cluster based on MySql engine.我创建了一个基于 MySql 引擎的多区域(例如两个区域)Aurora 集群。 It has primary cluster with 1 writer and 1 reader instance, and secondary cluster with only Reader instances.它具有包含 1 个写入器实例和 1 个读取器实例的主集群,以及仅包含读取器实例的辅助集群。

As per the Aurora documentation here , following command in secondary region on reader instance, can forward any write call to primary cluster writer instance.根据此处的 Aurora 文档,在读取器实例的次要区域中执行命令,可以将任何写入调用转发到主集群写入器实例。

SET aurora_replica_read_consistency = 'session';

This works fine, when I do the same via mysql client.这工作正常,当我通过mysql客户端执行相同操作时。 And I can use secondary reader instance for write operations too.我也可以使用辅助读取器实例进行写入操作。

Now, I have created an application having separate instance for these two regions.现在,我已经为这两个区域创建了一个具有单独实例的应用程序。 Primary application instance connected with primary Aurora cluster having writer and reader, hence I can do both read and write operation there.与具有写入器和读取器的主要 Aurora 集群连接的主要应用程序实例,因此我可以在那里进行读取和写入操作。

For secondary application instance, which is connected to secondary Aurora cluster having only reader instance, only read operations are working.对于连接到只有读取器实例的辅助 Aurora 集群的辅助应用程序实例,只有读取操作有效。

As a solution I created writeForward.sql in spring boot application to execute and set aurora_replica_read_consistency during application initialisation on secondary cluster only.作为解决方案,我在spring启动应用程序中创建了 writeForward.sql 以仅在辅助集群上的应用程序初始化期间执行和设置aurora_replica_read_consistency For this, I added following property to parameter store in secondary region only:为此,我仅在次要区域的参数存储中添加了以下属性:

spring.datasource.data=classpath:writeForward.sql

But this is somehow not working and secondary application is still not able to do any write operation.但这在某种程度上不起作用,辅助应用程序仍然无法执行任何写操作。

I am looking for some help on how to handle this.我正在寻找有关如何处理此问题的帮助。

After reading through the Aurora documentation again, I realise that write forwarding from secondary region only works when property aurora_replica_read_consistency is set for each session.再次阅读 Aurora 文档后,我意识到仅当为每个 session 设置属性aurora_replica_read_consistency时,从次区域写入转发才有效。

Always set the aurora_replica_read_consistency parameter for any session for which you want to forward writes.始终为要转发写入的任何 session 设置 aurora_replica_read_consistency 参数。 If you don't, Aurora doesn't enable write forwarding for that session.如果不这样做,Aurora 不会为该 session 启用写转发。

To make this possible, each DB connection made by application need to execute this command:为了实现这一点,应用程序建立的每个数据库连接都需要执行此命令:

SET aurora_replica_read_consistency = 'session';

For Spring Boot application using Hikari DB Connection pool, I used following property, which automatically executes above SQL command for each connection that is maintain with DB.对于使用 Hikari DB 连接池的 Spring Boot 应用程序,我使用了以下属性,它会为与 DB 维护的每个连接自动执行上述 SQL 命令。

spring.datasource.hikari.connection-init-sql= SET aurora_replica_read_consistency = 'session'

Details about Hikari Connection Pool can be found here , which mentions about connectionInitSql property.关于 Hikari 连接池的详细信息可以在这里找到,其中提到了connectionInitSql属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从 Spring 引导应用程序属性加载 AWS 区域特定属性? - How do I load AWS region specific properties from Spring Boot application properties? Spring Boot-如何从多模块项目中的姐妹模块启动Spring Boot Application? - Spring Boot - How to start my Spring Boot Application from sister module in a multi-module project? 使用@SpringBootConfiguration的Spring Boot多模块应用程序 - Spring Boot Multi Module application with @SpringBootConfiguration 手动加载应用程序上下文以在spring启动应用程序中编写getBean() - Manually loading application context to write getBean() in spring boot application Spring Boot多上下文application.properties问题 - Spring Boot multi-context application.properties issue Spring Boot中多战应用的集成测试 - Integration testing of multi-war application in Spring Boot @Transaction在多数据源Spring Boot + MyBatis应用程序上不起作用 - @Transaction not working on multi datasource Spring Boot + MyBatis application Spring boot application.properties maven 多模块项目 - Spring boot application.properties maven multi-module projects 多模块spring-boot jpa应用程序 - Multi-module spring-boot jpa application 无法在多模块项目中正确打包Spring Boot应用程序 - Cannot package Spring Boot application properly in a multi module project
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM