1 | /* |
2 | * This Source Code Form is subject to the terms of the Mozilla Public |
3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
5 | * |
6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2019 MonetDB B.V. |
7 | */ |
8 | |
9 | #ifndef _LOGGER_H_ |
10 | #define _LOGGER_H_ |
11 | |
12 | #define LOGFILE "log" |
13 | |
14 | typedef struct logaction { |
15 | int type; /* type of change */ |
16 | lng nr; |
17 | int ht; /* vid(-1),void etc */ |
18 | int tt; |
19 | lng id; |
20 | char *name; /* optional */ |
21 | char tpe; /* tpe of column */ |
22 | oid cid; /* id of object */ |
23 | BAT *b; /* temporary bat with changes */ |
24 | BAT *uid; /* temporary bat with bun positions to update */ |
25 | } logaction; |
26 | |
27 | /* during the recover process a number of transactions could be active */ |
28 | typedef struct trans { |
29 | int tid; /* transaction id */ |
30 | int sz; /* sz of the changes array */ |
31 | int nr; /* nr of changes */ |
32 | |
33 | logaction *changes; |
34 | |
35 | struct trans *tr; |
36 | } trans; |
37 | |
38 | typedef gdk_return (*preversionfix_fptr)(int oldversion, int newversion); |
39 | typedef gdk_return (*postversionfix_fptr)(void *lg); |
40 | |
41 | typedef struct logger { |
42 | int debug; |
43 | int version; |
44 | lng changes; |
45 | lng id; |
46 | int tid; |
47 | bool with_ids; |
48 | bool inmemory; |
49 | #ifdef GDKLIBRARY_NIL_NAN |
50 | /* convert old style floating point NIL values to NaN */ |
51 | bool convert_nil_nan; |
52 | #endif |
53 | #ifdef GDKLIBRARY_OLDDATE |
54 | /* convert old date values to new */ |
55 | bool convert_date; |
56 | #endif |
57 | char *fn; |
58 | char *dir; |
59 | char *local_dir; /* the directory in which the log is written */ |
60 | preversionfix_fptr prefuncp; |
61 | postversionfix_fptr postfuncp; |
62 | stream *log; |
63 | lng end; /* end of pre-allocated blocks for faster f(data)sync */ |
64 | /* Store log_bids (int) to circumvent trouble with reference counting */ |
65 | BAT *catalog_bid; /* int bid column */ |
66 | BAT *catalog_nme; /* str name column */ |
67 | BAT *catalog_tpe; /* type of column */ |
68 | BAT *catalog_oid; /* object identifier of column (the pair type,oid is unique) */ |
69 | BAT *dcatalog; /* deleted from catalog table */ |
70 | BAT *seqs_id; /* int id column */ |
71 | BAT *seqs_val; /* lng value column */ |
72 | BAT *dseqs; /* deleted from seqs table */ |
73 | BAT *snapshots_bid; /* int bid column */ |
74 | BAT *snapshots_tid; /* int tid column */ |
75 | BAT *dsnapshots; /* deleted from snapshots table */ |
76 | BAT *freed; /* snapshots can be created and destroyed, |
77 | in a single logger transaction. |
78 | These snapshot bats should be freed |
79 | directly (on transaction |
80 | commit). */ |
81 | void *buf; |
82 | size_t bufsize; |
83 | } logger; |
84 | |
85 | #define BATSIZE 0 |
86 | |
87 | typedef int log_bid; |
88 | |
89 | /* |
90 | * @+ Sequence numbers |
91 | * The logger also keeps sequence numbers. A sequence needs to store |
92 | * each requested (block) of sequence numbers. This is done using the |
93 | * log_sequence function. The logger_sequence function can be used to |
94 | * return the last logged sequence number. Sequences identifiers |
95 | * should be unique. The first OBJ_SID is for |
96 | * frontend objects, for example the sql objects have a global |
97 | * sequence counter such that each table, trigger, sequence etc. has a |
98 | * unique number. |
99 | */ |
100 | /* the sequence identifier for frontend objects */ |
101 | #define OBJ_SID 1 |
102 | |
103 | /* type of object id's, to log */ |
104 | #define LOG_NONE 0 |
105 | #define LOG_TAB 1 |
106 | #define LOG_COL 2 |
107 | #define LOG_IDX 3 |
108 | |
109 | gdk_export logger *logger_create(int debug, const char *fn, const char *logdir, int version, preversionfix_fptr prefuncp, postversionfix_fptr postfuncp); |
110 | gdk_export void logger_destroy(logger *lg); |
111 | gdk_export gdk_return logger_exit(logger *lg); |
112 | gdk_export gdk_return logger_restart(logger *lg); |
113 | gdk_export gdk_return logger_cleanup(logger *lg); |
114 | gdk_export void logger_with_ids(logger *lg); |
115 | gdk_export lng logger_changes(logger *lg); |
116 | gdk_export int logger_sequence(logger *lg, int seq, lng *id); |
117 | |
118 | /* todo pass the transaction id */ |
119 | gdk_export gdk_return log_bat(logger *lg, BAT *b, const char *n, char tpe, oid id); |
120 | gdk_export gdk_return log_bat_clear(logger *lg, const char *n, char tpe, oid id); |
121 | gdk_export gdk_return log_bat_persists(logger *lg, BAT *b, const char *n, char tpe, oid id); |
122 | gdk_export gdk_return log_bat_transient(logger *lg, const char *n, char tpe, oid id); |
123 | gdk_export gdk_return log_delta(logger *lg, BAT *uid, BAT *uval, const char *n, char tpe, oid id); |
124 | |
125 | gdk_export gdk_return log_tstart(logger *lg); /* TODO return transaction id */ |
126 | gdk_export gdk_return log_tend(logger *lg); |
127 | gdk_export gdk_return log_abort(logger *lg); |
128 | |
129 | gdk_export gdk_return log_sequence(logger *lg, int seq, lng id); |
130 | |
131 | gdk_export gdk_return logger_add_bat(logger *lg, BAT *b, const char *name, char tpe, oid id) |
132 | __attribute__ ((__warn_unused_result__)); |
133 | gdk_export gdk_return logger_del_bat(logger *lg, log_bid bid) |
134 | __attribute__ ((__warn_unused_result__)); |
135 | gdk_export log_bid logger_find_bat(logger *lg, const char *name, char tpe, oid id); |
136 | gdk_export gdk_return logger_upgrade_bat(logger *lg, const char *name, char tpe, oid id) |
137 | __attribute__ ((__warn_unused_result__)); |
138 | |
139 | typedef int (*geomcatalogfix_fptr)(void *, int); |
140 | gdk_export void geomcatalogfix_set(geomcatalogfix_fptr); |
141 | gdk_export geomcatalogfix_fptr geomcatalogfix_get(void); |
142 | |
143 | typedef str (*geomsqlfix_fptr)(int); |
144 | gdk_export void geomsqlfix_set(geomsqlfix_fptr); |
145 | gdk_export geomsqlfix_fptr geomsqlfix_get(void); |
146 | |
147 | gdk_export void geomversion_set(void); |
148 | gdk_export int geomversion_get(void); |
149 | |
150 | #endif /*_LOGGER_H_*/ |
151 | |