Using byte-range locking

By default, the database server uses whole lock-all locks when it needs to lock a smart large object. Lock-all locks are an all or nothing lock; that is, they lock the entire smart large object.

About this task

When the database server obtains an exclusive lock, no other user can access the data of the smart large object as long as the lock is held.

If this locking is too restrictive for the concurrency requirements of your application, you can use byte-range locking instead of lock-all locking. With byte-range locking, you can specify the range of bytes to lock in the smart-large-object data. If other users access other portions of the data, they can still acquire their own byte-range lock.

To use byte-range locking:

Procedure

  1. Enable the byte-range locking feature on the smart large object you need to lock.
    You can specify the byte-range locking feature either when you create the smart large object or when you open it, as follows:
    • At the time of smart-large-object creation

      You can specify the LO_LOCKRANGE lock-mode constant as a default open flag for the new smart large object.

    • When you open the smart large object

      You can specify the LO_LOCKRANGE lock-mode constant in the open-mode argument of mi_lo_open().

  2. Handle the lock requests for the byte-range locks with the appropriate function of the smart-large-object interface.
    The smart-large-object interface provides the following functions for handle lock requests of byte-range locks.
    mi_lo_lock()
    Obtains a byte-range lock on the specified number of bytes in a smart large object
    With the mi_lo_lock() function, you can specify the following information for the lock request of the byte-range lock
    • The location in the smart-large-object data at which to begin the byte-range lock
    • The number of bytes to lock
    • The type of lock to obtain: shared or exclusive lock
    mi_lo_unlock()
    Releases a byte-range lock on a smart large object