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