16.11. Submitting Patches

If you are new to submitting patches to open source or new to submitting patches to Apache, I'd suggest you start by reading the On Contributing Patches page from Apache Commons Project. Its a nice overview that applies equally to the Apache HBase Project.

16.11.1. Create Patch

See the aforementioned Apache Commons link for how to make patches against a checked out subversion repository. Patch files can also be easily generated from Eclipse, for example by selecting "Team -> Create Patch". Patches can also be created by git diff and svn diff.

Please submit one patch-file per Jira. For example, if multiple files are changed make sure the selected resource when generating the patch is a directory. Patch files can reflect changes in multiple files.

Generating patches using git:

$ git diff --no-prefix  > HBASE_XXXX.patch

Don't forget the 'no-prefix' option; and generate the diff from the root directory of project

Make sure you review Section, “Code Formatting” for code style.

16.11.2. Patch File Naming

The patch file should have the Apache HBase Jira ticket in the name. For example, if a patch was submitted for Foo.java, then a patch file called Foo_HBASE_XXXX.patch would be acceptable where XXXX is the Apache HBase Jira number.

If you generating from a branch, then including the target branch in the filename is advised, e.g., HBASE_XXXX-0.90.patch.

16.11.3. Unit Tests

Yes, please. Please try to include unit tests with every code patch (and especially new classes and large changes). Make sure unit tests pass locally before submitting the patch.

Also, see Section, “Mockito”.

If you are creating a new unit test class, notice how other unit test classes have classification/sizing annotations at the top and a static method on the end. Be sure to include these in any new unit test files you generate. See Section 16.7, “Tests” for more on how the annotations work.

16.11.4. Attach Patch to Jira

The patch should be attached to the associated Jira ticket "More Actions -> Attach Files". Make sure you click the ASF license inclusion, otherwise the patch can't be considered for inclusion.

Once attached to the ticket, click "Submit Patch" and the status of the ticket will change. Committers will review submitted patches for inclusion into the codebase. Please understand that not every patch may get committed, and that feedback will likely be provided on the patch. Fear not, though, because the Apache HBase community is helpful!

16.11.5. Common Patch Feedback

The following items are representative of common patch feedback. Your patch process will go faster if these are taken into account before submission.

See the Java coding standards for more information on coding conventions in Java. Space Invaders

Rather than do this...

if ( foo.equals( bar ) ) {     // don't do this

... do this instead...

if (foo.equals(bar)) {

Also, rather than do this...

foo = barArray[ i ];     // don't do this

... do this instead...

foo = barArray[i]; Auto Generated Code

Auto-generated code in Eclipse often looks like this...

 public void readFields(DataInput arg0) throws IOException {    // don't do this
   foo = arg0.readUTF();                                       // don't do this

... do this instead ...

 public void readFields(DataInput di) throws IOException {
   foo = di.readUTF();

See the difference? 'arg0' is what Eclipse uses for arguments by default. Long Lines

Keep lines less than 100 characters.

Bar bar = foo.veryLongMethodWithManyArguments(argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9);  // don't do this

... do something like this instead ...

Bar bar = foo.veryLongMethodWithManyArguments(
 argument1, argument2, argument3,argument4, argument5, argument6, argument7, argument8, argument9); Trailing Spaces

This happens more than people would imagine.

Bar bar = foo.getBar();     <--- imagine there's an extra space(s) after the semicolon instead of a line break.

Make sure there's a line-break after the end of your code, and also avoid lines that have nothing but whitespace. Implementing Writable

Applies pre-0.96 only

In 0.96, HBase moved to protobufs. The below section on Writables applies to 0.94.x and previous, not to 0.96 and beyond.

Every class returned by RegionServers must implement Writable. If you are creating a new class that needs to implement this interface, don't forget the default constructor. Javadoc

This is also a very common feedback item. Don't forget Javadoc!

Javadoc warnings are checked during precommit. If the precommit tool gives you a '-1', please fix the javadoc issue. Your patch won't be committed if it adds such warnings. Findbugs

Findbugs is used to detect common bugs pattern. As Javadoc, it is checked during the precommit build up on Apache's Jenkins, and as with Javadoc, please fix them. You can run findbugs locally with 'mvn findbugs:findbugs': it will generate the findbugs files locally. Sometimes, you may have to write code smarter than Findbugs. You can annotate your code to tell Findbugs you know what you're doing, by annotating your class with:

                    justification="I know what I'm doing")

Note that we're using the apache licensed version of the annotations. Javadoc - Useless Defaults

Don't just leave the @param arguments the way your IDE generated them. Don't do this...

   * @param bar             <---- don't do this!!!!
   * @return                <---- or this!!!!
  public Foo getFoo(Bar bar);

... either add something descriptive to the @param and @return lines, or just remove them. But the preference is to add something descriptive and useful. One Thing At A Time, Folks

If you submit a patch for one thing, don't do auto-reformatting or unrelated reformatting of code on a completely different area of code.

Likewise, don't add unrelated cleanup or refactorings outside the scope of your Jira. Ambigious Unit Tests

Make sure that you're clear about what you are testing in your unit tests and why.

16.11.6. Submitting a patch again

Sometimes committers ask for changes for a patch. After incorporating the suggested/requested changes, follow the following process to submit the patch again.

  • Do not delete the old patch file
  • version your new patch file using a simple scheme like this:
    HBASE-{jira number}-{version}.patch
    e.g: HBASE_XXXX-v2.patch
  • 'Cancel Patch' on JIRA.. bug status will change back to Open
  • Attach new patch file (e.g. HBASE_XXXX-v2.patch) using 'Files --> Attach'
  • Click on 'Submit Patch'. Now the bug status will say 'Patch Available'.
Committers will review the patch. Rinse and repeat as many times as needed :-)

16.11.7. Submitting incremental patches

At times you may want to break a big change into mulitple patches. Here is a sample work-flow using git

  • patch 1:
    • $ git diff --no-prefix > HBASE_XXXX-1.patch
  • patch 2:
    • create a new git branch
      $ git checkout -b my_branch
    • save your work $ git add file1 file2
      $ git commit -am 'saved after HBASE_XXXX-1.patch'
      now you have your own branch, that is different from remote master branch
    • make more changes...
    • create second patch
      $ git diff --no-prefix > HBASE_XXXX-2.patch

16.11.8. ReviewBoard

Larger patches should go through ReviewBoard.

For more information on how to use ReviewBoard, see the ReviewBoard documentation.

16.11.9. Committing Patches

Committers do this. See How To Commit in the Apache HBase wiki.

Commiters will also resolve the Jira, typically after the patch passes a build. Committers are responsible for making sure commits do not break the build or tests

If a committer commits a patch it is their responsibility to make sure it passes the test suite. It is helpful if contributors keep an eye out that their patch does not break the hbase build and/or tests but ultimately, a contributor cannot be expected to be up on the particular vagaries and interconnections that occur in a project like hbase. A committer should.

comments powered by Disqus