Library Version 12.1.6.1

DbEnv::failchk()
Prev | Chapter 5. The DbEnv Handle | Next

## DbEnv::failchk()

    #include <db_cxx.h>

    int
    DbEnv::failchk(u_int32_t flags);

The `DbEnv::failchk()` method checks for threads of control (either a true thread or a process) that have exited while manipulating Berkeley DB library data structures, while holding a logical database lock, or with an unresolved transaction (that is, a transaction that was never aborted or committed). For more information, see Architecting Data Store and Concurrent Data Store applications, and Architecting Transactional Data Store applications, both in the Berkeley DB Programmer's Reference Guide.

The `DbEnv::failchk()` method is used in conjunction with the DbEnv::set_thread_count(), DbEnv::set_isalive() and DbEnv::set_thread_id() methods. Before calling the `failchk()`method, applications must:

1. Configure their database using the DbEnv::set_thread_count() method.

2. Establish an `is_alive()` function and invoke DbEnv::set_isalive() with that function as the `is_alive` parameter.

3. Establish a `thread_id` function and invoke DbEnv::set_thread_id() with that function as the `thread_id` parameter.

If any of these methods are omitted, a program may be unable to allocate a thread control block. This is true of the standalone Berkeley DB utility programs. To avoid problems when using the standalone Berkeley DB utility programs with environments configured for failure checking, incorporate the utility's functionality directly in the application, or call the `DbEnv::failchk()` method along with its associated methods before running the utility.

If `DbEnv::failchk()` determines a thread of control exited while holding database read locks, it will release those locks. If `DbEnv::failchk()` determines a thread of control exited with an unresolved transaction, the transaction will be aborted. In either of these cases, `DbEnv::failchk()` will return 0 and the application may continue to use the database environment.

In either of these cases, the `DbEnv::failchk()` method will also report the process and thread IDs associated with any released locks or aborted transactions. The information is printed to a specified output channel (see the DbEnv::set_msgfile() method for more information), or passed to an application callback function (see the DbEnv::set_msgcall() method for more information).

If `DbEnv::failchk()` determines a thread of control has exited such that database environment recovery is required, it will return DB_RUNRECOVERY. In this case, the application should not continue to use the database environment. For a further description as to the actions the application should take when this failure occurs, see Handling failure in Data Store and Concurrent Data Store applications, and Handling failure in Transactional Data Store applications, both in the Berkeley DB Programmer's Reference Guide.

In multiprocess applications, it is recommended that the DbEnv handle used to invoke the `DbEnv::failchk()` method not be shared and therefore not free-threaded.

The `DbEnv::failchk()` method may not be called by the application before the DbEnv::open() method is called.

The `DbEnv::failchk()` 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.

### Parameters

#### flags

The flags parameter is currently unused, and must be set to 0.

### Errors

The `DbEnv::failchk()` 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:

#### EINVAL

An invalid flag value or parameter was specified.

### Class

DbEnv

### See Also

Database Environments and Related Methods

Prev | Up | Next
DbEnv::err() | Home | DbEnv::fileid_reset()