Finisky Garden

NLP, 软件工程, 产品设计

Change stream是什么?官方文档:

Change streams allow applications to access real-time data changes without the complexity and risk of tailing the oplog. Applications can use change streams to subscribe to all data changes on a single collection, a database, or an entire deployment, and immediately react to them. Because change streams use the aggregation framework, applications can also filter for specific changes or transform the notifications at will.

这里我们利用change stream来做实时的主从复制。网上没有找到相应的方案,想必是因为直接的做法可能是通过replica set来完成,不会手动进行主从复制。但业务层是有这样的需求的,比如跨地区的异构集群数据备份。

已有的轮子只找到了 MongoShake 。但MongoShake毕竟不是商业项目,代码拉下来运行时发现并不能在我们的环境中正常工作:

  • TLS验证有些问题,通过修改源码解决了
  • all同步模式下,只能通过oplog进行了全量复制,在用change stream进行增量复制时不停抛错,无法正常运行

考虑到改轮子可能比造个轮子更费劲,就研究了下如何自己做主从复制。最简单的原理就是从源库实时地读oplog,然后在目标库上重放oplog。说起来简单,但实现起来可能没那么容易,尤其在源库是分片集群时,不能直接用mongos拉oplog,而要手动从不同的shard上拉取数据,实现难度较高。

好消息是在MongoDB v3.6之后有了change stream功能,再加上我们使用MongoDB Ops Manager做分片集群的管理,可以轻松地做快照恢复,那么主从复制要做的就是从快照时间点之后重放实时的改动。

看起来这轮子自己能造。

阅读全文 »

By the official manual:

Change streams allow applications to access real-time data changes without the complexity and risk of tailing the oplog. Applications can use change streams to subscribe to all data changes on a single collection, a database, or an entire deployment, and immediately react to them. Because change streams use the aggregation framework, applications can also filter for specific changes or transform the notifications at will.

Here we leverage change stream to replicate data from one MongoDB to another in realtime.

There is some existing tools such as MongoShake do the same thing. However, MongoShake is a little bit complicated to use. We encoutered two issues:

  • Modify the source code to use TLS authentication
  • Cannot perform increment sync in all sync_mode

Since our goal is realtime replication, we choose a more straightforward and controllable way: MongoDB Ops Manager cluster restore and change stream to apply realtime changes.

阅读全文 »

MongoDB change stream is a nice feature. It allows applications to access real-time data changes without the complexity and risk of tailing the oplog.

Recently, when we use change stream to replicate data from one sharded cluster to another, it immediately made the cluster unstable (broke down several nodes and triggered the primary change). Then the read/write operations latency significantly increased.

阅读全文 »

升级Hexo到v8.5.0之后,发现mathjax不能正确显示公式。看了下文档,发现推荐的hexo renderer是hexo-renderer-pandoc,而目前使用的是hexo-renderer-kramed,而且这个包已经不再更新也不推荐使用了。

那就换用hexo-renderer-pandoc,虽然公式能正常渲染,但又有新的问题,一是内嵌html不能正确识别,另一个是引用和列表展示不换行。

阅读全文 »

卜算子自嘲 丁元英

本是后山人, 偶做前堂客。 醉舞经阁半卷书, 坐井说天阔。

大志戏功名, 海斗量福祸。 论到囊中羞涩时, 怒指乾坤错。

Recently I found that the Google auto ads significantly slows down the page loading speed. There are also many discussions about this. As a static website, fast loading speed is crutial. In this post, we will optimize the PageSpeed Insights score by delay loading auto ads.

阅读全文 »

# 提升Hexo NexT主题加载速度 中留了个尾巴,优化到最后发现最影响PageSpeed Insights得分的竟然是Google Auto Ads。 这里 有个有意思的讨论,说加上auto ads之后页面加载得分显著变低,采纳答案说“你啥也做不了,也不用care”,下面有人反对这个观点,加载速度评测认为网站慢就会导致搜索排序降低。我赞成后者的观点,风一样的加载速度即我所欲也,本来无一物,何处惹尘埃!

阅读全文 »

网站加载速度是影响搜索引擎排名的一个重要因素。# Google Page Speed Insight 是个很好的网页性能分析工具,可以根据它的分析结果有针对性地对网页进行优化。

用这个工具分析了自己的站吓一跳,原来它在Mobile的性能如此之差,只有27分!Desktop的性能尚可,86分。

PSI Mobile

PSI Desktop

之前看一些博客发现,有些页面风格极为简约,虽然没有很fancy的动效,但看起来很舒服,欣赏这种低调的奢华。道理很简单,文章的内容才是根本,页面做得再炫,也不能提升SEO效果,最好的SEO是优质的内容。后面发现动效反倒会拖慢页面加载速度,对SEO起到负面作用。

考虑到这些,那就可以操刀了,其实一个简单的HTML加上评论系统足够。就风格而言,最喜欢的是类似电子书质感的主题,但暂时没找到对应的模板。

阅读全文 »

说起牛肉面,第一反应可能是“兰州拉面”。可兰州人民已经澄清了这个概念:兰州没有拉面,只有牛肉面。去甘肃旅游时也吃过正宗的兰州牛肉面,确实不错。帝都的兰州拉面馆不少,个人觉得马华的还原度就挺高。

最近刷抖音看到北京两家很火的牛肉面馆,宇飞牛肉面和柴氏风味斋,便想找机会一试。这两家牛肉面与兰州牛肉面不同,简而言之,兰州牛肉面是清汤牛肉片面,北京牛肉面则是红汤牛肉块面。(这种清汤红汤的分类方法让我想起了苏州同德兴的白汤面和红汤面)

偶然发现宇飞在家附近就有家分店,只是从未注意到这家小馆。柴氏没有分号,只能去甘家口品尝了。

阅读全文 »
0%