# phxpaxos **Repository Path**: tjopenlab/phxpaxos ## Basic Information - **Project Name**: phxpaxos - **Description**: The Paxos library implemented in C++ that has been used in the WeChat production environment. https://github.com/Tencent/phxpaxos - **Primary Language**: C++ - **License**: BSD-3-Clause - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2022-01-10 - **Last Updated**: 2025-09-17 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # PhxPaxos状态同步库 ## 1 前言 PhxPaxos是微信使用的C++ Paxos库实现。[官方仓库](https://github.com/Tencent/phxpaxos) 该库在COMO中用于分布式数据同步。涉及COMO的部分(export_como)需在COMO环境下构建。 ## 2 使用方法 ### 2.1 编译共享库 在Ubuntu 22.04中安装Python包: ```sh sudo apt install python3 python-is-python3 ``` ### 2.2 配置COMO 如果没有配置过COMO环境,需要先clone como仓库并编译: ```sh git clone https://gitee.com/tjopenlab/como.git --recursive cd como source build/envsetup.sh como_linux_x64 build ``` 将本仓库clone到como仓库的external目录下: ```sh cd external git clone https://gitee.com/tjopenlab/ComoFramework.git --recursive ``` ### 2.3 编译PhxPaxos本体 ```sh # 需要先source为COMO环境 source ../../build/envsetup.sh ./MakeMe.sh ``` 输出路径:export_como/PhxPaxos.so ### 2.4 测试 分别设置PhxPaxos和comort库的路径: ```sh export LD_LIBRARY_PATH=/home/user/Work/4-2025/como/external/phxpaxos/export_como/ export LD_LIBRARY_PATH=/home/user/Work/4-2025/como/bin/target/como.linux.x64.rls/ ``` export_como路径下有若干测试程序,如: 1. phxcomo 2. phxcomo_dbus 3. phxcomo_normal_test 4. phxcomo_test ### 2.5 代码更新 每次代码更新后,需要分别`git pull`拉取como和PhxPaxos仓库的最新版。 ## 3 API ### 3.1 ComoPhxUtils 详见`./export_como/ComoPhxUtils.h`: ```cpp class ComoPhxUtils { public: /** * Input: * sMyNode: myip:myport * sNodeInfoList: * for example: * sMyNode: 127.0.0.1:11111 * sNodeInfoList: 127.0.0.1:11111,127.0.0.1:11112,127.0.0.1:11113 */ static int RunPaxos(const char *sMyNode, NodeInfo& oMyNode, const char *sNodeInfoList, NodeInfoList& vecNodeInfoList, PhxEchoServer **oEchoServer); /** * SyncStateData with key-value */ static int SyncStateData(PhxFscpServer* oEchoServer, uint32_t action, std::string key, std::string value, std::string& sEchoRespValue); /** * GetStateData by key into value */ static std::string GetStateData(std::string key, std::string& value, uint64_t& llInstanceID); }; ``` ### 3.2 leveldb ``` include/leveldb/db.h ```