Berkeley DB Reference Guide:
Sequences

PrevRefNext

Introduction

Sequences provide an arbitrary number of persistent objects that return an increasing or decreasing sequence of integers. Opening a sequence handle associates it with a record in a database. The handle can maintain a cache of values from the database so that a database update is not needed as the application allocates a value.

A sequence is stored as a record pair in a database. The database may be of any type, but may not have been configured to support duplicate data items. The sequence is referenced by the key used when the sequence is created, therefore the key must be compatible with the underlying access method. If the database stores fixed-length records, the record size must be at least 64 bytes long.

Since a sequence handle is opened using a database handle, the use of transactions with the sequence must follow how the database handle was opened. In other words, if the database handle was opened within a transaction, operations on the sequence handle must use transactions. Of course, if sequences are cached, not all operations will actually trigger a transaction.

For the highest concurrency, caching should be used and the DB_AUTO_COMMIT and DB_TXN_NOSYNC flags should be specified to the DB_SEQUENCE->get method call. If the allocation of the sequence value must be part of a transaction, and rolled back if the transaction aborts, then no caching should be specified and the transaction handle must be passed to the DB_SEQUENCE->get method.

Sequences and Related MethodsDescription
db_sequence_createCreate a sequence handle
DB_SEQUENCE->closeClose a sequence
DB_SEQUENCE->getGet the next sequence element(s)
DB_SEQUENCE->get_dbpReturn a handle for the underlying sequence database
DB_SEQUENCE->get_keyReturn the key for a sequence
DB_SEQUENCE->init_valueSet the initial value of a sequence
DB_SEQUENCE->openOpen a sequence
DB_SEQUENCE->removeRemove a sequence
DB_SEQUENCE->statReturn sequence statistics
Sequences Configuration
DB_SEQUENCE->set_cachesizeSet the cache size of a sequence
DB_SEQUENCE->set_flagsSet the flags for a sequence
DB_SEQUENCE->set_rangeSet the range for a sequence

PrevRefNext

Copyright (c) 1996-2004 Sleepycat Software, Inc. - All rights reserved.