none
Questions: Multi machine access on same network file resource.

    Question

  • Question #1: Do files on a network share (NAS) get stored in the windows cache?

     

    Question #2: When windows opens a file on a network share (NAS), does the network share keep track of which files are open to which machine, and their access type request? (ie: Machine A-read-share, Machine B-write-no share CFile::modeExclusive)

    I was wondering what best practices are for multi machine access to the same network file resource.  I was wondering if I needed to generate some type of global "lock" file to prevent data race conditions on the file. (Two machines writing at the same time)

     

    Friday, March 11, 2011 9:00 PM

Answers

  • 1) Network files are cached the same as normal files.
    2) Files opened through the network still create a handle on the source machine. This means that if you open a file on Machine A, a handle will be created on that machine and the file will be locked accordingly. That handle will then be transfered to the destination machine for that application to use. (This is simplified a lot but that doesn't matter) Everything you want to do with the files is automatically done by Windows.
    Any samples given are not meant to have error checking or show best practices. They are meant to just illustrate a point. I may also give inefficient code or introduce some problems to discourage copy/paste coding. This is because the major point of my posts is to aid in the learning process.
    Visit my (not very good) blog at
    http://ccprogramming.wordpress.com/
    Friday, March 11, 2011 11:47 PM

All replies

  • 1) Network files are cached the same as normal files.
    2) Files opened through the network still create a handle on the source machine. This means that if you open a file on Machine A, a handle will be created on that machine and the file will be locked accordingly. That handle will then be transfered to the destination machine for that application to use. (This is simplified a lot but that doesn't matter) Everything you want to do with the files is automatically done by Windows.
    Any samples given are not meant to have error checking or show best practices. They are meant to just illustrate a point. I may also give inefficient code or introduce some problems to discourage copy/paste coding. This is because the major point of my posts is to aid in the learning process.
    Visit my (not very good) blog at
    http://ccprogramming.wordpress.com/
    Friday, March 11, 2011 11:47 PM
  • Read on "Client side cache" in MSDN or Technet. When you create a share on Windows server, you can specify caching behavior on the server side.

    Note that NAS servers typically are not Windows machine but some kind of Linux, Samba etc, so they may deviate fom Windows behavior in various ways.

    --pa

     

     

     

    Saturday, March 12, 2011 12:28 AM
  • Read on "Client side cache" in MSDN or Technet. When you create a share on Windows server, you can specify caching behavior on the server side.

    Note that NAS servers typically are not Windows machine but some kind of Linux, Samba etc, so they may deviate fom Windows behavior in various ways.

    --pa

     

     

     


    Thank you for the tips.

    Unfortunately when our app is distributed there is no way to know where our users are storing their data.  It might be on Windows Server or a Linux based NAS presenting an NTFS file system.

    I think Crescens2K might have answered the question.  The file system on the host machine will keep track of which files are open and how.

    I have no idea if the Windows File System cache is smart enough to check modified time/date stamps everytime a file is opened on a network share.

    To circumvent this potential issue, I will safely bypass the OS local cache by selecting CFile::osNoBuffer (bypass read cache) and CFile::osWriteThrough (bypass write cache) options.  Since this is a small file with only occasional access this should be an acceptable solution.

    If Crescens2K is correct then CFile::modeExclusive should take care of the issue.  It's hard to test here as we don't have a NAS handy.

     

     

    Tuesday, March 15, 2011 2:14 PM