|
![]() ![]()
|
The Berkeley DB Btree, Queue and Recno access methods can operate on logical record numbers. Record numbers are 1-based, not 0-based, that is, the first record in a database is record number 1.
(DB Btree, Queue, Recno 액세스메소드는 논리적인 레코드번호로 작동가능하다.레코드번호는 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 methods 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.
(Queue , Recno의 모든경우와 Btree의 DB->get ,DBcursor->c_get를 DB_SET_RECNO flag로 설정후 호출할때 DBT의 data필드는 항상 db_recno_t 타입의 메모리 위치를 가르켜야 한다.DBT 의 size 필드는 타입의 크기로 설정된다.32bit unsigned 타입인 db_recno_t 은 으로 Queue 또는 Recno 의 논리적인 레코드번호의 한계번호이고 또한 BTree로 부터 직접 얻을수있는 논리적레코드 수의 최대값이다.이값의 최대값은 즉 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 methods will return the system error EFBIG.
(Queue의 레코드번호는 원형적이다.즉 Queue의 레코드번호가 최대값에 도달할때 추가되는 다음레코드의 번호는 1이된다.만약 해드가 큐의 테일을 따라잡게 되면 EFBIG를 리턴한다.)
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.
(Recno 의 레코드번호는 변화또는 고정모드로 설정될수 있다.변화모드에서는 레코드가 삭제또는 삽입될때 레코드번호가 변하게 된다.고정모드에서는 레코드번호는 변화하지 않는다.Btree의 레코드번호는 항상 변화모드다.그리고 레코드가 삭제,추가될때 데이타베이스에 있는 다른 레코드의 번호도 변하게 된다.)
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. 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.
(Btree가 레코드넘버를 지원하도록 설정하는것은 쓰레드를 사용하는 애플리케이션의 처리량을 감소시킨다.왜냐하면 레코드카운트를 저장하기 위해 사용되는 저장위치가 여러 쓰레드에 의해 업데이트되야 하기때문이다.데이타아이템의 복사를 지원하는 Btree의 경우 논리적인 레코드번호는 하나의 키와 이 키의 모든 데이타아이템을 참조하고 복사된 데이타아이템은 개별적으로 번호가 매겨지지 않는다.)
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.
(다음의 예제는 표준입력으로부터 레코드를 읽고 Recno에 레코드를 저장한다.또한 커서를 사용하여 데이타베이스를 이동하고 저장된 레코드를 디스플레이한다.)
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);
}
![]() ![]()
|
Copyright (c) 1996-2003 Sleepycat Software, Inc. - All rights reserved.