Privacy note: hostnames, IP addresses, export paths, and server names in this article are replaced with placeholders. The IPs use the documentation range 192.0.2.0/24. Mount options are kept as captured.
The file was called file_01.xlsx.
We created it in /2026/.
A moment later it was in /bak/2026/file_01_001.xlsx.bak.
Nobody had asked for that.
It happened again the next time. And the time after that. Any new file named file_01.xlsx ended up in the backup folder, renamed, with a .bak suffix.
We changed one line of Java and the problem stopped.
That should have been the end of the story. It was not. The line we changed may have hidden the problem. It probably did not cause it.
A fix that works is not proof of a cause. This article is about the gap between those two things.
What is confirmed: the symptom, the Java change, and that the symptom stopped after it. What is not confirmed: that the double NFS mount described below is the root cause. We are still verifying it.
The file moved after we had already moved it
The service has a simple job. It writes Excel files into a dated folder on shared storage. When a file is replaced, the old one goes to a backup folder with a numbered suffix.
The flow looked like this:
# Expected flow (simplified, illustrative)
/datastore/2026/file_01.xlsx <- new file written here
|
| (only when replacing an older file)
v
/datastore/bak/2026/file_01_001.xlsx.bak
The first move was correct. The old file_01.xlsx went to backup, as designed.
The problem started after that.
Every new file with the same name also went to backup. Not once. Every time. The folder /2026/ should have held the new file. It stayed empty, and the backup folder kept growing.
From the application’s point of view, nobody had issued a move.
That was the part that bothered us. Software does not move files on its own. Something was making a decision, and we could not see where.
We blamed Java on Linux first
The service had been developed and tested mostly on Windows machines. Production runs on Linux. The storage is an NFS share.
That combination made Java the obvious suspect.
The move code used Files.move with REPLACE_EXISTING:
// Before (illustrative, simplified from the real service)
Path source = Paths.get("/datastore/2026/file_01.xlsx");
Path target = Paths.get("/datastore/bak/2026/file_01_001.xlsx.bak");
Files.move(source, target, StandardCopyOption.REPLACE_EXISTING);
The team’s reasoning was reasonable. Files.move behaves differently depending on the operating system and the file system underneath it. On Linux over NFS, maybe the move was not completing cleanly. Maybe something was left behind or applied twice.
So we tried the other option:
// After (illustrative): the change that made the symptom stop Files.move(source, target, StandardCopyOption.ATOMIC_MOVE);
We deployed it.
The problem stopped.
New files named file_01.xlsx stayed in /2026/. The backup folder stopped growing. We closed the issue.
The fix explained the symptom. It did not explain the cause.
A few days later, someone asked a question we could not answer.
Why would REPLACE_EXISTING move a file we never told it to move?
REPLACE_EXISTING changes how Java handles a target that already exists. It does not create extra moves. It does not watch the folder. It does not run again later.
The change made the symptom go away. It did not tell us what was producing the symptom in the first place.
That was the boundary we had missed.
So we went back to the server and stopped looking at the code. We looked at the storage instead.
One path, two mounts
This is what the node showed:
# Captured output (hostname, IPs, and export path replaced) [root@k8s-worker-01 bak]# mount | grep /datastore nfs-share.storage.internal:/export/app_datastore on /datastore type nfs (rw,relatime,vers=3,rsize=1048576,wsize=1048576,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,mountaddr=192.0.2.56,mountvers=3,mountport=2050,mountproto=udp,local_lock=none,addr=192.0.2.56) nfs-share.storage.internal:/export/app_datastore on /datastore type nfs (rw,relatime,vers=3,rsize=1048576,wsize=1048576,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,mountaddr=192.0.2.58,mountvers=3,mountport=2050,mountproto=udp,local_lock=none,addr=192.0.2.58)
Two lines. Same hostname. Same export. Same mount point.
Different addresses: .56 and .58.
The hostname resolved to two IPs. At some point the share was mounted once through .56, and later mounted again through .58, on top of the first one, at the same path.
Nothing failed when that happened. Linux allows a second mount on top of an existing one. The new mount simply covers the old one for any new path lookup.
The old one does not disappear. It is only hidden.
Why a hidden mount can still be used
This is the part that turned a strange log into a plausible explanation.
When a mount is stacked on top of another, Linux keeps both. What a process sees depends on when it got its view of the directory:
- A process that resolves
/datastoreafter the second mount sees the top mount (.58). - A process that already had the directory open, or had its working directory or bind mount set up before the second mount, keeps using the lower mount (
.56).
In Kubernetes this is not an edge case. A pod that started before the second mount keeps the view it got at start time. A pod that started later gets the new one.
So two processes can write to “the same folder” and actually talk to the storage through two different mounts.
# Proposed model, not captured output
/datastore (path)
|
+-----------------+-----------------+
| |
lower mount (.56) upper mount (.58)
- pods started before - pods started after
the second mount the second mount
- own attribute cache - own attribute cache
- own directory cache - own directory cache
That alone would not move a file. The next two details are what make it dangerous.
Each mount remembers the folder differently
NFSv3 clients cache aggressively. They cache file attributes (size, timestamps, existence) and directory contents for a short time so they do not ask the server about every lookup.
The cache belongs to the mount.
Two mounts of the same export means two caches. They are not shared and they are not kept in sync with each other. Each one refreshes on its own schedule.
That gives us a possible sequence:
# Expected event order under our hypothesis (illustrative, not captured) t0 Pod A (lower mount) and Pod B (upper mount) both see /2026/file_01.xlsx t1 Pod B moves file_01.xlsx to /bak/2026/file_01_001.xlsx.bak t2 Pod B creates a new /2026/file_01.xlsx t3 Pod A's cache still describes the OLD file_01.xlsx t4 Pod A's logic sees "file_01.xlsx already exists" and backs it up t5 The NEW file ends up in /bak, with the next suffix
If any part of the application backs up a file when it finds an existing one, a stale view is enough to trigger it. From the outside, it looks like the file moved by itself.
We have not confirmed that this exact sequence happened. It is consistent with the symptom. We are still checking which pod performed each move.
The storage might not be one storage
There is a second possibility, and it would make the problem worse.
The two addresses may not point at the same storage controller. The naming of the storage environment suggested a primary and a warm standby that replicate to each other.
If .56 and .58 are two separate systems kept in sync by replication, then:
- A move made through one address reaches the other only when replication runs.
- During that delay, the two systems disagree about what is in
/2026/. - When replication catches up, a file can appear to “move on its own” or “come back.”
That matches the symptom even more closely. A file moving without a command is exactly what replication looks like from inside an application that did not ask for it.
This is a hypothesis. We have not yet confirmed with the storage team whether the two IPs are the same system or two replicated systems.
Then why did ATOMIC_MOVE help?
This is the question that remains open, so we will be careful.
On Linux, Java’s Files.move with REPLACE_EXISTING (and no ATOMIC_MOVE) roughly does this:
- Check whether the target exists.
- If it exists, delete it.
- Rename the source to the target.
- If the rename fails because the paths are on different file systems, fall back to copy and delete.
With ATOMIC_MOVE, Java goes straight to a single rename() call. If that cannot be done atomically, it throws AtomicMoveNotSupportedException instead of falling back.
On NFS, the difference matters. The non-atomic path makes several separate requests, and the first one (does the target exist?) can be answered from the client’s cache. A single rename() is one operation that the server applies.
So a plausible reading is this: ATOMIC_MOVE reduced the number of decisions made from cached, possibly stale, information. It shrank the window. It did not remove the second mount.
That explains why the symptom stopped. It does not explain why the symptom existed.
This reading is based on how the JDK implements Files.move on Unix. We have not traced the exact system calls in this environment yet.
What each fix actually covers
| Option | What it improves | What remains |
|---|---|---|
Keep ATOMIC_MOVE | Fewer cache-dependent steps in the move itself | Two mounts and two caches still exist. Any other read can still see stale state |
| Remove the duplicate mount | One cache, one view of the folder for every pod | Pods started on the old mount must be restarted to pick up the new view |
| Mount by a fixed IP or a single virtual IP | The duplicate cannot come back after a DNS change or remount | Fails over less gracefully if that IP goes down. Needs agreement with the storage team |
Tighter NFS caching (lookupcache=positive, lower actimeo) | Shorter window for stale existence checks | More metadata traffic. Does not fix two separate storage systems |
Write to a temp name, then ATOMIC_MOVE into place | The final file appears in one step | Still depends on every reader seeing the same mount |
None of these options removes every risk on its own. The duplicate mount is the part we most need to remove. ATOMIC_MOVE is worth keeping as a second layer.
Fix part 1: make the mount boring
The first goal is one mount, at one address, every time.
# Proposed checks (run on each node that mounts the share) # 1. How many mounts exist at this path? findmnt --list | grep /datastore # 2. What does the NFS hostname resolve to? getent ahosts nfs-share.storage.internal # 3. Which mount is a given process actually using? # (replace <pid> with the container's main process ID) grep /datastore /proc/<pid>/mountinfo
If findmnt shows more than one line for /datastore, the node is in the same state we were.
The third command is the important one. mountinfo for a running process shows which mount that process is really using. Two pods with two different mount IDs for the same path confirm that they are reading through different caches.
For Kubernetes, pin the server in the volume definition instead of relying on a name that can resolve to more than one address:
# Proposed (illustrative): pin the NFS server address in the PV
apiVersion: v1
kind: PersistentVolume
metadata:
name: app-datastore
spec:
capacity:
storage: 100Gi
accessModes:
- ReadWriteMany
nfs:
server: 192.0.2.56 # one agreed address, not a multi-IP hostname
path: /export/app_datastore
mountOptions:
- vers=3
- hard
Which address to pin, or whether to use a virtual IP instead, should be agreed with the storage team. Do not pick one on your own if the two IPs are a primary and a standby.
After removing the duplicate mount, restart the pods that started before the change. Otherwise they keep the old view.
Fix part 2: make the move less dependent on the cache
We kept ATOMIC_MOVE, but with an explicit fallback so it fails loudly instead of silently:
// Proposed (illustrative): atomic move with an explicit failure path
try {
Files.move(source, target, StandardCopyOption.ATOMIC_MOVE);
} catch (AtomicMoveNotSupportedException e) {
// Source and target are not on the same file system.
// Do not silently fall back to copy + delete on shared storage.
log.error("Atomic move not supported: {} -> {}", source, target, e);
throw e;
}
This block guarantees one thing: the move either happens as a single rename, or we hear about it. It does not guarantee that another pod’s cache is up to date.
We also reviewed every code path that checks “does this file exist?” before deciding to back it up. On shared NFS storage, Files.exists() answers from the client’s view, which may be a few seconds old.
Test the failure paths
A fix we cannot reproduce is a fix we cannot trust. This is the test plan we are using:
| Step | What we do | Evidence we expect |
|---|---|---|
| 1 | On a test node, mount the same export twice through two IPs | findmnt shows two lines for one path |
| 2 | Start process A with its working directory inside the mount | A’s mountinfo shows the lower mount ID |
| 3 | Start process B after the second mount | B’s mountinfo shows the upper mount ID |
| 4 | B moves file_01.xlsx to backup and creates a new one | B sees the new file |
| 5 | A checks Files.exists() and reads attributes immediately | If A still reports the old file, the cache hypothesis holds |
| 6 | Repeat with REPLACE_EXISTING, then ATOMIC_MOVE | Shows whether ATOMIC_MOVE only narrows the window |
| 7 | Repeat with a single mount | The symptom should not appear |
This is a proposed plan. We have not run all steps yet.
How we will know it is fixed
findmntshows exactly one mount for/datastoreon every node.- Every running pod reports the same mount ID for
/datastore. - No new
.bakfile appears without a matching log line from the service that created it. - The storage team confirms whether
.56and.58are one system or two.
The third point matters most. A backup file with no matching log line means something outside the application moved it. That is the signal we did not have before.
What we learned
- A fix that stops a symptom is a clue, not a conclusion.
ATOMIC_MOVEnarrowed the window. It did not close it.- Two mounts of one share are two views of the truth.
- A hidden mount is not a removed mount.
- NFS caches belong to the mount, not to the storage.
- When files move by themselves, look below the application first.
Next step
We are confirming with the storage team what .56 and .58 actually are. Then we will remove the duplicate mount, pin the address, restart the pods that hold the old view, and run the test plan above.
We are keeping ATOMIC_MOVE. We are no longer calling it the fix.
Frameworks change. Storage drivers change. Java will keep changing how Files.move behaves on each platform.
What does not change is this: when a change makes a problem disappear, we stop asking why it appeared. That is when the real cause gets to stay.
Run findmnt --list | grep <your shared path> on one of your nodes today. How many lines do you see?



