从 java 轮询 NFS 共享会破坏文件系统

发布于 2024-10-21 20:47:00 字数 403 浏览 3 评论 0 原文

我们有两台服务器,每个服务器都有一个通过 NFS 映射的目录。

服务器 A 上的进程(shell 脚本)将文件放入映射驱动器中。

服务器 B 上的 Java 进程定期轮询映射驱动器并在找到文件后立即处理该文件。文件处理后 - 它被重命名(然后由服务器 A 上的 cron 进程删除)

该文件是一个小的 .properties 文件。几个周期后一切都运转良好。之后,服务器 A 和服务器 B 开始以不同的方式查看映射驱动器的内容。我们禁用了 NFS 缓存和属性查找。问题仍然存在。

如果我转到视图已损坏的服务器并执行以下操作:

ls

我将看到停滞的文件。但是,如果我再次执行此操作 - 将打印正确的文件列表。

我们将不胜感激任何有关此问题的帮助。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

漫雪独思 2024-10-28 20:47:00

我的问题是,当使用计时器循环时,下面的命令会停止看到实际的目录内容。它与 NFS 服务器不同步。

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

我得到的解决方案是请求已知不存在的文件。我认为这会使 NFS 客户端修复或刷新其状态。

// 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();

如果您知道此解决方法背后的机制 - 请分享!

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!

贩梦商人 2024-10-28 20:47:00

使用哪个 NFS 服务器?如果该服务器支持文件更改通知,您可以使用它而不是轮询。

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

与酒说心事 2024-10-28 20:47:00

您禁用了哪种缓存? NFS 支持目录条目缓存,请参阅 acdirmin 和 acdirmax “nofollow">nfs Linux 手册页。或者同一手册中的“数据和元数据一致性”一章。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文