Advanced Programming in the UNIX® Environment

(lily) #1
ptg10805159

744 ADatabase Library Chapter 20


provided in SVR4’s BSD-compatibility library [AT&T 1990c]. The BSD developers
extended thedbmlibrary and called itndbm.Thendbmlibrary was included in BSD as
well as in SVR4. Thendbmfunctions arestandardized in the XSI option of the Single
UNIX Specification.
Seltzer and Yigit[ 1991 ]provide a detailed history of the dynamic hashing algorithm
used by thedbmlibrary and other implementations of this library,includinggdbm,the
GNU version of the dbm library.Unfortunately,abasic limitation of all these
implementations is that none allows concurrent updating of the database by multiple
processes. These implementations provide no type of concurrency controls (such as
recordlocking).
4.4BSD provided a newdb(3) library that supports three forms of access: (a) record
oriented, (b) hashing, and (c) a B-tree. Again, no form of concurrency was provided (as
was plainly stated in the BUGS section of thedb(3) manual page).

Oracle (http://www.oracle.com)provides versions of thedblibrary that do support
concurrent access, locking, and transactions.

Most commercial database libraries do provide the concurrency controls required
for multiple processes to update a database simultaneously.These systems typically
use advisory locking, as we described in Section 14.3, but they often implement their
own locking primitives to avoid the overhead of a system call to acquire an uncontested
lock. These commercial systems usually implement their database using B+ trees
[Comer 1979]or some dynamic hashing technique, such as linear hashing[Litwin 1980]
or extendible hashing [Fagin et al. 1979].
Figure20.1 summarizes the database libraries commonly found in the four
operating systems described in this book. Note that on Linux, the gdbm library
provides support for bothdbmandndbmfunctions.

FreeBSD Linux Mac OS X Solaris
Library POSIX.1 8.0 3.2.0 10.6.8 10

dbm gdbm •
ndbm XSI • gdbm ••
db •••

Figure 20.1 Support for database libraries on various platforms

20.3 The Librar y


The library we develop in this chapter will be similar to thendbmlibrary,but we’ll add
the concurrency control mechanisms to allow multiple processes to update the same
database at the same time.We first describe the C interface to the database library,then
in the next section describe the actual implementation.
When we open a database, we arereturned a handle (an opaque pointer)
representing the database.We’ll pass this handle to the remaining database functions.
Free download pdf