在django中设置Aurora_replica_cred_consisterency的适当方法是什么?
我正在寻找一种从冗余Django应用程序连接到Aurora的正确方法。我有一个在多个区域运行的Django应用程序。 AWS中的Aurora群集配置为在一个区域中具有可写的主人,而在另一个区域中具有写入方向的纯副本。据说,这允许应用程序“透明地”写入仅读取的DB。 它不是很透明,因为它需要每个会话才能设置aurora_replica_read_consistency = session 。 我希望在Django设置文件的数据库会话中实现这一目标:
DATABASES = {
'default': {
'ENGINE': 'django_prometheus.db.backends.mysql',
'NAME': 'mydb',
'USER': 'admin',
'PASSWORD': 'DB_PASSWORD',
'HOST': 'DB_HOST',
'PORT': '3306',
'OPTIONS': {
'init_command': 'SET aurora_replica_read_consistency=SESSION',
},
},
}
但是,这会在Aurora Master上引发错误,这是可写的。错误指出您只能在仅读取复制品上设置此变量的内容。即我的Django容器甚至都不会在主机上启动。 我尝试用连接信号拧紧;但是,我没有找到使其运行的方法作为与DB连接的任何新Django连接后的第一件事。信号似乎要求每个应用程序都具有信号处理程序。 我的故障转移的设置方式是Aurora Master可能位于任何区域。即确定此Django客户端是否连接到主或复制品并不容易。 我可以忽略init_command的错误,但我不明白如何实现。 关于如何解决这个问题的好主意?
I am looking for a proper way to connect to Aurora from a redundant django app. I have a django app that runs in multiple regions. The Aurora cluster in AWS is configured to have a writable master in one region and a read-only replica with write-forwarding in the other region. This, supposedly, allows apps to "transparently" write to the read-only DB.
It's not very transparent because it requires for every session to SET aurora_replica_read_consistency=SESSION
.
I was hoping to achieve this in the DATABASE session of the django settings file like so:
DATABASES = {
'default': {
'ENGINE': 'django_prometheus.db.backends.mysql',
'NAME': 'mydb',
'USER': 'admin',
'PASSWORD': 'DB_PASSWORD',
'HOST': 'DB_HOST',
'PORT': '3306',
'OPTIONS': {
'init_command': 'SET aurora_replica_read_consistency=SESSION',
},
},
}
However, this throws an error on the aurora master, which is writable. The error states something that you can only set this variable on the read-only replica. I.e. my django container won't even boot on the master.
I tried screwing with the connection signals; however, I did not find a way to make it run the SET command as the first thing after any new django connection to the DB. Signals seem to require each app to have a signal handler.
The way my failover is set up is that the Aurora master may be in any region. I.e. it's not easy to determine whether this django client connects to a master or a replica.
I can go as far as ignore the error from the init_command, but I don't understand how it's possible to accomplish.
Any good ideas on how to solve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论