|
| 1 | +# Repository Guidelines |
| 2 | + |
| 3 | +## Project Structure & Modules |
| 4 | +- `cmd/server`, `cmd/client`: entrypoints for running the KV server and client. |
| 5 | +- `store/`: MVCC storage engine, OCC/TTL, and related tests. |
| 6 | +- `kv/`: hybrid logical clock (HLC) utilities and KV interfaces. |
| 7 | +- `adapter/`: protocol adapters (e.g., Redis), plus integration tests. |
| 8 | +- `jepsen/`, `jepsen/redis/`: Jepsen test harnesses and workloads. |
| 9 | +- `proto/`, `distribution/`, `internal/`: supporting protobufs, build assets, and shared helpers. |
| 10 | + |
| 11 | +## Build, Test, and Development Commands |
| 12 | +- `go test ./...` — run unit/integration tests. If macOS sandbox blocks `$GOCACHE`, prefer `GOCACHE=$(pwd)/.cache GOTMPDIR=$(pwd)/.cache/tmp go test ./...`. |
| 13 | +- `GOCACHE=$(pwd)/.cache GOLANGCI_LINT_CACHE=$(pwd)/.golangci-cache golangci-lint run ./... --timeout=5m` — full lint suite. |
| 14 | +- `HOME=$(pwd)/jepsen/tmp-home LEIN_HOME=$(pwd)/jepsen/.lein LEIN_JVM_OPTS="-Duser.home=$(pwd)/jepsen/tmp-home" /tmp/lein test` (from `jepsen/` or `jepsen/redis/`) — Jepsen tests. |
| 15 | +- `go run ./cmd/server` / `go run ./cmd/client` — start server or CLI locally. |
| 16 | + |
| 17 | +## Coding Style & Naming |
| 18 | +- Go code: `gofmt` + project lint rules (`golangci-lint`). Avoid adding `//nolint` unless absolutely required; prefer refactoring. |
| 19 | +- Naming: Go conventions (MixedCaps for exported identifiers, short receiver names). Filenames remain lowercase with underscores only where existing. |
| 20 | +- Logging: use `slog` where present; maintain structured keys (`key`, `commit_ts`, etc.). |
| 21 | + |
| 22 | +## Testing Guidelines |
| 23 | +- Unit tests co-located with packages (`*_test.go`); prefer table-driven cases. |
| 24 | +- TTL/HLC behaviors live in `store/` and `kv/`; add coverage when touching clocks, OCC, or replication logic. |
| 25 | +- Integration: run Jepsen suites after changes affecting replication, MVCC, or Redis adapter. |
| 26 | + - `cd jepsen && HOME=$(pwd)/tmp-home LEIN_HOME=$(pwd)/.lein LEIN_JVM_OPTS="-Duser.home=$(pwd)/tmp-home" /tmp/lein test` |
| 27 | + - `cd jepsen/redis && HOME=$(pwd)/../tmp-home LEIN_HOME=$(pwd)/../.lein LEIN_JVM_OPTS="-Duser.home=$(pwd)/../tmp-home" /tmp/lein test` |
| 28 | + |
| 29 | +## Commit & Pull Request Guidelines |
| 30 | +- Messages: short imperative summary (e.g., "Add HLC TTL handling"). Include scope when helpful (`store:`, `adapter:`). |
| 31 | +- Pull requests: describe behavior change, risk, and test evidence (`go test`, lint, Jepsen). Add repro steps for bug fixes. |
| 32 | + |
| 33 | +## Security & Configuration Tips |
| 34 | +- Hybrid clock derives from wall-clock millis; keep system clock reasonably synchronized across nodes. |
| 35 | +- Avoid leader-local timestamps in persistence; timestamp issuance should originate from the Raft leader to prevent skewed OCC decisions. |
0 commit comments