Skip to content

Instantly share code, notes, and snippets.

@ideawu
Last active December 25, 2020 03:53
Show Gist options
  • Save ideawu/17dc914c2e147601d6855e2cd60e3f44 to your computer and use it in GitHub Desktop.
Save ideawu/17dc914c2e147601d6855e2cd60e3f44 to your computer and use it in GitHub Desktop.
TTL 处理 - 系统时钟和逻辑时钟

在分布式系统中, TTL 的处理不能依赖系统时钟, 而应该依赖逻辑时钟. 否则, 多个节点的数据会不一致.

当一个 key 过期时, 无论是系统内部发现, 或是系统外部发现, 都需要系统的所有节点先达到时间共识, 然后再删除. 通过外部工具显式地发送一个删除请求(需要 CAS), 也算是逻辑时钟的一种.

而且, 删除操作必须是一个原子操作.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment