dvalters / fuse-netcdf

ESoWC project to develop a Python utility to mount NetCDF files as a file-system in user space. (FUSE)
Other
8 stars 3 forks source link

Editing variables does not permanently modify file until netcdf file is closed/VFS unmounted #42

Open dvalters opened 6 years ago

dvalters commented 6 years ago

Supercedes #37

Consider implementation of truncate() Can 'write' edits to variable's DATA_REPR, but the change is not retained when the file is reopened.

dvalters commented 6 years ago

@blazk I've discovered this does not happen if you do the following steps:

  1. Mount the file as normal
  2. Edit the dimension variable (in vim)
  3. Save and exit vim
  4. Immediately unmount the file
  5. view with ncdump or remount the file to inspect it
  6. The modification is retained.

I think this is something to do with the way the netcdf library writes Variable data only when you close the dataset handle(?). i.e. dset.close()

So it is buffering the changes somehow and only writes them when unmounting (possibly? - I'm not 100% sure)

https://www.unidata.ucar.edu/software/netcdf/netcdf-4/newdocs/netcdf-f90/Writing-Data-in-an-Existing-NetCDF-Dataset.html

Finally, you should explicitly close any netCDF datasets into which data has been written by calling NF90_CLOSE before program termination. Otherwise, modifications to the dataset may be lost.

I've been looking if there are options to disable this somehow.

dvalters commented 6 years ago

There is dataset.sync() but it does not seem to have the expected effect... http://unidata.github.io/netcdf4-python/#netCDF4.Dataset.sync

https://www.unidata.ucar.edu/software/netcdf/netcdf-4/newdocs/netcdf-c/nc_005fsync.html

blazk commented 6 years ago

@dvalters the problem is caused by caching of the variable data representation, basically the data representation is generated only first time when the VardataAsFlatTextFiles() is called; all subsequent calls return cached representation. Quick fix is to disable caching: comment out @memoize decorator from VardataAsFlatTextFiles() definition.

blazk commented 6 years ago

Also i'm not sure the current implementation of writing to a variable is correct; it seems to be a bit more complex task than I thought. I'm currently experimenting with the code, will propose some changes later today