Skip to content

Commit

Permalink
last commit with h notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
ddwolf committed Jul 29, 2024
1 parent 1059813 commit 3cf73fe
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
23 changes: 22 additions & 1 deletion _posts/2024-06-04-ceph-beginers.md
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,8 @@ ElectionLogic::end_election_period() {
...
}
```
如果elector的个数超过半数,则宣布选主成功
如果elector的个数超过半数,则宣布选主成功。
选举相关的函数有锁保护,同一时刻只会有一个选主相关的函数在执行。`Dispatcher::ms_dispatch2` 函数调用了 `Monitor::ms_dispatch`,里面有加排它锁。

Paxos 请求发送
1. Paxos::collect {send MMonPaxos::OP_COLLECT}
Expand All @@ -359,3 +360,23 @@ Paxos 请求发送
}

peon节点和主节点必须有相同的last_commit才能返回OP_LEASE_OK,否则直接忽略OP_LEASE请求

### 关于 proposal_no
每次选主成功后会生成新的proposal_no,调用的是 `Paxos::get_new_proposal_number`。每个主的统治周期内只有一个proposal_no。
```cpp
version_t Paxos::get_new_proposal_number(version_t gt)
{
if (last_pn < gt)
last_pn = gt;

// update. make it unique among all monitors.
last_pn /= 100;
last_pn++;
last_pn *= 100;
last_pn += (version_t)mon.rank;

// write
// 省略持久化的代码
return last_pn;
}
```
13 changes: 12 additions & 1 deletion _posts/2024-07-08-cpp-type-conversion.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,15 @@ date: 2024-07-08
8
9 VTable indices for 'B' (1 entries).
10 1 | void B::g()
```
```
### 获取C++虚函数的真实地址
```cpp
struct B {
virtual void f() {}
};
void *addrOfF = reinterpret_cast<void*>(&B::f);
```

参考资料:
[C++:虚函数内存布局解析(以 clang 编译器为例)](https://www.less-bug.com/posts/cpp-vtable-and-object-memory-layout-clang-example/)

0 comments on commit 3cf73fe

Please sign in to comment.