#include <db_cxx.h> int Db::set_lk_exclusive(int nowait_onoff);
Configures the database handle to obtain a write lock on the entire database when it is opened. This gives the handle exclusive access to the database, because the write lock will block all other threads of control for both read and write access.
Use this method to improve the throughput performance on your database for the thread that is controlling this handle. When configured with this method, operations on the database do not acquire page locks as they perform read and/or write operations. Also, the exclusive lock means that operations performed on the database handle will never be blocked waiting for lock due to another thread's activities. The application will also be immune to deadlocks.
On the other hand, use of this method means that you can only have a single thread accessing the database until the handle is closed. For some applications, the loss of multiple threads concurrently operating on the database will result in performance degradation.
Also, use of this method means that you can only have one transaction active for the handle at a time.
The Db::set_lk_exclusive()
method may
not be called after the
Db::open()
method is called.
The Db::set_lk_exclusive()
method either returns a non-zero error value or throws an
exception that encapsulates a non-zero error value on
failure, and returns 0 on success.
Replication applications that use exclusive database handles
need to be written with caution. This is because replication
clients cannot process updates on an exclusive database until
all local handles on the database are closed. Also, attempting
to open an exclusive database handle on a currently operating
client will result in the open call failing with the error
EINVAL
.
Also, opening an exclusive database handle on a replication
master will result in all clients being locked out of the
database. On clients, existing handles on the exclusive
database will return the error
DB_REP_DEAD_HANDLE
when accessed, and must
be closed. New handles opened on the exclusive database will
block until the master closes its exclusive database handle.
The Db::set_lk_exclusive()
method may fail and throw a DbException
exception, encapsulating one of the following non-zero errors, or return one
of the following non-zero errors:
If the method was called after Db::open() was called; the method was called on a currently operating replication client; this method was called on a sliced database; or if an invalid flag value or parameter was specified.