dbTalk Databases Forums  

Bug in API docs?

comp.databases.berkeley-db comp.databases.berkeley-db


Discuss Bug in API docs? in the comp.databases.berkeley-db forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Ryan
 
Posts: n/a

Default Bug in API docs? - 08-03-2006 , 11:51 AM






Hi,

While testing out the memory pool API I encountered a bug in the
documentation for DbMpoolFile::get
(http://www.sleepycat.com/docs/api_cxx/memp_fget.html). In big bold
letters it explains that

"Page numbers begin at 0; that is, the first page in the file is page
number 0, not page number 1."

The C API says the same thing. However, the test program below seems to
argue otherwise. The first page written is 1, and trying to read page 0
fails. I'm running BDB v 4.4.20, x86, Linux.

Did I miss something?
Ryan

#include "db_cxx.h"
#include <cstdio>

static const size_t PAGE_SIZE = 512;

int main() {
DbEnv env(0);
// use a small number of pages
env.set_cachesize(0, PAGE_SIZE*4, 0);
env.set_tmp_dir("tmp");
env.set_msgfile(stdout);
env.open(NULL, DB_CREATE | DB_PRIVATE | DB_THREAD | DB_INIT_MPOOL,
0);


// open a file in the pool, set to delete on finish
DbMpoolFile* pool;
env.memp_fcreate(&pool, 0);
pool->set_flags(DB_MPOOL_UNLINK, true);
pool->open(NULL, DB_CREATE, 0644, PAGE_SIZE);

printf("<<<< Starting stats:\n");
env.memp_stat_print(DB_STAT_ALL);

const char* actions = "wwwwRwRwRRRR";
bool done = false;
db_pgno_t rpn=0, wpn;
void* p;
while(!done) {
switch(*(actions++)) {
case 'r':
case 'R':
pool->get(&rpn, 0, &p);
printf("\n\n<<<< Read page %d:\n", rpn);
// if(p)
pool->put(p, DB_MPOOL_CLEAN | DB_MPOOL_DISCARD);
rpn++;
break;
case 'w':
case 'W':
pool->get(&wpn, DB_MPOOL_NEW, &p);
printf("\n\n<<<< Wrote page %d:\n", wpn);
memset(p, 0, PAGE_SIZE);
memcpy(p, &wpn, sizeof(wpn));
pool->put(p, DB_MPOOL_DIRTY);
break;
default:
done = true;
}

env.memp_stat_print(0);
}

pool->close(0);
env.close(0);
return 0;
}


Reply With Quote
  #2  
Old   
Ryan
 
Posts: n/a

Default Re: Bug in API docs? - 08-03-2006 , 02:59 PM






Another couple points of potential confusion:

1. If you open a pool with a NULL file name it will be automatically
deleted independent of whether the DB_MPOOL_UNLINK flag is set. If
that's a feature it should probably be documented.

2. Calling close() on a temp file's pool handle will throw an ugly
exception. Fortunately unlink() refuses to delete directories! It might
be better to explicitly check for this condition and either silently
ignore it or return/throw a meaningful error message.

Ryan


Reply With Quote
  #3  
Old   
Ryan
 
Posts: n/a

Default Re: Bug in API docs? - 08-03-2006 , 03:29 PM



Update: It turns out that close() only fails if you specify
DB_MPOOL_UNLINK on a temp file.

Ryan

Ryan wrote:
Quote:
Another couple points of potential confusion:

1. If you open a pool with a NULL file name it will be automatically
deleted independent of whether the DB_MPOOL_UNLINK flag is set. If
that's a feature it should probably be documented.

2. Calling close() on a temp file's pool handle will throw an ugly
exception. Fortunately unlink() refuses to delete directories! It might
be better to explicitly check for this condition and either silently
ignore it or return/throw a meaningful error message.

Ryan


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.