Page tree
Skip to end of metadata
Go to start of metadata

What is Gerrit?

The Impala project uses Gerrit for all our code reviews. Gerrit is a git-based code review tool. The Impala project Gerrit server is here.

Logging in

To authenticate with Impala's Gerrit server, you'll need a Github account. Once you have one, logging in to Gerrit is as easy as clicking 'Github Sign-in' in the top-right corner.

You will need to authorize Gerrit to access some details of your Github account, and then you should be brought back to the Gerrit homepage. Unfortunately, there's a bug in the Gerrit OAuth plugin that will send you to a page that gives a 404 error. You'll need to manually go back to https://gerrit.cloudera.org/, and at that point you should be signed in as 'Anonymous Coward (X)'.

If your Gerrit username is different than your username on the system you want to send patches from, set your "GERRIT_USER" environment variable to your Gerrit username.

Add your public SSH key

Once you are logged in, click your user name in the top-right corner, and go to 'Settings'. Under 'SSH Public Keys' you'll need to paste in your public key:

cat ~/.ssh/id_\{r or d\}sa.pub

While you're in the settings page, please make sure to update your profile with your name, and your e-mail address!

Configuring Gerrit as a Git remote

Gerrit works by keeping a Git repository for all the projects it maintains, including Impala. The source of truth for what is in Impala is the official Apache git server. Gerrit serves as a staging ground for reviewing patches, and once a patch is approved, a sort of waiting room while patches wait for a committer to officially move them to the Apache git repo.

Sending a patch to Gerrit is exactly the same as 'pushing' a sequence of commits to a remote Git repository:

git push --no-thin asf-gerrit HEAD:refs/for/master

To set up Gerrit as a git remote for your Impala repository, do the following:

cd ${IMPALA_HOME}
git remote add asf-gerrit ssh://<your-github-username>@gerrit.cloudera.org:29418/Impala-ASF

Sending a patch for review

Install the Gerrit pre-commit hook

