dbm_store() returns -1, but no specific error is reported
dbm_store() returns -1, but no specific error is reported
- Subject: dbm_store() returns -1, but no specific error is reported
- From: "Christian Moen" <email@hidden>
- Date: Thu, 29 Nov 2007 01:45:34 +0900
darwin-dev,
I'm experiencing strange behaviour with DBM on a Mac OS X 10.5.1 (both
on G5 and Intel) and it would be great to get some feedback from the
list on what the problem might be.
The program below is storing 200 byte records into a hash with an
incrementing numeric string key using dbm_store(). However, at insert
(and key) number 232783, dbm_store() returns -1, which indicates
failure. However, errno is 0 and dbm_error() also returns 0, so the
error itself seems unspecified.
I believe the DBM implementation on Mac OS X is Berkeley DB
(http://www.opensource.apple.com/darwinsource/10.5/BerkeleyDB-15/).
I've heard that some people have had problems with databases becoming
corrupt after millions of store and fetch operations under heavy loads
with the implementations available at around year 2000. These people
also recommend against using Berkeley DB in general.
Feedback on the problem with the below program and the overall
suitability of the Berkeley DB implementation in Leopard is mostly
appreciated. Thanks.
Christian
#include <stdio.h>
#include <string.h>
#include <ndbm.h>
#include <errno.h>
#include <assert.h>
#define NUM_RECORDS 250000
#define MAX_KEY_SIZE 10
#define MAX_VALUE_SIZE 200
int main (int argc, const char * argv[]) {
DBM *db;
int i;
db = dbm_open("/tmp/testdb", O_RDWR | O_CREAT, 0660);
assert(db != NULL);
for (i = 0; i < NUM_RECORDS; i++) {
char key[MAX_KEY_SIZE];
char value[MAX_VALUE_SIZE];
datum k;
datum v;
int status;
memset(key, '\0', MAX_KEY_SIZE);
snprintf(key, MAX_KEY_SIZE, "%d", i);
k.dptr = key;
k.dsize = strlen(key);
memset(value, 'A', MAX_VALUE_SIZE);
v.dptr = value;
v.dsize = MAX_VALUE_SIZE;
status = dbm_store(db, k, v, DBM_REPLACE);
if (status != 0) {
fprintf(stderr, "key: %s, status: %d, errno=%d,
strerrno=%s, dbm_error=%d\n",
k.dptr, status, errno, strerror(errno), dbm_error(db));
return 1;
}
}
dbm_close(db);
return 0;
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden