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