Sven Ludwig
2018-Mar-14 17:07 UTC
[Gluster-users] How to sync content to a file through standard Java APIs
Hello, we have a Gluster FS mounted at some /mnt/... path on a Server. The actual physical device behind this resides on some other Server. Now, the requirement is to write files to this Gluster FS Volume in a durable fashion, i.e. for an officially succeeded write the contents MUST have been actually synced to disk on at least one of the Gluster FS nodes in the replica set. Our questions: 1. Which JDK 8 APIs can we use that would fulfill this requirement with an actually working sync? 2. Is java.nio.channels.FileChannel.open with StandardOpenOption#SYNC in the set of options given to this method an option, or would it perhaps not actually guarantee the sync? 3. Apart from 2., are there other ways to achieve the requirement through the standard JDK 8 APIs? Kind Regards Sven
Niels de Vos
2018-Mar-18 16:50 UTC
[Gluster-users] How to sync content to a file through standard Java APIs
On Wed, Mar 14, 2018 at 06:07:19PM +0100, Sven Ludwig wrote:> Hello, > > we have a Gluster FS mounted at some /mnt/... path on a Server. The > actual physical device behind this resides on some other Server. > > Now, the requirement is to write files to this Gluster FS Volume in a > durable fashion, i.e. for an officially succeeded write the contents > MUST have been actually synced to disk on at least one of the Gluster > FS nodes in the replica set. > > Our questions: > > 1. Which JDK 8 APIs can we use that would fulfill this requirement > with an actually working sync? > > 2. Is java.nio.channels.FileChannel.open with StandardOpenOption#SYNC > in the set of options given to this method an option, or would it > perhaps not actually guarantee the sync? > > 3. Apart from 2., are there other ways to achieve the requirement > through the standard JDK 8 APIs?There is nothing special to take care of, all languages should support the required features. These are the two things you need to take into account (just like with other filesystems): 1. call a flush() or sync() function after writing to a file(descriptor) 2. when creating a new file (or any directory entry), call flush() or sync() on the directory where the new entry is created to persist the metadata of the directory. See 'man 2 fsync' for a little more details. HTH, Niels