April 10, 2007, 12:13 a.m.

If You Wrote This Code, You Suck

I don't know who wrote the following code...somebody at Sun, but it's cost me my entire night:

#if !defined(O_DSYNC) || !defined(O_SYNC)
#define O_SYNC  (0x0800)
#define O_DSYNC (0x2000)
#endif

There I was building out my hadoop cluster. Everything was going pretty well on my laptop, so I decided to move it over to my FreeBSD box to get a real instance running. I configured it all up, formatted the namenode, and then tried to start it. Then it told me this:

07/04/10 00:17:23 ERROR dfs.NameNode:
java.io.FileNotFoundException:
/data/hadoop/data/dfs/name/current/VERSION (File exists)
  at java.io.RandomAccessFile.open(Native Method)
  at java.io.RandomAccessFile.<init>(RandomAccessFile.java:212)
  at org.apache.hadoop.dfs.Storage$StorageDirectory.read(Storage.java:144)
  [...]

So, it's pretty obvious what's happening there. The native method is opening my file with O_EXCL. But why? Must be a bug in Hadoop, right? RandomAccessFile has no option that's anything like O_EXCL, so it has to be a bug in the JVM.

I started digging through my source and it seemed pretty straightforward (although excessively limiting). The only thing it could be was something overriding O_SYNC to have the same value as FreeBSD's O_EXCL.

And there it was: j2se/src/share/native/java/io/io_util.h. Luckily, someone else had already found this problem between the time I installed this JVM and ran into it myself, so I'm doing a build.

I'll be cursing the author of the above for several hours while this JVM build completes. Curse you, anonymous Sun programmer. You must use your laziness for good, not for evil.

blog comments powered by Disqus