快照 Redis 是否原子化

huangapple go评论59阅读模式
英文:

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:

  1. Element A is at the position 3 in the sorted set;
  2. A Redis snapshot is writing "Element A is at the position 3";
  3. Element A moves to the position 100;
  4. 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.

huangapple
  • 本文由 发表于 2023年2月23日 19:23:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/75544152.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定