nosql mongodb 复制集自动分片,运行实验时数据丢失
我不断地将数据插入自动分片的 mongodb 中。 (不更新,仅插入)
实验设置 2个分片,每个分片有2个节点。
在 shard1 中 ->节点 1(主节点)、节点 2 在 shard2 中 -> 一个分片中的节点 3(主节点)、节点 4
我将辅助节点(节点 2)关闭 ->数据仍然正确插入 现在我也将主节点(node1)也关闭了 ->完整的分片现在已关闭
令人惊讶的是整个 mongo 设置没有进行任何写入。
故事还有另一个转折。 现在我已经启动了节点 2,因为这是唯一可用的节点,它成为主节点并开始接受数据。
大约 10 分钟后,我也启动了 node1。
但是当我检查插入到node1(当node2关闭时)的数据丢失了:(。
s1 s2
(n1,n2) (n3,n4)
--------- ---------
1. (up,up) (up, up) -> data was getting inserted
2. (up,down) (up, up) -> data was getting inserted properly (but got lost :( )
3. (down, down) (up, up) -> no data inserts were happening
4. (down, up) (up, up) -> started taking data again
5. (up, up) (up, up) -> n1 picked data from n2, but couldn't give the data to n2
在最后一步中,当我启动n1时,它从n2获取了新记录,但是n1在步骤2中获取了上面完全丢失了:(。
这是 mongo 的预期行为吗?
请有人帮助我,如果需要,我可以进行更多实验:)
。 维韦卡南达·塔达拉
I was continuously inserting data into autosharded mongodb.
(not updating, only insertion )
Experimental setup
2 shards, each shard has 2 nodes.
in shard1 -> node1 (primary), node2
in shard2 -> node3 (primary), node4
in one shard I brought secondary node (node2) down -> still the data got inserted properly
Now I brought the primary(node1) also down -> complete shard is down now
Surprisingly the whole mongo setup was not taking any writes.
there is another twist in the story.
Now I have brought the node2 up, as this is the only node available, it beccame primary and started accepting data.
After some 10 mins I have brought node1 also up.
But when I checked the data that I have inserted into node1 (when node2 is down) was lost :(.
s1 s2
(n1,n2) (n3,n4)
--------- ---------
1. (up,up) (up, up) -> data was getting inserted
2. (up,down) (up, up) -> data was getting inserted properly (but got lost :( )
3. (down, down) (up, up) -> no data inserts were happening
4. (down, up) (up, up) -> started taking data again
5. (up, up) (up, up) -> n1 picked data from n2, but couldn't give the data to n2
in the last step, when I brought n1 up, it got the new records from n2, but the that n1 got during step 2 above were completely lost :(.
Is this expected behaviour of mongo?
Someone please help me out, I can run more experiments if required :).
Thanks in advance,
Vivekananda Tadala
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您关闭两个成员副本集中的一个成员,另一个成员将停止接受写入。请参阅此说明< /a> 为什么你需要三个成员并且在玩游戏时总是使用安全模式。
MongoDB 中的复制是单向的:从属服务器从更新的从属服务器或主服务器复制数据。您还不能让两个节点相互复制数据。您可能对确保写入复制感兴趣与此同时。
插入已关闭的分片上的块将不起作用,但您可以插入其他分片上的分片上的块。您可以使用 db.printShardingStatus() 来查看哪些块位于何处。
If you bring down one member in a two member replica set, the other will stop accepting writes. See this explanation of why you need three members and always use safe mode when you're playing around.
Replication in MongoDB is one-directional: a slave copies data from a more up-to-date slave or the master. You can't have two nodes copying data from each other (yet). You may be interested in ensuring write replication in the meantime.
Inserting into chunks on a downed shard won't work, but you can insert into chunks on shards that are on the other shard. You can use
db.printShardingStatus()
to see which chunks are where.