Permalink
Newer
Older
100644 256 lines (200 sloc) 10.2 KB
1
# Contributing to Cockroach
2
3
- [Prerequisites](#prerequisites)
4
- [Getting and Building](#getting-and-building)
5
- [Style Guide](#style-guide)
6
- [Commit Messages](#commit-messages)
7
- [Code Review Workflow](#code-review-workflow)
8
- [Debugging](#debugging)
9
12
Before you start contributing, review these [basic
13
guidelines](https://www.cockroachlabs.com/docs/stable/contribute-to-cockroachdb.html)
14
on finding a project, determining its complexity, and learning what to
15
expect in your collaboration with the Cockroach Labs team.
17
If you *really* want to dig deep into our processes and mindset, you may also
18
want to peruse our extensive [first PR guide], which is part of our on-boarding for
19
new engineers.
20
21
## Getting and Building
23
1. Install the following prerequisites, as necessary:
24
25
- Either a working Docker install able to run GNU/Linux binaries
26
(e.g. Docker on Linux, macOS, Windows), so you can reuse our
27
pre-populated Docker image with all necessary development
28
dependencies; or
29
30
- The tools needed to build CockroachDB from scratch:
31
32
- A C++ compiler that supports C++11. Note that GCC prior to 6.0 doesn't
33
work due to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=48891
34
- The standard C/C++ development headers on your system.
35
- On GNU/Linux, the terminfo development libraries, which may be
36
part of a ncurses development package (e.g. `libtinfo-dev` on
37
Debian/Ubuntu, but `ncurses-devel` on CentOS).
38
- A Go environment with a recent 64-bit version of the toolchain. Note that
39
the Makefile enforces the specific version required, as it is updated
40
frequently.
41
- Git 1.9+
42
- Bash (4+ is preferred)
43
- GNU Make (3.81+ is known to work)
44
- CMake 3.1+
45
- Autoconf 2.68+
46
- NodeJS 6.x and Yarn 1.0+
48
Note that at least 4GB of RAM is required to build from source and run tests.
50
2. Get the CockroachDB code:
53
go get -d github.com/cockroachdb/cockroach
54
cd $(go env GOPATH)/src/github.com/cockroachdb/cockroach
55
```
56
57
3. Run `make build`, `make test`, or anything else our Makefile offers.
59
If you wish to reuse our builder image instead of installing all the
60
dependencies manually, prefix the `make` command with
61
`build/builder.sh`; for example `build/builder.sh make build`.
62
63
Note that the first time you run `make`, it can take some time to
64
download and install various dependencies. After running `make build`,
65
the `cockroach` executable will be in your current directory and can
66
be run as shown in the [README](README.md).
68
### Other Considerations
70
- The default binary contains core open-source functionally covered by
71
the Apache License 2 (APL2) and enterprise functionality covered by
72
the CockroachDB Community License (CCL). To build a pure open-source
73
(APL2) version excluding enterprise functionality, use `make
74
buildoss`. See this [blog post] for more details.
75
76
[blog post]: https://www.cockroachlabs.com/blog/how-were-building-a-business-to-last/
78
- If you edit a `.proto` or `.ts` file, you will need to manually
79
regenerate the associated `.pb.{go,cc,h}` or `.js` files using `make
80
generate`.
82
- If you edit the SQL built-in functions or operators or update the SQL grammar,
83
you will need to manually regenerate the associated `docs/generated` files via
84
`make generate PKG=./docs/...`.
85
86
- You can also run `build/builder.sh make generate` from the
87
repository root to get the intended result.
89
- If you plan on working on the UI, check out [the UI README](pkg/ui).
91
- To add or update a Go dependency:
92
- See [`build/README.md`](build/README.md) for details on adding or updating
93
dependencies.
94
- Run `make generate` to update generated files.
95
- Create a PR with all the changes.
99
See our separate [style guide](docs/style.md) document.
101
## Commit Messages
102
103
When you're ready to commit, be sure to write a Good Commit Message™. Consult
104
https://github.com/erlang/otp/wiki/Writing-good-commit-messages if you're
105
not sure what constitutes a Good Commit Message™.
106
In addition to the general rules referenced above, please also observe the
107
following guidelines:
108
109
- Prefix your commit subject line with the affected package, if one can easily
110
be chosen. For example, the subject line of a commit mostly affecting the
111
`server` package might read: "server: use net.Pipe instead of TCP HTTP/gRPC connections".
112
Commits which affect many packages as a result of a shared dependency change
113
should probably begin their subjects with the name of the shared dependency.
114
Finally, some commits may need to affect many packages in a way which does
115
not point to a specific package; those commits may begin with "\*:" or "all:"
116
to indicate their reach.
117
118
- We publish detailed [release notes](https://www.cockroachlabs.com/docs/releases/)
119
describing most non-test changes. To facilitate this, in every PR, at least one commit
120
should contain a brief description of the change in terms that a user would recognize.
121
Be sure to put these descriptions in commits and not in PR descriptions.
122
123
Each release note description should be prefixed with "Release note (category):",
124
where the "category" is one of the following:
125
- cli change
126
- sql change
128
- performance improvement
129
- bug fix
130
- general change (e.g., change of required Go version)
131
- build change (e.g., compatibility with older CPUs)
132
- enterprise change (e.g., change to backup/restore)
133
- backwards-incompatible change
134
135
This list is also documented in the commit message template, which lives in
136
githooks/prepare-commit-msg.
137
138
For example, a commit like ["distsql: pre-reserve memory needed
139
to mark rows in HashJoiner build phase"](https://github.com/cockroachdb/cockroach/pull/18975)
140
might say, "Release note (bug fix): Fixed a panic in queries with `JOIN` using the
141
distributed SQL engine."
142
143
When a commit falls into more than one category, choose the category that matches best
144
or is most affected from a user's perspective.
145
146
## Code Review Workflow
147
148
- All contributors need to sign the [Contributor License
149
Agreement](https://cla-assistant.io/cockroachdb/cockroach).
151
- Create a local feature branch to do work on, ideally on one thing at
152
a time. If you are working on your own fork, see [this
153
tip](http://blog.campoy.cat/2014/03/github-and-go-forking-pull-requests-and.html)
154
on forking in Go, which ensures that Go import paths will be
155
correct.
156
157
```shell
158
git checkout -b update-readme
159
```
160
161
- Hack away and commit your changes locally using `git add` and `git commit`.
162
Remember to write tests! The following are helpful for running specific
163
subsets of tests:
165
```shell
166
make test
167
# Run all tests in ./pkg/storage
168
make test PKG=./pkg/storage
169
# Run all kv tests matching '^TestFoo' with a timeout of 10s
170
make test PKG=./pkg/kv TESTS='^TestFoo' TESTTIMEOUT=10s
171
# Run the sql logic tests
172
make test PKG=./pkg/sql TESTS='TestLogic$$'
173
# or, using a shortcut,
174
make testlogic
175
# Run a specific sql logic subtest
176
make test PKG=./pkg/sql TESTS='TestLogic$$/select$$'
177
# or, using a shortcut,
178
make testlogic FILES=select
179
```
180
181
Logs are disabled during tests by default. To enable them, include
182
`TESTFLAGS="-v -show-logs"` as an argument the test command:
183
184
```shell
185
make test ... TESTFLAGS="-v -show-logs"
186
```
187
188
- Run the linters, code generators, and unit test suites locally:
191
make pre-push
192
````
193
194
This will take several minutes.
195
196
- When you’re ready for review, groom your work: each commit should pass tests
197
and contain a substantial (but not overwhelming) unit of work. You may also
198
want to `git fetch origin` and run
199
`git rebase -i --exec "make lint test" origin/master` to make sure you're
200
submitting your changes on top of the newest version of our code. Next, push
201
to your fork:
202
203
```shell
204
git push -u <yourfork> update-readme
205
```
Sep 10, 2014
206
207
- Then [create a pull request using GitHub’s
208
UI](https://help.github.com/articles/creating-a-pull-request). If
209
you know of another GitHub user particularly suited to reviewing
210
your pull request, be sure to mention them in the pull request
211
body. If you possess the necessary GitHub privileges, please also
212
[assign them to the pull request using GitHub's
213
UI](https://help.github.com/articles/assigning-issues-and-pull-requests-to-other-github-users/).
214
This will help focus and expedite the code review process.
Sep 10, 2014
215
216
- Address test failures and feedback by amending your commits. If your
217
change contains multiple commits, address each piece of feedback by
218
amending that commit to which the particular feedback is aimed. Wait
219
(or ask) for new feedback on those commits if they are not
220
straightforward. An `LGTM` ("looks good to me") by someone qualified
221
is usually posted when you're free to go ahead and merge. Most new
222
contributors aren't allowed to merge themselves; in that case, we'll
223
do it for you.
Oct 28, 2015
224
Oct 28, 2015
226
227
Peeking into a running cluster can be done in several ways:
228
229
- the [net/trace](https://godoc.org/golang.org/x/net/trace) endpoint
230
at `/debug/requests`. It has a breakdown of the recent traced
231
requests, in particularly slow ones. Two families are traced: `node`
232
and `coord`, the former (and likely more interesting one) containing
233
what happens inside of `Node`/`Store`/`Replica` and the other inside
234
of the coordinator (`TxnCoordSender`).
235
- [pprof](https://golang.org/pkg/net/http/pprof/) gives us (among
236
other things) heap and cpu profiles; [this wiki page](https://github.com/cockroachdb/cockroach/wiki/pprof)
237
gives an overview and walks you through using it to profile Cockroach.
238
[This golang blog post](http://blog.golang.org/profiling-go-programs)
239
explains it extremely well and [this one by Dmitry
240
Vuykov](https://software.intel.com/en-us/blogs/2014/05/10/debugging-performance-issues-in-go-programs)
241
goes into even more detail.
Oct 28, 2015
242
243
An easy way to locally run a workload against a cluster are the acceptance
244
tests. For example,
Oct 28, 2015
245
246
```shell
Oct 28, 2015
247
make acceptance TESTS='TestPut$$' TESTFLAGS='-v -d 1200s -l .' TESTTIMEOUT=1210s
248
```
249
250
runs the `Put` acceptance test for 20 minutes with logging (useful to look at
251
the stack trace in case of a node dying). When it starts, all the relevant
252
commands for `pprof`, `trace` and logs are logged to allow for convenient
253
inspection of the cluster.
254
255
[first PR guide]: docs/first-pr.md