Is mkdir still atomic? (Windows 7 file systems installed on a SAN)

We have several older applications that exchange data through directory-based queues. Each item in the queue is a file, and there is a header file that maintains an ordered list of file names for the items in the queue.

Naturally, this old code should block the queue while items are being pushed and unloaded. It does the creation of a lock subdirectory based on the assumption that mkdir () is an atomic operation - if several processes try to create a directory, only one of them will succeed.

One of my employees tried to pursue an incomprehensible problem, and he believes that the reason for this is that this lock no longer works when the processes work on different machines and when the file system is installed on the SAN.

Is there a chance that he might be right?

+4
source share
1 answer

A very old question that I know, but hopefully someone finds this interesting.

I also got confusing results using PowerShell to create a shared folder for use as a mutex, so I created a test script.

function New-FolderMutex { try { New-Item -ItemType directory -Path .\TheMutex -ErrorAction Stop > $null $true } catch { $false } } function Remove-FolderMutex { Remove-Item -Path .\TheMutex } 1..100 | % { if (New-FolderMutex) { Write-Host "Inside loop $_" Remove-FolderMutex } } 

This script is executed while the current directory is in the network share.

When I ran this script simultaneously in two separate PowerShell consoles, it was clear from the error messages that the approach was doomed. There are a number of different errors caused by the Remove-Item call, although it is only called by the process that created this folder. It seems like a whole bunch of non-nuclear steps are going on behind the scenes.

Of course, the OP asked about mkdir (possibly a system call), and my example uses PowerShell cmdlets with a much higher level, but I hope this is of some interest.

An example of the output of one of two processes (edited for brevity)

 Inside loop 30 Inside loop 31 Inside loop 32 Inside loop 33 Inside loop 34 Remove-Item : Access to the path 'H:\My Documents\PowerShell\MutexFolder\TheMutex' is denied. At H:\My Documents\PowerShell\MutexFolder\Test-FolderMutex.ps1:93 char:5 + Remove-Item -Path .\TheMutex + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : PermissionDenied: (H:\My Documents...Folder\TheMutex:String) [Remove-Item], UnauthorizedAccessException + FullyQualifiedErrorId : RemoveItemUnauthorizedAccessError,Microsoft.PowerShell.Commands.RemoveItemCommand Inside loop 39 Remove-Item : H:\My Documents\PowerShell\MutexFolder\TheMutex is a NTFS junction point. Use the Force parameter to delete or modify. At H:\My Documents\PowerShell\MutexFolder\Test-FolderMutex.ps1:93 char:5 + Remove-Item -Path .\TheMutex + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : WriteError: (H:\My Documents...Folder\TheMutex:DirectoryInfo) [Remove-Item], IOException + FullyQualifiedErrorId : DirectoryNotEmpty,Microsoft.PowerShell.Commands.RemoveItemCommand Inside loop 42 Remove-Item : Could not find a part of the path 'H:\My Documents\PowerShell\MutexFolder\TheMutex'. At H:\My Documents\PowerShell\MutexFolder\Test-FolderMutex.ps1:93 char:5 + Remove-Item -Path .\TheMutex + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : WriteError: (H:\My Documents...Folder\TheMutex:String) [Remove-Item], DirectoryNotFoundException + FullyQualifiedErrorId : RemoveItemIOError,Microsoft.PowerShell.Commands.RemoveItemCommand Inside loop 44 Inside loop 45 
0
source

All Articles