+I8Berkeley DB Reference Guide: Architecture[P2

Berkeley DB Reference Guide: Architecture



%

The big picture



FSo far, we've discussed applications that used only the Access Methods@for fast data storage and retrieval. Application code that uses0Berkeley DB in this way might appear as follows:



>The underlying Berkeley DB architecture that supports this is:

(



FAs you can see from this diagram, the application makes calls into theGAccess Methods, and the Access Methods use the underlying shared memory=buffer cache to hold recently used file pages in main memory.

DThe previous chapters in this Guide have described applications thatJuse only the Access Methods. The subsequent chapters will describe how to:build more complex applications that include full databaseErecoverability. However, writing recoverable applications requires aIsmall amount of additional complexity in the application, and quite a bit4of additional complexity in the Berkeley DB library.

HThe additional complexity in the application is that calls to the AccessEMethods must be wrapped in transaction begin and end calls, i.e., theLapplication must inform Berkeley DB where to begin and end transactions, andHmust be prepared for the possibility that it may not be possible to makeHa specific change to the database at any particular time (e.g., that thetransaction can abort).

HA typical example of transaction protected code might appear as follows:





EIn this example, the same operation is being done as before, however,Dit is wrapped in transaction calls. The transaction is started with>txn_begin, and finished with txn_commit. If theHoperation fails due to a deadlock, then the transaction is aborted usingBtxn_abort, and the operation is retried from the beginning.

OThere are five major subsystems in Berkeley DB: the Access Methods, the Memory/Buffer Pool, Transactions, Locking and Logging.

6Here is a complete picture of the Berkeley DB package:

&



HThe application makes calls to the Access Methods and to the TransactionHsubsystem. The Access Methods and Transaction subsystem make calls intoJthe Buffer Pool, Locking and Logging regions on behalf of the application.

GWhile each of the underlying subsystems (Lock, Log and Buffer Pool) canGbe called separately (e.g., the Buffer Pool subsystem can be used apartPfrom the rest of Berkeley DB by applications simply wanting shared memory bufferIpool functionality), most applications will either use the Access MethodsJonly, or the Access Methods wrapped in calls to the Transaction interfacesIif they need database recoverability in the face of application or systemfailure.

JAGÿÿ