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
14typedef 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 */
28typedef 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
38typedef gdk_return (*preversionfix_fptr)(int oldversion, int newversion);
39typedef gdk_return (*postversionfix_fptr)(void *lg);
40
41typedef 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
87typedef 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
109gdk_export logger *logger_create(int debug, const char *fn, const char *logdir, int version, preversionfix_fptr prefuncp, postversionfix_fptr postfuncp);
110gdk_export void logger_destroy(logger *lg);
111gdk_export gdk_return logger_exit(logger *lg);
112gdk_export gdk_return logger_restart(logger *lg);
113gdk_export gdk_return logger_cleanup(logger *lg);
114gdk_export void logger_with_ids(logger *lg);
115gdk_export lng logger_changes(logger *lg);
116gdk_export int logger_sequence(logger *lg, int seq, lng *id);
117
118/* todo pass the transaction id */
119gdk_export gdk_return log_bat(logger *lg, BAT *b, const char *n, char tpe, oid id);
120gdk_export gdk_return log_bat_clear(logger *lg, const char *n, char tpe, oid id);
121gdk_export gdk_return log_bat_persists(logger *lg, BAT *b, const char *n, char tpe, oid id);
122gdk_export gdk_return log_bat_transient(logger *lg, const char *n, char tpe, oid id);
123gdk_export gdk_return log_delta(logger *lg, BAT *uid, BAT *uval, const char *n, char tpe, oid id);
124
125gdk_export gdk_return log_tstart(logger *lg); /* TODO return transaction id */
126gdk_export gdk_return log_tend(logger *lg);
127gdk_export gdk_return log_abort(logger *lg);
128
129gdk_export gdk_return log_sequence(logger *lg, int seq, lng id);
130
131gdk_export gdk_return logger_add_bat(logger *lg, BAT *b, const char *name, char tpe, oid id)
132 __attribute__ ((__warn_unused_result__));
133gdk_export gdk_return logger_del_bat(logger *lg, log_bid bid)
134 __attribute__ ((__warn_unused_result__));
135gdk_export log_bid logger_find_bat(logger *lg, const char *name, char tpe, oid id);
136gdk_export gdk_return logger_upgrade_bat(logger *lg, const char *name, char tpe, oid id)
137 __attribute__ ((__warn_unused_result__));
138
139typedef int (*geomcatalogfix_fptr)(void *, int);
140gdk_export void geomcatalogfix_set(geomcatalogfix_fptr);
141gdk_export geomcatalogfix_fptr geomcatalogfix_get(void);
142
143typedef str (*geomsqlfix_fptr)(int);
144gdk_export void geomsqlfix_set(geomsqlfix_fptr);
145gdk_export geomsqlfix_fptr geomsqlfix_get(void);
146
147gdk_export void geomversion_set(void);
148gdk_export int geomversion_get(void);
149
150#endif /*_LOGGER_H_*/
151