|
| 1 | +# Copilot Coding Agent Instructions for Dragonfly |
| 2 | + |
| 3 | +## Repository Overview |
| 4 | + |
| 5 | +Dragonfly is a high-performance, Redis and Memcached compatible in-memory data store written in C++17. It uses a shared-nothing architecture for efficient multi-threaded operation, delivering significantly higher throughput than traditional single-threaded Redis implementations. |
| 6 | + |
| 7 | +**Key characteristics:** |
| 8 | +- Large C++ codebase (~200k+ LOC) with Python integration tests |
| 9 | +- Uses CMake/Ninja build system with the `helio` submodule for I/O and threading |
| 10 | +- Targets Linux (kernel 5.11+ recommended), with io_uring and epoll support |
| 11 | +- Requires signed commits with conventional commit messages |
| 12 | + |
| 13 | +## Repository Structure |
| 14 | + |
| 15 | +``` |
| 16 | +src/ # Main C++ source code |
| 17 | +├── server/ # Core server implementation (main entry: dfly_main.cc) |
| 18 | +├── core/ # Core data structures |
| 19 | +├── facade/ # Network and command handling |
| 20 | +├── redis/ # Redis protocol implementation |
| 21 | +helio/ # Git submodule: I/O and threading library (must be initialized) |
| 22 | +tests/dragonfly/ # Python pytest integration/regression tests |
| 23 | +contrib/ # Docker configs, Helm charts, utility scripts |
| 24 | +docs/ # Documentation including build-from-source.md |
| 25 | +tools/ # Benchmarking and utility tools |
| 26 | +``` |
| 27 | + |
| 28 | +## Build Instructions |
| 29 | + |
| 30 | +### Prerequisites (Ubuntu/Debian) |
| 31 | + |
| 32 | +```bash |
| 33 | +sudo apt install ninja-build libunwind-dev libboost-context-dev libssl-dev \ |
| 34 | + autoconf-archive libtool cmake g++ bison zlib1g-dev |
| 35 | +``` |
| 36 | + |
| 37 | +### Alternative: Build with Docker (all prerequisites included) |
| 38 | + |
| 39 | +Use pre-built development containers that have all dependencies installed: |
| 40 | + |
| 41 | +```bash |
| 42 | +docker run -it --rm -v $(pwd):/src -w /src ghcr.io/romange/ubuntu-dev:24 bash |
| 43 | +# Or use Ubuntu 22.04: |
| 44 | +docker run -it --rm -v $(pwd):/src -w /src ghcr.io/romange/ubuntu-dev:22 bash |
| 45 | +``` |
| 46 | + |
| 47 | +### Initialize Submodules (REQUIRED) |
| 48 | + |
| 49 | +```bash |
| 50 | +git submodule update --init --recursive |
| 51 | +``` |
| 52 | + |
| 53 | +### Configure and Build |
| 54 | + |
| 55 | +**Debug build (recommended for development):** |
| 56 | +```bash |
| 57 | +./helio/blaze.sh # Creates build-dbg/ |
| 58 | +cd build-dbg && ninja dragonfly |
| 59 | +``` |
| 60 | + |
| 61 | +**Release build:** |
| 62 | +```bash |
| 63 | +./helio/blaze.sh -release # Creates build-opt/ |
| 64 | +cd build-opt && ninja dragonfly |
| 65 | +``` |
| 66 | + |
| 67 | +**Minimal debug build (faster compilation):** |
| 68 | +```bash |
| 69 | +./helio/blaze.sh -DWITH_GPERF=OFF -DWITH_AWS=OFF -DWITH_GCP=OFF \ |
| 70 | + -DWITH_TIERING=OFF -DWITH_SEARCH=OFF -DWITH_COLLECTION_CMDS=OFF \ |
| 71 | + -DWITH_EXTENSION_CMDS=OFF |
| 72 | +``` |
| 73 | + |
| 74 | +### Build Specific Test |
| 75 | + |
| 76 | +```bash |
| 77 | +cd build-dbg && ninja generic_family_test |
| 78 | +./generic_family_test |
| 79 | +``` |
| 80 | + |
| 81 | +## Testing |
| 82 | + |
| 83 | +### C++ Unit Tests |
| 84 | + |
| 85 | +```bash |
| 86 | +cd build-dbg |
| 87 | +ninja src/all # Build all targets in src/ |
| 88 | +ctest -V -L DFLY # Run all tests labeled DFLY |
| 89 | +``` |
| 90 | + |
| 91 | +Individual test execution with environment variables: |
| 92 | +```bash |
| 93 | +GLOG_alsologtostderr=1 FLAGS_fiber_safety_margin=4096 timeout 20m ctest -V -L DFLY |
| 94 | +``` |
| 95 | + |
| 96 | +### Python Regression Tests |
| 97 | + |
| 98 | +```bash |
| 99 | +cd tests |
| 100 | +pip3 install -r dragonfly/requirements.txt |
| 101 | +export DRAGONFLY_PATH="../build-dbg/dragonfly" |
| 102 | +pytest dragonfly/ --log-cli-level=INFO |
| 103 | +``` |
| 104 | + |
| 105 | +**Test markers:** |
| 106 | +- `slow`: Long-running tests |
| 107 | +- `opt_only`: Only run on release builds |
| 108 | +- `debug_only`: Only run on debug builds |
| 109 | +- `exclude_epoll`: Skip when using epoll |
| 110 | + |
| 111 | +### Helm Chart Tests |
| 112 | + |
| 113 | +```bash |
| 114 | +cd contrib/charts/dragonfly |
| 115 | +go test -v ./... -update # Update golden files if needed |
| 116 | +``` |
| 117 | + |
| 118 | +## Code Style and Pre-commit Hooks |
| 119 | + |
| 120 | +**ALWAYS install pre-commit hooks before making changes:** |
| 121 | + |
| 122 | +```bash |
| 123 | +pipx install pre-commit clang-format black |
| 124 | +pre-commit install |
| 125 | +``` |
| 126 | + |
| 127 | +**Style guidelines:** |
| 128 | +- C++: [Google C++ Style Guide (2020 version)](https://github.com/google/styleguide/blob/505ba68c74eb97e6966f60907ce893001bedc706/cppguide.html), clang-format v14.0.6, 100 column limit |
| 129 | +- Python: Black formatter, 100 character line length |
| 130 | +- Commits: Conventional Commits format, must be signed (`git commit -s`) |
| 131 | + |
| 132 | +**Commit message format:** |
| 133 | +``` |
| 134 | +<type>(<scope>): <description> |
| 135 | +
|
| 136 | +Valid types: feat, fix, build, chore, ci, docs, perf, refactor, revert, style, test |
| 137 | +``` |
| 138 | + |
| 139 | +Example: `fix(server): correct memory leak in db_slice #123` |
| 140 | + |
| 141 | +## CI/CD Pipeline |
| 142 | + |
| 143 | +The main CI workflow (`.github/workflows/ci.yml`) runs on PRs to main: |
| 144 | + |
| 145 | +1. **pre-commit**: Validates formatting and commit messages |
| 146 | +2. **build**: Tests on ghcr.io/romange containers (ubuntu-dev:20, ubuntu-dev:24, alpine-dev) |
| 147 | + - Debug and Release configurations |
| 148 | + - GCC and Clang compilers |
| 149 | + - With/without ASAN/UBSAN sanitizers |
| 150 | +3. **Unit tests**: IoUring mode, Epoll mode, Cluster mode variants |
| 151 | +4. **Regression tests**: Python pytest suite |
| 152 | +5. **Helm chart tests**: Lint and installation tests |
| 153 | + |
| 154 | +## Key Files for Reference |
| 155 | + |
| 156 | +| Purpose | File | |
| 157 | +|---------|------| |
| 158 | +| Main entry point | `src/server/dfly_main.cc` | |
| 159 | +| Server configuration | `src/server/main_service.cc` | |
| 160 | +| CMake root | `CMakeLists.txt` | |
| 161 | +| Build script | `helio/blaze.sh` | |
| 162 | +| CI workflow | `.github/workflows/ci.yml` | |
| 163 | +| Pre-commit config | `.pre-commit-config.yaml` | |
| 164 | +| C++ formatting | `.clang-format` | |
| 165 | +| Python formatting | `pyproject.toml` | |
| 166 | +| Pytest config | `tests/pytest.ini` | |
| 167 | +| Test requirements | `tests/dragonfly/requirements.txt` | |
| 168 | + |
| 169 | +## Common Pitfalls |
| 170 | + |
| 171 | +1. **Submodule not initialized**: Always run `git submodule update --init --recursive` after cloning |
| 172 | +2. **Missing pre-commit hooks**: Run `pre-commit install` to avoid commit failures |
| 173 | +3. **Unsigned commits**: Always use `git commit -s` for signed commits |
| 174 | +4. **Build directory confusion**: Debug builds go to `build-dbg/`, release to `build-opt/` |
| 175 | +5. **Test timeouts**: Use `timeout` command for long-running tests to avoid hangs |
| 176 | + |
| 177 | +## Validation Checklist |
| 178 | + |
| 179 | +Before submitting changes: |
| 180 | + |
| 181 | +1. ✅ Code compiles: `cd build-dbg && ninja dragonfly` |
| 182 | +2. ✅ Unit tests pass: `ctest -V -L DFLY` |
| 183 | +3. ✅ Pre-commit checks pass: `pre-commit run` (runs on staged files) or `pre-commit run --files path/to/file1 path/to/file2` |
| 184 | +4. ✅ Commits are signed and follow conventional format |
| 185 | +5. ✅ For Python changes: `pytest tests/dragonfly/ -k <test_name>` |
| 186 | + |
| 187 | +Trust these instructions. Only search for additional information if these instructions are incomplete or produce errors. |
0 commit comments