당신은 단지 하나의 프로세스가 파일 때문에 데이터베이스를 얻을 수 있음을 보장하기 위해 POSIX O_EXCL
and O_CREAT
flags to open(2)
을 사용할 수 있습니다; O_EXCL
은 NFSv2 또는 이전 버전에서 작동하지 않으며 다른 네트워크 파일 시스템에 의존하는 것이 매우 불안정합니다.
liblockfile
라이브러리는 open(2)
맨 페이지에 설명 된 네트워크 파일 시스템 안전 잠금 메커니즘을 구현하는데 편리합니다. 하지만 미리 만든 Ruby와 Perl 바인딩 만 볼 수 있습니다.
O_EXCL Ensure that this call creates the file: if this flag is
specified in conjunction with O_CREAT, and pathname
already exists, then open() will fail. The behavior of
O_EXCL is undefined if O_CREAT is not specified.
When these two flags are specified, symbolic links are not
followed: if pathname is a symbolic link, then open()
fails regardless of where the symbolic link points to.
O_EXCL is only supported on NFS when using NFSv3 or later
on kernel 2.6 or later. In environments where NFS O_EXCL
support is not provided, programs that rely on it for
performing locking tasks will contain a race condition.
Portable programs that want to perform atomic file locking
using a lockfile, and need to avoid reliance on NFS
support for O_EXCL, can create a unique file on the same
file system (e.g., incorporating hostname and PID), and
use link(2) to make a link to the lockfile. If link(2)
returns 0, the lock is successful. Otherwise, use stat(2)
on the unique file to check if its link count has
increased to 2, in which case the lock is also successful.
어쩌면 내가 오해 해요,하지만 당신은 단지 각 DB의 파일 위치를 이름을 바꿀 수 없습니다 : 사용자의 필요에 따라, 어쩌면 파이썬 바인딩을 제공하는 다시 구현 알고리즘을 단지에 유용한, 또는 것? – dfb