~ubuntu-branches/ubuntu/trusty/mariadb-5.5/trusty-proposed

« back to all changes in this revision

Viewing changes to storage/pbxt/src/xactlog_xt.h

  • Committer: Package Import Robot
  • Author(s): James Page, Otto Kekäläinen
  • Date: 2014-02-17 16:51:52 UTC
  • mfrom: (2.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20140217165152-k315d3175g865kkx
Tags: 5.5.35-1
[ Otto Kekäläinen ]
* New upstream release, fixing the following security issues:
  - Buffer overflow in client/mysql.cc (Closes: #737597).
    - CVE-2014-0001
  - http://www.oracle.com/technetwork/topics/security/cpujan2014-1972949.html
    - CVE-2013-5891
    - CVE-2013-5908
    - CVE-2014-0386
    - CVE-2014-0393
    - CVE-2014-0401
    - CVE-2014-0402
    - CVE-2014-0412
    - CVE-2014-0420
    - CVE-2014-0437
* Upstream https://mariadb.atlassian.net/browse/MDEV-4902
  fixes compatibility with Bison 3.0 (Closes: #733002)
* Updated Russian debconf translation (Closes: #734426)
* Updated Japanese debconf translation (Closes: #735284)
* Updated French debconf translation (Closes: #736480)
* Renamed SONAME properly (Closes: #732967)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (c) 2007 PrimeBase Technologies GmbH
2
 
 *
3
 
 * PrimeBase XT
4
 
 *
5
 
 * This program is free software; you can redistribute it and/or modify
6
 
 * it under the terms of the GNU General Public License as published by
7
 
 * the Free Software Foundation; either version 2 of the License, or
8
 
 * (at your option) any later version.
9
 
 *
10
 
 * This program is distributed in the hope that it will be useful,
11
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
 
 * GNU General Public License for more details.
14
 
 *
15
 
 * You should have received a copy of the GNU General Public License
16
 
 * along with this program; if not, write to the Free Software
17
 
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
 
 *
19
 
 * 2007-10-31   Paul McCullagh
20
 
 *
21
 
 * H&G2JCtL
22
 
 *
23
 
 * The new table cache. Caches all non-index data. This includes the data
24
 
 * files and the row pointer files.
25
 
 */
26
 
 
27
 
#ifndef __xactlog_xt_h__
28
 
#define __xactlog_xt_h__
29
 
 
30
 
#include "pthread_xt.h"
31
 
#include "filesys_xt.h"
32
 
#include "sortedlist_xt.h"
33
 
 
34
 
struct XTThread;
35
 
struct XTOpenTable;
36
 
struct XTDatabase;
37
 
 
38
 
#ifdef DEBUG
39
 
//#define XT_USE_CACHE_DEBUG_SIZES
40
 
#endif
41
 
 
42
 
#ifdef XT_USE_CACHE_DEBUG_SIZES
43
 
#define XT_XLC_BLOCK_SHIFTS                     5
44
 
#define XT_XLC_FILE_SLOTS                       7
45
 
#define XT_XLC_SEGMENT_SHIFTS           1
46
 
#define XT_XLC_MAX_FLUSH_SEG_COUNT      10
47
 
#define XT_XLC_MAX_FREE_COUNT           10
48
 
#else
49
 
/* Block size is determined by the number of shifts 1 << 15 = 32K */
50
 
#define XT_XLC_BLOCK_SHIFTS                     15
51
 
#define XT_XLC_FILE_SLOTS                       71
52
 
/* The number of segments are determined by the segment shifts 1 << 3 = 8 */
53
 
#define XT_XLC_SEGMENT_SHIFTS           3
54
 
#define XT_XLC_MAX_FLUSH_SEG_COUNT      250
55
 
#define XT_XLC_MAX_FREE_COUNT           100
56
 
#endif
57
 
 
58
 
#define XT_XLC_BLOCK_SIZE                       (1 << XT_XLC_BLOCK_SHIFTS)
59
 
#define XT_XLC_BLOCK_MASK                       (XT_XLC_BLOCK_SIZE - 1)
60
 
 
61
 
#define XT_TIME_DIFF(start, now) (\
62
 
        ((xtWord4) (now) < (xtWord4) (start)) ? \
63
 
        ((xtWord4) 0XFFFFFFFF - ((xtWord4) (start) - (xtWord4) (now))) : \
64
 
        ((xtWord4) (now) - (xtWord4) (start)))
65
 
 
66
 
#define XLC_SEGMENT_COUNT                       ((off_t) 1 << XT_XLC_SEGMENT_SHIFTS)
67
 
#define XLC_SEGMENT_MASK                        (XLC_SEGMENT_COUNT - 1)
68
 
#define XLC_MAX_FLUSH_COUNT                     (XT_XLC_MAX_FLUSH_SEG_COUNT * XLC_SEGMENT_COUNT)
69
 
 
70
 
#define XLC_BLOCK_FREE                          0
71
 
#define XLC_BLOCK_READING                       1
72
 
#define XLC_BLOCK_CLEAN                         2
73
 
 
74
 
#define XT_RECYCLE_LOGS                         0
75
 
#define XT_DELETE_LOGS                          1
76
 
#define XT_KEEP_LOGS                            2
77
 
 
78
 
#define XT_XLOG_NO_WRITE_NO_FLUSH       0
79
 
#define XT_XLOG_WRITE_AND_FLUSH         1
80
 
#define XT_XLOG_WRITE_AND_NO_FLUSH      2
81
 
 
82
 
/* LOG CACHE ---------------------------------------------------- */
83
 
 
84
 
typedef struct XTXLogBlock {
85
 
        off_t                                   xlb_address;                                    /* The block address. */
86
 
        xtLogID                                 xlb_log_id;                                             /* The log id of the block. */
87
 
        xtWord4                                 xlb_state;                                              /* Block status. */
88
 
        struct XTXLogBlock              *xlb_next;                                              /* Pointer to next block on hash list, or next free block on free list. */
89
 
        xtWord1                                 xlb_data[XT_XLC_BLOCK_SIZE];
90
 
} XTXLogBlockRec, *XTXLogBlockPtr;
91
 
 
92
 
/* A disk cache segment. The cache is divided into a number of segments
93
 
 * to improve concurrency.
94
 
 */
95
 
typedef struct XTXLogCacheSeg {
96
 
        xt_mutex_type                   lcs_lock;                                               /* The cache segment lock. */
97
 
        xt_cond_type                    lcs_cond;
98
 
        XTXLogBlockPtr                  *lcs_hash_table;
99
 
} XTXLogCacheSegRec, *XTXLogCacheSegPtr;
100
 
 
101
 
typedef struct XTXLogCache {
102
 
        xt_mutex_type                   xlc_lock;                                               /* The public cache lock. */
103
 
        xt_cond_type                    xlc_cond;                                               /* The public cache wait condition. */
104
 
        XTXLogCacheSegRec               xlc_segment[XLC_SEGMENT_COUNT];
105
 
        XTXLogBlockPtr                  xlc_blocks;
106
 
        XTXLogBlockPtr                  xlc_blocks_end;
107
 
        XTXLogBlockPtr                  xlc_next_to_free;
108
 
        xtWord4                                 xlc_free_count;
109
 
        xtWord4                                 xlc_hash_size;
110
 
        xtWord4                                 xlc_block_count;
111
 
        xtWord8                                 xlc_upper_limit;
112
 
} XTXLogCacheRec;
113
 
 
114
 
/* LOG ENTRIES ---------------------------------------------------- */
115
 
 
116
 
#define XT_LOG_ENT_EOF                          0
117
 
#define XT_LOG_ENT_HEADER                       1
118
 
#define XT_LOG_ENT_NEW_LOG                      2                                       /* Move to the next log! NOTE!! May not appear in a group!! */
119
 
#define XT_LOG_ENT_DEL_LOG                      3                                       /* Delete the given transaction/data log. */
120
 
#define XT_LOG_ENT_NEW_TAB                      4                                       /* This record indicates a new table was created. */
121
 
 
122
 
#define XT_LOG_ENT_COMMIT                       5                                       /* Transaction was committed. */
123
 
#define XT_LOG_ENT_ABORT                        6                                       /* Transaction was aborted. */
124
 
#define XT_LOG_ENT_CLEANUP                      7                                       /* Written after a cleanup. */
125
 
 
126
 
#define XT_LOG_ENT_REC_MODIFIED         8                                       /* This records has been modified by the transaction. */
127
 
#define XT_LOG_ENT_UPDATE                       9
128
 
#define XT_LOG_ENT_UPDATE_BG            10
129
 
#define XT_LOG_ENT_UPDATE_FL            11
130
 
#define XT_LOG_ENT_UPDATE_FL_BG         12
131
 
#define XT_LOG_ENT_INSERT                       13
132
 
#define XT_LOG_ENT_INSERT_BG            14
133
 
#define XT_LOG_ENT_INSERT_FL            15
134
 
#define XT_LOG_ENT_INSERT_FL_BG         16
135
 
#define XT_LOG_ENT_DELETE                       17
136
 
#define XT_LOG_ENT_DELETE_BG            18
137
 
#define XT_LOG_ENT_DELETE_FL            19
138
 
#define XT_LOG_ENT_DELETE_FL_BG         20
139
 
 
140
 
#define XT_LOG_ENT_REC_FREED            21                                      /* This record has been placed in the free list. */
141
 
#define XT_LOG_ENT_REC_REMOVED          22                                      /* Free record and dependecies: index references, blob references. */
142
 
#define XT_LOG_ENT_REC_REMOVED_EXT      23                                      /* Free record and dependecies: index references, extended data, blob references. */
143
 
#define XT_LOG_ENT_REC_REMOVED_BI       38                                      /* Free record and dependecies: includes before image of record, for freeing index, etc. */
144
 
 
145
 
#define XT_LOG_ENT_REC_MOVED            24                                      /* The record has been moved by the compactor. */
146
 
#define XT_LOG_ENT_REC_CLEANED          25                                      /* This record has been cleaned by the sweeper. */
147
 
#define XT_LOG_ENT_REC_CLEANED_1        26                                      /* This record has been cleaned by the sweeper (short form). */
148
 
#define XT_LOG_ENT_REC_UNLINKED         27                                      /* The record after this record is unlinked from the variation list. */
149
 
 
150
 
#define XT_LOG_ENT_ROW_NEW                      28                                      /* Row allocated from the EOF. */
151
 
#define XT_LOG_ENT_ROW_NEW_FL           29                                      /* Row allocated from the free list. */
152
 
#define XT_LOG_ENT_ROW_ADD_REC          30                                      /* Record added to the row. */
153
 
#define XT_LOG_ENT_ROW_SET                      31
154
 
#define XT_LOG_ENT_ROW_FREED            32
155
 
 
156
 
#define XT_LOG_ENT_OP_SYNC                      33                                      /* Operations syncronised. */
157
 
#define XT_LOG_ENT_EXT_REC_OK           34                                      /* An extended record */
158
 
#define XT_LOG_ENT_EXT_REC_DEL          35                                      /* A deleted extended record */
159
 
 
160
 
#define XT_LOG_ENT_NO_OP                        36                                      /* If write to the database fails, we still try to log the
161
 
                                                                                                                 * op code, in an attempt to continue, if writting to log
162
 
                                                                                                                 * still works.
163
 
                                                                                                                 */
164
 
#define XT_LOG_ENT_END_OF_LOG           37                                      /* This is a record that indicates the end of the log, and
165
 
                                                                                                                 * fills to the end of a 512 byte block.
166
 
                                                                                                                 */
167
 
#define XT_LOG_ENT_PREPARE                      39                                      /* XA prepare log entry. */
168
 
 
169
 
#define XT_LOG_FILE_MAGIC                       0xAE88FE12
170
 
#define XT_LOG_VERSION_NO                       1
171
 
 
172
 
typedef struct XTXactLogHeader {
173
 
        xtWord1                                 xh_status_1;            /* XT_LOG_ENT_HEADER */
174
 
        xtWord1                                 xh_checksum_1;          
175
 
        XTDiskValue4                    xh_size_4;                      /* Must be set to sizeof(XTXactLogHeaderDRec). */
176
 
        XTDiskValue8                    xh_free_space_8;        /* The accumulated free space in this file. */
177
 
        XTDiskValue8                    xh_file_len_8;          /* The last confirmed correct file length (always set on close). */
178
 
        XTDiskValue8                    xh_comp_pos_8;          /* Compaction position (XT_DL_STATUS_CO_SOURCE only). */
179
 
        xtWord1                                 xh_comp_stat_1;         /* The compaction status XT_DL_STATUS_CO_SOURCE/XT_DL_STATUS_CO_TARGET */
180
 
        XTDiskValue4                    xh_log_id_4;
181
 
        XTDiskValue4                    xh_version_2;           /* XT_LOG_VERSION_NO */
182
 
        XTDiskValue4                    xh_magic_4;                     /* MUST always be at the end of the structure!! */
183
 
} XTXactLogHeaderDRec, *XTXactLogHeaderDPtr;
184
 
 
185
 
/* This is the original log head size (don't change): */
186
 
#define XT_MIN_LOG_HEAD_SIZE            (offsetof(XTXactLogHeaderDRec, xh_log_id_4) + 4)
187
 
#define XT_LOG_HEAD_MAGIC(b, l)         XT_GET_DISK_4(((xtWord1 *) (b)) + (l) - 4)
188
 
 
189
 
typedef struct XTXactNewLogEntry {
190
 
        xtWord1                                 xl_status_1;            /* XT_LOG_ENT_NEW_LOG, XT_LOG_ENT_DEL_LOG */
191
 
        xtWord1                                 xl_checksum_1;          
192
 
        XTDiskValue4                    xl_log_id_4;            /* Store the current table ID. */
193
 
} XTXactNewLogEntryDRec, *XTXactNewLogEntryDPtr;
194
 
 
195
 
typedef struct XTXactNewTabEntry {
196
 
        xtWord1                                 xt_status_1;            /* XT_LOG_ENT_NEW_TAB */
197
 
        xtWord1                                 xt_checksum_1;          
198
 
        XTDiskValue4                    xt_tab_id_4;            /* Store the current table ID. */
199
 
} XTXactNewTabEntryDRec, *XTXactNewTabEntryDPtr;
200
 
 
201
 
/* This record must appear in a transaction group, and therefore has no transaction ID: */
202
 
typedef struct XTXactEndEntry {
203
 
        xtWord1                                 xe_status_1;            /* XT_LOG_ENT_COMMIT, XT_LOG_ENT_ABORT */
204
 
        xtWord1                                 xe_checksum_1;          
205
 
        XTDiskValue4                    xe_xact_id_4;           /* The transaction. */
206
 
        XTDiskValue4                    xe_not_used_4;          /* Was the end sequence number (no longer used - v1.0.04+), set to zero). */
207
 
} XTXactEndEntryDRec, *XTXactEndEntryDPtr;
208
 
 
209
 
typedef struct XTXactPrepareEntry {
210
 
        xtWord1                                 xp_status_1;            /* XT_LOG_ENT_PREPARE */
211
 
        XTDiskValue2                    xp_checksum_2;          
212
 
        XTDiskValue4                    xp_xact_id_4;           /* The transaction. */
213
 
        xtWord1                                 xp_xa_len_1;            /* The length of the XA data. */
214
 
        xtWord1                                 xp_xa_data[XT_MAX_XA_DATA_SIZE];
215
 
} XTXactPrepareEntryDRec, *XTXactPrepareEntryDPtr;
216
 
 
217
 
typedef struct XTXactCleanupEntry {
218
 
        xtWord1                                 xc_status_1;            /* XT_LOG_ENT_CLEANUP */
219
 
        xtWord1                                 xc_checksum_1;          
220
 
        XTDiskValue4                    xc_xact_id_4;           /* The transaction that was cleaned up. */
221
 
} XTXactCleanupEntryDRec, *XTXactCleanupEntryDPtr;
222
 
 
223
 
typedef struct XTactUpdateEntry {
224
 
        xtWord1                                 xu_status_1;            /* XT_LOG_ENT_REC_MODIFIED, XT_LOG_ENT_UPDATE, XT_LOG_ENT_INSERT, XT_LOG_ENT_DELETE */
225
 
                                                                                                /* XT_LOG_ENT_UPDATE_BG, XT_LOG_ENT_INSERT_BG, XT_LOG_ENT_DELETE_BG */
226
 
        XTDiskValue2                    xu_checksum_2;          
227
 
        XTDiskValue4                    xu_op_seq_4;            /* Operation sequence number. */
228
 
        XTDiskValue4                    xu_tab_id_4;            /* Table ID of the record. */
229
 
        xtDiskRecordID4                 xu_rec_id_4;            /* Offset of the new updated record. */
230
 
        XTDiskValue2                    xu_size_2;                      /* Size of the record data. */
231
 
        /* This is the start of the actual record data: */
232
 
        xtWord1                                 xu_rec_type_1;          /* Type of the record. */
233
 
        xtWord1                                 xu_stat_id_1;
234
 
        xtDiskRecordID4                 xu_prev_rec_id_4;               /* The previous variation of this record. */
235
 
        XTDiskValue4                    xu_xact_id_4;           /* The transaction ID. */
236
 
        XTDiskValue4                    xu_row_id_4;            /* The row ID of this record. */
237
 
} XTactUpdateEntryDRec, *XTactUpdateEntryDPtr;
238
 
 
239
 
typedef struct XTactUpdateFLEntry {
240
 
        xtWord1                                 xf_status_1;            /* XT_LOG_ENT_UPDATE_FL, XT_LOG_ENT_INSERT_FL, XT_LOG_ENT_DELETE_FL */
241
 
                                                                                                /* XT_LOG_ENT_UPDATE_FL_BG, XT_LOG_ENT_INSERT_FL_BG, XT_LOG_ENT_DELETE_FL_BG */
242
 
        XTDiskValue2                    xf_checksum_2;          
243
 
        XTDiskValue4                    xf_op_seq_4;            /* Operation sequence number. */
244
 
        XTDiskValue4                    xf_tab_id_4;            /* Table ID of the record. */
245
 
        xtDiskRecordID4                 xf_rec_id_4;            /* Offset of the new updated record. */
246
 
        XTDiskValue2                    xf_size_2;                      /* Size of the record data. */
247
 
        xtDiskRecordID4                 xf_free_rec_id_4;       /* Update to the free list. */
248
 
        /* This is the start of the actual record data: */
249
 
        xtWord1                                 xf_rec_type_1;          /* Type of the record. */
250
 
        xtWord1                                 xf_stat_id_1;
251
 
        xtDiskRecordID4                 xf_prev_rec_id_4;       /* The previous variation of this record. */
252
 
        XTDiskValue4                    xf_xact_id_4;           /* The transaction ID. */
253
 
        XTDiskValue4                    xf_row_id_4;            /* The row ID of this record. */
254
 
} XTactUpdateFLEntryDRec, *XTactUpdateFLEntryDPtr;
255
 
 
256
 
typedef struct XTactFreeRecEntry {
257
 
        xtWord1                                 fr_status_1;            /* XT_LOG_ENT_REC_REMOVED, XT_LOG_ENT_REC_REMOVED_EXT, XT_LOG_ENT_REC_FREED */
258
 
        xtWord1                                 fr_checksum_1;          
259
 
        XTDiskValue4                    fr_op_seq_4;            /* Operation sequence number. */
260
 
        XTDiskValue4                    fr_tab_id_4;            /* Table ID of the record. */
261
 
        xtDiskRecordID4                 fr_rec_id_4;            /* Offset of the new written record. */
262
 
        /* This data confirms the record state for release of
263
 
         * attached resources (extended records, indexes and blobs)
264
 
         */
265
 
        xtWord1                                 fr_stat_id_1;           /* The statement ID of the record. */
266
 
        XTDiskValue4                    fr_xact_id_4;           /* The transaction ID of the record. */
267
 
        /* This is the start of the actual record data: */
268
 
        xtWord1                                 fr_rec_type_1;
269
 
        xtWord1                                 fr_not_used_1;
270
 
        xtDiskRecordID4                 fr_next_rec_id_4;       /* The next block on the free list. */
271
 
} XTactFreeRecEntryDRec, *XTactFreeRecEntryDPtr;
272
 
 
273
 
typedef struct XTactRemoveBIEntry {
274
 
        xtWord1                                 rb_status_1;            /* XT_LOG_ENT_REC_REMOVED_BI */
275
 
        XTDiskValue2                    rb_checksum_2;          
276
 
        XTDiskValue4                    rb_op_seq_4;            /* Operation sequence number. */
277
 
        XTDiskValue4                    rb_tab_id_4;            /* Table ID of the record. */
278
 
        xtDiskRecordID4                 rb_rec_id_4;            /* Offset of the new written record. */
279
 
        XTDiskValue2                    rb_size_2;                      /* Size of the record data. */
280
 
 
281
 
        xtWord1                                 rb_new_rec_type_1;      /* New type of the record (needed for below). */
282
 
 
283
 
        /* This is the start of the record data, with some fields overwritten for the free: */
284
 
        xtWord1                                 rb_rec_type_1;          /* Type of the record. */
285
 
        xtWord1                                 rb_stat_id_1;
286
 
        xtDiskRecordID4                 rb_next_rec_id_4;       /* The next block on the free list (overwritten). */
287
 
        XTDiskValue4                    rb_xact_id_4;           /* The transaction ID. */
288
 
        XTDiskValue4                    rb_row_id_4;            /* The row ID of this record. */
289
 
} XTactRemoveBIEntryDRec, *XTactRemoveBIEntryDPtr;
290
 
 
291
 
typedef struct XTactWriteRecEntry {
292
 
        xtWord1                                 xw_status_1;            /* XT_LOG_ENT_REC_MOVED, XT_LOG_ENT_REC_CLEANED, XT_LOG_ENT_REC_CLEANED_1,
293
 
                                                                                                 * XT_LOG_ENT_REC_UNLINKED */
294
 
        xtWord1                                 xw_checksum_1;          
295
 
        XTDiskValue4                    xw_op_seq_4;            /* Operation sequence number. */
296
 
        XTDiskValue4                    xw_tab_id_4;            /* Table ID of the record. */
297
 
        xtDiskRecordID4                 xw_rec_id_4;            /* Offset of the new written record. */
298
 
        /* This is the start of the actual record data: */
299
 
        xtWord1                                 xw_rec_type_1;
300
 
        xtWord1                                 xw_stat_id_1;
301
 
        xtDiskRecordID4                 xw_next_rec_id_4;       /* The next block on the free list. */
302
 
} XTactWriteRecEntryDRec, *XTactWriteRecEntryDPtr;
303
 
 
304
 
typedef struct XTactRowAddedEntry {
305
 
        xtWord1                                 xa_status_1;            /* XT_LOG_ENT_ROW_NEW or XT_LOG_ENT_ROW_NEW_FL */
306
 
        xtWord1                                 xa_checksum_1;          
307
 
        XTDiskValue4                    xa_op_seq_4;            /* Operation sequence number. */
308
 
        XTDiskValue4                    xa_tab_id_4;            /* Table ID of the record. */
309
 
        XTDiskValue4                    xa_row_id_4;            /* The row ID of the row allocated. */
310
 
        XTDiskValue4                    xa_free_list_4;         /* Change to the free list (ONLY for XT_LOG_ENT_ROW_NEW_FL). */
311
 
} XTactRowAddedEntryDRec, *XTactRowAddedEntryDPtr;
312
 
 
313
 
typedef struct XTactWriteRowEntry {
314
 
        xtWord1                                 wr_status_1;            /* XT_LOG_ENT_ROW_ADD_REC, XT_LOG_ENT_ROW_SET, XT_LOG_ENT_ROW_FREED */
315
 
        xtWord1                                 wr_checksum_1;          
316
 
        XTDiskValue4                    wr_op_seq_4;            /* Operation sequence number. */
317
 
        XTDiskValue4                    wr_tab_id_4;            /* Table ID of the record. */
318
 
        XTDiskValue4                    wr_row_id_4;            /* Row ID of the row that was modified. */
319
 
        /* This is the start of the actual record data: */
320
 
        XTDiskValue4                    wr_ref_id_4;            /* The row reference data. */
321
 
} XTactWriteRowEntryDRec, *XTactWriteRowEntryDPtr;
322
 
 
323
 
typedef struct XTactOpSyncEntry {
324
 
        xtWord1                                 os_status_1;            /* XT_LOG_ENT_OP_SYNC  */
325
 
        xtWord1                                 os_checksum_1;          
326
 
        XTDiskValue4                    os_time_4;                      /* Time of the restart. */
327
 
} XTactOpSyncEntryDRec, *XTactOpSyncEntryDPtr;
328
 
 
329
 
typedef struct XTactNoOpEntry {
330
 
        xtWord1                                 no_status_1;            /* XT_LOG_ENT_NO_OP */
331
 
        xtWord1                                 no_checksum_1;          
332
 
        XTDiskValue4                    no_op_seq_4;            /* Operation sequence number. */
333
 
        XTDiskValue4                    no_tab_id_4;            /* Table ID of the record. */
334
 
} XTactNoOpEntryDRec, *XTactNoOpEntryDPtr;
335
 
 
336
 
typedef struct XTactExtRecEntry {
337
 
        xtWord1                                 er_status_1;            /* XT_LOG_ENT_EXT_REC_OK, XT_LOG_ENT_EXT_REC_DEL */
338
 
        XTDiskValue4                    er_data_size_4;         /* Size of this record data area only. */
339
 
        XTDiskValue4                    er_tab_id_4;            /* The table referencing this extended record. */
340
 
        xtDiskRecordID4                 er_rec_id_4;            /* The ID of the reference record. */
341
 
        xtWord1                                 er_data[XT_VAR_LENGTH];
342
 
} XTactExtRecEntryDRec, *XTactExtRecEntryDPtr;
343
 
 
344
 
typedef union XTXactLogBuffer {
345
 
        XTXactLogHeaderDRec             xh;
346
 
        XTXactNewLogEntryDRec   xl;
347
 
        XTXactNewTabEntryDRec   xt;
348
 
        XTXactEndEntryDRec              xe;
349
 
        XTXactCleanupEntryDRec  xc;
350
 
        XTactUpdateEntryDRec    xu;
351
 
        XTactUpdateFLEntryDRec  xf;
352
 
        XTactFreeRecEntryDRec   fr;
353
 
        XTactRemoveBIEntryDRec  rb;
354
 
        XTactWriteRecEntryDRec  xw;
355
 
        XTactRowAddedEntryDRec  xa;
356
 
        XTactWriteRowEntryDRec  wr;
357
 
        XTactOpSyncEntryDRec    os;
358
 
        XTactExtRecEntryDRec    er;
359
 
        XTactNoOpEntryDRec              no;
360
 
        XTXactPrepareEntryDRec  xp;
361
 
} XTXactLogBufferDRec, *XTXactLogBufferDPtr;
362
 
 
363
 
/* ---------------------------------------- */
364
 
 
365
 
typedef struct XTXactSeqRead {
366
 
        size_t                                  xseq_buffer_size;               /* Size of the buffer. */
367
 
        xtBool                                  xseq_load_cache;                /* TRUE if reads should load the cache! */
368
 
 
369
 
        xtLogID                                 xseq_log_id;
370
 
        XTOpenFilePtr                   xseq_log_file;
371
 
        off_t                                   xseq_log_eof;
372
 
 
373
 
        xtLogOffset                             xseq_buf_log_offset;    /* File offset of the buffer. */
374
 
        size_t                                  xseq_buffer_len;                /* Amount of data in the buffer. */
375
 
        xtWord1                                 *xseq_buffer;
376
 
 
377
 
        xtLogID                                 xseq_rec_log_id;                /* The current record log ID. */
378
 
        xtLogOffset                             xseq_rec_log_offset;    /* The current log read position. */
379
 
        size_t                                  xseq_record_len;                /* The length of the current record. */
380
 
} XTXactSeqReadRec, *XTXactSeqReadPtr;
381
 
 
382
 
typedef struct XTXactLogFile {
383
 
        xtLogID                                 lf_log_id;
384
 
        off_t                                   lr_file_len;                                    /* The log file size (0 means this is the last log) */
385
 
} XTXactLogFileRec, *XTXactLogFilePtr;
386
 
 
387
 
/*
388
 
 * The transaction log. Each database has one.
389
 
 */
390
 
 
391
 
/* Does not seem to make much difference... */
392
 
#ifndef XT_NO_ATOMICS
393
 
/* This function uses atomic ops: */
394
 
//#define XT_XLOG_WAIT_SPINS
395
 
#endif
396
 
 
397
 
typedef struct XTDatabaseLog {
398
 
        struct XTDatabase               *xl_db;
399
 
 
400
 
        off_t                                   xl_log_file_threshold;
401
 
        u_int                                   xl_log_file_count;                              /* Number of logs to use (>= 1). */
402
 
        u_int                                   xt_log_file_dyn_count;                  /* A dynamic value to add to log file count. */
403
 
        u_int                                   xt_log_file_dyn_dec;                    /* Used to descide when to decrement the dynamic count. */
404
 
        size_t                                  xl_size_of_buffers;                             /* The size of both log buffers. */
405
 
        xtWord8                                 xl_log_bytes_written;                   /* The total number of bytes written to the log, after recovery. */
406
 
        xtWord8                                 xl_log_bytes_flushed;                   /* The total number of bytes flushed to the log, after recovery. */
407
 
        xtWord8                                 xl_log_bytes_read;                              /* The total number of log bytes read, after recovery. */
408
 
 
409
 
        u_int                                   xl_last_flush_time;                             /* Last flush time in micro-seconds. */
410
 
 
411
 
        /* The writer log buffer: */
412
 
        xt_mutex_type                   xl_write_lock;
413
 
        xt_cond_type                    xl_write_cond;
414
 
#ifdef XT_XLOG_WAIT_SPINS
415
 
        xtWord4                                 xt_writing;                                             /* 1 if a thread is writing. */
416
 
        xtWord4                                 xt_waiting;                                             /* Count of the threads waiting on the xl_write_cond. */
417
 
#else
418
 
        xtBool                                  xt_writing;                                             /* TRUE if a thread is writing. */
419
 
#endif
420
 
        xtLogID                                 xl_log_id;                                              /* The number of the write log. */
421
 
        XTOpenFilePtr                   xl_log_file;                                    /* The open write log. */
422
 
 
423
 
        XTSpinLockRec                   xl_buffer_lock;                                 /* This locks both the write and the append log buffers. */
424
 
 
425
 
        xtLogID                                 xl_max_log_id;                                  /* The ID of the highest log on disk. */
426
 
 
427
 
        xtLogID                                 xl_write_log_id;                                /* This is the log ID were the write data will go. */
428
 
        xtLogOffset                             xl_write_log_offset;                    /* The file offset of the write log. */
429
 
        size_t                                  xl_write_buf_pos;
430
 
        size_t                                  xl_write_buf_pos_start;
431
 
        xtWord1                                 *xl_write_buffer;
432
 
        xtBool                                  xl_write_done;                                  /* TRUE if the write buffer has been written! */
433
 
 
434
 
        xtLogID                                 xl_append_log_id;                               /* This is the log ID were the append data will go. */
435
 
        xtLogOffset                             xl_append_log_offset;                   /* The file offset in the log were the append data will go. */
436
 
        size_t                                  xl_append_buf_pos;                              /* The amount of data in the append buffer. */
437
 
        size_t                                  xl_append_buf_pos_start;                /* The amount of data in the append buffer already written. */
438
 
        xtWord1                                 *xl_append_buffer;
439
 
 
440
 
        xtLogID                                 xl_flush_log_id;                                /* The last log flushed. */
441
 
        xtLogOffset                             xl_flush_log_offset;                    /* The position in the log flushed. */
442
 
 
443
 
        void                                    xlog_setup(struct XTThread *self, struct XTDatabase *db, off_t log_file_size, size_t transaction_buffer_size, int log_count);
444
 
        xtBool                                  xlog_set_write_offset(xtLogID log_id, xtLogOffset log_offset, xtLogID max_log_id, struct XTThread *thread);
445
 
        void                                    xlog_close(struct XTThread *self);
446
 
        void                                    xlog_exit(struct XTThread *self);
447
 
        void                                    xlog_name(size_t size, char *path, xtLogID log_id);
448
 
        int                                             xlog_delete_log(xtLogID del_log_id, struct XTThread *thread);
449
 
 
450
 
        xtBool                                  xlog_append(struct XTThread *thread, size_t size1, xtWord1 *data1, size_t size2, xtWord1 *data2, int flush_log_at_trx_commit, xtLogID *log_id, xtLogOffset *log_offset);
451
 
        xtBool                                  xlog_flush(struct XTThread *thread);
452
 
        xtBool                                  xlog_flush_pending();
453
 
 
454
 
        xtBool                                  xlog_seq_init(XTXactSeqReadPtr seq, size_t buffer_size, xtBool load_cache);
455
 
        void                                    xlog_seq_exit(XTXactSeqReadPtr seq);
456
 
        void                                    xlog_seq_close(XTXactSeqReadPtr seq);
457
 
        xtBool                                  xlog_seq_start(XTXactSeqReadPtr seq, xtLogID log_id, xtLogOffset log_offset, xtBool missing_ok);
458
 
        xtBool                                  xlog_rnd_read(XTXactSeqReadPtr seq, xtLogID log_id, xtLogOffset log_offset, size_t size, xtWord1 *data, size_t *read, struct XTThread *thread);
459
 
        size_t                                  xlog_bytes_to_write();
460
 
        xtBool                                  xlog_read_from_cache(XTXactSeqReadPtr seq, xtLogID log_id, xtLogOffset log_offset, size_t size, off_t eof, xtWord1 *buffer, size_t *data_read, struct XTThread *thread);
461
 
        xtBool                                  xlog_write_thru(XTXactSeqReadPtr seq, size_t size, xtWord1 *data, struct XTThread *thread);
462
 
        xtBool                                  xlog_verify(XTXactLogBufferDPtr record, size_t rec_size, xtLogID log_id);
463
 
        xtBool                                  xlog_seq_next(XTXactSeqReadPtr seq, XTXactLogBufferDPtr *entry, xtBool verify, struct XTThread *thread);
464
 
        void                                    xlog_seq_skip(XTXactSeqReadPtr seq, size_t size);
465
 
 
466
 
private:
467
 
        xtBool                                  xlog_open_log(xtLogID log_id, off_t curr_eof, struct XTThread *thread);
468
 
} XTDatabaseLogRec, *XTDatabaseLogPtr;
469
 
 
470
 
xtBool                  xt_xlog_flush_log(struct XTDatabase *db, struct XTThread *thread);
471
 
xtBool                  xt_xlog_log_data(struct XTThread *thread, size_t len, XTXactLogBufferDPtr log_entry, int flush_log_at_trx_commit);
472
 
xtBool                  xt_xlog_modify_table(xtTableID tab_id, u_int status, xtOpSeqNo op_seq, xtRecordID free_list, xtRecordID address, size_t size, xtWord1 *data, struct XTThread *thread);
473
 
 
474
 
void                    xt_xlog_init(struct XTThread *self, size_t cache_size);
475
 
void                    xt_xlog_exit(struct XTThread *self);
476
 
xtInt8                  xt_xlog_get_usage();
477
 
xtInt8                  xt_xlog_get_size();
478
 
xtLogID                 xt_xlog_get_min_log(struct XTThread *self, struct XTDatabase *db);
479
 
void                    xt_xlog_delete_logs(struct XTThread *self, struct XTDatabase *db);
480
 
 
481
 
void                    xt_start_writer(struct XTThread *self, struct XTDatabase *db);
482
 
void                    xt_wait_for_writer(struct XTThread *self, struct XTDatabase *db);
483
 
void                    xt_stop_writer(struct XTThread *self, struct XTDatabase *db);
484
 
 
485
 
#endif
486