Berkeley DB Reference Guide: Introduction
Description: Berkeley DB: An embedded database programmatic toolkit.
Keywords: embedded,database,programmatic,toolkit,b+tree,btree,hash,hashing,transaction,transactions,locking,logging,access method,access methods,java,C,C++

### Berkeley DB Reference Guide: Distributed Transactions |

# Introduction

Berkeley DB provides support for distributed transactions using a two-phase commit protocol via its txn_prepare and txn_recover interfaces. The txn_prepare function performs the first phase of a two-phase commit, flushing the log to disk, and associating a global transaction ID with the underlying Berkeley DB transaction. This global transaction ID should be used by the global transaction manager to identify the Berkeley DB transaction, and will be returned by the txn_recover function when it is called during recovery.

Distributed transactions are necessary whenever an application wants to transaction-protect data in multiple Berkeley DB environments, even if those environments are on the same machine. However, Berkeley DB does not perform distributed deadlock detection, therefore it is the responsibility of the application to ensure that accesses in different environments cannot deadlock (this can be accomplished through careful ordering of operations to the multiple environments), or by using the DB_LOCK_NOWAIT option and eventually abort transactions that have been waiting "too long" (where "too long" is determined by an application-specific timeout).

In order to use the two-phase commit feature of Berkeley DB, an application must either implement its own global transaction manager or use an XA-compliant transaction manager (as Berkeley DB can act as an XA-compliant resource manager).

When using distributed transactions, there is no way to perform hot backups of multiple environments and guarantee that the backups are global-transaction-consistent across these multiple environments. If backups are desired, then all write transactions should be suspended; that is, active write transactions must be allowed to complete and no new write transactions should be begun. Once there are no active write transactions, the logs may be copied for backup purposes and the backup will be consistent across the multiple environments.

Copyright Sleepycat Software