OpenAtomFoundation / pikiwidb

a high-performance, large-capacity, multi-tenant, data-persistent, strong data consistency based on raft, Redis-compatible elastic KV data storage system based on RocksDB
BSD 3-Clause "New" or "Revised" License
198 stars 63 forks source link

refactor:Replacement network library #349

Closed lqxhub closed 2 months ago

lqxhub commented 3 months ago

去掉libevent依赖, 重写网络库, 目前检查format还有问题, 等明天有时间再看

还有两个地方可能是有风险的

  1. 直接使用 fd 作为了 client的唯一ID
  2. 在初始化 client的时候,使用了模板构造函数, 这样可能导致通用性不好, 比如 PClient 如果修改了, 可能导致 初始化失败. https://github.com/OpenAtomFoundation/pikiwidb/pull/349/files#diff-2fe737c7212297d7ce5a3812df52450f0af5dacb22954ff20bd3acd673fc5954R31-R47

Summary by CodeRabbit

coderabbitai[bot] commented 3 months ago

Walkthrough

这次更改涉及多个文件,主要集中在PClient类的重构、CMake配置的更新、以及事件处理和套接字管理的增强。许多不再使用的功能被注释掉,同时引入了新的库和头文件。类的构造函数和成员函数进行了调整,并新增了命名空间以优化代码组织。整体结构更加清晰,异步处理能力得到了提升。

Changes

文件路径 更改摘要
CMakeLists.txt 添加-Wno-restrict标志,移除libevent.cmake,添加llhttp.cmake
src/client.cc, .h 修改和注释掉PClient类中与数据包处理和连接管理相关的代码
src/cmd_raft.cc 注释掉对"net/event_loop.h"的包含
src/cmd_thread_pool.h 将CmdThreadPoolTask的构造函数改为显式
src/common.h 包含"unbounded_buffer.h",注释掉UnboundedBuffer类的声明
src/config.h 修改包含文件路径
src/config_parser.cc, .h 将ConfigParser类包裹在pikiwidb命名空间中
src/io_thread_pool.cc, .h 注释掉IOThreadPool和WorkIOThreadPool类及其成员方法
src/net/CMakeLists.txt 更新CMake配置,设置C++标准为20,调整库链接
src/net/base_event.h 添加BaseEvent类及其构造函数、虚函数和成员函数
src/net/base_socket.cc, .h 增强BaseSocket类,增加多种套接字操作方法
src/net/callback_function.h 引入与网络事件处理相关的概念和函数
src/net/client_socket.cc, .h 扩展ClientSocket类,添加连接方法和失败回调函数
src/net/config.h 引入条件编译指令,定义平台特定宏
src/net/epoll_event.cc, .h 添加EpollEvent类,处理epoll事件,包括初始化、添加、删除和轮询
src/net/kqueue_event.cc 引入KqueueEvent类,实现Kqueue事件处理系统

Poem

代码如歌,蜕变如舞,
连接处理,更加稳固。
事件流转,轻松自如,
编译配置,焕然一新。
代码的兔子,欢快跳跃,
迎接变化,无畏无惧。
🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)
Tips ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit .` - `Generate unit testing code for this file.` - `Open a follow-up GitHub issue for this discussion.` - Files and specific lines of code (under the "Files changed" tab): Tag `@coderabbitai` in a new review comment at the desired location with your query. Examples: - `@coderabbitai generate unit testing code for this file.` - `@coderabbitai modularize this function.` - PR comments: Tag `@coderabbitai` in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples: - `@coderabbitai generate interesting stats about this repository and render them as a table.` - `@coderabbitai show all the console.log statements in this repository.` - `@coderabbitai read src/utils.ts and generate unit testing code.` - `@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.` - `@coderabbitai help me debug CodeRabbit configuration file.` Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. ### CodeRabbit Commands (invoked as PR comments) - `@coderabbitai pause` to pause the reviews on a PR. - `@coderabbitai resume` to resume the paused reviews. - `@coderabbitai review` to trigger an incremental review. This is useful when automatic reviews are disabled for the repository. - `@coderabbitai full review` to do a full review from scratch and review all the files again. - `@coderabbitai summary` to regenerate the summary of the PR. - `@coderabbitai resolve` resolve all the CodeRabbit review comments. - `@coderabbitai configuration` to show the current CodeRabbit configuration for the repository. - `@coderabbitai help` to get help. Additionally, you can add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed. ### CodeRabbit Configuration File (`.coderabbit.yaml`) - You can programmatically configure CodeRabbit by adding a `.coderabbit.yaml` file to the root of your repository. - Please see the [configuration documentation](https://docs.coderabbit.ai/guides/configure-coderabbit) for more information. - If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: `# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json` ### Documentation and Community - Visit our [Documentation](https://coderabbit.ai/docs) for detailed information on how to use CodeRabbit. - Join our [Discord Community](https://discord.com/invite/GsXnASn26c) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.
panlei-coder commented 3 months ago

