/* Open the database handle */ TCBDB * tc_bdb_create (const char *dbname, int module) { TCBDB *bdb; char *path = NULL; int ecode; uint32_t lcnum, ncnum, lmemb, nmemb, bnum, flags; path = tc_db_set_path (dbname, module); bdb = tcbdbnew (); lcnum = conf.cache_lcnum > 0 ? conf.cache_lcnum : TC_LCNUM; ncnum = conf.cache_ncnum > 0 ? conf.cache_ncnum : TC_NCNUM; /* set the caching parameters of a B+ tree database object */ if (!tcbdbsetcache (bdb, lcnum, ncnum)) { free (path); FATAL ("Unable to set TCB cache"); } /* set the size of the extra mapped memory */ if (conf.xmmap > 0 && !tcbdbsetxmsiz (bdb, conf.xmmap)) { free (path); FATAL ("Unable to set TCB xmmap."); } lmemb = conf.tune_lmemb > 0 ? conf.tune_lmemb : TC_LMEMB; nmemb = conf.tune_nmemb > 0 ? conf.tune_nmemb : TC_NMEMB; bnum = conf.tune_bnum > 0 ? conf.tune_bnum : TC_BNUM; /* compression */ flags = BDBTLARGE; if (conf.compression == TC_BZ2) { flags |= BDBTBZIP; } else if (conf.compression == TC_ZLIB) { flags |= BDBTDEFLATE; } /* set the tuning parameters */ tcbdbtune (bdb, lmemb, nmemb, bnum, 8, 10, flags); /* open flags */ flags = BDBOWRITER | BDBOCREAT; if (!conf.load_from_disk) flags |= BDBOTRUNC; /* attempt to open the database */ if (!tcbdbopen (bdb, path, flags)) { free (path); ecode = tcbdbecode (bdb); FATAL ("%s", tcbdberrmsg (ecode)); } free (path); return bdb; }
/* Get the file path for the given a database name */ static char * get_dbname (const char *dbname, int module) { char *path = NULL; #ifdef TCB_MEMHASH (void) dbname; (void) module; path = alloc_string ("*"); #endif #ifdef TCB_BTREE char *db = NULL; path = tc_db_set_path (dbname, module); if (module >= 0) { db = xmalloc (snprintf (NULL, 0, "%s", path) + 1); sprintf (db, "%s", path); free (path); return db; } #endif return path; }