Permalink
Newer
Older
100644 210 lines (164 sloc) 8.13 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
## Getting and Building
18
1. Install the following prerequisites, as necessary:
19
20
- Either a working Docker install able to run GNU/Linux binaries
21
(e.g. Docker on Linux, macOS, Windows), so you can reuse our
22
pre-populated Docker image with all necessary development
23
dependencies; or
24
25
- The tools needed to build CockroachDB from scratch:
26
27
- A C++ compiler that supports C++11. Note that GCC prior to 6.0 doesn't
28
work due to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=48891
29
- The standard C/C++ development headers on your system.
30
- A Go environment with a recent 64-bit version of the toolchain. Note that
31
the Makefile enforces the specific version required, as it is updated
32
frequently.
33
- Git 1.9+
34
- Bash (4+ is preferred)
35
- GNU Make (3.81+ is known to work)
36
- CMake 3.1+
37
- Autoconf 2.68+
38
- Optional: NodeJS 6.x and Yarn 0.22.0+. Required when compiling protocol
39
buffers.
41
Note that at least 4GB of RAM is required to build from source and run tests.
43
2. Get the CockroachDB code:
46
go get -d github.com/cockroachdb/cockroach
47
cd $GOPATH/src/github.com/cockroachdb/cockroach
48
```
49
50
3. Run `make build`, `make test`, or anything else our Makefile offers.
52
If you wish to reuse our builder image instead of installing all the
53
dependencies manually, prefix the `make` command with
54
`build/builder.sh`; for example `build/builder.sh make build`.
55
56
Note that the first time you run `make`, it can take some time to
57
download and install various dependencies. After running `make build`,
58
the `cockroach` executable will be in your current directory and can
59
be run as shown in the [README](README.md).
61
### Other Considerations
63
- The default binary contains core open-source functionally covered by
64
the Apache License 2 (APL2) and enterprise functionality covered by
65
the CockroachDB Community License (CCL). To build a pure open-source
66
(APL2) version excluding enterprise functionality, use `make
67
buildoss`. See this [blog post] for more details.
68
69
[blog post]: https://www.cockroachlabs.com/blog/how-were-building-a-business-to-last/
71
- If you edit a `.proto` or `.ts` file, you will need to manually
72
regenerate the associated `.pb.{go,cc,h}` or `.js` files using `make
73
generate`.
75
- You can also run `build/builder.sh make generate` from the
76
repository root to get the intended result.
78
- If you plan on working on the UI, check out [the UI README](pkg/ui).
80
- To add or update a Go dependency:
81
- See [`build/README.md`](build/README.md) for details on adding or updating
82
dependencies.
83
- Run `make generate` to update generated files.
84
- Create a PR with all the changes.
88
See our separate [style guide](STYLE.md) document.
90
## Code Review Workflow
92
- All contributors need to sign the [Contributor License
93
Agreement](https://cla-assistant.io/cockroachdb/cockroach).
95
- Create a local feature branch to do work on, ideally on one thing at
96
a time. If you are working on your own fork, see [this
97
tip](http://blog.campoy.cat/2014/03/github-and-go-forking-pull-requests-and.html)
98
on forking in Go, which ensures that Go import paths will be
99
correct.
100
101
```shell
102
git checkout -b update-readme
103
```
104
105
- Hack away and commit your changes locally using `git add` and `git commit`.
106
Remember to write tests! The following are helpful for running specific
107
subsets of tests:
109
```shell
110
make test
111
# Run all tests in ./pkg/storage
112
make test PKG=./pkg/storage
113
# Run all kv tests matching '^TestFoo' with a timeout of 10s
114
make test PKG=./pkg/kv TESTS='^TestFoo' TESTTIMEOUT=10s
115
# Run the sql logic tests
116
make test PKG=./pkg/sql TESTS='TestLogic$$'
117
# or, using a shortcut,
118
make testlogic
119
# Run a specific sql logic subtest
120
make test PKG=./pkg/sql TESTS='TestLogic$$/select$$'
121
# or, using a shortcut,
122
make testlogic FILES=select
123
```
124
125
Logs are disabled during tests by default. To enable them, include
126
`TESTFLAGS="-v -show-logs"` as an argument the test command:
127
128
```shell
129
make test ... TESTFLAGS="-v -show-logs"
130
```
131
132
When you're ready to commit, be sure to write a Good Commit Message™. Consult
133
https://github.com/erlang/otp/wiki/Writing-good-commit-messages if you're
134
not sure what constitutes a Good Commit Message™.
135
In addition to the general rules referenced above, please also prefix your
136
commit subject line with the affected package, if one can easily be chosen.
137
For example, the subject line of a commit mostly affecting the
138
`server/serverpb` package might read: "server/serverpb: made great again".
139
Commits which affect many packages as a result of a shared dependency change
140
should probably begin their subjects with the name of the shared dependency.
141
Finally, some commits may need to affect many packages in a way which does
142
not point to a specific package; those commits may begin with "*:" or "all:"
143
to indicate their reach.
145
- Run the linters, code generators, and unit test suites locally:
148
make pre-push
149
````
150
151
This will take several minutes.
152
153
- When you’re ready for review, groom your work: each commit should pass tests
154
and contain a substantial (but not overwhelming) unit of work. You may also
155
want to `git fetch origin` and run
156
`git rebase -i --exec "make lint test" origin/master` to make sure you're
157
submitting your changes on top of the newest version of our code. Next, push
158
to your fork:
159
160
```shell
161
git push -u <yourfork> update-readme
162
```
Sep 10, 2014
163
164
- Then [create a pull request using GitHub’s
165
UI](https://help.github.com/articles/creating-a-pull-request). If
166
you know of another GitHub user particularly suited to reviewing
167
your pull request, be sure to mention them in the pull request
168
body. If you possess the necessary GitHub privileges, please also
169
[assign them to the pull request using GitHub's
170
UI](https://help.github.com/articles/assigning-issues-and-pull-requests-to-other-github-users/).
171
This will help focus and expedite the code review process.
Sep 10, 2014
172
173
- Address test failures and feedback by amending your commits. If your
174
change contains multiple commits, address each piece of feedback by
175
amending that commit to which the particular feedback is aimed. Wait
176
(or ask) for new feedback on those commits if they are not
177
straightforward. An `LGTM` ("looks good to me") by someone qualified
178
is usually posted when you're free to go ahead and merge. Most new
179
contributors aren't allowed to merge themselves; in that case, we'll
180
do it for you.
Oct 28, 2015
181
Oct 28, 2015
183
184
Peeking into a running cluster can be done in several ways:
185
186
- the [net/trace](https://godoc.org/golang.org/x/net/trace) endpoint
187
at `/debug/requests`. It has a breakdown of the recent traced
188
requests, in particularly slow ones. Two families are traced: `node`
189
and `coord`, the former (and likely more interesting one) containing
190
what happens inside of `Node`/`Store`/`Replica` and the other inside
191
of the coordinator (`TxnCoordSender`).
192
- [pprof](https://golang.org/pkg/net/http/pprof/) gives us (among
193
other things) heap and cpu profiles; [this golang blog
194
post](http://blog.golang.org/profiling-go-programs) explains it
195
extremely well and [this one by Dmitry
196
Vuykov](https://software.intel.com/en-us/blogs/2014/05/10/debugging-performance-issues-in-go-programs)
197
goes into even more detail.
Oct 28, 2015
198
199
An easy way to locally run a workload against a cluster are the acceptance
200
tests. For example,
Oct 28, 2015
201
202
```shell
Oct 28, 2015
203
make acceptance TESTS='TestPut$$' TESTFLAGS='-v -d 1200s -l .' TESTTIMEOUT=1210s
204
```
205
206
runs the `Put` acceptance test for 20 minutes with logging (useful to look at
207
the stack trace in case of a node dying). When it starts, all the relevant
208
commands for `pprof`, `trace` and logs are logged to allow for convenient
209
inspection of the cluster.