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