+I$Berkeley DB: txn_open[P

txn_open





#include <db.h>

int*txn_open(const char *dir, u_int32_t flags,2 int mode, DB_ENV *dbenv, DB_TXNMGR **regionp);





Description

The txn_openYfunction copies a pointer, to the "transaction region" identified by the directoryBdir, into the memory location referenced by regionp.

The;dir pathname argument is interpreted as described in@Berkeley DB File Naming.

KThe flags and mode arguments specify how files will be opened,and/or created if they do not already exist.SThe flags value is specified by logically OR'ing together one or more of thefollowing values:

[

DB_CREATE
Create any underlying files, as necessary. If the files do not alreadyBexist and the DB_CREATE flag is not specified, the call will fail.X

DB_THREAD
Cause the m4_reg(DbTxnMgr) handle returned by txn_open to be useable>by multiple threads within a single address space, i.e., to befree-threaded.R

DB_TXN_NOSYNC
On transaction commit, do not synchronously flush the log.HThis means that transactions exhibit the ACI (atomicity, consistency andGisolation) properties, but not D (durability), i.e., database integrityBwill be maintained but it is possible that some number of the mostHrecently committed transactions may be undone during recovery instead of being redone.

FThe number of transactions that are potentially at risk is governed bylhow often the log is checkpointed (see db_checkpoint for moreCinformation) and how many log updates can fit on a single log page.



^All files created by the transaction subsystem are created with mode mode (as describedHin chmod(2)) and modified by the process' umask value at the time$of creation (see umask(2)))).IThe group ownership of created files is based on the system and directory6defaults, and is not further specified by Berkeley DB.

'The transaction subsystem is configuredDbased on the dbenv argument to txn_open which is a pointer toFa structure of type DB_ENV. Applications normally use the same DB_ENVkstructure (initialized by db_appinit) as an argument to all of*the subsystems in the Berkeley DB package.

OReferences to the DB_ENV structure are maintained by Berkeley DB, so it may notDbe discarded until the last close function, corresponding to an open?function for which it was an argument, has returned. To ensureKcompatibility with future releases of Berkeley DB, all fields of the DB_ENVGstructure that are not explicitly set should be initialized to 0 beforeIthe first time the structure is used. Do this by declaring the structure?external or static, or by calling one of the C library routines$bzero(3) or memset(3).

HThe fields of the DB_ENV structure used by txn_open are described below.CIf dbenv is NULL or any of its fields are set to 0, defaults3appropriate for the system are used where possible.

FThe following fields in the DB_ENV structure may be initialized beforecalling txn_open:

>

void *(*db_errcall)(char *db_errpfx, char *buffer);

FILE *db_errfile;

const char *db_errpfx;
int db_verbose;
The error fields of the DB_ENV behave as described for db_appinit.b

DB_LOG *lg_info;
The logging region that is being used for this transaction environment.vThe lg_info field contains a return value from the log_open function.4Logging is required for transaction environments,7and it is an error to not specify a logging region.f

DB_LOCKTAB *lk_info;
The locking region that is being used for this transaction environment.{The lk_info field contains a return value from the lock_open function.AIf lk_info is NULL, no locking is done in this transaction environment._

u_int32_t tx_max;
The maximum number of simultaneous transactions that are supported.FThis bounds the size of backing files and is used to derive limits for)the size of the lock region and logfiles.HWhen there are more than tx_max concurrent transactions, calls toXtxn_begin may cause backing files to grow./If tx_max is 0, a default value is used.

Áint (*tx_recover)(DB_LOG *logp, DBT *log_rec, DB_LSN *lsnp, int redo, void *info);
A function that is called by txn_abort during transaction abort.#This function takes five arguments:
;

logp
A pointer to the transaction log (DB_LOG *).

log_rec
A log record.=

lsnp
A pointer to a log sequence number (DB_LSN *).K

redo
An integer value that is set to one of the following values:
g

DB_TXN_BACKWARD_ROLL
The log is being read backward to determine which transactions have beenJcommitted and which transactions were not (and should therefore be abortedduring recovery).c

DB_TXN_FORWARD_ROLL
The log is being played forward, any transaction ids encountered that1have not been entered into the list referenced byinfo should be ignored.d

DB_TXN_OPENFILES
The log is being read to open all the files required to perform recovery.E

DB_TXN_REDO
Redo the operation described by the log record.E

DB_TXN_UNDO
Undo the operation described by the log record.
Z

info
An opaque pointer used to reference the list of transaction IDs encounteredduring recovery.


PIf tx_recover is NULL, the default is that only Berkeley DB access methodFoperations are transaction protected, and the default recover function will be used.



The txn_openHfunction returns the value of errno on failure, and 0 on success.

Environment Variables



P

DB_HOME
If the dbenv argument to txn_open was initialized usingcdb_appinit the environment variable DB_HOME mayBbe used as the path of the database home for the interpretation ofthe dir argument.


U

TMPDIR
If the dbenv argument to txn_open was NULL or not initializedhusing db_appinit the environment variable TMPDIR maySbe used as the directory in which to create the transaction region, as described in txn_open.




Errors

QIf a fatal error occurs in Berkeley DB, the txn_open function may fail and returnFDB_RUNRECOVERY, at which point all subsequent database calls will alsoreturn DB_RUNRECOVERY.

The txn_open)function may fail and return errnoKfor any of the errors specified for the following Berkeley DB and C library functions: abort(3), close(3),8db_version, fcntl(3), fflush(3), fprintf(3),free(3), fstat(3), fsync(3), getenv(3), getpid(3), getuid(3), isdigit(3), lseek(3), malloc(3), memcpy(3), memset(3),mmap(3), munmap(3),open(3),pstat_getdynamic(3),read(3), shmat(3),S shmctl(3), shmdt(3),!sigfillset(3),sigprocmask(3), stat(3), strerror(3), strlen(3), sysconf(3),btime(3),:txn_unlink, unlink(3), vfprintf(3), vsnprintf(3),:andm write(3).b

rIn addition, the txn_opent)function may fail and return errnoefor the following conditions:r

R

EAGAIN
The shared memory region was locked and (repeatedly) unavailable.
/
B

EINVAL
An invalid flag value or parameter was specified.

&FThe DB_THREAD flag was specified and spinlocks are not implemented forthis architecture.

M$The dbenv parameter was NULL.

o

>

See Also

c5txn_abort,t8txn_begin,Btxn_checkpoint,8txn_close,7txn_commit,p/txn_id,e txn_open,l9txn_prepare,x5txn_statband :txn_unlink.
nRpÿÿdt>DB_CREATE
Create any underlying files, as necessary. If the files do not alreadyBexist and the DB_CREATE flag is not specified, the call will fail.X

DB_THREAD
Cause the m4_reg(DbTxnMgr)