Gerrit keeps track of different patches by generating a unique Change-Id that is constant over all iterations of a patch (obviously the Git hash won't do, since that changes every time the patch changes). That Change-Id is appended to every commit message:

IMPALA-1726: Move JNI / Thrift utilities to separate header

To avoid pulling in jni.h in the codegen module (where it does not
compile), this patch moves the methods that depend on both Thrift and
JNI to a separate header where it can be included more precisely.

Change-Id: I4d97f1816b24149d9163dce59f31b2afe2642b11

Gerrit provides a "pre-commit hook" that automates Change-Id generation. Installing it is very easy:

cd ${IMPALA_HOME}
curl -o .git/hooks/commit-msg https://gerrit.cloudera.org/tools/hooks/commit-msg
chmod u+x .git/hooks/commit-msg

After the hook is installed, every commit you make will get its own Change-Id. Without it, Gerrit will reject all patches.

Rebase Your Branch

Commit all outstanding changes:

Rebase against asf-gerrit/master (good practice to catch conflicts introduced by recent commits)

You might have to resolve merge conflicts during 'git rebase'. Follow the instructions, then continue with

Squash everything down to a single commit:

Make sure to pick only the first commit and 's' (squash) following lines, then edit the commit message into something coherent. Run the git log command to see that you're exactly one commit ahead of asf-gerrit/master

Tip

I have these helpers in my .bashrc to simplify branching from the latest trunk (branch-trunk my_new_branch) and rebase against the latest trunk (rebase-trunk).

Do not push directly to asf-gerrit/master, or any other branch. This will bypass the code-review process.

Sending a patch for review

To send a patch for review, you should push it to a Gerrit-specific 'branch' on the Gerrit remote. That branch has the form refs/for/<branch-name>. For the vast majority of patches the target branch will be master, which is where all mainline development happens. During releases, release managers may push commits to a specific release branch, however most new development will happen on master.

One thing to note is that Gerrit will send all patches between the HEAD of the target branch and your current branch's HEAD for review. So:

git push --no-thin asf-gerrit HEAD:refs/for/master

... will push all commits between asf-gerrit/master and your HEAD. Please therefore make certain that you are only pushing the commits you want reviewed: every separate commit translates to an e-mail in everyone's inbox!

Testing your configuration

If you want to check that you set up gerrit correctly, you can

This will push a patch that only you can see. When you see it has worked, you can click "Abandon" on it in the web interface.

Verifying and submitting a patch (Impala committers only)

Once a change has a +2 from a committer and no -1 from any committer, it is ready to be verified and merged to gerrit. Remember that the source of truth for what is in Impala is the official Apache git server. Gerrit serves as a staging ground for reviewing patches, and once a patch is approved, a sort of waiting room while patches wait for a committer to officially move them to the Apache git repo.

To verify a patch, we use one of two different automated processes. Both are restricted to use by committers. If you are not a committer and your patch has been +2ed, please ask a committer to run the verification for you.

First, log in to http://jenkins.impala.io:8080. If you are a committer and forgot your password, ask dev@impala.apache.org for help. Someone will reset your password.

Then, if your commit changes only files in the docs/ folder:

  1. Go to http://jenkins.impala.io:8080/job/gerrit-docs-submit/build?delay=0sec. Put your gerrit patch URL in the PATCH_URL field. Leave the other fields with their default values. Press "Build".
  2. If all goes well, you will see messages like "Build started: http://jenkins.impala.io:8080/job/gerrit-docs-submit/4/" and "Verified+1" and "Change has been successfully cherry-picked as 84ee40428dbb18146760adec8c5a03559f527ddb by Impala Public Jenkins" on your patch.
  3. If something breaks, go to the URL Jenkins posted to your patch. It will look something like this: http://jenkins.impala.io:8080/job/gerrit-docs-submit/10/. Click on the "Build Artifact" and "Console Output" to look at the logs and figure out what went wrong.

If your commit doesn't change any files in the docs/ folder: 

  1. Go to http://jenkins.impala.io:8080/job/gerrit-verify-dryrun/build?delay=0sec. Put your gerrit patch URL in the PATCH_URL field. Leave the other fields with their default values. Press "Build".
  2. If all goes well, you will see messages like "Build started: http://jenkins.impala.io:8080/job/gerrit-verify-dryrun/151/" and "Verified+1" and "Change has been successfully cherry-picked as 84ee40428dbb18146760adec8c5a03559f527ddb by Impala Public Jenkins" on your patch.
  3. If something breaks, go to the URL Jenkins posted to your patch. It will look something like this: http://jenkins.impala.io:8080/view/Gerrit/job/gerrit-verify-dryrun/141/. Click on the "Build Artifact" and "Console Output" to look at the logs and figure out what went wrong.

If your commit touches files both in and out of the docs/ folder, run http://jenkins.impala.io:8080/job/gerrit-verify-dryrun/build?delay=0sec first, following the directions above. Once it succeeds, run http://jenkins.impala.io:8080/job/gerrit-docs-submit/build?delay=0sec.

 

Verifying and cherry-picking a patch can be simplified with a bookmarklet. Here is how to do that in Chrome:

  1. Go to any webpage you like, say http://example.com.

  2. Press control-d.

  3. In the Folder drop down, select "Bookmarks Bar".

  4. If your bookmarks bar is not visible, press control-shift-b.

  5. If your new bookmark is not visible, click on the ">>" on the right-hand side of the bookmarks bar, then drag it to the visible part of the bar.

  6. Right-click on it and select "Edit".

  7. Change the name to "Jenkins code pre-commit" and the URL to javascript:location.href='http://jenkins.impala.io:8080/job/gerrit-verify-dryrun/parambuild/?PATCH_URL='+encodeURIComponent(document.location.href);

  8. When you are ready to have Jenkins +Verify and cherry-pick a patch, go to the patch, ala https://gerrit.cloudera.org/#/c/5664/, then click your bookmarklet.

  9. Press Build.

By changing the javascript URL, you can also make a bookmarklet for the docs Jenkins job.

When Jenkins has completed successfully, your change is in the master gerrit repo, but not yet in the official Apache repo. Apache does not allow non-sentient robots like Jenkins to submit patches. To get your patch to the official Apache repo, a committer needs to push the commit to the Apache git repository, by running:

 

push_to_asf.py checks the latest commits in gerrit and checks if they are in the Apache git repo. If some are not in the Apache git repo yet, it will ask you if you want to update the Apache git repo with the missing commits found in the Gerrit repo. It does not check what your local state is at all. It only compares remote Gerrit with the remote Apache repo. Keep in mind that if you are a committer, it will allow you to commit any change authored by anyone that has passed the Jenkins cherry-picking described above.

Creating a branch (Impala committers only) 

According to project bylaws, branch creation is by lazy consensus of the PMC. We recommend that you email the dev mailing list to let people know about your branch so they understand its purpose.

The steps to create a branch are:

  1. Create the branch in gerrit: https://gerrit.cloudera.org/#/admin/projects/Impala-ASF,branches . You need to enter the branch name and the commit you want the branch to be based on (e.g. master if you're branching from master).
  2. Fetch the branch from gerrit and push it to the ASF Impala repository

Once the branch is created in both gerrit and the ASF repository, all commits should go to gerrit first, then be pushed to the ASF repository with push_to_asf.py.

Git and Gerrit etiquette

Contribution guidelines

Before you send a patch, please make sure that you've read the contribution guidelines.

Squash your commits

As described above, Gerrit generates one review request per new commit. It's much easier to review everything related to a patch together in one single commit, so please make sure to squash all your related commits together before sending. If you don't, your review requests will probably get forcibly removed

Other Useful Tools and Information

Searching for all Impala reviews

You might want to bookmark this link, which shows all open reviews for Impala.

git-review (Python Gerrit helper module)

git-review is a Python module that can simplify publishing gerrit reviews. To install it use:

By default, git-review will look for a remote named 'gerrit'. The usage is:

git-review can be used to apply changes from a review locally and compare patch sets. For a full set of options see: https://pypi.python.org/pypi/git-review

Gerrit documentation

The documentation for Gerrit is here:

http://gerrit.cloudera.org/Documentation/index.html

  • No labels