@Tangruilin

Issues-translate-bot commented 3 months ago

Bot detected the issue body's language is not English, translate it automatically.


@Tangruilin

panlei-coder commented 3 months ago

image 我在本地跑了一下,好像建立客户端连接后输出的信息没有处理好

happy-v587 commented 2 months ago

问题

client 退出会引起 Segmentation fault: 11 image

原因是使用了空指针 image

修复

先 close 后 erase image

不再报错 image

Issues-translate-bot commented 2 months ago

Bot detected the issue body's language is not English, translate it automatically.


Client exit will cause Segmentation fault: 11 image

The reason is the use of a null pointer image

lqxhub commented 2 months ago

问题

client 退出会引起 Segmentation fault: 11 image

原因是使用了空指针 image

修复

先 close 后 erase image

不再报错 image 多谢, 万万没想到是这里的问题😅

Issues-translate-bot commented 2 months ago

Bot detected the issue body's language is not English, translate it automatically.


问题

client 退出会引起 Segmentation fault: 11 ![image](https://private-user-images.githubusercontent.com/20750625/346613809-6c44d8f4-29b1-4b39-8b09-279e24c5d0ca.png?jwt=eyJhbGci OiJIUzI1NiIsInR5cCI6IkpXVCJ9..XqfX6ECiOw9LDV0VeqWkaQ6N9jABmOHmNQAxb3Uv5sc )

原因是使用了空指针 ![image](https://private-user-images.githubusercontent.com/20750625/346613756-65d575f3-2adc-47de-a3b9-608ebf124c4e.png?jwt=eyJhbGciO iJIUzI1NiIsInR5cCI6IkpXVCJ9..amBxf5kyt9f_LYifz1O5-HorwB6Wpu -IT4OoKyXACXI)

修复

先 close 后 erase ![image](https://private-user-images.githubusercontent.com/20750625/346616801-2803949f-e647-4e2f-9ea5-1d6b703cbb09.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6 IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjA0ODY3NzgsIm5iZiI6MTcyMDQ4NjQ3OCwicGF0aCI 6Ii8yMDc1MDYyNS8zNDY2MTY4MDEtMjgwMzk0OWYtZTY0Ny00ZTJmLTllYTUtMWQ2YjcwM2NiYjA5LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50a WFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MDklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzA5VDAwNTQzOFomWC1BbXotRXhwaXJlcz0zMDAm WC1BbXotU2lnbmF0dXJlPTNlMjU0YzEwOWNjZmExYTU3ZTJkNTQ1YjcxMDBhMTRkZjFmODc4YmUyZDBhZTE0ZTkxNDQ5NjYxOGQ0YTc3ZmEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0 JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.wTBZlaLxb8qciuipioMpJnAXOhvy2Dg5cK-RkOSlkxY)

不再报错 ![image](https://private-user-images.githubusercontent.com/20750625/346616615-7cc2f977-8bfa-42cd-a5d0-6ba38f883219.png?jwt=eyJhbGciOiJIUzI1NiIsInR5 cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjA0ODY3NzgsIm5iZiI6MTcyMDQ4NjQ3OCwicGF 0aCI6Ii8yMDc1MDYyNS8zNDY2MTY2MTUtN2NjMmY5NzctOGJmYS00MmNkLWE1ZDAtNmJhMzhmODgzMjE5LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW5 0aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MDklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzA5VDAwNTQzOFomWC1BbXotRXhwaXJlcz0zMD AmWC1BbXotU2lnbmF0dXJlPTJhNTBhZWY4NWQxZTA0NTI0ZTI0YzdkZWFhMDAzMWU1OTYyYjMyOTdlZGU3Mjg0NDZjYTk2NjdkZDZjNDA5Y2MmWC1BbXotU2lnbmVkSGVhZGVycz1ob3 N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.8RaGl84DWLhypqWCuJWugFgl5bHYu7xwPuoNTvPPX3w) 多谢, 万万没想到是这里的问题😅

happy-v587 commented 2 months ago

还没处理完,go test时还有问题,我继续看下

Issues-translate-bot commented 2 months ago

Bot detected the issue body's language is not English, translate it automatically.


It's not finished yet. There are still problems during go test. I'll continue to look at it.