英文:
Is snapshot of Redis atomic
问题
如果Redis快照是原子性的,我不应该在快照中看到A出现两次。
英文:
I used the sorted set of Redis to store some data in RAM. The scores of elements in the sorted set keep updating.
My question is if we may get such a case:
- Element A is at the position 3 in the sorted set;
- A Redis snapshot is writing "Element A is at the position 3";
- Element A moves to the position 100;
- The same Redis snapshot is writing "Element A is at the position 100".
At last, in the snapshot, A appears two times in the same sorted set.
If the Redis snapshot is atomic, I should never see A twice in shapshot.
答案1
得分: 0
是的,它是原子性的。
当Redis创建快照时,它会fork一个子进程来执行转储工作,父进程对内存中的数据集进行写时复制。
因此,您描述的情况不应该发生,也就是说,在快照中您永远不会看到A两次。相反,一旦创建一个子进程来转储快照,父进程中的新写操作将不会写入快照。
英文:
Yes, it's atomic.
When Redis creates a snapshot, it forks a child process to do the dump work, and parent process does copy-on-write for the data set in memory.
So the case you described should not happen, i.e. you never see A twice in snapshot. Instead, once it creates a child process to dump snapshot, new writes in parent process won't be written to the snapshot.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论