mcBegin — Begin a New Transaction (C API)
#include <memcom.h> int mcBegin(int handle, const char* mode, const char* sname);
mcBegin
ends any previously started
transaction and attempts to start a new transaction, if
handle
represents a remote database. In the case
of a local database, mcBegin
always returns
immediately. If the database is remote, the server may block until
it is safe for the client to access the database. An
mcBegin
is issued implicitely during
mcDBopenFile
or
mcDBopenFileBuffered
to a remote
database.
handle
Database handle (input).
mode
Access mode. r
means read access,
a
means adding new datasets, and
w
means adding new and modifying existing
datasets. Note that the access mode of a transaction has a
significant influence on the efficiency of concurrent
access.
sname
Name of a dataset which should be present before the
transaction can start. If sname
is NULL,
it will be ignored. If sname
is not NULL
and the dataset does not exist in the remote database, the
transaction remains blocked until another transaction, which
created sname
, terminates.
A transaction is a set of operations which act (read, write) on a set of resources (in this case the datasets of the database). Transactions are the only way to ensure database consistency and correct program operation if non-cooperative tasks access the set of resources (here: multiple MemCom client programs accessing the same remote database). For reasons of efficiency, MemCom cannot fully provide the required semantics for transactions. A real transaction must have the following properties:
Atomicity: Either all operations are reflected in the database or none is.
Consistency: Execution of a transaction in isolation preserves the consistency of the database.
Isolation: To each transaction it appears as if it was executing in isolation, although there may be other transactions executing in parallel.
Durability: After a transaction completes successfully, the changes it has made to the database persist, even if there are system failures.
MemCom only guarantees the consistency and isolation properties, which is sufficient to ensure database consistency, provided that all of the tasks (programs) accessing the database are programmed correctly. MemCom cannot restore database consistency if a task fails.