head 1.2; access; symbols RPM_4_2_1:1.1.1.5 RPM_4_2:1.1.1.5 RPM_4_1_1:1.1.1.5 RPM_4_1:1.1.1.4 RPM_4_0_5:1.1.1.3 RPM_4_0_4:1.1.1.2 RPM_4_0_3:1.1.1.1 RPM:1.1.1; locks; strict; comment @# @; 1.2 date 2008.01.02.09.54.42; author rse; state dead; branches; next 1.1; commitid z4cpSiAhOCXk5PLs; 1.1 date 2001.07.23.20.45.37; author rse; state Exp; branches 1.1.1.1; next ; 1.1.1.1 date 2001.07.23.20.45.37; author rse; state Exp; branches; next 1.1.1.2; 1.1.1.2 date 2002.01.08.00.30.11; author rse; state Exp; branches; next 1.1.1.3; 1.1.1.3 date 2003.01.18.13.49.01; author rse; state Exp; branches; next 1.1.1.4; 1.1.1.4 date 2001.12.06.00.08.14; author rse; state Exp; branches; next 1.1.1.5; 1.1.1.5 date 2003.01.18.14.04.59; author rse; state Exp; branches; next ; desc @@ 1.2 log @remove the ancient RPM 4.2.1 source tree copy @ text @ Berkeley DB Reference Guide: Logical record numbers

Berkeley DB Reference Guide:
Access Methods

PrevRefNext

Logical record numbers

The Berkeley DB Btree, Queue and Recno access methods can operate on logical record numbers. Logical record numbers are 1-based, not 0-based, that is, the first record in the database is record number 1. In all cases for the Queue and Recno access methods, and when calling the Btree access method using the DB->get and DBcursor->c_get functions with the DB_SET_RECNO flag specified, the data field of the key must be a pointer to a memory location of type db_recno_t, as typedef'd in the standard Berkeley DB include file. This type is a 32-bit unsigned type, which limits the number of logical records in a Queue or Recno database, and the maximum logical record which may be directly retrieved from a Btree database, to 4,294,967,295. The size field of the key should be the size of that type, for example, in the C programming language, sizeof(db_recno_t). In the case of Btree supporting duplicate data items, the logical record number refers to a key and all of its data items.

Record numbers in Recno databases can be configured to run in either mutable or fixed mode: mutable, where logical record numbers change as records are deleted or inserted, and fixed, where record numbers never change regardless of the database operation. Record numbers in Queue databases are always fixed, and never change regardless of the database operation. Record numbers in Btree databases are always mutable, and as records are deleted or inserted, the logical record number for other records in the database can change. See Logically renumbering records for more information.

Configuring Btree databases to support record numbers can severely limit the throughput of applications with multiple concurrent threads writing the database, because locations used to store record counts often become hot spots that many different threads all need to update.

The following is an example function that reads records from standard input and stores them into a Recno database. The function then uses a cursor to step through the database and display the stored records.

int
recno_build(dbp)
	DB *dbp;
{
	DBC *dbcp;
	DBT key, data;
	db_recno_t recno;
	u_int32_t len;
	int ret;
	char buf[1024];

/* Insert records into the database. */ memset(&key, 0, sizeof(DBT)); memset(&data, 0, sizeof(DBT)); for (recno = 1;; ++recno) { printf("record #%lu> ", (u_long)recno); fflush(stdout); if (fgets(buf, sizeof(buf), stdin) == NULL) break; if ((len = strlen(buf)) <= 1) continue;

key.data = &recno; key.size = sizeof(recno); data.data = buf; data.size = len - 1;

switch (ret = dbp->put(dbp, NULL, &key, &data, 0)) { case 0: break; default: dbp->err(dbp, ret, "DB->put"); break; } } printf("\n");

/* Acquire a cursor for the database. */ if ((ret = dbp->cursor(dbp, NULL, &dbcp, 0)) != 0) { dbp->err(dbp, ret, "DB->cursor"); return (1); }

/* Re-initialize the key/data pair. */ memset(&key, 0, sizeof(key)); memset(&data, 0, sizeof(data));

/* Walk through the database and print out the key/data pairs. */ while ((ret = dbcp->c_get(dbcp, &key, &data, DB_NEXT)) == 0) printf("%lu : %.*s\n", *(u_long *)key.data, (int)data.size, (char *)data.data); if (ret != DB_NOTFOUND) dbp->err(dbp, ret, "DBcursor->get");

/* Close the cursor. */ if ((ret = dbcp->c_close(dbcp)) != 0) { dbp->err(dbp, ret, "DBcursor->close"); return (1); } return (0); }


PrevRefNext

Copyright Sleepycat Software @ 1.1 log @Initial revision @ text @d1 1 a1 1 @ 1.1.1.1 log @Import: RPM 4.0.3 @ text @@ 1.1.1.2 log @Import: RPM 4.0.4 @ text @d1 1 a1 1 d19 14 a32 18 record numbers. Record numbers are 1-based, not 0-based, that is, the first record in a database is record number 1.

In all cases for the Queue and Recno access methods, and when calling the Btree access method using the DB->get and DBcursor->c_get functions with the DB_SET_RECNO flag specified, the data field of the key DBT must be a pointer to a memory location of type db_recno_t, as typedef'd in the standard Berkeley DB include file. The size field of the key DBT should be the size of that type (for example, "sizeof(db_recno_t)" in the C programming language). The db_recno_t type is a 32-bit unsigned type, which limits the number of logical records in a Queue or Recno database, and the maximum logical record which may be directly retrieved from a Btree database, to 4,294,967,295.

Record numbers in Queue databases wrap around. When the tail of the queue reaches the maximum record number, the next record appended will be given record number 1. If the head of the queue ever catches up to the tail of the queue, the Berkeley DB interface will return the system error EFBIG. d46 1 a46 4 hot spots that many different threads all need to update. In the case of a Btree supporting duplicate data items, the logical record number refers to a key and all of its data items, as duplicate data items are not individually numbered. @ 1.1.1.3 log @Import: RPM 4.0.5 @ text @d1 2 a2 2 a3 1 d22 1 a22 1 the Btree access method using the DB->get and DBcursor->c_get methods d24 1 a24 1 the key DBT must be a pointer to a memory location of type d26 1 a26 1 The size field of the key DBT should be the size of that @ 1.1.1.4 log @Import: RPM 4.1 @ text @d1 2 a2 2 d4 1 d23 1 a23 1 the Btree access method using the DB->get and DBcursor->c_get functions d25 1 a25 1 the key DBT must be a pointer to a memory location of type d27 1 a27 1 The size field of the key DBT should be the size of that @ 1.1.1.5 log @Import: RPM 4.1.1 @ text @d1 2 a2 2 a3 1 d22 1 a22 1 the Btree access method using the DB->get and DBcursor->c_get methods d24 1 a24 1 the key DBT must be a pointer to a memory location of type d26 1 a26 1 The size field of the key DBT should be the size of that @