我正在寻找边缘案例场景的解决方案,其中客户端不断询问服务器由于时间戳而失败的新内容。
在这个例子中,由于另一个边缘情况问题,我没有使用序列号。你可以在这里看到这个问题:A Client Walks Into a Server And Asks "What's New?" – Problems With Sequence Numbers
假设我们正在使用时间戳。每行更新都会添加服务器时间的时间戳。客户不断询问自收到的最后一个项目的时间戳以来的新内容。简单?是的,但是......
失败情景:
以下时间对于可读性而言是任意的。假设现实世界中的毫秒数。
2:50 Client C checks for updates.
2:59 Client A starts update on a row. (Sets lastModified to 2:59)
2:59 Client B starts update on a row. (Sets lastModified to 2:59)
3:00 Client A Row update becomes visible on DB. (lastModified still at 2:59)
3:00 Client C checks for updates >2:50. Get’s A’s update. Good.
3:01 Client B Row update becomes visible on DB. (lastModified still at 2:59)
3:10 Client C checks for updates >2:59. Gets nothing. Misses B's update. Bad.
这假定lastModified不能以原子方式设置,并且它的设置与数据库中可用的行之间可能存在延迟。如果数据库是分片的,这种延迟可能会大得多。
我们可以将更新检查设置为任意询问导致重叠的早期时间。这是低效的,因为可能检索到重复的数据但不是致命的。但是,是否可以知道所有情况需要多少重叠?分片数据库是否很少会延迟显示更新秒数?分钟?
让客户反复询问“什么是新的”似乎是一个常见的用例,我发现在这方面找不到更好的最佳实践,我感到很惊讶。
有关解决此方案或建议更好的,最好是平台无关的解决方案以寻求更改的任何想法吗?