CUBRID Engine  latest
system_catalog.h
Go to the documentation of this file.
1 /*
2  * Copyright 2008 Search Solution Corporation
3  * Copyright 2016 CUBRID Corporation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 
20 /*
21  * system_catalog.h : Catalog manager interface header file
22  */
23 
24 #ifndef _SYSTEM_CATALOG_H_
25 #define _SYSTEM_CATALOG_H_
26 
27 #ident "$Id$"
28 
29 #if !defined (SERVER_MODE) && !defined (SA_MODE)
30 #error Belongs to server module
31 #endif /* !defined (SERVER_MODE) && !defined (SA_MODE) */
32 
33 #include "config.h"
34 
35 #include "error_manager.h"
36 #include "log_manager.h"
37 #include "memory_alloc.h"
38 #include "statistics.h"
39 #include "disk_manager.h"
40 #include "storage_common.h"
41 
42 #define CATALOG_DIR_REPR_KEY -2
43 
44 typedef struct ctid CTID;
45 struct ctid
46 {
47  VFID vfid; /* catalog volume identifier */
48 #if 1 /* TODO - not used */
49  EHID xhid; /* extendible hash index identifier */
50 #endif
51  PAGEID hpgid; /* catalog header page identifier */
52 }; /* catalog identifier */
53 
54 
55 
56 /*
57  * disk_representation
58  *
59  * This is the primary communication structure between the schema manager
60  * and the catalog manager. It contains information on the order and
61  * location of attributes for a particular class of object.
62  */
63 
66 {
67  REPR_ID id; /* representation identifier */
68  int n_fixed; /* number of fixed attributes */
69  struct disk_attribute *fixed; /* fixed attribute structures */
70  int fixed_length; /* total length of fixed attributes */
71  int n_variable; /* number of variable attributes */
72  struct disk_attribute *variable; /* variable attribute structures */
73 #if 0 /* reserved for future use */
74  int repr_reserved_1;
75 #endif
76 }; /* object disk representation */
77 
78 
79 
80 
81 typedef struct disk_attribute DISK_ATTR;
83 {
84  ATTR_ID id; /* attribute identifier */
85  int location; /* location in disk representation exact offset if fixed attr. index to offset table if
86  * var attr. */
87  DB_TYPE type; /* datatype */
88  int val_length; /* default value length >= 0 */
89  void *value; /* default value. Currently, we do not keep default expression. */
90  int position; /* storage position (fixed attributes only) */
91  OID classoid; /* source class object id */
92  int n_btstats; /* number of B+tree statistics information */
93  BTREE_STATS *bt_stats; /* pointer to array of BTREE_STATS; BTREE_STATS[n_btstats] */
94 }; /* disk attribute structure */
95 
96 typedef struct cls_info CLS_INFO;
97 struct cls_info
98 {
99  HFID ci_hfid; /* heap file identifier for the class */
100  int ci_tot_pages; /* total number of pages in the heap file */
101  int ci_tot_objects; /* total number of objects for this class */
102  unsigned int ci_time_stamp; /* timestamp of last update */
103  OID ci_rep_dir; /* representation directory record OID */
104 }; /* class specific information */
105 
108 {
111  char *class_name;
112  bool is_update;
116 #if !defined (NDEBUG)
118 #endif
119 };
120 
121 #if !defined (NDEBUG)
122 #define CATALOG_ACCESS_INFO_INITIALIZER \
123  {NULL, NULL, NULL, false, false, false, false, false}
124 #else
125 #define CATALOG_ACCESS_INFO_INITIALIZER \
126  {NULL, NULL, NULL, false, false, false, false}
127 #endif
128 
129 #define CLS_INFO_INITIALIZER \
130  { HFID_INITIALIZER, 0, 0, 0, { NULL_PAGEID, NULL_SLOTID, NULL_VOLID } }
131 
132 #define catalog_free_class_info_and_init(class_info_p) \
133  do \
134  { \
135  if ((class_info_p) != NULL) \
136  { \
137  catalog_free_class_info ((class_info_p)); \
138  (class_info_p) = NULL; \
139  } \
140  } \
141  while (0)
142 
143 #define catalog_free_representation_and_init(repr_p) \
144  do \
145  { \
146  if ((repr_p) != NULL) \
147  { \
148  catalog_free_representation ((repr_p)); \
149  (repr_p) = NULL; \
150  } \
151  } \
152  while (0)
153 
154 extern CTID catalog_Id; /* global catalog identifier */
155 
156 extern void catalog_free_representation (DISK_REPR * repr_p);
157 extern void catalog_free_class_info (CLS_INFO * class_info_p);
158 extern void catalog_initialize (CTID * catid);
159 extern void catalog_finalize (void);
160 
161 /* these two routines should be called only once and by the root */
162 extern CTID *catalog_create (THREAD_ENTRY * thread_p, CTID * catid);
163 extern int catalog_destroy (void);
164 
165 extern int catalog_reclaim_space (THREAD_ENTRY * thread_p);
166 extern int catalog_add_representation (THREAD_ENTRY * thread_p, OID * class_id, REPR_ID repr_id, DISK_REPR * Disk_Repr,
167  OID * rep_dir_p, CATALOG_ACCESS_INFO * catalog_access_info_p);
168 extern int catalog_add_class_info (THREAD_ENTRY * thread_p, OID * class_oid_p, CLS_INFO * class_info_p,
169  CATALOG_ACCESS_INFO * catalog_access_info_p);
171  CATALOG_ACCESS_INFO * catalog_access_info_p, bool skip_logging);
172 extern int catalog_drop_old_representations (THREAD_ENTRY * thread_p, OID * class_id);
173 extern DISK_REPR *catalog_get_representation (THREAD_ENTRY * thread_p, OID * class_id, REPR_ID repr_id,
174  CATALOG_ACCESS_INFO * catalog_access_info_p);
176  CATALOG_ACCESS_INFO * catalog_access_info_p);
177 extern int catalog_get_representation_directory (THREAD_ENTRY * thread_p, OID * class_id, REPR_ID ** reprid_set,
178  int *repr_cnt);
179 extern int catalog_get_last_representation_id (THREAD_ENTRY * thread_p, OID * cls_oid, REPR_ID * repr_id);
180 extern int catalog_insert (THREAD_ENTRY * thread_p, RECDES * record, OID * classoid, OID * rep_dir_p);
181 extern int catalog_update (THREAD_ENTRY * thread_p, RECDES * record, OID * classoid);
182 extern int catalog_delete (THREAD_ENTRY * thread_p, OID * classoid);
183 
184 extern int catalog_get_cardinality (THREAD_ENTRY * thread_p, OID * class_oid, DISK_REPR * rep, BTID * btid,
185  const int key_pos, int *cardinality);
186 extern int catalog_get_cardinality_by_name (THREAD_ENTRY * thread_p, const char *class_name, const char *index_name,
187  const int key_pos, int *cardinality);
188 
189 /* Checkdb consistency check routines */
191 
192 /* Dump routines */
193 extern void catalog_dump (THREAD_ENTRY * thread_p, FILE * fp, int dump_flg);
194 
195 /* Recovery routines */
196 extern int catalog_rv_new_page_redo (THREAD_ENTRY * thread_p, LOG_RCV * recv);
197 extern int catalog_rv_insert_redo (THREAD_ENTRY * thread_p, LOG_RCV * recv);
198 extern int catalog_rv_insert_undo (THREAD_ENTRY * thread_p, LOG_RCV * recv);
199 extern int catalog_rv_delete_redo (THREAD_ENTRY * thread_p, LOG_RCV * recv);
200 extern int catalog_rv_delete_undo (THREAD_ENTRY * thread_p, LOG_RCV * recv);
201 extern int catalog_rv_update (THREAD_ENTRY * thread_p, LOG_RCV * recv);
202 extern int catalog_rv_ovf_page_logical_insert_undo (THREAD_ENTRY * thread_p, LOG_RCV * recv);
203 extern int catalog_get_dir_oid_from_cache (THREAD_ENTRY * thread_p, const OID * class_id_p, OID * dir_oid_p);
205  LOCK lock_mode);
207  int error);
208 #endif /* _SYSTEM_CATALOG_H_ */
int catalog_reclaim_space(THREAD_ENTRY *thread_p)
int catalog_rv_update(THREAD_ENTRY *thread_p, LOG_RCV *recv)
int ci_tot_pages
DB_TYPE
Definition: dbtype_def.h:670
int catalog_rv_insert_redo(THREAD_ENTRY *thread_p, LOG_RCV *recv)
CTID catalog_Id
int catalog_rv_ovf_page_logical_insert_undo(THREAD_ENTRY *thread_p, LOG_RCV *recv)
int catalog_add_class_info(THREAD_ENTRY *thread_p, OID *class_oid_p, CLS_INFO *class_info_p, CATALOG_ACCESS_INFO *catalog_access_info_p)
unsigned int ci_time_stamp
CLS_INFO * catalog_update_class_info(THREAD_ENTRY *thread_p, OID *class_id, CLS_INFO *cls_info, CATALOG_ACCESS_INFO *catalog_access_info_p, bool skip_logging)
void catalog_initialize(CTID *catid)
int catalog_delete(THREAD_ENTRY *thread_p, OID *classoid)
int ci_tot_objects
void THREAD_ENTRY
VFID vfid
int ATTR_ID
void catalog_free_class_info(CLS_INFO *class_info_p)
LOCK
int catalog_add_representation(THREAD_ENTRY *thread_p, OID *class_id, REPR_ID repr_id, DISK_REPR *Disk_Repr, OID *rep_dir_p, CATALOG_ACCESS_INFO *catalog_access_info_p)
BTREE_STATS * bt_stats
void catalog_finalize(void)
int catalog_rv_delete_undo(THREAD_ENTRY *thread_p, LOG_RCV *recv)
int catalog_get_dir_oid_from_cache(THREAD_ENTRY *thread_p, const OID *class_id_p, OID *dir_oid_p)
int catalog_start_access_with_dir_oid(THREAD_ENTRY *thread_p, CATALOG_ACCESS_INFO *catalog_access_info, LOCK lock_mode)
int catalog_get_representation_directory(THREAD_ENTRY *thread_p, OID *class_id, REPR_ID **reprid_set, int *repr_cnt)
int catalog_update(THREAD_ENTRY *thread_p, RECDES *record, OID *classoid)
CLS_INFO * catalog_get_class_info(THREAD_ENTRY *thread_p, OID *class_id, CATALOG_ACCESS_INFO *catalog_access_info_p)
struct disk_attribute * variable
EHID xhid
int catalog_rv_new_page_redo(THREAD_ENTRY *thread_p, LOG_RCV *recv)
int catalog_insert(THREAD_ENTRY *thread_p, RECDES *record, OID *classoid, OID *rep_dir_p)
struct disk_attribute * fixed
static void error(const char *msg)
Definition: gencat.c:331
DISK_ISVALID catalog_check_consistency(THREAD_ENTRY *thread_p)
int catalog_get_cardinality(THREAD_ENTRY *thread_p, OID *class_oid, DISK_REPR *rep, BTID *btid, const int key_pos, int *cardinality)
void catalog_dump(THREAD_ENTRY *thread_p, FILE *fp, int dump_flg)
CTID * catalog_create(THREAD_ENTRY *thread_p, CTID *catid)
int catalog_end_access_with_dir_oid(THREAD_ENTRY *thread_p, CATALOG_ACCESS_INFO *catalog_access_info, int error)
int REPR_ID
INT32 PAGEID
int catalog_get_last_representation_id(THREAD_ENTRY *thread_p, OID *cls_oid, REPR_ID *repr_id)
int catalog_get_cardinality_by_name(THREAD_ENTRY *thread_p, const char *class_name, const char *index_name, const int key_pos, int *cardinality)
void catalog_free_representation(DISK_REPR *repr_p)
int catalog_drop_old_representations(THREAD_ENTRY *thread_p, OID *class_id)
HFID ci_hfid
int catalog_rv_insert_undo(THREAD_ENTRY *thread_p, LOG_RCV *recv)
DISK_REPR * catalog_get_representation(THREAD_ENTRY *thread_p, OID *class_id, REPR_ID repr_id, CATALOG_ACCESS_INFO *catalog_access_info_p)
int class_id
Definition: load_common.hpp:40
int catalog_destroy(void)
PAGEID hpgid
DISK_ISVALID
Definition: disk_manager.h:53
int catalog_rv_delete_redo(THREAD_ENTRY *thread_p, LOG_RCV *recv)