Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update how_update.md #251

Merged
merged 3 commits into from
May 23, 2024
Merged

Update how_update.md #251

merged 3 commits into from
May 23, 2024

Conversation

Navyum
Copy link
Contributor

@Navyum Navyum commented May 17, 2024

依据:

  1. 如果先更新内存记录,此时断电就不是crash-safe的
  2. flush 链表的脏页需要保存redo log对应的lsn值,用来做checkpoint操作,所以先有redo log写入,再有脏页

依据:
1. 如果先更新内存记录,此时断电就不是crash-safe的
2. flush 链表的脏页需要保存redo log对应的lsn值,用来做checkpoint操作,所以先有redo log写入,再有脏页
依据下面的例子:
- 「元素:abc,权重:3」节点的  leve[1] 的下一个指针指向了「元素:abcde,权重:4」的节点,然后将其和要查找的节点比较。虽然「元素:abcde,权重:4」的节点的权重和要查找的权重相同,但是当前节点的 SDS 类型数据「大于」要查找的数据,所以会继续跳到「元素:abc,权重:3」节点的下一层去找,也就是 leve[0];

说明:abcde的SDS不满足,权重满足,如果直接到该节点的下一层level0,已经没有后续节点,正确结果无法找到。
参考源码:
循环中比较时,实际比的是当前节点的forward指针对应的节点的score和ele
```
for (i = zsl->level-1; i >= 0; i--) {
        /* store rank that is crossed to reach the insert position */
        rank[i] = i == (zsl->level-1) ? 0 : rank[i+1];
        while (x->level[i].forward &&
                (x->level[i].forward->score < score ||
                    (x->level[i].forward->score == score &&
                    sdscmp(x->level[i].forward->ele,ele) < 0)))
        {
            x = x->level[i].forward;
        }
        update[i] = x;
    }
```
@xiaolincoder xiaolincoder merged commit 7776b7c into xiaolincoder:main May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants