Library Version 12.1.6.0

DB_ENV->txn_recover()
Prev | Chapter 12. The DB_TXN Handle | Next

## DB_ENV->txn_recover()

    #include <db.h>

    int
    DB_ENV->txn_recover(DB_ENV *dbenv, DB_PREPLIST preplist[],
        long count, long *retp, u_int32_t flags);

Database environment recovery restores transactions that were prepared, but not yet resolved at the time of the system shut down or crash, to their state prior to the shut down or crash, including any locks previously held. The `DB_ENV->txn_recover()` method returns a list of those prepared transactions.

The `DB_ENV->txn_recover()` method should only be called after the environment has been recovered.

Multiple threads of control may call `DB_ENV->txn_recover()`, but only one thread of control may resolve each returned transaction, that is, only one thread of control may call DB_TXN->commit() or DB_TXN->abort() on each returned transaction. Callers of `DB_ENV->txn_recover()` must call DB_TXN->discard() to discard each transaction they do not resolve.

On return from `DB_ENV->txn_recover()`, the preplist parameter will be filled in with a list of transactions that must be resolved by the application (committed, aborted or discarded). The preplist parameter is a structure of type `DB_PREPLIST`; the following `DB_PREPLIST` fields will be filled in:

- DB_TXN * txn;

  The transaction handle for the transaction.

- u_int8_t gid[DB_GID_SIZE];

  The global transaction ID for the transaction. The global transaction ID is the one specified when the transaction was prepared. The application is responsible for ensuring uniqueness among global transaction IDs.

The `DB_ENV->txn_recover()` method returns a non-zero error value on failure and 0 on success.

### Parameters

#### preplist

The preplist parameter references memory into which the list of transactions to be resolved by the application is copied.

#### count

The count parameter specifies the number of available entries in the passed-in preplist array. The retp parameter returns the number of entries `DB_ENV->txn_recover()` has filled in, in the array.

#### flags

The flags parameter must be set to one of the following values:

- `DB_FIRST`

  Begin returning a list of prepared, but not yet resolved transactions. Specifying this flag begins a new pass over all prepared, but not yet completed transactions, regardless of whether they have already been returned in previous calls to `DB_ENV->txn_recover.()` Calls to `DB_ENV->txn_recover()` from different threads of control should not be intermixed in the same environment.

- `DB_NEXT`

  Continue returning a list of prepared, but not yet resolved transactions, starting where the last call to `DB_ENV->txn_recover()` left off.

### Class

DB_ENV, DB_TXN

### See Also

Transaction Subsystem and Related Methods

Prev | Up | Next
DB_ENV->set_tx_timestamp() | Home | DB_ENV->txn_begin()