diff options
Diffstat (limited to 'lib/db3.c')
-rw-r--r-- | lib/db3.c | 101 |
1 files changed, 75 insertions, 26 deletions
@@ -10,12 +10,35 @@ static int _debug = 1; /*@access dbiIndex@*/ /*@access dbiIndexSet@*/ -static const char * dberrpfx = "rpmdb"; -static int dbcachesize = 1024 * 1024; -static int dbpagesize = 32 * 1024; /* 0 - 64K */ - #if DB_VERSION_MAJOR == 3 #define __USE_DB3 1 + +/* XXX dbenv parameters */ +static int db_lorder = 0; /* 0 is native order */ +static void (*db_errcall) (const char *db_errpfx, char *buffer) = NULL; +static FILE * db_errfile = NULL; +static const char * db_errpfx = "rpmdb"; +static int db_verbose = 1; + +static int dbmp_mmapsize = 16 * 1024 * 1024; /* XXX db2 default: 10 Mb */ +static int dbmp_size = 16 * 1024 * 1024; /* XXX db2 default: 128 Kb */ + +/* XXX dbinfo parameters */ +static int db_cachesize = 0; +static int db_pagesize = 0; /* 512 - 64K, 0 is fs blksize */ +static void * (*db_malloc) (size_t nbytes) = NULL; + +static u_int32_t (*dbh_hash) (const void *, u_int32_t) = NULL; +static u_int32_t dbh_ffactor = 0; /* db1 default: 8 */ +static u_int32_t dbh_nelem = 0; /* db1 default: 1 */ +static u_int32_t dbh_flags = 0; + +#if defined(__ISE_DB3) +static int dbopenflags = 0; +#else +static int dbopenflags = DB_INIT_MPOOL; +#endif + #define _mymemset(_a, _b, _c) memset((_a), (_b), (_c)) static inline DBTYPE dbi_to_dbtype(DBI_TYPE dbitype) @@ -101,9 +124,9 @@ static int cvtdberr(dbiIndex dbi, const char * msg, int error, int printit) { if (error == 0) rc = 0; else if (error < 0) - rc = -1; - else if (error > 0) rc = 1; + else if (error > 0) + rc = -1; if (printit && rc) { fprintf(stderr, "*** db%d %s rc %d %s\n", dbi->dbi_major, msg, @@ -117,11 +140,13 @@ static int db_init(dbiIndex dbi, const char *home, int dbflags, DB_ENV **dbenvp, void **dbinfop) { DB_ENV *dbenv = NULL; - FILE * dberrfile = stderr; + int mydbopenflags; int rc; if (dbenvp == NULL || dbinfop == NULL) return 1; + if (db_errfile == NULL) + db_errfile = stderr; rc = db_env_create(&dbenv, 0); rc = cvtdberr(dbi, "db_env_create", rc, _debug); @@ -130,43 +155,60 @@ static int db_init(dbiIndex dbi, const char *home, int dbflags, #if defined(__USE_DB3) { int xx; - /* dbenv->set_errcall(???) */ - dbenv->set_errfile(dbenv, dberrfile); - dbenv->set_errpfx(dbenv, dberrpfx); + dbenv->set_errcall(dbenv, db_errcall); + dbenv->set_errfile(dbenv, db_errfile); + dbenv->set_errpfx(dbenv, db_errpfx); /* dbenv->set_paniccall(???) */ - /* dbenv->set_verbose(???) */ + dbenv->set_verbose(dbenv, DB_VERB_CHKPOINT, db_verbose); + dbenv->set_verbose(dbenv, DB_VERB_DEADLOCK, db_verbose); + dbenv->set_verbose(dbenv, DB_VERB_RECOVERY, db_verbose); + dbenv->set_verbose(dbenv, DB_VERB_WAITSFOR, db_verbose); /* dbenv->set_lg_max(???) */ /* dbenv->set_lk_conflicts(???) */ /* dbenv->set_lk_detect(???) */ /* dbenv->set_lk_max(???) */ - /* dbenv->set_mp_mmapsize(???) */ - xx = dbenv->set_cachesize(dbenv, 0, dbcachesize, 0); + xx = dbenv->set_mp_mmapsize(dbenv, dbmp_mmapsize); + xx = cvtdberr(dbi, "dbenv->set_mp_mmapsize", xx, _debug); + xx = dbenv->set_cachesize(dbenv, 0, dbmp_size, 0); xx = cvtdberr(dbi, "dbenv->set_cachesize", xx, _debug); /* dbenv->set_tx_max(???) */ /* dbenv->set_tx_recover(???) */ } #else - dbenv->db_errfile = dberrfile; - dbenv->db_errpfx = dberrpfx; - dbenv->mp_size = dbcachesize; + dbenv->db_errcall = db_errcall; + dbenv->db_errfile = db_errfile; + dbenv->db_errpfx = db_errpfx; + dbenv->db_verbose = db_verbose; + dbenv->mp_mmapsize = dbmp_mmapsize; /* XXX default is 10 Mb */ + dbenv->mp_size = dbmp_size; /* XXX default is 128 Kb */ #endif #define _DBFMASK (DB_CREATE|DB_NOMMAP|DB_THREAD) + mydbopenflags = (dbflags & _DBFMASK) | dbopenflags; #if defined(__USE_DB3) - rc = dbenv->open(dbenv, home, NULL, (dbflags & _DBFMASK), 0); + rc = dbenv->open(dbenv, home, NULL, mydbopenflags, 0); rc = cvtdberr(dbi, "dbenv->open", rc, _debug); if (rc) goto errxit; *dbinfop = NULL; #else - rc = db_appinit(home, NULL, dbenv, (dbflags & _DBFMASK)); + rc = db_appinit(home, NULL, dbenv, mydbopenflags); rc = cvtdberr(dbi, "db_appinit", rc, _debug); if (rc) goto errxit; { DB_INFO * dbinfo = xcalloc(1, sizeof(*dbinfo)); /* XXX W2DO? */ - dbinfo->db_pagesize = dbpagesize; + dbinfo->db_cachesize = db_cachesize; + dbinfo->db_lorder = db_lorder; + dbinfo->db_pagesize = db_pagesize; + dbinfo->db_malloc = db_malloc; + if (dbflags & DB_CREATE) { + dbinfo->h_ffactor = dbh_ffactor; + dbinfo->h_hash = dbh_hash; + dbinfo->h_nelem = dbh_nelem; + dbinfo->flags = dbh_flags; + } *dbinfop = dbinfo; } #endif @@ -252,6 +294,7 @@ static int db3GetFirstKey(dbiIndex dbi, const char ** keyp) { DBT key, data; DB * db; + int _printit; int rc, xx; if (dbi == NULL || dbi->dbi_db == NULL) @@ -274,7 +317,8 @@ static int db3GetFirstKey(dbiIndex dbi, const char ** keyp) rc = cvtdberr(dbi, "db->cursor", rc, _debug); if (rc == 0) { rc = dbcursor->c_get(dbcursor, &key, &data, DB_FIRST); - rc = cvtdberr(dbi, "dbcursor->c_get", rc, _debug); + _printit = (rc == DB_NOTFOUND ? 0 : _debug); + rc = cvtdberr(dbi, "dbcursor->c_get", rc, _printit); } if (dbcursor) { xx = dbcursor->c_close(dbcursor); @@ -299,6 +343,7 @@ static int db3SearchIndex(dbiIndex dbi, const char * str, dbiIndexSet * set) { DBT key, data; DB * db = GetDB(dbi); + int _printit; int rc; if (set) *set = NULL; @@ -312,7 +357,8 @@ static int db3SearchIndex(dbiIndex dbi, const char * str, dbiIndexSet * set) #if defined(__USE_DB2) || defined(__USE_DB3) rc = db->get(db, NULL, &key, &data, 0); - rc = cvtdberr(dbi, "db->get", rc, _debug); + _printit = (rc == DB_NOTFOUND ? 0 : _debug); + rc = cvtdberr(dbi, "db->get", rc, _printit); #else rc = db->get(db, &key, &data, 0); #endif @@ -387,12 +433,13 @@ static int db3open(dbiIndex dbi) rc = db_create(&db, dbenv, 0); rc = cvtdberr(dbi, "db_create", rc, _debug); if (rc == 0) { - int xx; + if (db_pagesize) { + rc = db->set_pagesize(db, db_pagesize); + rc = cvtdberr(dbi, "db->set_pagesize", rc, _debug); + } rc = db->open(db, dbi->dbi_file, NULL, dbi_to_dbtype(dbi->dbi_type), dbflags, dbi->dbi_perms); rc = cvtdberr(dbi, "db->open", rc, _debug); - xx = db->set_pagesize(db, dbpagesize); - xx = cvtdberr(dbi, "db->set_pagesize", xx, _debug); } #else rc = db_open(dbi->dbi_file, dbi_to_dbtype(dbi->dbi_type), dbflags, @@ -410,10 +457,12 @@ static int db3open(dbiIndex dbi) dbi_to_dbtype(dbi->dbi_type), dbi->dbi_openinfo); #endif /* __USE_DB2 || __USE_DB3 */ - if (rc == 0 && dbi->dbi_db != NULL) + if (rc == 0 && dbi->dbi_db != NULL) { rc = 0; - else +fprintf(stderr, "*** db%dopen: %s\n", dbi->dbi_major, dbi->dbi_file); + } else { rc = 1; + } return rc; } |