Now we want to build a slave database server in China,the master is in USA.Using mysql replication to keep master-slave consistent,but there is a problem:"Delay".In php code ,there are some script like below:
$que= "insert into test values(100,200)";
$res = $dbw->query($que);
$que = "select id,name from test";
$res = $dbw->query($que);
When read point to slave,maybe can't get anything because "Delay",and then the logic has made a mistake.
Deal with this problem,we could modify PHP code ,when read and write all in one logic,connecting to master,other reads,connecting to slave.But this time,the web has already completed 80%,and team leader don't want modify php code,and ask me to solve this problem on database level.Mysql-proxy provide the function of w-r split,but when replication is not normal,it is also read on slave.
Our real intention is when page views from China,"China server" handle the request ,when page views from USA,"USA server" handle the request.
Can you give me some suggest about my question?
Best Regards.
Bruce.
$que= "insert into test values(100,200)";
$res = $dbw->query($que);
$que = "select id,name from test";
$res = $dbw->query($que);
When read point to slave,maybe can't get anything because "Delay",and then the logic has made a mistake.
Deal with this problem,we could modify PHP code ,when read and write all in one logic,connecting to master,other reads,connecting to slave.But this time,the web has already completed 80%,and team leader don't want modify php code,and ask me to solve this problem on database level.Mysql-proxy provide the function of w-r split,but when replication is not normal,it is also read on slave.
Our real intention is when page views from China,"China server" handle the request ,when page views from USA,"USA server" handle the request.
Can you give me some suggest about my question?
Best Regards.
Bruce.
解决方案 »
- 为何使用了GRANT ALL 创建了一个user后,试图用这个user访问database时出错?ERROR 1045
- 求这种时间方面的MYSQL语句
- 能建一张表,其中一个字段作为外键参照到的是表中的另一个字段么??
- mysql运行了向导,修改了数据库属性里,还是不能输入中文,求解
- 建立索引问题 ?
- vc 开发mysql,用什么连接数据库最好呢?ADO 可以么?
- 各位大虾,请问MySQL-Front为什么进行远程连接时报了个这样的错误?
- mysql数据排序问题
- 视图的 EXPLAIN 时权限不足,求指点,谢谢
- [求组]db2中的with ... as (...) 在mysql中应该如何表示
- 我在使用Java做一个mySql数据备份动作时出错
- 请教一条SQL写法
这么高级。。
默认的mysql-proxy 不管来自哪里的访问,只按照访问类型来分流的(不知道能不能修改perl来判断)。不改程序的条件下我也不知道如何实现。交给楼下的回答。。
第一个难点在复制的延迟,受限于网络环境,属于硬伤。
第二个难点在写后的立刻读,需要读MASTER上的数据,才能保证逻辑一致性,但是现在要去修改程序来完成这个操作很难了,要对程序动大手术,开发的时候没有考虑过将来的扩展。现在就想了解下,有没有其他什么方案,能够达到这个目的的:中国的访问读中国的服务器,美国的访问读美国的服务器,写入全部到美国。
百度,谷歌,新浪等在全球各地都有服务器,他们是怎么配置的呢?
有没有什么代理软件,处在WEB和DB中间,能智能判断出什么操作到MASTER,什么操作到SLAVE?
修改PERL脚本肯定可以实现,但是我不会,悲催的。
如果曾经封装过,那还有机会。数据库层面,没什么机会了。另外,你们的系统是什么应用,如果读写量不大,一般的访客的请求都不会产生写操作,是否可以考虑把所有相关的页面模块放到一个统一的域名下,这个域名下的应用,无论如何,数据库都是US的
帖子里面举了个例子,代码里是这样访问数据库的。
没有封装。把相关的页面模块放到统一的域名下,这个相关的模块怎么定义的?
有的读是纯粹的读,来了浏览后就走了,这时候可以去读SLAVE。还有些读是先写,后读出刚才写的内容,比如回复一个帖子,你要看到你自己的回复内容,这时候的读必须在MASTER上才保险。如果在程序里面处理的话,完全可以做到,因为程序是知道哪些读是先写后读的,哪些是纯粹的读的。
现在不能改代码,咋整啊?
差个几秒无所谓??为什么?比如百度百科,你回答一个问题后,写入到MASTER,然后展现你刚才的回答,读如果是SLAVE的话,就不能有几秒的延迟,要么会有404错误了。如果读的还是MASTER,就没问题。