Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

VIII. HDFS consistency flush

Shulou Source: shulou.com Published: 2022-06-03 07:09:03 11月23日 Update

I. background

During the process of writing, hdfs will not be visible to other client until the contents of the entire file are fully written, otherwise it will not be visible during the write process. If you want to be visible immediately, you need to be consistent with the operation of flush.

II. Consistent flush

Code example:

@ Test public void writeFile () throws Exception {/ / 1 create configuration information object Configuration configuration = new Configuration (); fs = FileSystem.get (configuration); / / 2 create file output stream Path path = new Path ("F:\\ date\\ H.txt"); FSDataOutputStream fos = fs.create (path); / / 3 write data fos.write ("hello Andy" .getBytes ()) / / 4 consistency refresh fos.hflush (); fos.close ();}

The method is simple by calling the hflush () method of the output stream and brushing the buffer of the client so that other client can see the written content immediately. Generally speaking, in the case of concurrent read and write, it is required that the data of multiple client are consistent.

Tags: Consistency consistency content data file method procedure output code example information only multiple object namely case buffer background buffer configuration Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Shulou Tech Info Redmi MySQL Docker