An Introduction to Lore's Transactions, Multi-user Support, Concurrency Control and Logging/Recovery

The following descriptions assumes a basic understanding of the transaction management concepts as described in any introduction to database systems. Readers unfamiliar with these concepts are asked to read such a book before continuing.

Developers, please read the implementation notes on concurrency control and DietLore for more information.

Content

  1. What is the difference between Lore and DietLore?
  2. Transactions
  3. Logging & Recovery
  4. Lore
    1. Lore multi-user support
    2. Concurrency Control
    3. Logging & Recovery
    4. Utilities
  5. DietLore
    1. Logging & Recovery
    2. Utilities
  6. Examples
    1. Command Line Interface
    2. Application Programming Interface (API)


1. What is the difference between Lore and DietLore?

Currently, Lore provides multi-user support on same platform databases. The multi-user support consists of concurrency control and the ability to lock databases in single-user mode and to enforce this lock. In order to provide these functionalities, the implementation relies on operating system semaphores, shared memory (implemented via mapped files) and shared memory semaphores. Due to the various differences in operating systems, Lore is currently only available for a limited number of platforms and will only be ported to a new platform if necessary.

DietLore is a single-user version of Lore which does not provide any multi-user functionality. Concurrency control is not available and while DietLore assumes a single-user mode, it does not prohibit several connections to the same database. It is supposed to be available on a larger number of platforms than Lore and could easily be ported to new platforms.

Both implementations provide transactions and support logging and recovery. While Lore provides atomicity, consistency, isolation and durability for its transactions, DietLore only provides atomicity and durability.

At the moment a database generated with Lore cannot be used with DietLore or viceversa.


2. Transactions

As mentioned above, both Lore versions support transactions. This section describes the general usage of transactions, while the apects which are more specific to a particular Lore version are discussed in the relevant sections below.

When connecting to a database, a system transaction will perform the startup operations before the first user transaction of this connection is automatically opened. A user then performs queries and updates on the database and can finish a transaction by either committing it (the transaction finishes successfully) or by aborting it (the transaction finishes unsuccessfully and all work performed during this transaction is undone). After finishing a transaction, the system automatically opens a new transaction. When the user disconnects, the currently open transaction is committed before the cleanup is performed during a system transaction.

The Lore API provides the following transaction related commands:

The command line interface lore provides the following two transaction modi:

The utilities dbcreate, dbload2, and dbrecover all run within a single transaction.


3. Logging & Recovery

This section describes the logging and recovery common to both Lore versions. See their individual sections for version specific features.

In order to be able to abort transactions and perform recovery, both Lore versions write page based undo and redo log records. The currently implemented logging and recovery allows to recover from application program, database engine and operating system failures, but it does not provide recovery from media failures.

In order to flush the data and log buffer to disk and therefore avoid long recovery phases, the user can set a checkpoint with the API function LoreConnection::ChkPt(); or the command line interface command ChkPt;. Flushing the database or disconnecting from a database automatically sets a checkpoint.

dbrecover is provided for performing database recoveries. For both Lore versions it reinitialises the database and performs recovery by redoing all transactions starting at last checkpoint and then undoing all active transactions. Finally, the garbage collector is called and the log file is deleted.

The utility logshow [-i sec] dbname dumps the log file and log manager status. -i sec specifies the interval for repeating the dump in seconds. If it is not specified the utility dumps the current snapshot.


4. Lore

This section describes the full version of Lore.

4.1 Lore multi-user support

Lore can be used in multi-user (default) or single-user mode. If there is already a connection to the database, the single-user mode connection will fail.

Users of the command line interface lore can connect in single-user mode with the command line flag -s. Note that this flag is only available with Lore.

Example: lore -s mydatabase connects in single-user mode.

Users of the API can set the brt_flag to FALSE if they want to connect in single-user mode. The default is TRUE and connects in multi-user mode.

Example:
LoreConnection lc.Connect("mydatabase", NULL, FALSE); connects in single-user mode, while
LoreConnection lc.Connect("mydatabase", NULL); connects in multi-user mode.

Some of the utilities request single-user mode.

4.2 Concurrency Control

Lore's concurrency control operates on the page level and uses a strict two phase locking protocol with a timeout based deadlock detection. The concurrency control mechanism allows several readers on the same page, but if a transaction locks a page for writing, no concurrent readers or writers are allowed on this page until the transaction holding the lock finishes. If a lock cannot be granted after a certain amount of time, a deadlock is assumed and the waiting transaction is aborted.

