dbTalk Databases Forums  

Is DB_HASH support broken in BerkeleyDB 4.6.19 ?

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


Discuss Is DB_HASH support broken in BerkeleyDB 4.6.19 ? in the comp.databases.berkeley-db forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Gregory P. Smith
 
Posts: n/a

Default Is DB_HASH support broken in BerkeleyDB 4.6.19 ? - 09-08-2007 , 06:31 PM






On both Linux and Mac OS X 10.4.9 the following simple code to write
values into a DB_HASH database locks up when compiled with BerkeleyDB
4.6.19. It works fine when compiled against 4.5. Why?


#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <db.h>

int main()
{
DB_ENV *db_env = NULL;
DB *db = NULL;
char *db_home;
char tmpstr[128];
char keystr[5];
char datastr[30];
DBT key = { 0 };
DBT data = { 0 };
int err, x;

strncpy(tmpstr, "/tmp/cdbtest.XXXXXX", sizeof(tmpstr)-1);
db_home = mkdtemp(tmpstr);
printf("running in %s.\n", db_home);

err = db_env_create(&db_env, 0);
if (err) { printf("a: %s\n", db_strerror(err)); goto errorexit; }
err = db_env->open(db_env, db_home,
DB_CREATE | DB_THREAD | DB_INIT_CDB | DB_INIT_MPOOL,
0660);
if (err) { printf("b: %s\n", db_strerror(err)); goto errorexit; }
err = db_create(&db, db_env, 0);
if (err) { printf("c: %s\n", db_strerror(err)); goto errorexit; }
err = db->open(db, NULL, "cdbtest", NULL, DB_HASH, DB_CREATE |
DB_THREAD, 0660);
if (err) { printf("d: %s\n", db_strerror(err)); goto errorexit; }
for (x = 0; x < 1000; ++x) {
snprintf(keystr,sizeof(keystr),"%04x",x);
key.data = keystr;
key.size = strlen(keystr);

snprintf(datastr,sizeof(datastr),"%04x-%04x-%04x-%04x-
%04x",x,x,x,x,x);
data.data = datastr;
data.size = strlen(datastr);

err = db->put(db, NULL, &key, &data, 0);
if (err) { printf("e: %s\n", db_strerror(err)); goto
errorexit; }
if (x % 50 == 0)
printf("put with x = %d\n", x);
}
db->close(db, 0);
db_env->remove(db_env, db_home, DB_FORCE);
printf("done.\n");
printf("remember to rm -r %s\n", db_home);

return 0;

errorexit:
if (db)
db->close(db, 0);
if (db_env)
db_env->remove(db_env, db_home, DB_FORCE);
return 1;
}


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.