/usr/lib/swipl/library/ext/bdb/bdb.pl
All Application Manual Name SummaryHelp

  • bdb
    • bdb.pl -- Berkeley DB interface
      • bdb_init/1
      • bdb_init/2
      • bdb_close_environment/1
      • bdb_current_environment/1
      • bdb_environment_property/2
      • bdb_open/4
      • bdb_close/1
      • bdb_put/3
      • bdb_del/3
      • bdb_delall/3
      • bdb_get/3
      • bdb_enum/3
      • bdb_getall/3
      • bdb_current/1
      • bdb_closeall/0
      • bdb_transaction/1
      • bdb_transaction/2
      • bdb_version/1
 bdb_transaction(:Goal) is semidet
 bdb_transaction(+Environment, :Goal) is semidet
Start a transaction, execute Goal and terminate the transaction. Only if Goal succeeds, the transaction is commited. If Goal fails or raises an exception, the transaction is aborted and bdb_transaction/1 either fails or rethrows the exception. Of special interest is the exception
error(package(db, deadlock), _)

This exception indicates a deadlock was raised by one of the DB predicates. Deadlocks may arise if multiple processes or threads access the same keys in a different order. The DB infra-structure causes one of the processes involved in the deadlock to abort its transaction. This process may choose to restart the transaction.

For example, a DB application may define {Goal} to realise transactions and restart these automatically is a deadlock is raised:

{Goal} :-
    catch(bdb_transaction(Goal), E, true),
    (   var(E)
    ->  true
    ;   E = error(package(db, deadlock), _)
    ->  {Goal}
    ;   throw(E)
    ).
Arguments:
Environment- defines the environment to which the transaction applies. If omitted, the default environment is used. See bdb_init/1 and bdb_init/2.