HDFS的数据流(三)一致性模型
1)debug调试如下代码
1 /** 2 * 一致性hflush 3 */ 4 @Test 5 public void hflushWriteFile() throws Exception { 6 //1.配置 7 Configuration conf = new Configuration(); 8 9 //2.连接文件系统 10 FileSystem fs = FileSystem.get(conf); 11 12 //3.创建文件的输出流 13 FSDataOutputStream fos = fs.create(new Path("D:/f1.txt")); 14 15 //4.写数据 16 fos.write("Renne".getBytes()); 17 18 //5.一致性hflush刷新 19 fos.hflush(); 20 21 //6.关闭 22 fos.close(); 23 }
2)总结
写入数据时,如果希望数据被其他client立即可见,调用如下方法
FSDataOutputStream. hflush (); //清理客户端缓冲区数据,被其他client立即可见
浙公网安备 33010602011771号