Permalink
Newer
Older
100644 162 lines (127 sloc) 7.01 KB
1
# Contributing to Cockroach
2
3
### Getting and building
4
5
1. Install the following prerequisites, as necessary:
6
- A C++ compiler that supports C++11. Note that GCC prior to 6.0 doesn't
7
work due to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=48891
8
- A Go environment with a recent 64-bit version of the toolchain. Note that
9
the Makefile enforces the specific version required, as it is updated
10
frequently.
16
```bash
17
go get -d github.com/cockroachdb/cockroach
18
cd $GOPATH/src/github.com/cockroachdb/cockroach
19
```
21
3. Run `make build`, `make test`, or anything else our Makefile offers. Note
22
that at least 4GB of RAM is required to build from source and run tests. Also,
23
the first time you run `make`, it can take some time to download and install
24
various dependencies. After running `make build`, the `cockroach` executable
25
will be in your current directory and can be run as shown in the
26
[README](README.md).
28
Note that if you edit a `.proto` or `.ts` file, you will need to manually
29
regenerate the associated `.pb.{go,cc,h}` or `.js` files using `go generate
30
./...`.
32
We advise to run `go generate` using our embedded Docker setup.
33
`build/builder.sh` is a wrapper script designed to make this convenient. You can
34
run `build/builder.sh env SKIP_BOOTSTRAP=0 go generate ./...` from the repository
35
root to get the intended result.
37
If you want to run it outside of Docker, `go generate` requires a collection
38
of Node.js modules which will be automatically installed into the project tree
39
(not globally).
Oct 13, 2016
41
If you plan on working on the UI, check out [the ui readme](pkg/ui).
43
To add or update a go dependency:
45
- see `vendor/README.md` for details on adding or updating dependencies
46
- run `go generate ./pkg/...` to update generated files.
47
- create a PR with all the changes
49
### Style guide
51
[Style Guide](STYLE.md)
Andrew Bonventre
Sep 7, 2014
53
### Code review workflow
55
+ All contributors need to sign the [Contributor License Agreement]
56
(https://cla-assistant.io/cockroachdb/cockroach).
58
+ Create a local feature branch to do work on, ideally on one thing at a time.
59
If you are working on your own fork, see [this tip]
60
(http://blog.campoy.cat/2014/03/github-and-go-forking-pull-requests-and.html)
61
on forking in Go, which ensures that Go import paths will be correct.
63
`git checkout -b update-readme`
64
65
+ Hack away and commit your changes locally using `git add` and `git commit`.
66
Remember to write tests! The following are helpful for running specific
67
subsets of tests:
68
69
```bash
70
make test
71
# Run all tests in ./pkg/storage
72
make test PKG=./pkg/storage
73
# Run all kv tests matching `^TestFoo` with a timeout of 10s
74
make test PKG=./pkg/kv TESTS='^TestFoo' TESTTIMEOUT=10s
75
```
76
77
When you're ready to commit, be sure to write a Good Commit Message™. Consult
78
https://github.com/erlang/otp/wiki/Writing-good-commit-messages if you're
79
not sure what constitutes a Good Commit Message™.
80
In addition to the general rules referenced above, please also prefix your
81
commit subject line with the affected package, if one can easily be chosen.
82
For example, the subject line of a commit mostly affecting the
83
`server/serverpb` package might read: "server/serverpb: made great again".
84
Commits which affect many packages as a result of a shared dependency change
85
should probably begin their subjects with the name of the shared dependency.
86
Finally, some commits may need to affect many packages in a way which does
87
not point to a specific package; those commits may begin with "*:" or "all:"
88
to indicate their reach.
90
+ Run the whole CI test suite locally: `./build/circle-local.sh`. This requires
91
the Docker setup; if you don't have/want that,
92
`go generate ./... && make check test testrace` is a good first approximation.
93
94
+ When you’re ready for review, groom your work: each commit should pass tests
95
and contain a substantial (but not overwhelming) unit of work. You may also
96
want to `git fetch origin` and run
97
`git rebase -i --exec "make check test" origin/master` to make sure you're
98
submitting your changes on top of the newest version of our code. Next, push
100
101
`git push -u <yourfork> update-readme`
Sep 10, 2014
102
103
+ Then [create a pull request using GitHub’s UI]
104
(https://help.github.com/articles/creating-a-pull-request). If you know of
105
another GitHub user particularly suited to reviewing your pull request, be
106
sure to mention them in the pull request body. If you possess the necessary
107
GitHub privileges, please also [assign them to the pull request using
108
GitHub's UI] (https://help.github.com/articles/assigning-issues-and-pull-requests-to-other-github-users/).
109
This will help focus and expedite the code review process.
Sep 10, 2014
110
111
+ If you get a test failure in CircleCI, check the Test Failure tab to see why
112
the test failed. When the failure is logged in `excerpt.txt`, you can find
113
the file from the Artifacts tab and see log messages. (You need to sign in to
114
see the Artifacts tab.)
Sep 10, 2014
115
116
+ Address feedback by amending your commits. If your change contains multiple
117
commits, address each piece of feedback by amending that commit to which the
118
particular feedback is aimed. Wait (or ask) for new feedback on those
119
commits if they are not straightforward. An `LGTM` ("looks good to me") by
120
someone qualified is usually posted when you're free to go ahead and merge.
121
Most new contributors aren't allowed to merge themselves; in that case, we'll
122
do it for you.
Oct 28, 2015
123
124
### Debugging
125
126
Peeking into a running cluster can be done in several ways:
127
128
* the [net/trace](https://godoc.org/golang.org/x/net/trace) endpoint at
129
`/debug/requests`. It has a breakdown of the recent traced requests, in
130
particularly slow ones. Two families are traced: `node` and `coord`, the
131
former (and likely more interesting one) containing what happens inside of
132
`Node`/`Store`/`Replica` and the other inside of the coordinator
133
(`TxnCoordSender`).
134
* [pprof](https://golang.org/pkg/net/http/pprof/) gives us (among other things)
135
heap and cpu profiles; [this golang blog post]
136
(http://blog.golang.org/profiling-go-programs) explains it extremely well and
137
[this one by Dmitry Vuykov]
138
(https://software.intel.com/en-us/blogs/2014/05/10/debugging-performance-issues-in-go-programs)
139
goes into even more detail. Two caveats: the `cockroach` binary passed to
140
`pprof` must be the same as the one creating the profile (not true on OSX in
141
acceptance tests!), and the HTTP client used by `pprof` doesn't simply
142
swallow self-signed certs (relevant when using SSL). For the latter, a
143
workaround of the form
Oct 28, 2015
144
145
```
146
go tool pprof cockroach <(curl -k https://$(hostname):26257/debug/pprof/profile)
147
```
Oct 28, 2015
149
will do the trick.
150
151
An easy way to locally run a workload against a cluster are the acceptance
152
tests. For example,
Oct 28, 2015
153
154
```bash
155
make acceptance TESTS='TestPut$$' TESTFLAGS='-v -d 1200s -l .' TESTTIMEOUT=1210s
156
```
157
158
runs the `Put` acceptance test for 20 minutes with logging (useful to look at
159
the stacktrace in case of a node dying). When it starts, all the relevant
160
commands for `pprof`, `trace` and logs are logged to allow for convenient
161
inspection of the cluster.