#include <stdlib.h>#include <syslog.h>#include <sys/stat.h>#include <db.h>#include "../../str.h"#include "../../db/db.h"#include "../../db/db_val.h"#include "../../locking.h"


Go to the source code of this file.
Data Structures | |
| struct | _column |
| struct | _database |
| struct | _db_parms |
| struct | _row |
| struct | _table |
| struct | _tbl_cache |
Defines | |
| #define | DELIM "|" |
| #define | DELIM_LEN (sizeof(DELIM)-1) |
| #define | JLOG_DELETE 2 |
| #define | JLOG_FILE 8 |
| #define | JLOG_INSERT 1 |
| #define | JLOG_NONE 0 |
| #define | JLOG_STDOUT 16 |
| #define | JLOG_SYSLOG 32 |
| #define | JLOG_UPDATE 4 |
| #define | MAX_NUM_COLS 32 |
| #define | MAX_ROW_SIZE 2048 |
| #define | MAX_TABLENAME_SIZE 64 |
| #define | METADATA_COLUMNS "METADATA_COLUMNS" |
| #define | METADATA_DEFAULTS "METADATA_DEFAULTS" |
| #define | METADATA_KEY "METADATA_KEY" |
| #define | METADATA_LOGFLAGS "METADATA_LOGFLAGS" |
| #define | METADATA_READONLY "METADATA_READONLY" |
Typedefs | |
| typedef db_val_t * | bdb_val_p |
| typedef db_val_t | bdb_val_t |
| typedef struct _column * | column_p |
| typedef struct _column | column_t |
| typedef struct _database * | database_p |
| typedef struct _database | database_t |
| typedef struct _db_parms * | db_parms_p |
| typedef struct _db_parms | db_parms_t |
| typedef struct _row * | row_p |
| typedef struct _row | row_t |
| typedef struct _table * | table_p |
| typedef struct _table | table_t |
| typedef struct _tbl_cache * | tbl_cache_p |
| typedef struct _tbl_cache | tbl_cache_t |
Functions | |
| int | bdblib_close (char *_n) |
| int | bdblib_create_dbenv (DB_ENV **dbenv, char *home) |
| int | bdblib_create_journal (table_p _tp) |
| table_p | bdblib_create_table (database_p _db, str *_s) |
| int | bdblib_destroy (void) |
| database_p | bdblib_get_db (str *_s) |
| tbl_cache_p | bdblib_get_table (database_p _db, str *_s) |
| int | bdblib_init (db_parms_p _parms) |
| void | bdblib_log (int op, table_p _tp, char *_msg, int len) |
| int | bdblib_recover (table_p _tp, int error_code) |
| int | bdblib_reopen (char *_n) |
| int | bdblib_valtochar (table_p _tp, int *_lres, char *_k, int *_klen, db_val_t *_v, int _n, int _ko) |
| int | db_free (database_p _dbp) |
| int | load_metadata_columns (table_p _tp) |
| int | load_metadata_defaults (table_p _tp) |
| int | load_metadata_keys (table_p _tp) |
| int | load_metadata_logflags (table_p _tp) |
| int | load_metadata_readonly (table_p _tp) |
| int | tbl_cache_free (tbl_cache_p _tbc) |
| int | tbl_free (table_p _tp) |
| #define DELIM "|" |
Definition at line 68 of file bdb_lib.h.
Referenced by bdb_append_row(), bdb_convert_row(), bdb_update(), bdblib_valtochar(), and load_metadata_defaults().
| #define DELIM_LEN (sizeof(DELIM)-1) |
| #define JLOG_DELETE 2 |
| #define JLOG_FILE 8 |
| #define JLOG_INSERT 1 |
| #define JLOG_NONE 0 |
| #define JLOG_STDOUT 16 |
| #define JLOG_SYSLOG 32 |
| #define JLOG_UPDATE 4 |
| #define MAX_NUM_COLS 32 |
Definition at line 45 of file bdb_lib.h.
Referenced by bdblib_create_table(), and load_metadata_columns().
| #define MAX_ROW_SIZE 2048 |
Definition at line 48 of file bdb_lib.h.
Referenced by _bdb_delete_cursor(), bdb_check_reload(), bdb_delete(), bdb_insert(), bdb_query(), bdb_update(), bdblib_log(), bdblib_valtochar(), load_metadata_columns(), load_metadata_defaults(), load_metadata_keys(), load_metadata_logflags(), and load_metadata_readonly().
| #define MAX_TABLENAME_SIZE 64 |
Definition at line 51 of file bdb_lib.h.
Referenced by bdb_check_reload(), and bdblib_create_table().
| #define METADATA_COLUMNS "METADATA_COLUMNS" |
| #define METADATA_DEFAULTS "METADATA_DEFAULTS" |
| #define METADATA_KEY "METADATA_KEY" |
| #define METADATA_LOGFLAGS "METADATA_LOGFLAGS" |
| #define METADATA_READONLY "METADATA_READONLY" |
| typedef struct _database * database_p |
| typedef struct _database database_t |
| typedef struct _db_parms * db_parms_p |
| typedef struct _db_parms db_parms_t |
| typedef struct _tbl_cache * tbl_cache_p |
| typedef struct _tbl_cache tbl_cache_t |
| int bdblib_close | ( | char * | _n | ) |
closes the underlying Berkeley DB. assumes the lib data-structures are already initialzed; used to sync and reload the db file.
Definition at line 104 of file bdb_lib.c.
References _table::db, _database::dbenv, _tbl_cache::dtp, _str::len, LM_CRIT, LM_DBG, _table::name, _database::name, _tbl_cache::next, NULL, _str::s, s, _table::sem, and _database::tables.
Referenced by bdb_reload().
| int bdblib_create_dbenv | ( | DB_ENV ** | dbenv, | |
| char * | home | |||
| ) |
Definition at line 298 of file bdb_lib.c.
References _db_parms::cache_size, and LM_ERR.
Referenced by bdblib_get_db(), and bdblib_reopen().
| int bdblib_create_journal | ( | table_p | _tp | ) |
Definition at line 716 of file bdb_lib.c.
References _table::fp, _str::len, LM_ERR, _db_parms::log_enable, _table::name, _database::name, NULL, _str::s, s, and _table::t.
Referenced by bdblib_create_table(), and bdblib_log().
| table_p bdblib_create_table | ( | database_p | _db, | |
| str * | _s | |||
| ) |
The function is called to create a handle to a db table.
On startup, we do not create any of the db handles. Instead it is done on first-use (lazy-initialized) to only create handles to files (db) that we require.
There is one db file per openser table (eg. acc), and they should exist in your DB_PATH (refer to kamctlrc) directory.
This function does _not_ create the underlying binary db tables. Creating the tables MUST be manually performed before openser startup by 'kamdbctl create'
Function returns NULL on error, which will cause openser to exit.
Definition at line 562 of file bdb_lib.c.
References bdblib_create_journal(), _table::colp, _table::db, _database::dbenv, _table::fp, _table::ino, JLOG_FILE, _str::len, LM_DBG, LM_ERR, LM_INFO, load_metadata_columns(), load_metadata_defaults(), load_metadata_keys(), load_metadata_logflags(), load_metadata_readonly(), _table::logflags, MAX_NUM_COLS, MAX_TABLENAME_SIZE, _table::name, _table::ncols, _table::nkeys, NULL, pkg_free, pkg_malloc, _table::ro, _str::s, _table::sem, and _table::t.
Referenced by bdblib_get_table().
| int bdblib_destroy | ( | void | ) |
| database_p bdblib_get_db | ( | str * | _s | ) |
Definition at line 358 of file bdb_lib.c.
References bdb_is_database(), bdblib_create_dbenv(), _database::dbenv, _str::len, LM_DBG, LM_ERR, _database::name, NULL, pkg_free, pkg_malloc, _str::s, and _database::tables.
Referenced by bdb_init().
| tbl_cache_p bdblib_get_table | ( | database_p | _db, | |
| str * | _s | |||
| ) |
look thru a linked list for the table. if dne, create a new one and add to the list
Definition at line 421 of file bdb_lib.c.
References bdblib_create_table(), _database::dbenv, _tbl_cache::dtp, _str::len, LM_DBG, LM_ERR, _table::name, _tbl_cache::next, NULL, pkg_free, pkg_malloc, _str::s, _tbl_cache::sem, and _database::tables.
Referenced by _bdb_delete_cursor(), bdb_check_reload(), bdb_delete(), bdb_insert(), bdb_query(), and bdb_update().
| int bdblib_init | ( | db_parms_p | _parms | ) |
Definition at line 49 of file bdb_lib.c.
References _db_parms::auto_reload, _db_parms::cache_size, _db_parms::journal_roll_interval, LM_CRIT, _db_parms::log_enable, NULL, and pkg_malloc.
Referenced by mod_init().
| void bdblib_log | ( | int | op, | |
| table_p | _tp, | |||
| char * | _msg, | |||
| int | len | |||
| ) |
Definition at line 486 of file bdb_lib.c.
References bdblib_create_journal(), buf, _table::fp, JLOG_DELETE, JLOG_INSERT, JLOG_NONE, JLOG_STDOUT, JLOG_SYSLOG, JLOG_UPDATE, _db_parms::journal_roll_interval, LM_ERR, _db_parms::log_enable, _table::logflags, MAX_ROW_SIZE, NULL, and _table::t.
Referenced by bdb_delete(), bdb_insert(), and bdb_update().
| int bdblib_recover | ( | table_p | _tp, | |
| int | error_code | |||
| ) |
Definition at line 1309 of file bdb_lib.c.
References bdblib_destroy(), and LM_ERR.
Referenced by _bdb_delete_cursor(), bdb_delete(), bdb_insert(), bdb_query(), bdb_update(), and bdblib_reopen().
| int bdblib_reopen | ( | char * | _n | ) |
opens the underlying Berkeley DB. assumes the lib data-structures are already initialzed; used to sync and reload the db file.
Definition at line 188 of file bdb_lib.c.
References bdblib_create_dbenv(), bdblib_recover(), _table::db, _database::dbenv, _tbl_cache::dtp, _str::len, LM_CRIT, LM_DBG, _table::name, _database::name, _tbl_cache::next, NULL, _str::s, s, _table::sem, and _database::tables.
Referenced by bdb_reload().
| int bdblib_valtochar | ( | table_p | _tp, | |
| int * | _lres, | |||
| char * | _k, | |||
| int * | _klen, | |||
| db_val_t * | _v, | |||
| int | _n, | |||
| int | _ko | |||
| ) |
Definition at line 1047 of file bdb_lib.c.
References bdb_val2str(), _table::colp, DELIM, DELIM_LEN, _column::dv, _column::flag, _str::len, len, LM_DBG, LM_ERR, MAX_ROW_SIZE, _column::name, _table::name, _table::ncols, _str::s, and ZSW.
Referenced by bdb_delete(), bdb_insert(), bdb_query(), and bdb_update().
| int db_free | ( | database_p | _dbp | ) |
Definition at line 1233 of file bdb_lib.c.
References _database::dbenv, _database::name, _tbl_cache::next, NULL, pkg_free, _str::s, _database::tables, and tbl_cache_free().
Referenced by bdblib_destroy().
| int load_metadata_columns | ( | table_p | _tp | ) |
Definition at line 770 of file bdb_lib.c.
References _table::colp, _table::db, DB_DATETIME, DB_DOUBLE, DB_INT, DB_STRING, _column::flag, _str::len, len, LM_ERR, MAX_NUM_COLS, MAX_ROW_SIZE, METADATA_COLUMNS, _column::name, _table::ncols, NULL, pkg_malloc, _str::s, s, and _column::type.
Referenced by bdblib_create_table().
| int load_metadata_defaults | ( | table_p | _tp | ) |
Definition at line 966 of file bdb_lib.c.
References _table::colp, _table::db, DELIM, _column::dv, _str::len, len, LM_DBG, MAX_ROW_SIZE, METADATA_DEFAULTS, _column::name, _table::ncols, NULL, pkg_malloc, _str::s, s, and ZSW.
Referenced by bdblib_create_table().
| int load_metadata_keys | ( | table_p | _tp | ) |
Definition at line 857 of file bdb_lib.c.
References _table::colp, _table::db, _column::flag, LM_ERR, MAX_ROW_SIZE, METADATA_KEY, _table::nkeys, NULL, and s.
Referenced by bdblib_create_table().
| int load_metadata_logflags | ( | table_p | _tp | ) |
Definition at line 934 of file bdb_lib.c.
References _table::db, _table::logflags, MAX_ROW_SIZE, METADATA_LOGFLAGS, and NULL.
Referenced by bdblib_create_table().
| int load_metadata_readonly | ( | table_p | _tp | ) |
Definition at line 902 of file bdb_lib.c.
References _table::db, MAX_ROW_SIZE, METADATA_READONLY, NULL, and _table::ro.
Referenced by bdblib_create_table().
| int tbl_cache_free | ( | tbl_cache_p | _tbc | ) |
Definition at line 1263 of file bdb_lib.c.
References _tbl_cache::dtp, pkg_free, _tbl_cache::sem, and tbl_free().
Referenced by db_free().
| int tbl_free | ( | table_p | _tp | ) |
close DB (sync data to disk) and free mem
Definition at line 1283 of file bdb_lib.c.
References _table::colp, _table::db, _column::dv, _table::fp, _column::name, _table::name, _table::ncols, pkg_free, and _str::s.
Referenced by tbl_cache_free().
1.5.6