java - is FSDataInputStream limited to those bytes that were already written when it was created? -


so i'm trying understand behavior in hdfs. goal set configuration open fsdataoutputstream location , have other part of application open fsdatainputstream same location immediately, before write bytes.

the idea write bytes fsdataoutputstream, flush them, , call 'sync()', access fsdatainputstream same location should able read bytes.

sadly, doesn't seem work way. when set code way happens:

fsdataoutputstream writer = fs.create(new path("/foo/bar")); fsdatainputstream reader = fs.open(new path("/foo/bar")); writer.write(new byte[]{1, 1, 1, 1, 1}); writer.flush(); writer.sync(); system.out.println(reader.available()); // writes '0' 

however! when set code way, happens:

fsdataoutputstream writer = fs.create(new path("/foo/bar")); writer.write(new byte[] {1, 1, 1, 1, 1}); writer.flush(); writer.sync(); fsdatainputstream reader = fs.open(new path("/foo/bar")); system.out.println(reader.available()); // writes '5' 

finally, third test ran this:

fsdataoutputstream writer = fs.create(new path("/foo/bar")); writer.write(new byte[] {1, 1, 1, 1, 1}); writer.flush(); writer.sync(); fsdatainputstream reader = fs.open(new path("/foo/bar")); writer.write(new byte[] {2, 2, 2, 2, 2}); writer.flush(); writer.sync(); system.out.println(reader.available()); // writes '5' 

my takeaway fsdatainputstream going limited in scope bytes written when input stream created. there way around this? don't see 'refresh()' method on input stream or that.

i really, if there way me force input stream update available bytes. missing? doing wrong? wrong way stuff this?

as far can tell, dfsinputstream refreshes list of located blocks on open , when has encounters error trying read block. regardless of in output stream, input stream won't updated.

if trying implement single-producer/multiple-consumer system, might using zookeeper coordination.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -