title: Why is hsync() not flushing my hdfs file?
body: <p>Despite all the resources about this subject, I have issues flushing my hdfs files on disk (hadoop 2.6)
  Calling <code>FSDataOutputStream.hsync()</code> should do the trick, but it actually only works once for unknown reasons...</p>
  
  <p>Here is a simple unit test that fails:</p>
  
  <pre><code>@Test
  public void test() throws InterruptedException, IOException {
      final FileSystem filesys = HdfsTools.getFileSystem();
      final Path file = new Path("myHdfsFile"); 
      try (final FSDataOutputStream stream = filesys.create(file)) {
          Assert.assertEquals(0, getSize(filesys, file));  
          stream.writeBytes("0123456789");
          stream.hsync();
          stream.hflush();
          stream.flush();
          Thread.sleep(100);
          Assert.assertEquals(10, getSize(filesys, file)); // Works
          stream.writeBytes("0123456789");
          stream.hsync();
          stream.hflush();
          stream.flush();
          Thread.sleep(100);
          Assert.assertEquals(20, getSize(filesys, file)); // Fails, still 10           
      }
      Assert.assertEquals(20, getSize(filesys, file)); // works
  }
  
  
  private long getSize(FileSystem filesys, Path file) throws IOException {
      return filesys.getFileStatus(file).getLen();
  }
  </code></pre>
  
  <p>Any idea why?</p>