While the user performs queries and updates on the database, the concurrency control automatically issues the correct locks for the affected pages. The lock of a page which is read by one statement within a transaction and then later written by another statement of the same transaction is automatically upgraded if no other transactions possesses a read-lock on this page. All locks are automatically release when finishing the transaction.

4.3 Logging & Recovery

See the general description.

4.4 Utilities

All the utilities which run within a transaction are automatically handled by the concurrency control.

dbdestroy and dbrecover both request a single-user connection. In both cases, a already existing lock on the database can be overwritten. This is useful, if the database crashed and the system keeps a lock for the failed connection, otherwise be very careful when overwriting another database lock.

In addition to the above mentioned tasks, the Lore version dbrecover utility also removes OS semaphores, deletes mapped files for buffer and lock manager, resets log semaphores and finally deletes the buffer file.

The following additional utilities are available for the full Lore version:

lshow [-i sec] dbname

bufshow [-i sec] dbname


5. DietLore

This section describes the DietLore specific features.

5.1 Logging & Recovery

See the general description for the basic information. In addition, DietLore allows to turn logging off at runtime on a per session basis. This of course disables transactions and the possibility to perform an abort (the transaction commands are still accepted but do nothing). The database will only be fully persistent after a checkpoint or after a disconnect.

Users of the command line interface lore and of the utilities dbcreate and dbload2 can turn off logging with the command line flag -nl. It is allowed to create and load a database without logging and then use it with logging turned on. Note that this flag is only available with DietLore.

Example: lore -nl mydatabase connects without logging.

Users of the API can set the brt_flag to FALSE if they want to turn off logging. The default is TRUE (logging enabled).

Example:
LoreConnection lc.Connect("mydatabase", NULL, FALSE); connects with logging disabled, while
LoreConnection lc.Connect("mydatabase", NULL); connects with logging turned on.

5.2 Utilities

As already mentioned, the utilities dbcreate and dbload2 allow to turn off logging. The utilities lshow and bufshow are not available.


6. Examples

6.1 Command Line Interface

The following shows a simple command line interface session with lore. Note that the example works for both the full Lore version and the DietLore version for which the example is shown. Bold is used to show the user's entries. Note that only the relevant verbose output is shown.

lore -v mydatabase


DietLORE (Version 1.0)
======================

Compiled at: Dec 10 1997 - 22:09:31

Compiler: g++
Operating system: Solaris
Processor: Sparc

[Locking disabled, Logging enabled, single user, verbose]

Transaction 1 started.
Transaction 1 committed.
Transaction 2 started.

LORE: Global!x := "This is a test";

LORE: select x;

Query result:

(2,(1,10)) Answer
(2,(1,1)) x This is a test

LORE: commit;
Transaction 2 committed.
Transaction 3 started.

LORE: Global!x := 6;

LORE: select x;

Query result:

(2,(1,20)) Answer
(2,(1,11)) x 6

LORE: abort;
Undo LSN 46708 (page <1122222,2> of ta 3)
Undo LSN 42564 (page <1122222,1> of ta 3)
Undo LSN 38420 (page <1122226,0> of ta 3)
Undo LSN 34276 (page <1122226,1> of ta 3)
Transaction 3 aborted.
Transaction 4 started.

LORE: select x;

Query result:

(2,(1,15)) Answer
(2,(1,1)) x This is a test

LORE: exit;
Transaction 4 committed.
Transaction 5 started.
Checkpoint set.
Checkpoint set.
Transaction 5 committed.

6.2 Application Programming Interface (API)

The following is an example for doing the same queries and updates using the API. Please note, that for improved presentation, the code which handles the result of queries is left away.

#include "loreapi.h"

...

LoreOem *oem;
LoreConnection lc;
LR r;

r = lc.Connect("mydatabase", NULL);
r = lc.Submit("Global!x := \"This is a test\";", &oem);
r = lc.Submit("select x;", &oem);
r = lc.Commit();
r = lc.Submit("Global!x := 6;", &oem);
r = lc.Submit("select x;", &oem);
r = lc.Abort();
r = lc.Submit("select x;", &oem);
r = lc.Disconnect();


Michael Rys < rys@db.stanford.edu >