Permalink
cockroach/CONTRIBUTING.md
Newer
100644
111 lines (80 sloc)
6.31 KB
6
* A working C++ compiler (on mac os x something like `xcode-select
7
--install` will get you started). The compiler must support C++11
8
(GCC 4.9+ and clang 3.6+ are known to work).
9
* [Go environment](http://golang.org/doc/code.html). Currently a
10
64-bit version of go 1.5 is required.
11
* Git 1.8+ and Mercurial (for retrieving dependencies).
12
13
If you're on Mac OS X, [homebrew](http://brew.sh/) can be very helpful to fulfill these dependencies.
14
15
You can `go get -d github.com/cockroachdb/cockroach` or, alternatively,
18
mkdir -p $GOPATH/src/github.com/cockroachdb/
19
cd $GOPATH/src/github.com/cockroachdb/
20
git clone git@github.com:cockroachdb/cockroach.git
21
cd cockroach
24
Now you should be all set for `make build`, `make test` and everything else our Makefile has to
25
offer. Note that the first time you run `make` various dependent libraries and tools will be
26
downloaded and installed which can be somewhat time consuming. Be patient.
28
Note that if you edit a `.proto` or `.ts` file, you will need to manually regenerate the associated `.pb.{go,cc,h}` or `.js` files using `go generate ./...`.
29
`go generate` requires a collection of node modules which are installed via npm. If you don't have npm, it typically comes with node. To get it via homebrew:
31
If you're not using homebrew, make sure you install both [node.js](https://nodejs.org/) and [npm](https://www.npmjs.com/).
32
If you plan on working on the UI, check out [the ui readme](ui).
35
- `(cd $GOPATH/src && go get -u ./...)` to update the dependencies or `go get {package}` to add a dependency
36
- `glock save github.com/cockroachdb/cockroach` to update the GLOCKFILE
41
We're following the [Google Go Code Review](https://code.google.com/p/go-wiki/wiki/CodeReviewComments) fairly closely. In particular, you want to watch out for proper punctuation and capitalization in comments. We use two-space indents in non-Go code (in Go, we follow `gofmt` which indents with tabs). Format your code assuming it will be read in a window 100 columns wide. Wrap code and comments at 100 characters unless doing so makes the code less legible.
46
[Contributor License Agreement](https://cla-assistant.io/cockroachdb/cockroach).
48
+ Create a local feature branch to do work on, ideally on one thing at a time.
50
[this tip](http://blog.campoy.cat/2014/03/github-and-go-forking-pull-requests-and.html)
51
on forking in Go, which ensures that Go import paths will be correct.
55
+ Hack away and commit your changes locally using `git add` and `git commit`. Remember to write tests! The following are helpful for running specific subsets of tests:
56
```
57
make test
58
# Run all tests in ./storage
59
make test PKG=./storage
60
# Run all kv tests matching `^TestFoo` with a timeout of 10s
61
make test PKG=./kv TESTS='^TestFoo' TESTTIMEOUT=10s
62
```
64
When you're ready to commit, do just that with a succinct title and informative
65
message. For example,
67
```bash
68
$ git commit
69
> 'update CONTRIBUTING.md
70
>
71
> Added details on running specific tests via `make`, and
72
> the CircleCI-equivalent test suite.
73
>
74
> Fixed some formatting.'
75
```
77
+ Run the whole CI test suite locally: `./build/circle-local.sh`. This requires the Docker setup; if you don't have/want that, `go generate ./... && make check test testrace` is a good first approximation.
79
+ When you’re ready for review, groom your work: each commit should pass tests and contain a substantial (but not overwhelming) unit of work. You may also want to `git fetch origin` and run `git rebase -i --exec "make check test" origin/master` to make sure you're submitting your changes on top of the newest version of our code. Next, push to your fork:
83
+ Then [create a pull request using GitHub’s UI](https://help.github.com/articles/creating-a-pull-request).
85
+ If you get a test failure in CircleCI, check the Test Failure tab to see why the test failed. When the failure is logged in `excerpt.txt`, you can find the file from the Artifacts tab and see log messages. (You need to sign in to see the Artifacts tab.)
87
+ Address feedback in new commits. Wait (or ask) for new feedback on those commits if they are not straightforward. An `LGTM` ("looks good to me") by someone qualified is usually posted when you're free to go ahead and merge. Most new contributors aren't allowed to merge themselves; in that case, we'll do it for you. You may also be asked to re-groom your commits.
89
90
### Debugging
91
92
Peeking into a running cluster can be done in several ways:
93
94
* the [net/trace](https://godoc.org/golang.org/x/net/trace) endpoint at `/debug/requests`.
95
It has a breakdown of the recent traced requests, in particularly slow ones. Two families are traced: `node` and `coord`, the former (and likely more interesting one) containing what happens inside of `Node`/`Store`/`Replica` and the other inside of the coordinator (`TxnCoordSender`).
96
* [pprof](https://golang.org/pkg/net/http/pprof/) gives us (among other things) heap and cpu profiles; [this golang blog post](http://blog.golang.org/profiling-go-programs) explains it extremely well and [this one by Dmitry Vuykov](https://software.intel.com/en-us/blogs/2014/05/10/debugging-performance-issues-in-go-programs) goes into even more detail. Two caveats: the `cockroach` binary passed to `pprof` must be the same as the one creating the profile (not true on OSX in acceptance tests!), and the HTTP client used by `pprof` doesn't simply swallow self-signed certs (relevant when using SSL). For the latter, a workaround of the form
97
98
```
99
go tool pprof cockroach <(curl -k https://$(hostname):26257/debug/pprof/profile)
100
```
101
will do the trick.
102
103
An easy way to locally run a workload against a cluster are the acceptance tests.
104
For example,
105
106
```bash
107
make acceptance TESTS='TestPut$$' TESTFLAGS='-v -d 1200s -l .' TESTTIMEOUT=1210s
108
```
109
110
runs the `Put` acceptance test for 20 minutes with logging (useful to look at the stacktrace in case of a node dying). When it starts, all the relevant commands for `pprof`, `trace` and logs are logged to allow for convenient inspection of the cluster.