kambdb_recover.h

00001 /*
00002  * $Id$
00003  *
00004  * recovery for berkeley_db module
00005  * 
00006  * Copyright (C) 2007 Cisco Systems
00007  *
00008  * This file is part of Kamailio, a free SIP server.
00009  *
00010  * Kamailio is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version
00014  *
00015  * Kamailio is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License 
00021  * along with this program; if not, write to the Free Software 
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023  * 
00024  * History:
00025  * --------
00026  * 2007-09-19  genesis (wiquan)
00027  */
00028  
00029 #include <stdio.h>
00030 #include <string.h>
00031 #include <stdlib.h>
00032 #include <dirent.h>
00033 #include <time.h>
00034 #include <db.h>
00035 
00036 /*max number of journal files that we are reading*/
00037 #define MAXFILES 64
00038 
00039 /*max number of columns in a table*/
00040 #define MAX_NUM_COLS 32
00041 
00042 /*max char width of a table row*/
00043 #define MAX_ROW_SIZE 2048
00044 
00045 /*max char width of a table name*/
00046 #define MAX_TABLENAME_SIZE 64
00047 
00048 #define MAX_FILENAME_SIZE 512
00049 
00050 #define METADATA_KEY "METADATA_KEY"
00051 #define METADATA_COLUMNS "METADATA_COLUMNS"
00052 
00053 /*operations*/
00054 enum 
00055 {
00056         INSERT,
00057         UPDATE,
00058         DELETE,
00059         UNKNOWN_OP
00060 };
00061 
00062 
00063 typedef struct _lnode
00064 {
00065         char* p;
00066         struct _lnode *prev;
00067         struct _lnode *next;
00068 } lnode_t, *lnode_p;
00069 
00070 
00071 typedef struct _column
00072 {
00073         char* name;
00074         char* type;
00075         int kflag;
00076 } column_t, *column_p;
00077 
00078 
00079 typedef struct _table
00080 {
00081         char* name;
00082         column_p colp [MAX_NUM_COLS];
00083         int ncols;
00084         int nkeys;
00085         int ro;
00086         int logflags;
00087         DB* db;
00088 } table_t, *table_p;
00089 
00090 
00091 typedef struct _tbl_cache
00092 {
00093         table_p dtp;
00094         struct _tbl_cache *prev;
00095         struct _tbl_cache *next;
00096 } tbl_cache_t, *tbl_cache_p;
00097 
00098 
00099 int usage(void);
00100 DB* get_db(table_p tp);
00101 int get_op(char* op, int len);
00102 int delete(table_p tp, char* v, int len);
00103 int insert(table_p tp, char* v, int len);
00104 int _insert(DB* db, char* k, char* v, int klen, int vlen);
00105 int update(table_p tp, char* v, int len);
00106 int create(char* tn);
00107 int _version(DB* db);
00108 int create_all(void);
00109 int recover(char* tn);
00110 int recover_all(int lastn);
00111 lnode_p file_list(char* d, char* tn);
00112 int compare (const void *a, const void *b);
00113 int extract_key(table_p tp, char* key, char* data);
00114 int load_schema(char* dir);
00115 tbl_cache_p get_table(char *s);
00116 table_p create_table(char *_s);
00117 int load_metadata_columns(table_p _tp, char* line);
00118 int load_metadata_key(table_p _tp, char* line);
00119 int import_schema(table_p tp);
00120 void cleanup(void);