Class JournalFileOpenLock
- Namespace
- OptunaSharp.Storages.Journal
- Assembly
- OptunaSharp.dll
Lock class for synchronizing processes for NFSv3 or later.
Port of JournalFileOpenLock.
On acquiring the lock, the lock file is created with exclusive-create semantics
(O_CREAT | O_EXCL). The file is deleted when the lock is released. This is the
recommended lock on Windows.
public class JournalFileOpenLock : BaseJournalFileLock
- Inheritance
-
JournalFileOpenLock
- Inherited Members
Constructors
JournalFileOpenLock(string, int?)
Creates a journal lock policy with optional stale-lock recovery.
public JournalFileOpenLock(string filepath, int? gracePeriod = 30)
Parameters
filepathstringThe path of the file whose race condition must be protected.
gracePeriodint?Grace period before an existing lock is forcibly released.
Exceptions
- ValueError
A non-null grace period is zero or negative.
Properties
GracePeriod
Grace period before an existing lock is forcibly released.
public int? GracePeriod { get; }
Property Value
- int?
Methods
Acquire()
Acquire a lock in a blocking way by creating a lock file.
public override bool Acquire()
Returns
- bool
True after acquiring exclusive ownership.
Remarks
Waits out a lock path that is "delete pending" on Windows (see
OptunaSharp.Storages.Journal.JournalFileLockProtocol.MaxDeniedStreakMilliseconds): a stale lock someone deletes by hand while
this waits no longer kills the waiter. This departs from Optuna, whose waiter raises PermissionError there.
Exceptions
- IOException
Lock creation fails for a reason other than an existing lock.
- UnauthorizedAccessException
Lock-file creation is denied: off Windows on the first denial, as in Optuna; on Windows once denials have run unbroken for longer than OptunaSharp.Storages.Journal.JournalFileLockProtocol.MaxDeniedStreakMilliseconds (a lock file being deleted in place is waited out, not reported).
Release()
Release a lock by removing the created file.
public override void Release()
Exceptions
- RuntimeError
The lock cannot be renamed and deleted, including when ownership was lost.