user431529
user431529

Reputation: 2382

Polling NFS share from java breaks filesystem

We've got two servers having a directory mapped via NFS to each of them.

Process on server A (shell script) places file into mapped drive.

Java process on server B regularly polls mapped drive and processes the file as soon as it is found. After file is processed - it is renamed (and deleted by cron'ed process on server A afterwards)

The file is a small .properties file. Everything works well for couple of cycles. After that server A and server B start to see contents of mapped drive differently. We disabled NFS caching and attribute lookup. Problem is still there.

If I go to a server which has broken view and do:

ls

I'll see stalled files. BUT, if I do it again - correct file listing is printed.

We'd appreciate any help on the issue.

Upvotes: 0

Views: 2318

Answers (3)

Eduard Wirch
Eduard Wirch

Reputation: 9922

Which kind of caching have you disabled? NFS supports directory entry caching see the options acdirmin and acdirmax in the nfs Linux man page. Or the chapter "Data And Metadata Coherence" in the same manual.

Upvotes: 0

user431529
user431529

Reputation: 2382

My problem was that when looping with timer, command below stops seeng actual directory content. It gets out of sync with NFS server.

File[] files = dir.listFiles(new MyFileFilter() );

The solution I've got is to request knowingly unexisting file. I assume that this makes NFS client to fix or refresh its state.

// Key point is here: we ask NFS client to obtain unexisting file. Since the client
// cannot find it locally - it will make a call to the NFS server which will 
// fix client cache or whatever it uses locally when cache is disabled.
File temp = new File(dir, "unexisting.file");
temp.exists();

If you know the mechanism behind this workaround - please share!

Upvotes: 1

Shamit Verma
Shamit Verma

Reputation: 3827

Which NFS server is used? If that server supports file change notification, you can use that instead of polling.

Upvotes: 0

Related Questions