Permalink
Switch branches/tags
v2.2.0-alpha.00000000 v2.1.0-beta.20181015 v2.1.0-beta.20181008 v2.1.0-beta.20181001 v2.1.0-beta.20180924 v2.1.0-beta.20180917 v2.1.0-beta.20180910 v2.1.0-beta.20180904 v2.1.0-beta.20180827 v2.1.0-alpha.20180730 v2.1.0-alpha.20180702 v2.1.0-alpha.20180604 v2.1.0-alpha.20180507 v2.1.0-alpha.20180416 v2.1.0-alpha.00000000 v2.0.6 v2.0.6-rc.1 v2.0.5 v2.0.4 v2.0.3 v2.0.2 v2.0.1 v2.0.0 v2.0-rc.1 v2.0-beta.20180326 v2.0-beta.20180319 v2.0-beta.20180312 v2.0-beta.20180305 v2.0-alpha.20180212 v2.0-alpha.20180129 v2.0-alpha.20180122 v2.0-alpha.20180116 v2.0-alpha.20171218 v2.0-alpha.20171218-plus-left-join-fix v1.2-alpha.20171211 v1.2-alpha.20171204 v1.2-alpha.20171113 v1.2-alpha.20171026 v1.2-alpha.20170901 v1.1.9 v1.1.9-rc.1 v1.1.8 v1.1.7 v1.1.6 v1.1.5 v1.1.4 v1.1.3 v1.1.2 v1.1.1 v1.1.0 v1.1.0-rc.1 v1.1-beta.20170928 v1.1-beta.20170921 v1.1-beta.20170907 v1.1-alpha.20170817 v1.1-alpha.20170810 v1.1-alpha.20170803 v1.1-alpha.20170720 v1.1-alpha.20170713 v1.1-alpha.20170629 v1.1-alpha.20170622 v1.1-alpha.20170608 v1.1-alpha.20170601 v1.0.7 v1.0.6 v1.0.5 v1.0.4 v1.0.3 v1.0.2 v1.0.1 v1.0 v1.0-rc.3 v1.0-rc.2 v1.0-rc.1 v0.1-alpha beta-20170420 beta-20170413 beta-20170406 beta-20170330 beta-20170323 beta-20170309 beta-20170223 beta-20170216 beta-20170209 beta-20170126 beta-20170112 beta-20170105 beta-20161215 beta-20161208 beta-20161201 beta-20161110 beta-20161103 beta-20161027 beta-20161013 beta-20161006 beta-20160929 beta-20160915 beta-20160908 beta-20160829 beta-20160728
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
164 lines (126 sloc) 7.11 KB

Contributing to Cockroach

Getting and Building

  1. Install the following prerequisites, as necessary:
  • A C++ compiler that supports C++11. Note that GCC prior to 6.0 doesn't work due to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=48891
  • A Go environment with a recent 64-bit version of the toolchain. Note that the Makefile enforces the specific version required, as it is updated frequently.
  • Git 1.8+
  • Bash

Note that at least 4GB of RAM is required to build from source and run tests.

  1. Get the CockroachDB code:

    go get -d github.com/cockroachdb/cockroach
    cd $GOPATH/src/github.com/cockroachdb/cockroach
  2. Run make build, make test, or anything else our Makefile offers. Note that the first time you run make, it can take some time to download and install various dependencies. After running make build, the cockroach executable will be in your current directory and can be run as shown in the README.

Other Considerations

  • The default binary contains core open-source functionally covered by the Apache License 2 (APL2) and enterprise functionality covered by the CockroachDB Community License (CCL). To build a pure open-source (APL2) version excluding enterprise functionality, use make buildoss. See this blog post for more details.

  • 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 ./pkg/....

  • We advise to run go generate using our embedded Docker setup. build/builder.sh is a wrapper script designed to make this convenient. You can run build/builder.sh go generate ./pkg/... from the repository root to get the intended result.

  • If you plan on working on the UI, check out the UI README.

  • To add or update a Go dependency:

    • See build/README.md for details on adding or updating dependencies.
    • Run go generate ./pkg/... to update generated files.
    • Create a PR with all the changes.

Style Guide

Style Guide

Code Review Workflow

  • All contributors need to sign the Contributor License Agreement.

  • Create a local feature branch to do work on, ideally on one thing at a time. If you are working on your own fork, see this tip on forking in Go, which ensures that Go import paths will be correct.

    git checkout -b update-readme

  • 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:

    make test
    # Run all tests in ./pkg/storage
    make test PKG=./pkg/storage
    # Run all kv tests matching '^TestFoo' with a timeout of 10s
    make test PKG=./pkg/kv TESTS='^TestFoo' TESTTIMEOUT=10s
    # Run the sql logic tests
    make test PKG=./pkg/sql TESTS='TestLogic$$'
    # Run a specific sql logic subtest
    make test PKG=./pkg/sql TESTS='TestLogic$$/select$$'

    Logs are disabled during tests by default. To enable them, include TESTFLAGS="-v -show-logs" as an argument the test command:

    make test ... TESTFLAGS="-v -show-logs"

    When you're ready to commit, be sure to write a Good Commit Message™. Consult https://github.com/erlang/otp/wiki/Writing-good-commit-messages if you're not sure what constitutes a Good Commit Message™. In addition to the general rules referenced above, please also prefix your commit subject line with the affected package, if one can easily be chosen. For example, the subject line of a commit mostly affecting the server/serverpb package might read: "server/serverpb: made great again". Commits which affect many packages as a result of a shared dependency change should probably begin their subjects with the name of the shared dependency. Finally, some commits may need to affect many packages in a way which does not point to a specific package; those commits may begin with "*:" or "all:" to indicate their reach.

  • Run the test suite locally:

    go generate ./pkg/... && make check test testrace

  • 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:

    git push -u <yourfork> update-readme

  • Then create a pull request using GitHub’s UI. If you know of another GitHub user particularly suited to reviewing your pull request, be sure to mention them in the pull request body. If you possess the necessary GitHub privileges, please also assign them to the pull request using GitHub's UI. This will help focus and expedite the code review process.

  • 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.)

  • Address feedback by amending your commits. If your change contains multiple commits, address each piece of feedback by amending that commit to which the particular feedback is aimed. 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.

Debugging

Peeking into a running cluster can be done in several ways:

  • the net/trace endpoint at /debug/requests. 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).
  • pprof gives us (among other things) heap and cpu profiles; this golang blog post explains it extremely well and this one by Dmitry Vuykov goes into even more detail.

An easy way to locally run a workload against a cluster are the acceptance tests. For example,

make acceptance TESTS='TestPut$$' TESTFLAGS='-v -d 1200s -l .' TESTTIMEOUT=1210s

runs the Put acceptance test for 20 minutes with logging (useful to look at the stack trace 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.