結構、仕事でがっつりHBaseを作ってるのに、今まであまりHBaseに貢献できてなかったので、そろそろ真面目にやろうかと思い、とりあえずHBaseのビルド環境を作ってみたのでそのメモ。環境はMacOSX。
HBaseのプロジェクトをgit cloneする
HBaseのプロジェクトはGitHubにあるので、git cloneしてくる。
$ git clone git@github.com:apache/hbase.git
そこそこ、時間かかる。
コンパイルしてみる
hbaseのディレクトリに移動して、mvnコマンドでコンパイルできる。
$ mvn compile -DskipTests
ただし、普通にコンパイルしたら、以下のエラーが出た。
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] HBase .............................................. SUCCESS [ 1.645 s]
[INFO] HBase - Checkstyle ................................. SUCCESS [ 0.252 s]
[INFO] HBase - Annotations ................................ SUCCESS [ 0.049 s]
[INFO] HBase - Common ..................................... FAILURE [ 3.866 s]
[INFO] HBase - Protocol ................................... SKIPPED
[INFO] HBase - Client ..................................... SKIPPED
[INFO] HBase - Hadoop Compatibility ....................... SKIPPED
[INFO] HBase - Hadoop Two Compatibility ................... SKIPPED
[INFO] HBase - Prefix Tree ................................ SKIPPED
[INFO] HBase - Server ..................................... SKIPPED
[INFO] HBase - Testing Util ............................... SKIPPED
[INFO] HBase - Thrift ..................................... SKIPPED
[INFO] HBase - Shell ...................................... SKIPPED
[INFO] HBase - Integration Tests .......................... SKIPPED
[INFO] HBase - Examples ................................... SKIPPED
[INFO] HBase - Rest ....................................... SKIPPED
[INFO] HBase - Assembly ................................... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.310 s
[INFO] Finished at: 2014-11-18T23:53:47+09:00
[INFO] Final Memory: 41M/174M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.2:compile (default-compile) on project hbase-common: Fatal error compiling: com.sun.tools.javac.main.Main$Result cannot be cast to java.lang.Integer -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR] mvn <goals> -rf :hbase-common
どうやら、jdk1.8に対応してないようなので、以下を参考にしてjdk1.7に下げたらコンパイルできた。
MacでJDKのバージョンを切り替える
http://qiita.com/mas0061/items/2fe9333f045800d00b5c
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] HBase .............................................. SUCCESS [ 2.003 s]
[INFO] HBase - Checkstyle ................................. SUCCESS [ 0.456 s]
[INFO] HBase - Annotations ................................ SUCCESS [ 0.291 s]
[INFO] HBase - Common ..................................... SUCCESS [ 4.381 s]
[INFO] HBase - Protocol ................................... SUCCESS [ 11.187 s]
[INFO] HBase - Client ..................................... SUCCESS [ 7.315 s]
[INFO] HBase - Hadoop Compatibility ....................... SUCCESS [ 0.444 s]
[INFO] HBase - Hadoop Two Compatibility ................... SUCCESS [ 1.218 s]
[INFO] HBase - Prefix Tree ................................ SUCCESS [ 1.210 s]
[INFO] HBase - Server ..................................... SUCCESS [ 12.370 s]
[INFO] HBase - Testing Util ............................... SUCCESS [ 1.927 s]
[INFO] HBase - Thrift ..................................... SUCCESS [ 5.335 s]
[INFO] HBase - Shell ...................................... SUCCESS [ 0.762 s]
[INFO] HBase - Integration Tests .......................... SUCCESS [ 0.697 s]
[INFO] HBase - Examples ................................... SUCCESS [ 1.238 s]
[INFO] HBase - Rest ....................................... SUCCESS [ 2.871 s]
[INFO] HBase - Assembly ................................... SUCCESS [ 0.716 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 55.170 s
[INFO] Finished at: 2014-11-18T23:57:20+09:00
[INFO] Final Memory: 84M/526M
[INFO] ------------------------------------------------------------------------
テストを動かしてみる
次に、テストを動かしてみる。
$ mvn test
普通に実行するとかなり時間がかかるので、以下のようにスキップしたりできる。
$ mvn test -PskipServerTests -PskipCommonTests
また、HBaseのテストは、Smallとか、Mediumとか、Largeとかでカテゴライズされているようで、以下のようにすることで、そのカテゴリのテストのみ実行することができる。
- Small Tests
$ mvn test -P runSmallTests
- Medium Tests
$ mvn test -P runMediumTests
- Large Tests
$ mvn test -P runLargeTests
そこら辺の詳細は、以下に書いてある。
ただ、テストが何故かコケる、、
Tests run: 2, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 25.445 sec <<< FAILURE! - in org.apache.hadoop.hbase.zookeeper.TestZooKeeperMainServer
testCommandLineWorks(org.apache.hadoop.hbase.zookeeper.TestZooKeeperMainServer) Time elapsed: 24.924 sec <<< ERROR!
org.apache.zookeeper.KeeperException$ConnectionLossException: KeeperErrorCode = ConnectionLoss for /testCommandLineWorks
at org.apache.zookeeper.KeeperException.create(KeeperException.java:99)
at org.apache.zookeeper.KeeperException.create(KeeperException.java:51)
at org.apache.zookeeper.ZooKeeper.delete(ZooKeeper.java:873)
at org.apache.zookeeper.ZooKeeperMain.processZKCmd(ZooKeeperMain.java:700)
at org.apache.zookeeper.ZooKeeperMain.processCmd(ZooKeeperMain.java:588)
at org.apache.hadoop.hbase.zookeeper.ZooKeeperMainServer$HACK_UNTIL_ZOOKEEPER_1897_ZooKeeperMain.runCmdLine(ZooKeeperMainServer.java:60)
at org.apache.hadoop.hbase.zookeeper.ZooKeeperMainServer.main(ZooKeeperMainServer.java:106)
at org.apache.hadoop.hbase.zookeeper.TestZooKeeperMainServer.testCommandLineWorks(TestZooKeeperMainServer.java:81)
仕方がないので、CentOS6.5の環境でテストを動かしてみたら動いた。
環境依存的な何かがあるのだろうか。一旦テストはそっちの環境で動かすことにする。
テストはかなり時間がかかるので、高速化の方法として以下でtmpfsを使う方法が紹介されている。
Eclipseにインポートする
mavenのプロジェクトなので、普通にEclipseのmavenのプラグイン(m2eclipseとか?)を使えばインポートできる。
ただし、Eclipse上で、なぜかいくつかのサブプロジェクトがJavaプロジェクトとして認識されなかったので、以下をしてからインポートしたら、ちゃんと認識された。
$ mvn eclipse:eclipse
フォーマッターはdev-support/hbase_eclipse_formatter.xmlを使えばOK。
JavaのEditorのSave Actionsで以下をチェックしとくと便利。
- Perform the selected actions on save
- Format source code
- Format edited lines
まとめ
とりあえず、ビルド環境を作ることができたので、何をコントリビュートしようか。
参考