Class | Ferret::Store::Lock |
In: |
ext/r_store.c
|
Parent: | Object |
A Lock is used to lock a data source so that not more than one output stream can access a data source at one time. It is possible that locks could be disabled. For example a read only index stored on a CDROM would have no need for a lock.
You can use a lock in two ways. Firstly:
write_lock = @directory.make_lock(LOCK_NAME) write_lock.obtain(WRITE_LOCK_TIME_OUT) ... # Do your file modifications # ... write_lock.release()
Alternatively you could use the while locked method. This ensures that the lock will be released once processing has finished.
write_lock = @directory.make_lock(LOCK_NAME) write_lock.while_locked(WRITE_LOCK_TIME_OUT) do ... # Do your file modifications # ... end
Obtain a lock. Returns true if lock was successfully obtained. Make sure the lock is released using Lock#release. Otherwise you‘ll be left with a stale lock file.
The timeout defaults to 1 second and 5 attempts are made to obtain the lock. If you‘re doing large batch updates on the index with multiple processes you may need to increase the lock timeout but 1 second will be substantial in most cases.
timeout: | seconds to wait to obtain lock before timing out and returning false |
return: | true if lock was successfully obtained. Raises a Lock::LockError otherwise. |
Run the code in a block while a lock is obtained, automatically releasing the lock when the block returns.
See Lock#obtain for more information on lock timeout.
timeout: | seconds to wait to obtain lock before timing out and returning false |
return: | true if lock was successfully obtained. Raises a Lock::LockError otherwise. |