kambdb_recover.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * $Id$
  3. *
  4. * recovery for berkeley_db module
  5. *
  6. * Copyright (C) 2007 Cisco Systems
  7. *
  8. * This file is part of Kamailio, a free SIP server.
  9. *
  10. * Kamailio is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version
  14. *
  15. * Kamailio is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  23. *
  24. * History:
  25. * --------
  26. * 2007-09-19 genesis (wiquan)
  27. */
  28. #include <stdio.h>
  29. #include <string.h>
  30. #include <stdlib.h>
  31. #include <dirent.h>
  32. #include <time.h>
  33. #include <db.h>
  34. /*max number of journal files that we are reading*/
  35. #define MAXFILES 64
  36. /*max number of columns in a table*/
  37. #define MAX_NUM_COLS 32
  38. /*max char width of a table row*/
  39. #define MAX_ROW_SIZE 2048
  40. /*max char width of a table name*/
  41. #define MAX_TABLENAME_SIZE 64
  42. #define MAX_FILENAME_SIZE 512
  43. #define METADATA_KEY "METADATA_KEY"
  44. #define METADATA_COLUMNS "METADATA_COLUMNS"
  45. /*operations*/
  46. enum
  47. {
  48. INSERT,
  49. UPDATE,
  50. DELETE,
  51. UNKNOWN_OP
  52. };
  53. typedef struct _lnode
  54. {
  55. char* p;
  56. struct _lnode *prev;
  57. struct _lnode *next;
  58. } lnode_t, *lnode_p;
  59. typedef struct _column
  60. {
  61. char* name;
  62. char* type;
  63. int kflag;
  64. } column_t, *column_p;
  65. typedef struct _table
  66. {
  67. char* name;
  68. column_p colp [MAX_NUM_COLS];
  69. int ncols;
  70. int nkeys;
  71. int ro;
  72. int logflags;
  73. DB* db;
  74. } table_t, *table_p;
  75. typedef struct _tbl_cache
  76. {
  77. table_p dtp;
  78. struct _tbl_cache *prev;
  79. struct _tbl_cache *next;
  80. } tbl_cache_t, *tbl_cache_p;
  81. int usage(void);
  82. DB* get_db(table_p tp);
  83. int get_op(char* op, int len);
  84. int delete(table_p tp, char* v, int len);
  85. int insert(table_p tp, char* v, int len);
  86. int _insert(DB* db, char* k, char* v, int klen, int vlen);
  87. int update(table_p tp, char* v, int len);
  88. int create(char* tn);
  89. int _version(DB* db);
  90. int create_all(void);
  91. int recover(char* tn);
  92. int recover_all(int lastn);
  93. lnode_p file_list(char* d, char* tn);
  94. int compare (const void *a, const void *b);
  95. int extract_key(table_p tp, char* key, char* data);
  96. int load_schema(char* dir);
  97. tbl_cache_p get_table(char *s);
  98. table_p create_table(char *_s);
  99. int load_metadata_columns(table_p _tp, char* line);
  100. int load_metadata_key(table_p _tp, char* line);
  101. int import_schema(table_p tp);
  102. void cleanup(void);