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

feat: maintain the logidx-seqno in SST files #246

Merged

Conversation

longfar-ncy
Copy link
Collaborator

@longfar-ncy longfar-ncy commented Mar 30, 2024

  • Storage 中的 Redis 类封装了一个 RocksDB, 在 Redis 对象内增加一个队列,该队列保存了 raft applied log index 和 RocksDB 内所有 CF sequence number 的映射关系关系
    • 每次 apply 写入成功后向该队列追加 log index 和 sequence number 的映射
    • 增加一个 prop, 产生新 SST 文件的时候,通过该队列找到该 SST 文件中最大 sequence number 对应的 log index,并写入该 SST 文件的 prop meta block 进行持久化.
    • 监听 Flush 事件, 每次 Flush 完成后,清理队列中不再有用的映射关系.

方案详细内容
关于 LogIndexAndSequenceCollector 通过多队列来缓解🔒竞争的优化方案

@github-actions github-actions bot added the ✏️ Feature New feature or request label Mar 30, 2024
src/storage/src/log_index.h Outdated Show resolved Hide resolved
src/storage/src/log_index.h Outdated Show resolved Hide resolved
@longfar-ncy longfar-ncy marked this pull request as draft April 7, 2024 09:35
src/storage/src/log_index.h Show resolved Hide resolved
src/storage/src/log_index.cc Outdated Show resolved Hide resolved
@longfar-ncy longfar-ncy force-pushed the feat/logidx-seqno branch 4 times, most recently from 834534d to 56d8abd Compare April 10, 2024 01:46
src/storage/src/log_index.cc Show resolved Hide resolved
src/storage/src/log_index.cc Outdated Show resolved Hide resolved
src/storage/src/log_index.cc Outdated Show resolved Hide resolved
src/storage/src/log_index.cc Show resolved Hide resolved
@dingxiaoshuai123 dingxiaoshuai123 marked this pull request as ready for review April 10, 2024 02:53
@@ -42,6 +42,7 @@ enum ColumnFamilyIndex {
kZsetsMetaCF = 7,
kZsetsDataCF = 8,
kZsetsScoreCF = 9,
kColumnFamilyNum,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里应该给个赋值?

auto res = sscanf(s.c_str(), "%" PRIi64 "/%" PRIu64 "", &applied_log_index, &largest_seqno);
assert(res == 2);

LogIndexAndSequencePair p(applied_log_index, largest_seqno);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return LogIndexAndSequencePair(applied_log_index, largest_seqno);

// cf_[cf_id].applied_log_index = std::max(cf_[cf_id].applied_log_index.load(), cur_log_index);
// return cur_log_index == cf_[cf_id].applied_log_index.load();
// }
bool IsAppliedOrUpdate(size_t cf_id, LogIndex cur_log_index) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IsApplied可能就够了,就是命名上还是有点问题,会误以为只是判断实际上还有隐式的置值。

for (const auto& entry : log.entries()) {
// If the log has been applied, skip it. Otherwise, update the logidx of the column family.
if (inst->IsRestarting() && inst->IsAppliedOrUpdate(entry.cf_idx(), log_idx)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里可以加个hint unlikely(),表示正常情况不会走进来。

@longfar-ncy longfar-ncy force-pushed the feat/logidx-seqno branch 2 times, most recently from 4e7ade7 to 59d5a2b Compare April 11, 2024 08:01
@AlexStocks AlexStocks merged commit 540f937 into OpenAtomFoundation:import-braft Apr 12, 2024
2 checks passed
@Mixficsol Mixficsol mentioned this pull request Apr 15, 2024
24 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✏️ Feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants