[Google Docs] Document Server 是怎么merge俩个不同version的document的

例如两个user: u1, u2,u1的第一次operation叫u1o1,u2的第一次operation叫u2o1
如果u1,u2 同时做改动 文本的版本 v1
那么queue 里如下
[ u2o1(based v1),u1o1(basedv1) ]
Document server handle u1o1 first, so it can save below info:

  1. doc_v1 -> start version
  2. u1o1 -> the changes need to do
  3. doc_v2 -> version after change
    so when the server start to handle u2o1 from the second user, the server would apply the u2o1 to doc_v1, here we got doc_v2*.
    So now there are two versions: doc_v2 and doc_v2*.
    And document server would somehow ‘merge’ the doc_v2 and doc_v2* to get doc_v3.
    doc_v3 would be response to u2.

不同版本是这么merge然后得到新的版本么?还是我想的以上步骤不对。总感觉不太对。
谢谢老师!

第三步的时候 服务器状态是 doc_v2 (with change u1o1),然后接收到一个 request: u2o1(based v1),这时候服务器这边就运行 OT,拿 doc_v2 和 doc_v1 的区别,也就是 u1o1 和 u2o1 进行 OT 的计算,得到 u1o1’ 和 u2o1’。
服务器的状态更新到 doc_v3,同时把 {u2o1’ + 版本号v3} 发给 u1,把 {u1o1’ + 版本号v3} 发给 u2。

1 个赞

明白了 谢谢老师