在应对大数据量的电商网站时,通常我们把热门数据放在elasticsearch中。但如何保证es和mysql的数据同步?
方法一:.双写模式
1、首先添加商品入数据库,添加商品成功后,商品入ES,
2、若入ES失败,将失败的商品ID放入redis(或MQ),且失败的商品ID入log文件(若出现redis挂掉,可从日志中取异常商品ID然后再入ES)
3、指定定时task任务每秒刷新一下redis缓存,若是从缓存中取到商品ID,则根据商品ID从数据库中获取商品数据然后入ES。
ES的异常分析
org.elasticsearch.ElasticsearchStatusException: Elasticsearch exception [type=circuit_breaking_exception, reason=[parent] Data too large, data for [<http_request>] would be [123581616/117.8mb], which is larger than the limit of [123273216/117.5mb], real usage: [123577712/117.8mb], new bytes reserved: [3904/3.8kb], usages [request=0/0b, fielddata=1557/1.5kb,
解释如下 data too large 问题解释