Merge lp:~vkolesnikov/pbxt/pbxt-bug-379315 into lp:pbxt
- pbxt-bug-379315
- Merge into trunk
Proposed by
Vladimir Kolesnikov
Status: | Merged | ||||
---|---|---|---|---|---|
Merged at revision: | not available | ||||
Proposed branch: | lp:~vkolesnikov/pbxt/pbxt-bug-379315 | ||||
Merge into: | lp:pbxt | ||||
Diff against target: | None lines | ||||
To merge this branch: | bzr merge lp:~vkolesnikov/pbxt/pbxt-bug-379315 | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
PBXT Core | Pending | ||
Review via email: mp+7292@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
- 657. By Paul McCullagh
-
Merged RN245
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'ChangeLog' | |||
2 | --- ChangeLog 2009-06-03 14:53:00 +0000 | |||
3 | +++ ChangeLog 2009-06-10 16:26:33 +0000 | |||
4 | @@ -3,6 +3,10 @@ | |||
5 | 3 | 3 | ||
6 | 4 | ------- 1.0.08 RC - Not yet released | 4 | ------- 1.0.08 RC - Not yet released |
7 | 5 | 5 | ||
8 | 6 | RN245: Fixed bug #379315: Inconsistent behavior of DELETE IGNORE and FK constraint | ||
9 | 7 | |||
10 | 8 | RN244: Fixed a recovery problem: during the recovery of "record modified" action the table was updated before the old index entries were removed; then the xres_remove_index_entries was supplied the new record which lead to incorrect index update | ||
11 | 9 | |||
12 | 6 | RN243: Fixed a bug that caused a recovery failure if partitioned pbxt tables where present. This happended because the recovery used a MySQL function to open tables and the PBXT handler was not yet registered | 10 | RN243: Fixed a bug that caused a recovery failure if partitioned pbxt tables where present. This happended because the recovery used a MySQL function to open tables and the PBXT handler was not yet registered |
13 | 7 | 11 | ||
14 | 8 | RN242: Fixed a bug that caused a deadlock if pbxt initialization failed. This happened because pbxt ceanup was done from pbxt_init() with PLUGIN_lock being held by MySQL which lead to a deadlock in the freeer thread | 12 | RN242: Fixed a bug that caused a deadlock if pbxt initialization failed. This happened because pbxt ceanup was done from pbxt_init() with PLUGIN_lock being held by MySQL which lead to a deadlock in the freeer thread |
15 | 9 | 13 | ||
16 | === modified file 'src/ha_pbxt.cc' | |||
17 | --- src/ha_pbxt.cc 2009-06-03 14:07:54 +0000 | |||
18 | +++ src/ha_pbxt.cc 2009-06-10 16:26:33 +0000 | |||
19 | @@ -1565,7 +1565,11 @@ | |||
20 | 1565 | freer_(); // xt_unlock_mutex(share->sh_ex_mutex) | 1565 | freer_(); // xt_unlock_mutex(share->sh_ex_mutex) |
21 | 1566 | } | 1566 | } |
22 | 1567 | 1567 | ||
23 | 1568 | #ifdef PBXT_ALLOW_PRINTING | ||
24 | 1569 | static void ha_release_exclusive_use(XTThreadPtr self, XTSharePtr share) | ||
25 | 1570 | #else | ||
26 | 1568 | static void ha_release_exclusive_use(XTThreadPtr XT_UNUSED(self), XTSharePtr share) | 1571 | static void ha_release_exclusive_use(XTThreadPtr XT_UNUSED(self), XTSharePtr share) |
27 | 1572 | #endif | ||
28 | 1569 | { | 1573 | { |
29 | 1570 | XT_PRINT1(self, "ha_release_exclusive_use %s PBXT X UNLOCK\n", share->sh_table_path->ps_path); | 1574 | XT_PRINT1(self, "ha_release_exclusive_use %s PBXT X UNLOCK\n", share->sh_table_path->ps_path); |
30 | 1571 | xt_lock_mutex_ns((xt_mutex_type *) share->sh_ex_mutex); | 1575 | xt_lock_mutex_ns((xt_mutex_type *) share->sh_ex_mutex); |
31 | @@ -4164,10 +4168,15 @@ | |||
32 | 4164 | pb_open_tab->ot_is_modify = FALSE; | 4168 | pb_open_tab->ot_is_modify = FALSE; |
33 | 4165 | if ((pb_open_tab->ot_for_update = (lock_type == F_WRLCK))) { | 4169 | if ((pb_open_tab->ot_for_update = (lock_type == F_WRLCK))) { |
34 | 4166 | switch ((int) thd_sql_command(thd)) { | 4170 | switch ((int) thd_sql_command(thd)) { |
35 | 4171 | case SQLCOM_DELETE: | ||
36 | 4172 | case SQLCOM_DELETE_MULTI: | ||
37 | 4173 | /* turn DELETE IGNORE into normal DELETE. The IGNORE option causes problems because | ||
38 | 4174 | * when a record is deleted we add an xlog record which we cannot "rollback" later | ||
39 | 4175 | * when we find that an FK-constraint has failed. | ||
40 | 4176 | */ | ||
41 | 4177 | thd->lex->ignore = false; | ||
42 | 4167 | case SQLCOM_UPDATE: | 4178 | case SQLCOM_UPDATE: |
43 | 4168 | case SQLCOM_UPDATE_MULTI: | 4179 | case SQLCOM_UPDATE_MULTI: |
44 | 4169 | case SQLCOM_DELETE: | ||
45 | 4170 | case SQLCOM_DELETE_MULTI: | ||
46 | 4171 | case SQLCOM_REPLACE: | 4180 | case SQLCOM_REPLACE: |
47 | 4172 | case SQLCOM_REPLACE_SELECT: | 4181 | case SQLCOM_REPLACE_SELECT: |
48 | 4173 | case SQLCOM_INSERT: | 4182 | case SQLCOM_INSERT: |
49 | @@ -4644,7 +4653,7 @@ | |||
50 | 4644 | { | 4653 | { |
51 | 4645 | THD *thd = current_thd; | 4654 | THD *thd = current_thd; |
52 | 4646 | int err = 0; | 4655 | int err = 0; |
54 | 4647 | XTThreadPtr self; | 4656 | XTThreadPtr self = NULL; |
55 | 4648 | XTSharePtr share; | 4657 | XTSharePtr share; |
56 | 4649 | 4658 | ||
57 | 4650 | STAT_TRACE(self, *thd_query(thd)); | 4659 | STAT_TRACE(self, *thd_query(thd)); |
58 | 4651 | 4660 | ||
59 | === modified file 'src/restart_xt.cc' | |||
60 | --- src/restart_xt.cc 2009-06-03 14:07:54 +0000 | |||
61 | +++ src/restart_xt.cc 2009-06-10 16:27:03 +0000 | |||
62 | @@ -1,3202 +1,3207 @@ | |||
3262 | 1 | /* Copyright (c) 2007 PrimeBase Technologies GmbH | 1 | /* Copyright (c) 2007 PrimeBase Technologies GmbH |
3263 | 2 | * | 2 | * |
3264 | 3 | * PrimeBase XT | 3 | * PrimeBase XT |
3265 | 4 | * | 4 | * |
3266 | 5 | * This program is free software; you can redistribute it and/or modify | 5 | * This program is free software; you can redistribute it and/or modify |
3267 | 6 | * it under the terms of the GNU General Public License as published by | 6 | * it under the terms of the GNU General Public License as published by |
3268 | 7 | * the Free Software Foundation; either version 2 of the License, or | 7 | * the Free Software Foundation; either version 2 of the License, or |
3269 | 8 | * (at your option) any later version. | 8 | * (at your option) any later version. |
3270 | 9 | * | 9 | * |
3271 | 10 | * This program is distributed in the hope that it will be useful, | 10 | * This program is distributed in the hope that it will be useful, |
3272 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
3273 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3274 | 13 | * GNU General Public License for more details. | 13 | * GNU General Public License for more details. |
3275 | 14 | * | 14 | * |
3276 | 15 | * You should have received a copy of the GNU General Public License | 15 | * You should have received a copy of the GNU General Public License |
3277 | 16 | * along with this program; if not, write to the Free Software | 16 | * along with this program; if not, write to the Free Software |
3278 | 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
3279 | 18 | * | 18 | * |
3280 | 19 | * 2007-11-12 Paul McCullagh | 19 | * 2007-11-12 Paul McCullagh |
3281 | 20 | * | 20 | * |
3282 | 21 | * H&G2JCtL | 21 | * H&G2JCtL |
3283 | 22 | * | 22 | * |
3284 | 23 | * Restart and write data to the database. | 23 | * Restart and write data to the database. |
3285 | 24 | */ | 24 | */ |
3286 | 25 | 25 | ||
3287 | 26 | #include "xt_config.h" | 26 | #include "xt_config.h" |
3288 | 27 | 27 | ||
3289 | 28 | #include <signal.h> | 28 | #include <signal.h> |
3290 | 29 | #include <time.h> | 29 | #include <time.h> |
3291 | 30 | 30 | ||
3292 | 31 | #ifndef DRIZZLED | 31 | #ifndef DRIZZLED |
3293 | 32 | #include "mysql_priv.h" | 32 | #include "mysql_priv.h" |
3294 | 33 | #endif | 33 | #endif |
3295 | 34 | 34 | ||
3296 | 35 | #include "ha_pbxt.h" | 35 | #include "ha_pbxt.h" |
3297 | 36 | 36 | ||
3298 | 37 | #include "xactlog_xt.h" | 37 | #include "xactlog_xt.h" |
3299 | 38 | #include "database_xt.h" | 38 | #include "database_xt.h" |
3300 | 39 | #include "util_xt.h" | 39 | #include "util_xt.h" |
3301 | 40 | #include "strutil_xt.h" | 40 | #include "strutil_xt.h" |
3302 | 41 | #include "filesys_xt.h" | 41 | #include "filesys_xt.h" |
3303 | 42 | #include "restart_xt.h" | 42 | #include "restart_xt.h" |
3304 | 43 | #include "myxt_xt.h" | 43 | #include "myxt_xt.h" |
3305 | 44 | #include "trace_xt.h" | 44 | #include "trace_xt.h" |
3306 | 45 | 45 | ||
3307 | 46 | #ifdef DEBUG | 46 | #ifdef DEBUG |
3308 | 47 | //#define DEBUG_PRINT | 47 | //#define DEBUG_PRINT |
3309 | 48 | //#define DEBUG_KEEP_LOGS | 48 | //#define DEBUG_KEEP_LOGS |
3310 | 49 | //#define PRINT_LOG_ON_RECOVERY | 49 | //#define PRINT_LOG_ON_RECOVERY |
3311 | 50 | //#define TRACE_RECORD_DATA | 50 | //#define TRACE_RECORD_DATA |
3312 | 51 | //#define SKIP_STARTUP_CHECKPOINT | 51 | //#define SKIP_STARTUP_CHECKPOINT |
3313 | 52 | //#define NEVER_CHECKPOINT | 52 | //#define NEVER_CHECKPOINT |
3314 | 53 | //#define TRACE_CHECKPOINT | 53 | //#define TRACE_CHECKPOINT |
3315 | 54 | #endif | 54 | #endif |
3316 | 55 | 55 | ||
3317 | 56 | #define PRINTF printf | 56 | #define PRINTF printf |
3318 | 57 | //#define PRINTF xt_ftracef | 57 | //#define PRINTF xt_ftracef |
3319 | 58 | //#define PRINTF xt_trace | 58 | //#define PRINTF xt_trace |
3320 | 59 | 59 | ||
3321 | 60 | void xt_print_bytes(xtWord1 *buf, u_int len) | 60 | void xt_print_bytes(xtWord1 *buf, u_int len) |
3322 | 61 | { | 61 | { |
3323 | 62 | for (u_int i=0; i<len; i++) { | 62 | for (u_int i=0; i<len; i++) { |
3324 | 63 | PRINTF("%02x ", (u_int) *buf); | 63 | PRINTF("%02x ", (u_int) *buf); |
3325 | 64 | buf++; | 64 | buf++; |
3326 | 65 | } | 65 | } |
3327 | 66 | } | 66 | } |
3328 | 67 | 67 | ||
3329 | 68 | void xt_print_log_record(xtLogID log, xtLogOffset offset, XTXactLogBufferDPtr record) | 68 | void xt_print_log_record(xtLogID log, xtLogOffset offset, XTXactLogBufferDPtr record) |
3330 | 69 | { | 69 | { |
3331 | 70 | const char *type = NULL; | 70 | const char *type = NULL; |
3332 | 71 | const char *rec_type = NULL; | 71 | const char *rec_type = NULL; |
3333 | 72 | xtOpSeqNo op_no = 0; | 72 | xtOpSeqNo op_no = 0; |
3334 | 73 | xtTableID tab_id = 0; | 73 | xtTableID tab_id = 0; |
3335 | 74 | xtRowID row_id = 0; | 74 | xtRowID row_id = 0; |
3336 | 75 | xtRecordID rec_id = 0; | 75 | xtRecordID rec_id = 0; |
3337 | 76 | xtBool xn_set = FALSE; | 76 | xtBool xn_set = FALSE; |
3338 | 77 | xtXactID xn_id = 0; | 77 | xtXactID xn_id = 0; |
3339 | 78 | char buffer[200]; | 78 | char buffer[200]; |
3340 | 79 | XTTabRecExtDPtr rec_buf; | 79 | XTTabRecExtDPtr rec_buf; |
3341 | 80 | XTTabRecExtDPtr ext_rec; | 80 | XTTabRecExtDPtr ext_rec; |
3342 | 81 | XTTabRecFixDPtr fix_rec; | 81 | XTTabRecFixDPtr fix_rec; |
3343 | 82 | u_int rec_len; | 82 | u_int rec_len; |
3344 | 83 | xtLogID log_id = 0; | 83 | xtLogID log_id = 0; |
3345 | 84 | xtLogOffset log_offset = 0; | 84 | xtLogOffset log_offset = 0; |
3346 | 85 | 85 | ||
3347 | 86 | rec_buf = NULL; | 86 | rec_buf = NULL; |
3348 | 87 | ext_rec = NULL; | 87 | ext_rec = NULL; |
3349 | 88 | fix_rec = NULL; | 88 | fix_rec = NULL; |
3350 | 89 | rec_len = 0; | 89 | rec_len = 0; |
3351 | 90 | switch (record->xl.xl_status_1) { | 90 | switch (record->xl.xl_status_1) { |
3352 | 91 | case XT_LOG_ENT_REC_MODIFIED: | 91 | case XT_LOG_ENT_REC_MODIFIED: |
3353 | 92 | case XT_LOG_ENT_UPDATE: | 92 | case XT_LOG_ENT_UPDATE: |
3354 | 93 | case XT_LOG_ENT_INSERT: | 93 | case XT_LOG_ENT_INSERT: |
3355 | 94 | case XT_LOG_ENT_DELETE: | 94 | case XT_LOG_ENT_DELETE: |
3356 | 95 | case XT_LOG_ENT_UPDATE_BG: | 95 | case XT_LOG_ENT_UPDATE_BG: |
3357 | 96 | case XT_LOG_ENT_INSERT_BG: | 96 | case XT_LOG_ENT_INSERT_BG: |
3358 | 97 | case XT_LOG_ENT_DELETE_BG: | 97 | case XT_LOG_ENT_DELETE_BG: |
3359 | 98 | op_no = XT_GET_DISK_4(record->xu.xu_op_seq_4); | 98 | op_no = XT_GET_DISK_4(record->xu.xu_op_seq_4); |
3360 | 99 | tab_id = XT_GET_DISK_4(record->xu.xu_tab_id_4); | 99 | tab_id = XT_GET_DISK_4(record->xu.xu_tab_id_4); |
3361 | 100 | rec_id = XT_GET_DISK_4(record->xu.xu_rec_id_4); | 100 | rec_id = XT_GET_DISK_4(record->xu.xu_rec_id_4); |
3362 | 101 | xn_id = XT_GET_DISK_4(record->xu.xu_xact_id_4); | 101 | xn_id = XT_GET_DISK_4(record->xu.xu_xact_id_4); |
3363 | 102 | row_id = XT_GET_DISK_4(record->xu.xu_row_id_4); | 102 | row_id = XT_GET_DISK_4(record->xu.xu_row_id_4); |
3364 | 103 | rec_len = XT_GET_DISK_2(record->xu.xu_size_2); | 103 | rec_len = XT_GET_DISK_2(record->xu.xu_size_2); |
3365 | 104 | xn_set = TRUE; | 104 | xn_set = TRUE; |
3366 | 105 | type="rec"; | 105 | type="rec"; |
3367 | 106 | rec_buf = (XTTabRecExtDPtr) &record->xu.xu_rec_type_1; | 106 | rec_buf = (XTTabRecExtDPtr) &record->xu.xu_rec_type_1; |
3368 | 107 | ext_rec = (XTTabRecExtDPtr) &record->xu.xu_rec_type_1; | 107 | ext_rec = (XTTabRecExtDPtr) &record->xu.xu_rec_type_1; |
3369 | 108 | if (XT_REC_IS_EXT_DLOG(ext_rec->tr_rec_type_1)) { | 108 | if (XT_REC_IS_EXT_DLOG(ext_rec->tr_rec_type_1)) { |
3370 | 109 | log_id = XT_GET_DISK_2(ext_rec->re_log_id_2); | 109 | log_id = XT_GET_DISK_2(ext_rec->re_log_id_2); |
3371 | 110 | log_offset = XT_GET_DISK_6(ext_rec->re_log_offs_6); | 110 | log_offset = XT_GET_DISK_6(ext_rec->re_log_offs_6); |
3372 | 111 | } | 111 | } |
3373 | 112 | else { | 112 | else { |
3374 | 113 | ext_rec = NULL; | 113 | ext_rec = NULL; |
3375 | 114 | fix_rec = (XTTabRecFixDPtr) &record->xu.xu_rec_type_1; | 114 | fix_rec = (XTTabRecFixDPtr) &record->xu.xu_rec_type_1; |
3376 | 115 | } | 115 | } |
3377 | 116 | break; | 116 | break; |
3378 | 117 | case XT_LOG_ENT_UPDATE_FL: | 117 | case XT_LOG_ENT_UPDATE_FL: |
3379 | 118 | case XT_LOG_ENT_INSERT_FL: | 118 | case XT_LOG_ENT_INSERT_FL: |
3380 | 119 | case XT_LOG_ENT_DELETE_FL: | 119 | case XT_LOG_ENT_DELETE_FL: |
3381 | 120 | case XT_LOG_ENT_UPDATE_FL_BG: | 120 | case XT_LOG_ENT_UPDATE_FL_BG: |
3382 | 121 | case XT_LOG_ENT_INSERT_FL_BG: | 121 | case XT_LOG_ENT_INSERT_FL_BG: |
3383 | 122 | case XT_LOG_ENT_DELETE_FL_BG: | 122 | case XT_LOG_ENT_DELETE_FL_BG: |
3384 | 123 | op_no = XT_GET_DISK_4(record->xf.xf_op_seq_4); | 123 | op_no = XT_GET_DISK_4(record->xf.xf_op_seq_4); |
3385 | 124 | tab_id = XT_GET_DISK_4(record->xf.xf_tab_id_4); | 124 | tab_id = XT_GET_DISK_4(record->xf.xf_tab_id_4); |
3386 | 125 | rec_id = XT_GET_DISK_4(record->xf.xf_rec_id_4); | 125 | rec_id = XT_GET_DISK_4(record->xf.xf_rec_id_4); |
3387 | 126 | xn_id = XT_GET_DISK_4(record->xf.xf_xact_id_4); | 126 | xn_id = XT_GET_DISK_4(record->xf.xf_xact_id_4); |
3388 | 127 | row_id = XT_GET_DISK_4(record->xf.xf_row_id_4); | 127 | row_id = XT_GET_DISK_4(record->xf.xf_row_id_4); |
3389 | 128 | rec_len = XT_GET_DISK_2(record->xf.xf_size_2); | 128 | rec_len = XT_GET_DISK_2(record->xf.xf_size_2); |
3390 | 129 | xn_set = TRUE; | 129 | xn_set = TRUE; |
3391 | 130 | type="rec"; | 130 | type="rec"; |
3392 | 131 | rec_buf = (XTTabRecExtDPtr) &record->xf.xf_rec_type_1; | 131 | rec_buf = (XTTabRecExtDPtr) &record->xf.xf_rec_type_1; |
3393 | 132 | ext_rec = (XTTabRecExtDPtr) &record->xf.xf_rec_type_1; | 132 | ext_rec = (XTTabRecExtDPtr) &record->xf.xf_rec_type_1; |
3394 | 133 | if (XT_REC_IS_EXT_DLOG(ext_rec->tr_rec_type_1)) { | 133 | if (XT_REC_IS_EXT_DLOG(ext_rec->tr_rec_type_1)) { |
3395 | 134 | log_id = XT_GET_DISK_2(ext_rec->re_log_id_2); | 134 | log_id = XT_GET_DISK_2(ext_rec->re_log_id_2); |
3396 | 135 | log_offset = XT_GET_DISK_6(ext_rec->re_log_offs_6); | 135 | log_offset = XT_GET_DISK_6(ext_rec->re_log_offs_6); |
3397 | 136 | } | 136 | } |
3398 | 137 | else { | 137 | else { |
3399 | 138 | ext_rec = NULL; | 138 | ext_rec = NULL; |
3400 | 139 | fix_rec = (XTTabRecFixDPtr) &record->xf.xf_rec_type_1; | 139 | fix_rec = (XTTabRecFixDPtr) &record->xf.xf_rec_type_1; |
3401 | 140 | } | 140 | } |
3402 | 141 | break; | 141 | break; |
3403 | 142 | case XT_LOG_ENT_REC_FREED: | 142 | case XT_LOG_ENT_REC_FREED: |
3404 | 143 | case XT_LOG_ENT_REC_REMOVED: | 143 | case XT_LOG_ENT_REC_REMOVED: |
3405 | 144 | case XT_LOG_ENT_REC_REMOVED_EXT: | 144 | case XT_LOG_ENT_REC_REMOVED_EXT: |
3406 | 145 | op_no = XT_GET_DISK_4(record->fr.fr_op_seq_4); | 145 | op_no = XT_GET_DISK_4(record->fr.fr_op_seq_4); |
3407 | 146 | tab_id = XT_GET_DISK_4(record->fr.fr_tab_id_4); | 146 | tab_id = XT_GET_DISK_4(record->fr.fr_tab_id_4); |
3408 | 147 | rec_id = XT_GET_DISK_4(record->fr.fr_rec_id_4); | 147 | rec_id = XT_GET_DISK_4(record->fr.fr_rec_id_4); |
3409 | 148 | xn_id = XT_GET_DISK_4(record->fr.fr_xact_id_4); | 148 | xn_id = XT_GET_DISK_4(record->fr.fr_xact_id_4); |
3410 | 149 | xn_set = TRUE; | 149 | xn_set = TRUE; |
3411 | 150 | type="rec"; | 150 | type="rec"; |
3412 | 151 | break; | 151 | break; |
3413 | 152 | case XT_LOG_ENT_REC_REMOVED_BI: | 152 | case XT_LOG_ENT_REC_REMOVED_BI: |
3414 | 153 | op_no = XT_GET_DISK_4(record->rb.rb_op_seq_4); | 153 | op_no = XT_GET_DISK_4(record->rb.rb_op_seq_4); |
3415 | 154 | tab_id = XT_GET_DISK_4(record->rb.rb_tab_id_4); | 154 | tab_id = XT_GET_DISK_4(record->rb.rb_tab_id_4); |
3416 | 155 | rec_id = XT_GET_DISK_4(record->rb.rb_rec_id_4); | 155 | rec_id = XT_GET_DISK_4(record->rb.rb_rec_id_4); |
3417 | 156 | xn_id = XT_GET_DISK_4(record->rb.rb_xact_id_4); | 156 | xn_id = XT_GET_DISK_4(record->rb.rb_xact_id_4); |
3418 | 157 | row_id = XT_GET_DISK_4(record->rb.rb_row_id_4); | 157 | row_id = XT_GET_DISK_4(record->rb.rb_row_id_4); |
3419 | 158 | rec_len = XT_GET_DISK_2(record->rb.rb_size_2); | 158 | rec_len = XT_GET_DISK_2(record->rb.rb_size_2); |
3420 | 159 | xn_set = TRUE; | 159 | xn_set = TRUE; |
3421 | 160 | type="rec"; | 160 | type="rec"; |
3422 | 161 | rec_buf = (XTTabRecExtDPtr) &record->rb.rb_rec_type_1; | 161 | rec_buf = (XTTabRecExtDPtr) &record->rb.rb_rec_type_1; |
3423 | 162 | ext_rec = (XTTabRecExtDPtr) &record->rb.rb_rec_type_1; | 162 | ext_rec = (XTTabRecExtDPtr) &record->rb.rb_rec_type_1; |
3424 | 163 | if (XT_REC_IS_EXT_DLOG(record->rb.rb_rec_type_1)) { | 163 | if (XT_REC_IS_EXT_DLOG(record->rb.rb_rec_type_1)) { |
3425 | 164 | log_id = XT_GET_DISK_2(ext_rec->re_log_id_2); | 164 | log_id = XT_GET_DISK_2(ext_rec->re_log_id_2); |
3426 | 165 | log_offset = XT_GET_DISK_6(ext_rec->re_log_offs_6); | 165 | log_offset = XT_GET_DISK_6(ext_rec->re_log_offs_6); |
3427 | 166 | } | 166 | } |
3428 | 167 | else { | 167 | else { |
3429 | 168 | ext_rec = NULL; | 168 | ext_rec = NULL; |
3430 | 169 | fix_rec = (XTTabRecFixDPtr) &record->rb.rb_rec_type_1; | 169 | fix_rec = (XTTabRecFixDPtr) &record->rb.rb_rec_type_1; |
3431 | 170 | } | 170 | } |
3432 | 171 | break; | 171 | break; |
3433 | 172 | case XT_LOG_ENT_REC_MOVED: | 172 | case XT_LOG_ENT_REC_MOVED: |
3434 | 173 | op_no = XT_GET_DISK_4(record->xw.xw_op_seq_4); | 173 | op_no = XT_GET_DISK_4(record->xw.xw_op_seq_4); |
3435 | 174 | tab_id = XT_GET_DISK_4(record->xw.xw_tab_id_4); | 174 | tab_id = XT_GET_DISK_4(record->xw.xw_tab_id_4); |
3436 | 175 | rec_id = XT_GET_DISK_4(record->xw.xw_rec_id_4); | 175 | rec_id = XT_GET_DISK_4(record->xw.xw_rec_id_4); |
3437 | 176 | log_id = XT_GET_DISK_2(&record->xw.xw_rec_type_1); // This is actually correct | 176 | log_id = XT_GET_DISK_2(&record->xw.xw_rec_type_1); // This is actually correct |
3438 | 177 | log_offset = XT_GET_DISK_6(record->xw.xw_next_rec_id_4); // This is actually correct! | 177 | log_offset = XT_GET_DISK_6(record->xw.xw_next_rec_id_4); // This is actually correct! |
3439 | 178 | type="rec"; | 178 | type="rec"; |
3440 | 179 | break; | 179 | break; |
3441 | 180 | case XT_LOG_ENT_REC_CLEANED: | 180 | case XT_LOG_ENT_REC_CLEANED: |
3442 | 181 | case XT_LOG_ENT_REC_CLEANED_1: | 181 | case XT_LOG_ENT_REC_CLEANED_1: |
3443 | 182 | case XT_LOG_ENT_REC_UNLINKED: | 182 | case XT_LOG_ENT_REC_UNLINKED: |
3444 | 183 | op_no = XT_GET_DISK_4(record->xw.xw_op_seq_4); | 183 | op_no = XT_GET_DISK_4(record->xw.xw_op_seq_4); |
3445 | 184 | tab_id = XT_GET_DISK_4(record->xw.xw_tab_id_4); | 184 | tab_id = XT_GET_DISK_4(record->xw.xw_tab_id_4); |
3446 | 185 | rec_id = XT_GET_DISK_4(record->xw.xw_rec_id_4); | 185 | rec_id = XT_GET_DISK_4(record->xw.xw_rec_id_4); |
3447 | 186 | type="rec"; | 186 | type="rec"; |
3448 | 187 | break; | 187 | break; |
3449 | 188 | case XT_LOG_ENT_ROW_NEW: | 188 | case XT_LOG_ENT_ROW_NEW: |
3450 | 189 | case XT_LOG_ENT_ROW_NEW_FL: | 189 | case XT_LOG_ENT_ROW_NEW_FL: |
3451 | 190 | case XT_LOG_ENT_ROW_ADD_REC: | 190 | case XT_LOG_ENT_ROW_ADD_REC: |
3452 | 191 | case XT_LOG_ENT_ROW_SET: | 191 | case XT_LOG_ENT_ROW_SET: |
3453 | 192 | case XT_LOG_ENT_ROW_FREED: | 192 | case XT_LOG_ENT_ROW_FREED: |
3454 | 193 | op_no = XT_GET_DISK_4(record->xa.xa_op_seq_4); | 193 | op_no = XT_GET_DISK_4(record->xa.xa_op_seq_4); |
3455 | 194 | tab_id = XT_GET_DISK_4(record->xa.xa_tab_id_4); | 194 | tab_id = XT_GET_DISK_4(record->xa.xa_tab_id_4); |
3456 | 195 | rec_id = XT_GET_DISK_4(record->xa.xa_row_id_4); | 195 | rec_id = XT_GET_DISK_4(record->xa.xa_row_id_4); |
3457 | 196 | type="row"; | 196 | type="row"; |
3458 | 197 | break; | 197 | break; |
3459 | 198 | case XT_LOG_ENT_NO_OP: | 198 | case XT_LOG_ENT_NO_OP: |
3460 | 199 | op_no = XT_GET_DISK_4(record->no.no_op_seq_4); | 199 | op_no = XT_GET_DISK_4(record->no.no_op_seq_4); |
3461 | 200 | tab_id = XT_GET_DISK_4(record->no.no_tab_id_4); | 200 | tab_id = XT_GET_DISK_4(record->no.no_tab_id_4); |
3462 | 201 | type="-"; | 201 | type="-"; |
3463 | 202 | break; | 202 | break; |
3464 | 203 | case XT_LOG_ENT_END_OF_LOG: | 203 | case XT_LOG_ENT_END_OF_LOG: |
3465 | 204 | break; | 204 | break; |
3466 | 205 | } | 205 | } |
3467 | 206 | 206 | ||
3468 | 207 | switch (record->xl.xl_status_1) { | 207 | switch (record->xl.xl_status_1) { |
3469 | 208 | case XT_LOG_ENT_HEADER: | 208 | case XT_LOG_ENT_HEADER: |
3470 | 209 | rec_type = "HEADER"; | 209 | rec_type = "HEADER"; |
3471 | 210 | break; | 210 | break; |
3472 | 211 | case XT_LOG_ENT_NEW_LOG: | 211 | case XT_LOG_ENT_NEW_LOG: |
3473 | 212 | rec_type = "NEW LOG"; | 212 | rec_type = "NEW LOG"; |
3474 | 213 | break; | 213 | break; |
3475 | 214 | case XT_LOG_ENT_DEL_LOG: | 214 | case XT_LOG_ENT_DEL_LOG: |
3476 | 215 | sprintf(buffer, "DEL LOG log=%d ", (int) XT_GET_DISK_4(record->xl.xl_log_id_4)); | 215 | sprintf(buffer, "DEL LOG log=%d ", (int) XT_GET_DISK_4(record->xl.xl_log_id_4)); |
3477 | 216 | rec_type = buffer; | 216 | rec_type = buffer; |
3478 | 217 | break; | 217 | break; |
3479 | 218 | case XT_LOG_ENT_NEW_TAB: | 218 | case XT_LOG_ENT_NEW_TAB: |
3480 | 219 | rec_type = "NEW TABLE"; | 219 | rec_type = "NEW TABLE"; |
3481 | 220 | break; | 220 | break; |
3482 | 221 | case XT_LOG_ENT_COMMIT: | 221 | case XT_LOG_ENT_COMMIT: |
3483 | 222 | rec_type = "COMMIT"; | 222 | rec_type = "COMMIT"; |
3484 | 223 | xn_id = XT_GET_DISK_4(record->xe.xe_xact_id_4); | 223 | xn_id = XT_GET_DISK_4(record->xe.xe_xact_id_4); |
3485 | 224 | xn_set = TRUE; | 224 | xn_set = TRUE; |
3486 | 225 | break; | 225 | break; |
3487 | 226 | case XT_LOG_ENT_ABORT: | 226 | case XT_LOG_ENT_ABORT: |
3488 | 227 | rec_type = "ABORT"; | 227 | rec_type = "ABORT"; |
3489 | 228 | xn_id = XT_GET_DISK_4(record->xe.xe_xact_id_4); | 228 | xn_id = XT_GET_DISK_4(record->xe.xe_xact_id_4); |
3490 | 229 | xn_set = TRUE; | 229 | xn_set = TRUE; |
3491 | 230 | break; | 230 | break; |
3492 | 231 | case XT_LOG_ENT_CLEANUP: | 231 | case XT_LOG_ENT_CLEANUP: |
3493 | 232 | rec_type = "CLEANUP"; | 232 | rec_type = "CLEANUP"; |
3494 | 233 | xn_id = XT_GET_DISK_4(record->xc.xc_xact_id_4); | 233 | xn_id = XT_GET_DISK_4(record->xc.xc_xact_id_4); |
3495 | 234 | xn_set = TRUE; | 234 | xn_set = TRUE; |
3496 | 235 | break; | 235 | break; |
3497 | 236 | case XT_LOG_ENT_REC_MODIFIED: | 236 | case XT_LOG_ENT_REC_MODIFIED: |
3498 | 237 | rec_type = "MODIFIED"; | 237 | rec_type = "MODIFIED"; |
3499 | 238 | break; | 238 | break; |
3500 | 239 | case XT_LOG_ENT_UPDATE: | 239 | case XT_LOG_ENT_UPDATE: |
3501 | 240 | rec_type = "UPDATE"; | 240 | rec_type = "UPDATE"; |
3502 | 241 | break; | 241 | break; |
3503 | 242 | case XT_LOG_ENT_UPDATE_FL: | 242 | case XT_LOG_ENT_UPDATE_FL: |
3504 | 243 | rec_type = "UPDATE-FL"; | 243 | rec_type = "UPDATE-FL"; |
3505 | 244 | break; | 244 | break; |
3506 | 245 | case XT_LOG_ENT_INSERT: | 245 | case XT_LOG_ENT_INSERT: |
3507 | 246 | rec_type = "INSERT"; | 246 | rec_type = "INSERT"; |
3508 | 247 | break; | 247 | break; |
3509 | 248 | case XT_LOG_ENT_INSERT_FL: | 248 | case XT_LOG_ENT_INSERT_FL: |
3510 | 249 | rec_type = "INSERT-FL"; | 249 | rec_type = "INSERT-FL"; |
3511 | 250 | break; | 250 | break; |
3512 | 251 | case XT_LOG_ENT_DELETE: | 251 | case XT_LOG_ENT_DELETE: |
3513 | 252 | rec_type = "DELETE"; | 252 | rec_type = "DELETE"; |
3514 | 253 | break; | 253 | break; |
3515 | 254 | case XT_LOG_ENT_DELETE_FL: | 254 | case XT_LOG_ENT_DELETE_FL: |
3516 | 255 | rec_type = "DELETE-FL-BG"; | 255 | rec_type = "DELETE-FL-BG"; |
3517 | 256 | break; | 256 | break; |
3518 | 257 | case XT_LOG_ENT_UPDATE_BG: | 257 | case XT_LOG_ENT_UPDATE_BG: |
3519 | 258 | rec_type = "UPDATE-BG"; | 258 | rec_type = "UPDATE-BG"; |
3520 | 259 | break; | 259 | break; |
3521 | 260 | case XT_LOG_ENT_UPDATE_FL_BG: | 260 | case XT_LOG_ENT_UPDATE_FL_BG: |
3522 | 261 | rec_type = "UPDATE-FL-BG"; | 261 | rec_type = "UPDATE-FL-BG"; |
3523 | 262 | break; | 262 | break; |
3524 | 263 | case XT_LOG_ENT_INSERT_BG: | 263 | case XT_LOG_ENT_INSERT_BG: |
3525 | 264 | rec_type = "INSERT-BG"; | 264 | rec_type = "INSERT-BG"; |
3526 | 265 | break; | 265 | break; |
3527 | 266 | case XT_LOG_ENT_INSERT_FL_BG: | 266 | case XT_LOG_ENT_INSERT_FL_BG: |
3528 | 267 | rec_type = "INSERT-FL-BG"; | 267 | rec_type = "INSERT-FL-BG"; |
3529 | 268 | break; | 268 | break; |
3530 | 269 | case XT_LOG_ENT_DELETE_BG: | 269 | case XT_LOG_ENT_DELETE_BG: |
3531 | 270 | rec_type = "DELETE-BG"; | 270 | rec_type = "DELETE-BG"; |
3532 | 271 | break; | 271 | break; |
3533 | 272 | case XT_LOG_ENT_DELETE_FL_BG: | 272 | case XT_LOG_ENT_DELETE_FL_BG: |
3534 | 273 | rec_type = "DELETE-FL-BG"; | 273 | rec_type = "DELETE-FL-BG"; |
3535 | 274 | break; | 274 | break; |
3536 | 275 | case XT_LOG_ENT_REC_FREED: | 275 | case XT_LOG_ENT_REC_FREED: |
3537 | 276 | rec_type = "FREE REC"; | 276 | rec_type = "FREE REC"; |
3538 | 277 | break; | 277 | break; |
3539 | 278 | case XT_LOG_ENT_REC_REMOVED: | 278 | case XT_LOG_ENT_REC_REMOVED: |
3540 | 279 | rec_type = "REMOVED REC"; | 279 | rec_type = "REMOVED REC"; |
3541 | 280 | break; | 280 | break; |
3542 | 281 | case XT_LOG_ENT_REC_REMOVED_EXT: | 281 | case XT_LOG_ENT_REC_REMOVED_EXT: |
3543 | 282 | rec_type = "REMOVED-X REC"; | 282 | rec_type = "REMOVED-X REC"; |
3544 | 283 | break; | 283 | break; |
3545 | 284 | case XT_LOG_ENT_REC_REMOVED_BI: | 284 | case XT_LOG_ENT_REC_REMOVED_BI: |
3546 | 285 | rec_type = "REMOVED-BI REC"; | 285 | rec_type = "REMOVED-BI REC"; |
3547 | 286 | break; | 286 | break; |
3548 | 287 | case XT_LOG_ENT_REC_MOVED: | 287 | case XT_LOG_ENT_REC_MOVED: |
3549 | 288 | rec_type = "MOVED REC"; | 288 | rec_type = "MOVED REC"; |
3550 | 289 | break; | 289 | break; |
3551 | 290 | case XT_LOG_ENT_REC_CLEANED: | 290 | case XT_LOG_ENT_REC_CLEANED: |
3552 | 291 | rec_type = "CLEAN REC"; | 291 | rec_type = "CLEAN REC"; |
3553 | 292 | break; | 292 | break; |
3554 | 293 | case XT_LOG_ENT_REC_CLEANED_1: | 293 | case XT_LOG_ENT_REC_CLEANED_1: |
3555 | 294 | rec_type = "CLEAN REC-1"; | 294 | rec_type = "CLEAN REC-1"; |
3556 | 295 | break; | 295 | break; |
3557 | 296 | case XT_LOG_ENT_REC_UNLINKED: | 296 | case XT_LOG_ENT_REC_UNLINKED: |
3558 | 297 | rec_type = "UNLINK REC"; | 297 | rec_type = "UNLINK REC"; |
3559 | 298 | break; | 298 | break; |
3560 | 299 | case XT_LOG_ENT_ROW_NEW: | 299 | case XT_LOG_ENT_ROW_NEW: |
3561 | 300 | rec_type = "NEW ROW"; | 300 | rec_type = "NEW ROW"; |
3562 | 301 | break; | 301 | break; |
3563 | 302 | case XT_LOG_ENT_ROW_NEW_FL: | 302 | case XT_LOG_ENT_ROW_NEW_FL: |
3564 | 303 | rec_type = "NEW ROW-FL"; | 303 | rec_type = "NEW ROW-FL"; |
3565 | 304 | break; | 304 | break; |
3566 | 305 | case XT_LOG_ENT_ROW_ADD_REC: | 305 | case XT_LOG_ENT_ROW_ADD_REC: |
3567 | 306 | rec_type = "REC ADD ROW"; | 306 | rec_type = "REC ADD ROW"; |
3568 | 307 | break; | 307 | break; |
3569 | 308 | case XT_LOG_ENT_ROW_SET: | 308 | case XT_LOG_ENT_ROW_SET: |
3570 | 309 | rec_type = "SET ROW"; | 309 | rec_type = "SET ROW"; |
3571 | 310 | break; | 310 | break; |
3572 | 311 | case XT_LOG_ENT_ROW_FREED: | 311 | case XT_LOG_ENT_ROW_FREED: |
3573 | 312 | rec_type = "FREE ROW"; | 312 | rec_type = "FREE ROW"; |
3574 | 313 | break; | 313 | break; |
3575 | 314 | case XT_LOG_ENT_OP_SYNC: | 314 | case XT_LOG_ENT_OP_SYNC: |
3576 | 315 | rec_type = "OP SYNC"; | 315 | rec_type = "OP SYNC"; |
3577 | 316 | break; | 316 | break; |
3578 | 317 | case XT_LOG_ENT_NO_OP: | 317 | case XT_LOG_ENT_NO_OP: |
3579 | 318 | rec_type = "NO OP"; | 318 | rec_type = "NO OP"; |
3580 | 319 | break; | 319 | break; |
3581 | 320 | case XT_LOG_ENT_END_OF_LOG: | 320 | case XT_LOG_ENT_END_OF_LOG: |
3582 | 321 | rec_type = "END OF LOG"; | 321 | rec_type = "END OF LOG"; |
3583 | 322 | break; | 322 | break; |
3584 | 323 | } | 323 | } |
3585 | 324 | 324 | ||
3586 | 325 | if (log) | 325 | if (log) |
3587 | 326 | PRINTF("log=%d offset=%d ", (int) log, (int) offset); | 326 | PRINTF("log=%d offset=%d ", (int) log, (int) offset); |
3588 | 327 | PRINTF("%s ", rec_type); | 327 | PRINTF("%s ", rec_type); |
3589 | 328 | if (type) | 328 | if (type) |
3590 | 329 | PRINTF("op=%lu tab=%lu %s=%lu ", (u_long) op_no, (u_long) tab_id, type, (u_long) rec_id); | 329 | PRINTF("op=%lu tab=%lu %s=%lu ", (u_long) op_no, (u_long) tab_id, type, (u_long) rec_id); |
3591 | 330 | if (row_id) | 330 | if (row_id) |
3592 | 331 | PRINTF("row=%lu ", (u_long) row_id); | 331 | PRINTF("row=%lu ", (u_long) row_id); |
3593 | 332 | if (log_id) | 332 | if (log_id) |
3594 | 333 | PRINTF("log=%lu offset=%lu ", (u_long) log_id, (u_long) log_offset); | 333 | PRINTF("log=%lu offset=%lu ", (u_long) log_id, (u_long) log_offset); |
3595 | 334 | if (xn_set) | 334 | if (xn_set) |
3596 | 335 | PRINTF("xact=%lu ", (u_long) xn_id); | 335 | PRINTF("xact=%lu ", (u_long) xn_id); |
3597 | 336 | 336 | ||
3598 | 337 | #ifdef TRACE_RECORD_DATA | 337 | #ifdef TRACE_RECORD_DATA |
3599 | 338 | if (rec_buf) { | 338 | if (rec_buf) { |
3600 | 339 | switch (rec_buf->tr_rec_type_1 & XT_TAB_STATUS_MASK) { | 339 | switch (rec_buf->tr_rec_type_1 & XT_TAB_STATUS_MASK) { |
3601 | 340 | case XT_TAB_STATUS_FREED: | 340 | case XT_TAB_STATUS_FREED: |
3602 | 341 | PRINTF("FREE"); | 341 | PRINTF("FREE"); |
3603 | 342 | break; | 342 | break; |
3604 | 343 | case XT_TAB_STATUS_DELETE: | 343 | case XT_TAB_STATUS_DELETE: |
3605 | 344 | PRINTF("DELE"); | 344 | PRINTF("DELE"); |
3606 | 345 | break; | 345 | break; |
3607 | 346 | case XT_TAB_STATUS_FIXED: | 346 | case XT_TAB_STATUS_FIXED: |
3608 | 347 | PRINTF("FIX-"); | 347 | PRINTF("FIX-"); |
3609 | 348 | break; | 348 | break; |
3610 | 349 | case XT_TAB_STATUS_VARIABLE: | 349 | case XT_TAB_STATUS_VARIABLE: |
3611 | 350 | PRINTF("VAR-"); | 350 | PRINTF("VAR-"); |
3612 | 351 | break; | 351 | break; |
3613 | 352 | case XT_TAB_STATUS_EXT_DLOG: | 352 | case XT_TAB_STATUS_EXT_DLOG: |
3614 | 353 | PRINTF("EXT-"); | 353 | PRINTF("EXT-"); |
3615 | 354 | break; | 354 | break; |
3616 | 355 | } | 355 | } |
3617 | 356 | if (rec_buf->tr_rec_type_1 & XT_TAB_STATUS_CLEANED_BIT) | 356 | if (rec_buf->tr_rec_type_1 & XT_TAB_STATUS_CLEANED_BIT) |
3618 | 357 | PRINTF("C"); | 357 | PRINTF("C"); |
3619 | 358 | else | 358 | else |
3620 | 359 | PRINTF(" "); | 359 | PRINTF(" "); |
3621 | 360 | } | 360 | } |
3622 | 361 | if (ext_rec) { | 361 | if (ext_rec) { |
3623 | 362 | rec_len -= offsetof(XTTabRecExtDRec, re_data); | 362 | rec_len -= offsetof(XTTabRecExtDRec, re_data); |
3624 | 363 | xt_print_bytes((xtWord1 *) ext_rec, offsetof(XTTabRecExtDRec, re_data)); | 363 | xt_print_bytes((xtWord1 *) ext_rec, offsetof(XTTabRecExtDRec, re_data)); |
3625 | 364 | PRINTF("| "); | 364 | PRINTF("| "); |
3626 | 365 | if (rec_len > 20) | 365 | if (rec_len > 20) |
3627 | 366 | rec_len = 20; | 366 | rec_len = 20; |
3628 | 367 | xt_print_bytes(ext_rec->re_data, rec_len); | 367 | xt_print_bytes(ext_rec->re_data, rec_len); |
3629 | 368 | } | 368 | } |
3630 | 369 | if (fix_rec) { | 369 | if (fix_rec) { |
3631 | 370 | rec_len -= offsetof(XTTabRecFixDRec, rf_data); | 370 | rec_len -= offsetof(XTTabRecFixDRec, rf_data); |
3632 | 371 | xt_print_bytes((xtWord1 *) fix_rec, offsetof(XTTabRecFixDRec, rf_data)); | 371 | xt_print_bytes((xtWord1 *) fix_rec, offsetof(XTTabRecFixDRec, rf_data)); |
3633 | 372 | PRINTF("| "); | 372 | PRINTF("| "); |
3634 | 373 | if (rec_len > 20) | 373 | if (rec_len > 20) |
3635 | 374 | rec_len = 20; | 374 | rec_len = 20; |
3636 | 375 | xt_print_bytes(fix_rec->rf_data, rec_len); | 375 | xt_print_bytes(fix_rec->rf_data, rec_len); |
3637 | 376 | } | 376 | } |
3638 | 377 | #endif | 377 | #endif |
3639 | 378 | 378 | ||
3640 | 379 | PRINTF("\n"); | 379 | PRINTF("\n"); |
3641 | 380 | } | 380 | } |
3642 | 381 | 381 | ||
3643 | 382 | #ifdef DEBUG_PRINT | 382 | #ifdef DEBUG_PRINT |
3644 | 383 | void check_rows(void) | 383 | void check_rows(void) |
3645 | 384 | { | 384 | { |
3646 | 385 | static XTOpenFilePtr of = NULL; | 385 | static XTOpenFilePtr of = NULL; |
3647 | 386 | 386 | ||
3648 | 387 | if (!of) | 387 | if (!of) |
3649 | 388 | of = xt_open_file_ns("./test/test_tab-1.xtr", XT_FS_DEFAULT); | 388 | of = xt_open_file_ns("./test/test_tab-1.xtr", XT_FS_DEFAULT); |
3650 | 389 | if (of) { | 389 | if (of) { |
3651 | 390 | size_t size = (size_t) xt_seek_eof_file(NULL, of); | 390 | size_t size = (size_t) xt_seek_eof_file(NULL, of); |
3652 | 391 | xtWord8 *buffer = (xtWord8 *) xt_malloc_ns(size); | 391 | xtWord8 *buffer = (xtWord8 *) xt_malloc_ns(size); |
3653 | 392 | xt_pread_file(of, 0, size, size, buffer, NULL); | 392 | xt_pread_file(of, 0, size, size, buffer, NULL); |
3654 | 393 | for (size_t i=0; i<size/8; i++) { | 393 | for (size_t i=0; i<size/8; i++) { |
3655 | 394 | if (!buffer[i]) | 394 | if (!buffer[i]) |
3656 | 395 | printf("%d is NULL\n", (int) i); | 395 | printf("%d is NULL\n", (int) i); |
3657 | 396 | } | 396 | } |
3658 | 397 | } | 397 | } |
3659 | 398 | } | 398 | } |
3660 | 399 | 399 | ||
3661 | 400 | #endif | 400 | #endif |
3662 | 401 | 401 | ||
3663 | 402 | /* ---------------------------------------------------------------------- | 402 | /* ---------------------------------------------------------------------- |
3664 | 403 | * APPLYING CHANGES IN SEQUENCE | 403 | * APPLYING CHANGES IN SEQUENCE |
3665 | 404 | */ | 404 | */ |
3666 | 405 | 405 | ||
3667 | 406 | typedef struct XTOperation { | 406 | typedef struct XTOperation { |
3668 | 407 | xtOpSeqNo or_op_seq; | 407 | xtOpSeqNo or_op_seq; |
3669 | 408 | xtWord4 or_op_len; | 408 | xtWord4 or_op_len; |
3670 | 409 | xtLogID or_log_id; | 409 | xtLogID or_log_id; |
3671 | 410 | xtLogOffset or_log_offset; | 410 | xtLogOffset or_log_offset; |
3672 | 411 | } XTOperationRec, *XTOperationPtr; | 411 | } XTOperationRec, *XTOperationPtr; |
3673 | 412 | 412 | ||
3674 | 413 | static int xres_cmp_op_seq(struct XTThread *XT_UNUSED(self), register const void *XT_UNUSED(thunk), register const void *a, register const void *b) | 413 | static int xres_cmp_op_seq(struct XTThread *XT_UNUSED(self), register const void *XT_UNUSED(thunk), register const void *a, register const void *b) |
3675 | 414 | { | 414 | { |
3676 | 415 | xtOpSeqNo lf_op_seq = *((xtOpSeqNo *) a); | 415 | xtOpSeqNo lf_op_seq = *((xtOpSeqNo *) a); |
3677 | 416 | XTOperationPtr lf_ptr = (XTOperationPtr) b; | 416 | XTOperationPtr lf_ptr = (XTOperationPtr) b; |
3678 | 417 | 417 | ||
3679 | 418 | if (lf_op_seq == lf_ptr->or_op_seq) | 418 | if (lf_op_seq == lf_ptr->or_op_seq) |
3680 | 419 | return 0; | 419 | return 0; |
3681 | 420 | if (XTTableSeq::xt_op_is_before(lf_op_seq, lf_ptr->or_op_seq)) | 420 | if (XTTableSeq::xt_op_is_before(lf_op_seq, lf_ptr->or_op_seq)) |
3682 | 421 | return -1; | 421 | return -1; |
3683 | 422 | return 1; | 422 | return 1; |
3684 | 423 | } | 423 | } |
3685 | 424 | 424 | ||
3686 | 425 | xtPublic void xt_xres_init_tab(XTThreadPtr self, XTTableHPtr tab) | 425 | xtPublic void xt_xres_init_tab(XTThreadPtr self, XTTableHPtr tab) |
3687 | 426 | { | 426 | { |
3688 | 427 | tab->tab_op_list = xt_new_sortedlist(self, sizeof(XTOperationRec), 20, 1000, xres_cmp_op_seq, NULL, NULL, TRUE, FALSE); | 427 | tab->tab_op_list = xt_new_sortedlist(self, sizeof(XTOperationRec), 20, 1000, xres_cmp_op_seq, NULL, NULL, TRUE, FALSE); |
3689 | 428 | } | 428 | } |
3690 | 429 | 429 | ||
3691 | 430 | xtPublic void xt_xres_exit_tab(XTThreadPtr self, XTTableHPtr tab) | 430 | xtPublic void xt_xres_exit_tab(XTThreadPtr self, XTTableHPtr tab) |
3692 | 431 | { | 431 | { |
3693 | 432 | if (tab->tab_op_list) { | 432 | if (tab->tab_op_list) { |
3694 | 433 | xt_free_sortedlist(self, tab->tab_op_list); | 433 | xt_free_sortedlist(self, tab->tab_op_list); |
3695 | 434 | tab->tab_op_list = NULL; | 434 | tab->tab_op_list = NULL; |
3696 | 435 | } | 435 | } |
3697 | 436 | } | 436 | } |
3698 | 437 | 437 | ||
3699 | 438 | static xtBool xres_open_table(XTThreadPtr self, XTWriterStatePtr ws, xtTableID tab_id) | 438 | static xtBool xres_open_table(XTThreadPtr self, XTWriterStatePtr ws, xtTableID tab_id) |
3700 | 439 | { | 439 | { |
3701 | 440 | XTOpenTablePtr ot; | 440 | XTOpenTablePtr ot; |
3702 | 441 | 441 | ||
3703 | 442 | if ((ot = ws->ws_ot)) { | 442 | if ((ot = ws->ws_ot)) { |
3704 | 443 | if (ot->ot_table->tab_id == tab_id) | 443 | if (ot->ot_table->tab_id == tab_id) |
3705 | 444 | return OK; | 444 | return OK; |
3706 | 445 | xt_db_return_table_to_pool(self, ot); | 445 | xt_db_return_table_to_pool(self, ot); |
3707 | 446 | ws->ws_ot = NULL; | 446 | ws->ws_ot = NULL; |
3708 | 447 | } | 447 | } |
3709 | 448 | 448 | ||
3710 | 449 | if (ws->ws_tab_gone == tab_id) | 449 | if (ws->ws_tab_gone == tab_id) |
3711 | 450 | return FAILED; | 450 | return FAILED; |
3712 | 451 | if ((ws->ws_ot = xt_db_open_pool_table(self, ws->ws_db, tab_id, NULL, TRUE))) { | 451 | if ((ws->ws_ot = xt_db_open_pool_table(self, ws->ws_db, tab_id, NULL, TRUE))) { |
3713 | 452 | XTTableHPtr tab; | 452 | XTTableHPtr tab; |
3714 | 453 | 453 | ||
3715 | 454 | tab = ws->ws_ot->ot_table; | 454 | tab = ws->ws_ot->ot_table; |
3716 | 455 | if (!tab->tab_ind_rec_log_id) { | 455 | if (!tab->tab_ind_rec_log_id) { |
3717 | 456 | /* Should not happen... */ | 456 | /* Should not happen... */ |
3718 | 457 | tab->tab_ind_rec_log_id = ws->ws_ind_rec_log_id; | 457 | tab->tab_ind_rec_log_id = ws->ws_ind_rec_log_id; |
3719 | 458 | tab->tab_ind_rec_log_offset = ws->ws_ind_rec_log_offset; | 458 | tab->tab_ind_rec_log_offset = ws->ws_ind_rec_log_offset; |
3720 | 459 | } | 459 | } |
3721 | 460 | return OK; | 460 | return OK; |
3722 | 461 | } | 461 | } |
3723 | 462 | ws->ws_tab_gone = tab_id; | 462 | ws->ws_tab_gone = tab_id; |
3724 | 463 | return FAILED; | 463 | return FAILED; |
3725 | 464 | } | 464 | } |
3726 | 465 | 465 | ||
3727 | 466 | /* {INDEX-RECOV_ROWID} | 466 | /* {INDEX-RECOV_ROWID} |
3728 | 467 | * Add missing index entries during recovery. | 467 | * Add missing index entries during recovery. |
3729 | 468 | * Set the row ID even if the index entry | 468 | * Set the row ID even if the index entry |
3730 | 469 | * is not committed. It will be removed later by | 469 | * is not committed. It will be removed later by |
3731 | 470 | * the sweeper. | 470 | * the sweeper. |
3732 | 471 | */ | 471 | */ |
3733 | 472 | static xtBool xres_add_index_entries(XTOpenTablePtr ot, xtRowID row_id, xtRecordID rec_id, xtWord1 *rec_data) | 472 | static xtBool xres_add_index_entries(XTOpenTablePtr ot, xtRowID row_id, xtRecordID rec_id, xtWord1 *rec_data) |
3734 | 473 | { | 473 | { |
3735 | 474 | XTTableHPtr tab = ot->ot_table; | 474 | XTTableHPtr tab = ot->ot_table; |
3736 | 475 | u_int idx_cnt; | 475 | u_int idx_cnt; |
3737 | 476 | XTIndexPtr *ind; | 476 | XTIndexPtr *ind; |
3738 | 477 | //XTIdxSearchKeyRec key; | 477 | //XTIdxSearchKeyRec key; |
3739 | 478 | 478 | ||
3740 | 479 | if (tab->tab_dic.dic_disable_index) | 479 | if (tab->tab_dic.dic_disable_index) |
3741 | 480 | return OK; | 480 | return OK; |
3742 | 481 | 481 | ||
3743 | 482 | for (idx_cnt=0, ind=tab->tab_dic.dic_keys; idx_cnt<tab->tab_dic.dic_key_count; idx_cnt++, ind++) { | 482 | for (idx_cnt=0, ind=tab->tab_dic.dic_keys; idx_cnt<tab->tab_dic.dic_key_count; idx_cnt++, ind++) { |
3744 | 483 | if (!xt_idx_insert(ot, *ind, row_id, rec_id, rec_data, NULL, TRUE)) { | 483 | if (!xt_idx_insert(ot, *ind, row_id, rec_id, rec_data, NULL, TRUE)) { |
3745 | 484 | /* Check the error, certain errors are recoverable! */ | 484 | /* Check the error, certain errors are recoverable! */ |
3746 | 485 | XTThreadPtr self = xt_get_self(); | 485 | XTThreadPtr self = xt_get_self(); |
3747 | 486 | 486 | ||
3748 | 487 | if (self->t_exception.e_xt_err == XT_SYSTEM_ERROR && | 487 | if (self->t_exception.e_xt_err == XT_SYSTEM_ERROR && |
3749 | 488 | (XT_FILE_IN_USE(self->t_exception.e_sys_err) || | 488 | (XT_FILE_IN_USE(self->t_exception.e_sys_err) || |
3750 | 489 | XT_FILE_ACCESS_DENIED(self->t_exception.e_sys_err) || | 489 | XT_FILE_ACCESS_DENIED(self->t_exception.e_sys_err) || |
3751 | 490 | XT_FILE_TOO_MANY_OPEN(self->t_exception.e_sys_err) || | 490 | XT_FILE_TOO_MANY_OPEN(self->t_exception.e_sys_err) || |
3752 | 491 | self->t_exception.e_sys_err == XT_ENOMEM)) { | 491 | self->t_exception.e_sys_err == XT_ENOMEM)) { |
3753 | 492 | ot->ot_err_index_no = (*ind)->mi_index_no; | 492 | ot->ot_err_index_no = (*ind)->mi_index_no; |
3754 | 493 | return FAILED; | 493 | return FAILED; |
3755 | 494 | } | 494 | } |
3756 | 495 | 495 | ||
3757 | 496 | /* TODO: Write something to the index header to indicate that | 496 | /* TODO: Write something to the index header to indicate that |
3758 | 497 | * it is corrupted. | 497 | * it is corrupted. |
3759 | 498 | */ | 498 | */ |
3760 | 499 | tab->tab_dic.dic_disable_index = XT_INDEX_CORRUPTED; | 499 | tab->tab_dic.dic_disable_index = XT_INDEX_CORRUPTED; |
3761 | 500 | xt_log_and_clear_exception_ns(); | 500 | xt_log_and_clear_exception_ns(); |
3762 | 501 | return OK; | 501 | return OK; |
3763 | 502 | } | 502 | } |
3764 | 503 | } | 503 | } |
3765 | 504 | return OK; | 504 | return OK; |
3766 | 505 | } | 505 | } |
3767 | 506 | 506 | ||
3768 | 507 | static void xres_remove_index_entries(XTOpenTablePtr ot, xtRecordID rec_id, xtWord1 *rec_data) | 507 | static void xres_remove_index_entries(XTOpenTablePtr ot, xtRecordID rec_id, xtWord1 *rec_data) |
3769 | 508 | { | 508 | { |
3770 | 509 | XTTableHPtr tab = ot->ot_table; | 509 | XTTableHPtr tab = ot->ot_table; |
3771 | 510 | u_int idx_cnt; | 510 | u_int idx_cnt; |
3772 | 511 | XTIndexPtr *ind; | 511 | XTIndexPtr *ind; |
3773 | 512 | 512 | ||
3774 | 513 | if (tab->tab_dic.dic_disable_index) | 513 | if (tab->tab_dic.dic_disable_index) |
3775 | 514 | return; | 514 | return; |
3776 | 515 | 515 | ||
3777 | 516 | for (idx_cnt=0, ind=tab->tab_dic.dic_keys; idx_cnt<tab->tab_dic.dic_key_count; idx_cnt++, ind++) { | 516 | for (idx_cnt=0, ind=tab->tab_dic.dic_keys; idx_cnt<tab->tab_dic.dic_key_count; idx_cnt++, ind++) { |
3778 | 517 | if (!xt_idx_delete(ot, *ind, rec_id, rec_data)) | 517 | if (!xt_idx_delete(ot, *ind, rec_id, rec_data)) |
3779 | 518 | xt_log_and_clear_exception_ns(); | 518 | xt_log_and_clear_exception_ns(); |
3780 | 519 | } | 519 | } |
3781 | 520 | } | 520 | } |
3782 | 521 | 521 | ||
3783 | 522 | static xtWord1 *xres_load_record(XTThreadPtr self, XTOpenTablePtr ot, xtRecordID rec_id, xtWord1 *data, size_t red_size, XTInfoBufferPtr rec_buf, u_int cols_req) | 522 | static xtWord1 *xres_load_record(XTThreadPtr self, XTOpenTablePtr ot, xtRecordID rec_id, xtWord1 *data, size_t red_size, XTInfoBufferPtr rec_buf, u_int cols_req) |
3784 | 523 | { | 523 | { |
3785 | 524 | XTTableHPtr tab = ot->ot_table; | 524 | XTTableHPtr tab = ot->ot_table; |
3786 | 525 | xtWord1 *rec_data; | 525 | xtWord1 *rec_data; |
3787 | 526 | 526 | ||
3788 | 527 | rec_data = ot->ot_row_rbuffer; | 527 | rec_data = ot->ot_row_rbuffer; |
3789 | 528 | 528 | ||
3790 | 529 | ASSERT(red_size <= ot->ot_row_rbuf_size); | 529 | ASSERT(red_size <= ot->ot_row_rbuf_size); |
3791 | 530 | ASSERT(tab->tab_dic.dic_rec_size <= ot->ot_row_rbuf_size); | 530 | ASSERT(tab->tab_dic.dic_rec_size <= ot->ot_row_rbuf_size); |
3792 | 531 | if (data) { | 531 | if (data) { |
3793 | 532 | if (rec_data != data) | 532 | if (rec_data != data) |
3794 | 533 | memcpy(rec_data, data, red_size); | 533 | memcpy(rec_data, data, red_size); |
3795 | 534 | } | 534 | } |
3796 | 535 | else { | 535 | else { |
3797 | 536 | /* It can be that less than 'dic_rec_size' was written for | 536 | /* It can be that less than 'dic_rec_size' was written for |
3798 | 537 | * variable length type records. | 537 | * variable length type records. |
3799 | 538 | * If this is the last record in the file, then we will read | 538 | * If this is the last record in the file, then we will read |
3800 | 539 | * less than actual record size. | 539 | * less than actual record size. |
3801 | 540 | */ | 540 | */ |
3802 | 541 | if (!XT_PREAD_RR_FILE(ot->ot_rec_file, xt_rec_id_to_rec_offset(tab, rec_id), tab->tab_dic.dic_rec_size, 0, rec_data, &red_size, &self->st_statistics.st_rec, self)) | 541 | if (!XT_PREAD_RR_FILE(ot->ot_rec_file, xt_rec_id_to_rec_offset(tab, rec_id), tab->tab_dic.dic_rec_size, 0, rec_data, &red_size, &self->st_statistics.st_rec, self)) |
3803 | 542 | goto failed; | 542 | goto failed; |
3804 | 543 | 543 | ||
3805 | 544 | if (red_size < sizeof(XTTabRecHeadDRec)) | 544 | if (red_size < sizeof(XTTabRecHeadDRec)) |
3806 | 545 | return NULL; | 545 | return NULL; |
3807 | 546 | } | 546 | } |
3808 | 547 | 547 | ||
3809 | 548 | if (XT_REC_IS_FIXED(rec_data[0])) | 548 | if (XT_REC_IS_FIXED(rec_data[0])) |
3810 | 549 | rec_data = ot->ot_row_rbuffer + XT_REC_FIX_HEADER_SIZE; | 549 | rec_data = ot->ot_row_rbuffer + XT_REC_FIX_HEADER_SIZE; |
3811 | 550 | else { | 550 | else { |
3812 | 551 | if (!xt_ib_alloc(NULL, rec_buf, tab->tab_dic.dic_mysql_buf_size)) | 551 | if (!xt_ib_alloc(NULL, rec_buf, tab->tab_dic.dic_mysql_buf_size)) |
3813 | 552 | goto failed; | 552 | goto failed; |
3814 | 553 | if (XT_REC_IS_VARIABLE(rec_data[0])) { | 553 | if (XT_REC_IS_VARIABLE(rec_data[0])) { |
3815 | 554 | if (!myxt_load_row(ot, rec_data + XT_REC_FIX_HEADER_SIZE, rec_buf->ib_db.db_data, cols_req)) | 554 | if (!myxt_load_row(ot, rec_data + XT_REC_FIX_HEADER_SIZE, rec_buf->ib_db.db_data, cols_req)) |
3816 | 555 | goto failed; | 555 | goto failed; |
3817 | 556 | } | 556 | } |
3818 | 557 | else if (XT_REC_IS_EXT_DLOG(rec_data[0])) { | 557 | else if (XT_REC_IS_EXT_DLOG(rec_data[0])) { |
3819 | 558 | if (red_size < XT_REC_EXT_HEADER_SIZE) | 558 | if (red_size < XT_REC_EXT_HEADER_SIZE) |
3820 | 559 | return NULL; | 559 | return NULL; |
3821 | 560 | 560 | ||
3822 | 561 | ASSERT(cols_req); | 561 | ASSERT(cols_req); |
3823 | 562 | if (cols_req && cols_req <= tab->tab_dic.dic_fix_col_count) { | 562 | if (cols_req && cols_req <= tab->tab_dic.dic_fix_col_count) { |
3824 | 563 | if (!myxt_load_row(ot, rec_data + XT_REC_EXT_HEADER_SIZE, rec_buf->ib_db.db_data, cols_req)) | 563 | if (!myxt_load_row(ot, rec_data + XT_REC_EXT_HEADER_SIZE, rec_buf->ib_db.db_data, cols_req)) |
3825 | 564 | goto failed; | 564 | goto failed; |
3826 | 565 | } | 565 | } |
3827 | 566 | else { | 566 | else { |
3828 | 567 | if (!xt_tab_load_ext_data(ot, rec_id, rec_buf->ib_db.db_data, cols_req)) | 567 | if (!xt_tab_load_ext_data(ot, rec_id, rec_buf->ib_db.db_data, cols_req)) |
3829 | 568 | goto failed; | 568 | goto failed; |
3830 | 569 | } | 569 | } |
3831 | 570 | } | 570 | } |
3832 | 571 | else | 571 | else |
3833 | 572 | /* This is possible, the record has already been cleaned up. */ | 572 | /* This is possible, the record has already been cleaned up. */ |
3834 | 573 | return NULL; | 573 | return NULL; |
3835 | 574 | rec_data = rec_buf->ib_db.db_data; | 574 | rec_data = rec_buf->ib_db.db_data; |
3836 | 575 | } | 575 | } |
3837 | 576 | 576 | ||
3838 | 577 | return rec_data; | 577 | return rec_data; |
3839 | 578 | 578 | ||
3840 | 579 | failed: | 579 | failed: |
3841 | 580 | /* Running out of memory should not be ignored. */ | 580 | /* Running out of memory should not be ignored. */ |
3842 | 581 | if (self->t_exception.e_xt_err == XT_SYSTEM_ERROR && | 581 | if (self->t_exception.e_xt_err == XT_SYSTEM_ERROR && |
3843 | 582 | self->t_exception.e_sys_err == XT_ENOMEM) | 582 | self->t_exception.e_sys_err == XT_ENOMEM) |
3844 | 583 | xt_throw(self); | 583 | xt_throw(self); |
3845 | 584 | xt_log_and_clear_exception_ns(); | 584 | xt_log_and_clear_exception_ns(); |
3846 | 585 | return NULL; | 585 | return NULL; |
3847 | 586 | } | 586 | } |
3848 | 587 | 587 | ||
3849 | 588 | /* | 588 | /* |
3850 | 589 | * Apply a change from the log. | 589 | * Apply a change from the log. |
3851 | 590 | * | 590 | * |
3852 | 591 | * This function is basically very straight forward, were it not | 591 | * This function is basically very straight forward, were it not |
3853 | 592 | * for the option to apply operations out of sequence. | 592 | * for the option to apply operations out of sequence. |
3854 | 593 | * (i.e. in_sequence == FALSE) | 593 | * (i.e. in_sequence == FALSE) |
3855 | 594 | * | 594 | * |
3856 | 595 | * If operations are applied in sequence, then they can be | 595 | * If operations are applied in sequence, then they can be |
3857 | 596 | * applied blindly. The update operation is just executed as | 596 | * applied blindly. The update operation is just executed as |
3858 | 597 | * it was logged. | 597 | * it was logged. |
3859 | 598 | * | 598 | * |
3860 | 599 | * If the changes are not in sequence, then some operation are missing, | 599 | * If the changes are not in sequence, then some operation are missing, |
3861 | 600 | * however, the operations that are present are in the correct order. | 600 | * however, the operations that are present are in the correct order. |
3862 | 601 | * | 601 | * |
3863 | 602 | * This can only happen at the end of recovery!!! | 602 | * This can only happen at the end of recovery!!! |
3864 | 603 | * After we have applied all operations in the log we may be | 603 | * After we have applied all operations in the log we may be |
3865 | 604 | * left with some operations that have not been applied | 604 | * left with some operations that have not been applied |
3866 | 605 | * because operations were logged out of sequence. | 605 | * because operations were logged out of sequence. |
3867 | 606 | * | 606 | * |
3868 | 607 | * The application of these operations there has to take into | 607 | * The application of these operations there has to take into |
3869 | 608 | * account the current state of the database. | 608 | * account the current state of the database. |
3870 | 609 | * They are then applied in a manner that maintains the | 609 | * They are then applied in a manner that maintains the |
3871 | 610 | * database consistency. | 610 | * database consistency. |
3872 | 611 | * | 611 | * |
3873 | 612 | * For example, a record that is freed, is free by placing it | 612 | * For example, a record that is freed, is free by placing it |
3874 | 613 | * on the current free list. Part of the data logged for the | 613 | * on the current free list. Part of the data logged for the |
3875 | 614 | * operation is ignored. Namely: the "next block" pointer | 614 | * operation is ignored. Namely: the "next block" pointer |
3876 | 615 | * that was originally written into the freed record. | 615 | * that was originally written into the freed record. |
3877 | 616 | */ | 616 | */ |
3878 | 617 | static void xres_apply_change(XTThreadPtr self, XTOpenTablePtr ot, XTXactLogBufferDPtr record, xtBool in_sequence, xtBool check_index, XTInfoBufferPtr rec_buf) | 617 | static void xres_apply_change(XTThreadPtr self, XTOpenTablePtr ot, XTXactLogBufferDPtr record, xtBool in_sequence, xtBool check_index, XTInfoBufferPtr rec_buf) |
3879 | 618 | { | 618 | { |
3880 | 619 | XTTableHPtr tab = ot->ot_table; | 619 | XTTableHPtr tab = ot->ot_table; |
3881 | 620 | size_t len; | 620 | size_t len; |
3882 | 621 | xtRecordID rec_id; | 621 | xtRecordID rec_id; |
3883 | 622 | xtRefID free_ref_id; | 622 | xtRefID free_ref_id; |
3884 | 623 | XTTabRecFreeDRec free_rec; | 623 | XTTabRecFreeDRec free_rec; |
3885 | 624 | xtRowID row_id; | 624 | xtRowID row_id; |
3886 | 625 | XTTabRowRefDRec row_buf; | 625 | XTTabRowRefDRec row_buf; |
3887 | 626 | XTTabRecHeadDRec rec_head; | 626 | XTTabRecHeadDRec rec_head; |
3888 | 627 | size_t tfer; | 627 | size_t tfer; |
3889 | 628 | xtRecordID link_rec_id, prev_link_rec_id; | 628 | xtRecordID link_rec_id, prev_link_rec_id; |
3890 | 629 | xtWord1 *rec_data = NULL; | 629 | xtWord1 *rec_data = NULL; |
3891 | 630 | XTTabRecFreeDPtr free_data; | 630 | XTTabRecFreeDPtr free_data; |
3892 | 631 | 631 | ||
3893 | 632 | switch (record->xl.xl_status_1) { | 632 | switch (record->xl.xl_status_1) { |
3894 | 633 | case XT_LOG_ENT_REC_MODIFIED: | 633 | case XT_LOG_ENT_REC_MODIFIED: |
3895 | 634 | case XT_LOG_ENT_UPDATE: | 634 | case XT_LOG_ENT_UPDATE: |
3896 | 635 | case XT_LOG_ENT_INSERT: | 635 | case XT_LOG_ENT_INSERT: |
3897 | 636 | case XT_LOG_ENT_DELETE: | 636 | case XT_LOG_ENT_DELETE: |
3898 | 637 | case XT_LOG_ENT_UPDATE_BG: | 637 | case XT_LOG_ENT_UPDATE_BG: |
3899 | 638 | case XT_LOG_ENT_INSERT_BG: | 638 | case XT_LOG_ENT_INSERT_BG: |
3900 | 639 | case XT_LOG_ENT_DELETE_BG: | 639 | case XT_LOG_ENT_DELETE_BG: |
3901 | 640 | rec_id = XT_GET_DISK_4(record->xu.xu_rec_id_4); | 640 | rec_id = XT_GET_DISK_4(record->xu.xu_rec_id_4); |
3902 | 641 | len = (size_t) XT_GET_DISK_2(record->xu.xu_size_2); | 641 | |
3903 | 642 | if (!XT_PWRITE_RR_FILE(ot->ot_rec_file, xt_rec_id_to_rec_offset(tab, rec_id), len, (xtWord1 *) &record->xu.xu_rec_type_1, &ot->ot_thread->st_statistics.st_rec, ot->ot_thread)) | 642 | /* This should be done before we apply change to table, as otherwise we lose |
3904 | 643 | xt_throw(self); | 643 | * the key value that we need to remove from index |
3905 | 644 | tab->tab_bytes_to_flush += len; | 644 | */ |
3906 | 645 | 645 | if (check_index && ot->ot_table->tab_dic.dic_key_count && record->xl.xl_status_1 == XT_LOG_ENT_REC_MODIFIED) { | |
3907 | 646 | if (check_index && ot->ot_table->tab_dic.dic_key_count) { | 646 | if ((rec_data = xres_load_record(self, ot, rec_id, NULL, 0, rec_buf, tab->tab_dic.dic_ind_cols_req))) |
3908 | 647 | switch (record->xl.xl_status_1) { | 647 | xres_remove_index_entries(ot, rec_id, rec_data); |
3909 | 648 | case XT_LOG_ENT_DELETE: | 648 | } |
3910 | 649 | case XT_LOG_ENT_DELETE_BG: | 649 | |
3911 | 650 | break; | 650 | len = (size_t) XT_GET_DISK_2(record->xu.xu_size_2); |
3912 | 651 | case XT_LOG_ENT_REC_MODIFIED: | 651 | if (!XT_PWRITE_RR_FILE(ot->ot_rec_file, xt_rec_id_to_rec_offset(tab, rec_id), len, (xtWord1 *) &record->xu.xu_rec_type_1, &ot->ot_thread->st_statistics.st_rec, ot->ot_thread)) |
3913 | 652 | if ((rec_data = xres_load_record(self, ot, rec_id, NULL, 0, rec_buf, tab->tab_dic.dic_ind_cols_req))) | 652 | xt_throw(self); |
3914 | 653 | xres_remove_index_entries(ot, rec_id, rec_data); | 653 | tab->tab_bytes_to_flush += len; |
3915 | 654 | /* No break required: */ | 654 | |
3916 | 655 | default: | 655 | if (check_index && ot->ot_table->tab_dic.dic_key_count) { |
3917 | 656 | if ((rec_data = xres_load_record(self, ot, rec_id, &record->xu.xu_rec_type_1, len, rec_buf, tab->tab_dic.dic_ind_cols_req))) { | 656 | switch (record->xl.xl_status_1) { |
3918 | 657 | row_id = XT_GET_DISK_4(record->xu.xu_row_id_4); | 657 | case XT_LOG_ENT_DELETE: |
3919 | 658 | if (!xres_add_index_entries(ot, row_id, rec_id, rec_data)) | 658 | case XT_LOG_ENT_DELETE_BG: |
3920 | 659 | xt_throw(self); | 659 | break; |
3921 | 660 | } | 660 | default: |
3922 | 661 | break; | 661 | if ((rec_data = xres_load_record(self, ot, rec_id, &record->xu.xu_rec_type_1, len, rec_buf, tab->tab_dic.dic_ind_cols_req))) { |
3923 | 662 | } | 662 | row_id = XT_GET_DISK_4(record->xu.xu_row_id_4); |
3924 | 663 | } | 663 | if (!xres_add_index_entries(ot, row_id, rec_id, rec_data)) |
3925 | 664 | 664 | xt_throw(self); | |
3926 | 665 | if (!in_sequence) { | 665 | } |
3927 | 666 | /* A record has been allocated from the EOF, but out of sequence. | 666 | break; |
3928 | 667 | * This could leave a gap where other records were allocated | 667 | } |
3929 | 668 | * from the EOF, but those operations have been lost! | 668 | } |
3930 | 669 | * We compensate for this by adding all blocks between | 669 | |
3931 | 670 | * to the free list. | 670 | if (!in_sequence) { |
3932 | 671 | */ | 671 | /* A record has been allocated from the EOF, but out of sequence. |
3933 | 672 | free_rec.rf_rec_type_1 = XT_TAB_STATUS_FREED; | 672 | * This could leave a gap where other records were allocated |
3934 | 673 | free_rec.rf_not_used_1 = 0; | 673 | * from the EOF, but those operations have been lost! |
3935 | 674 | while (tab->tab_head_rec_eof_id < rec_id) { | 674 | * We compensate for this by adding all blocks between |
3936 | 675 | XT_SET_DISK_4(free_rec.rf_next_rec_id_4, tab->tab_head_rec_free_id); | 675 | * to the free list. |
3937 | 676 | if (!XT_PWRITE_RR_FILE(ot->ot_rec_file, tab->tab_head_rec_eof_id, sizeof(XTTabRecFreeDRec), (xtWord1 *) &free_rec, &ot->ot_thread->st_statistics.st_rec, ot->ot_thread)) | 676 | */ |
3938 | 677 | xt_throw(self); | 677 | free_rec.rf_rec_type_1 = XT_TAB_STATUS_FREED; |
3939 | 678 | tab->tab_bytes_to_flush += sizeof(XTTabRecFreeDRec); | 678 | free_rec.rf_not_used_1 = 0; |
3940 | 679 | tab->tab_head_rec_free_id = tab->tab_head_rec_eof_id; | 679 | while (tab->tab_head_rec_eof_id < rec_id) { |
3941 | 680 | tab->tab_head_rec_eof_id++; | 680 | XT_SET_DISK_4(free_rec.rf_next_rec_id_4, tab->tab_head_rec_free_id); |
3942 | 681 | } | 681 | if (!XT_PWRITE_RR_FILE(ot->ot_rec_file, tab->tab_head_rec_eof_id, sizeof(XTTabRecFreeDRec), (xtWord1 *) &free_rec, &ot->ot_thread->st_statistics.st_rec, ot->ot_thread)) |
3943 | 682 | } | 682 | xt_throw(self); |
3944 | 683 | if (tab->tab_head_rec_eof_id < rec_id + 1) | 683 | tab->tab_bytes_to_flush += sizeof(XTTabRecFreeDRec); |
3945 | 684 | tab->tab_head_rec_eof_id = rec_id + 1; | 684 | tab->tab_head_rec_free_id = tab->tab_head_rec_eof_id; |
3946 | 685 | tab->tab_flush_pending = TRUE; | 685 | tab->tab_head_rec_eof_id++; |
3947 | 686 | break; | 686 | } |
3948 | 687 | case XT_LOG_ENT_UPDATE_FL: | 687 | } |
3949 | 688 | case XT_LOG_ENT_INSERT_FL: | 688 | if (tab->tab_head_rec_eof_id < rec_id + 1) |
3950 | 689 | case XT_LOG_ENT_DELETE_FL: | 689 | tab->tab_head_rec_eof_id = rec_id + 1; |
3951 | 690 | case XT_LOG_ENT_UPDATE_FL_BG: | 690 | tab->tab_flush_pending = TRUE; |
3952 | 691 | case XT_LOG_ENT_INSERT_FL_BG: | 691 | break; |
3953 | 692 | case XT_LOG_ENT_DELETE_FL_BG: | 692 | case XT_LOG_ENT_UPDATE_FL: |
3954 | 693 | rec_id = XT_GET_DISK_4(record->xf.xf_rec_id_4); | 693 | case XT_LOG_ENT_INSERT_FL: |
3955 | 694 | len = (size_t) XT_GET_DISK_2(record->xf.xf_size_2); | 694 | case XT_LOG_ENT_DELETE_FL: |
3956 | 695 | free_ref_id = XT_GET_DISK_4(record->xf.xf_free_rec_id_4); | 695 | case XT_LOG_ENT_UPDATE_FL_BG: |
3957 | 696 | 696 | case XT_LOG_ENT_INSERT_FL_BG: | |
3958 | 697 | if (check_index && | 697 | case XT_LOG_ENT_DELETE_FL_BG: |
3959 | 698 | record->xf.xf_status_1 != XT_LOG_ENT_DELETE_FL && | 698 | rec_id = XT_GET_DISK_4(record->xf.xf_rec_id_4); |
3960 | 699 | record->xf.xf_status_1 != XT_LOG_ENT_DELETE_FL_BG) { | 699 | len = (size_t) XT_GET_DISK_2(record->xf.xf_size_2); |
3961 | 700 | if ((rec_data = xres_load_record(self, ot, rec_id, &record->xf.xf_rec_type_1, len, rec_buf, tab->tab_dic.dic_ind_cols_req))) { | 700 | free_ref_id = XT_GET_DISK_4(record->xf.xf_free_rec_id_4); |
3962 | 701 | row_id = XT_GET_DISK_4(record->xf.xf_row_id_4); | 701 | |
3963 | 702 | if (!xres_add_index_entries(ot, row_id, rec_id, rec_data)) | 702 | if (check_index && |
3964 | 703 | xt_throw(self); | 703 | record->xf.xf_status_1 != XT_LOG_ENT_DELETE_FL && |
3965 | 704 | } | 704 | record->xf.xf_status_1 != XT_LOG_ENT_DELETE_FL_BG) { |
3966 | 705 | } | 705 | if ((rec_data = xres_load_record(self, ot, rec_id, &record->xf.xf_rec_type_1, len, rec_buf, tab->tab_dic.dic_ind_cols_req))) { |
3967 | 706 | 706 | row_id = XT_GET_DISK_4(record->xf.xf_row_id_4); | |
3968 | 707 | if (!in_sequence) { | 707 | if (!xres_add_index_entries(ot, row_id, rec_id, rec_data)) |
3969 | 708 | /* This record was allocated from the free list. | 708 | xt_throw(self); |
3970 | 709 | * Because this operation is out of sequence, there | 709 | } |
3971 | 710 | * could have been other allocations from the | 710 | } |
3972 | 711 | * free list before this, that have gone missing. | 711 | |
3973 | 712 | * For this reason we have to search the current | 712 | if (!in_sequence) { |
3974 | 713 | * free list and remove the record. | 713 | /* This record was allocated from the free list. |
3975 | 714 | */ | 714 | * Because this operation is out of sequence, there |
3976 | 715 | link_rec_id = tab->tab_head_rec_free_id; | 715 | * could have been other allocations from the |
3977 | 716 | prev_link_rec_id = 0; | 716 | * free list before this, that have gone missing. |
3978 | 717 | while (link_rec_id) { | 717 | * For this reason we have to search the current |
3979 | 718 | if (!XT_PREAD_RR_FILE(ot->ot_rec_file, xt_rec_id_to_rec_offset(tab, link_rec_id), sizeof(XTTabRecFreeDRec), sizeof(XTTabRecFreeDRec), (xtWord1 *) &free_rec, NULL, &self->st_statistics.st_rec, self)) | 718 | * free list and remove the record. |
3980 | 719 | xt_throw(self); | 719 | */ |
3981 | 720 | if (link_rec_id == rec_id) | 720 | link_rec_id = tab->tab_head_rec_free_id; |
3982 | 721 | break; | 721 | prev_link_rec_id = 0; |
3983 | 722 | prev_link_rec_id = link_rec_id; | 722 | while (link_rec_id) { |
3984 | 723 | link_rec_id = XT_GET_DISK_4(free_rec.rf_next_rec_id_4); | 723 | if (!XT_PREAD_RR_FILE(ot->ot_rec_file, xt_rec_id_to_rec_offset(tab, link_rec_id), sizeof(XTTabRecFreeDRec), sizeof(XTTabRecFreeDRec), (xtWord1 *) &free_rec, NULL, &self->st_statistics.st_rec, self)) |
3985 | 724 | } | 724 | xt_throw(self); |
3986 | 725 | if (link_rec_id == rec_id) { | 725 | if (link_rec_id == rec_id) |
3987 | 726 | /* The block was found on the free list. | 726 | break; |
3988 | 727 | * remove it: */ | 727 | prev_link_rec_id = link_rec_id; |
3989 | 728 | if (prev_link_rec_id) { | 728 | link_rec_id = XT_GET_DISK_4(free_rec.rf_next_rec_id_4); |
3990 | 729 | /* We write the record from position 'link_rec_id' into | 729 | } |
3991 | 730 | * position 'prev_link_rec_id'. This unlinks 'link_rec_id'! | 730 | if (link_rec_id == rec_id) { |
3992 | 731 | */ | 731 | /* The block was found on the free list. |
3993 | 732 | if (!XT_PWRITE_RR_FILE(ot->ot_rec_file, xt_rec_id_to_rec_offset(tab, prev_link_rec_id), sizeof(XTTabRecFreeDRec), (xtWord1 *) &free_rec, &ot->ot_thread->st_statistics.st_rec, ot->ot_thread)) | 732 | * remove it: */ |
3994 | 733 | xt_throw(self); | 733 | if (prev_link_rec_id) { |
3995 | 734 | tab->tab_bytes_to_flush += sizeof(XTTabRecFreeDRec); | 734 | /* We write the record from position 'link_rec_id' into |
3996 | 735 | free_ref_id = tab->tab_head_rec_free_id; | 735 | * position 'prev_link_rec_id'. This unlinks 'link_rec_id'! |
3997 | 736 | } | 736 | */ |
3998 | 737 | else | 737 | if (!XT_PWRITE_RR_FILE(ot->ot_rec_file, xt_rec_id_to_rec_offset(tab, prev_link_rec_id), sizeof(XTTabRecFreeDRec), (xtWord1 *) &free_rec, &ot->ot_thread->st_statistics.st_rec, ot->ot_thread)) |
3999 | 738 | /* The block is at the front of the list: */ | 738 | xt_throw(self); |
4000 | 739 | free_ref_id = XT_GET_DISK_4(free_rec.rf_next_rec_id_4); | 739 | tab->tab_bytes_to_flush += sizeof(XTTabRecFreeDRec); |
4001 | 740 | } | 740 | free_ref_id = tab->tab_head_rec_free_id; |
4002 | 741 | else { | 741 | } |
4003 | 742 | /* Not found on the free list? */ | 742 | else |
4004 | 743 | if (tab->tab_head_rec_eof_id < rec_id + 1) | 743 | /* The block is at the front of the list: */ |
4005 | 744 | tab->tab_head_rec_eof_id = rec_id + 1; | 744 | free_ref_id = XT_GET_DISK_4(free_rec.rf_next_rec_id_4); |
4006 | 745 | goto write_mod_data; | 745 | } |
4007 | 746 | } | 746 | else { |
4008 | 747 | } | 747 | /* Not found on the free list? */ |
4009 | 748 | if (tab->tab_head_rec_eof_id < rec_id + 1) | 748 | if (tab->tab_head_rec_eof_id < rec_id + 1) |
4010 | 749 | tab->tab_head_rec_eof_id = rec_id + 1; | 749 | tab->tab_head_rec_eof_id = rec_id + 1; |
4011 | 750 | tab->tab_head_rec_free_id = free_ref_id; | 750 | goto write_mod_data; |
4012 | 751 | tab->tab_head_rec_fnum--; | 751 | } |
4013 | 752 | write_mod_data: | 752 | } |
4014 | 753 | if (!XT_PWRITE_RR_FILE(ot->ot_rec_file, xt_rec_id_to_rec_offset(tab, rec_id), len, (xtWord1 *) &record->xf.xf_rec_type_1, &ot->ot_thread->st_statistics.st_rec, ot->ot_thread)) | 753 | if (tab->tab_head_rec_eof_id < rec_id + 1) |
4015 | 754 | xt_throw(self); | 754 | tab->tab_head_rec_eof_id = rec_id + 1; |
4016 | 755 | tab->tab_bytes_to_flush += len; | 755 | tab->tab_head_rec_free_id = free_ref_id; |
4017 | 756 | tab->tab_flush_pending = TRUE; | 756 | tab->tab_head_rec_fnum--; |
4018 | 757 | break; | 757 | write_mod_data: |
4019 | 758 | case XT_LOG_ENT_REC_REMOVED: | 758 | if (!XT_PWRITE_RR_FILE(ot->ot_rec_file, xt_rec_id_to_rec_offset(tab, rec_id), len, (xtWord1 *) &record->xf.xf_rec_type_1, &ot->ot_thread->st_statistics.st_rec, ot->ot_thread)) |
4020 | 759 | case XT_LOG_ENT_REC_REMOVED_EXT: { | 759 | xt_throw(self); |
4021 | 760 | xtBool record_loaded; | 760 | tab->tab_bytes_to_flush += len; |
4022 | 761 | XTTabRecExtDPtr ext_rec; | 761 | tab->tab_flush_pending = TRUE; |
4023 | 762 | size_t red_size; | 762 | break; |
4024 | 763 | xtWord4 log_over_size = 0; | 763 | case XT_LOG_ENT_REC_REMOVED: |
4025 | 764 | xtLogID data_log_id = 0; | 764 | case XT_LOG_ENT_REC_REMOVED_EXT: { |
4026 | 765 | xtLogOffset data_log_offset = 0; | 765 | xtBool record_loaded; |
4027 | 766 | u_int cols_required = 0; | 766 | XTTabRecExtDPtr ext_rec; |
4028 | 767 | 767 | size_t red_size; | |
4029 | 768 | rec_id = XT_GET_DISK_4(record->fr.fr_rec_id_4); | 768 | xtWord4 log_over_size = 0; |
4030 | 769 | free_data = (XTTabRecFreeDPtr) &record->fr.fr_rec_type_1; | 769 | xtLogID data_log_id = 0; |
4031 | 770 | 770 | xtLogOffset data_log_offset = 0; | |
4032 | 771 | /* This is a short-cut, it does not require loading the record: */ | 771 | u_int cols_required = 0; |
4033 | 772 | if (!check_index && !tab->tab_dic.dic_blob_count && record->fr.fr_status_1 != XT_LOG_ENT_REC_REMOVED_EXT) | 772 | |
4034 | 773 | goto do_rec_freed; | 773 | rec_id = XT_GET_DISK_4(record->fr.fr_rec_id_4); |
4035 | 774 | 774 | free_data = (XTTabRecFreeDPtr) &record->fr.fr_rec_type_1; | |
4036 | 775 | ext_rec = (XTTabRecExtDPtr) ot->ot_row_rbuffer; | 775 | |
4037 | 776 | 776 | /* This is a short-cut, it does not require loading the record: */ | |
4038 | 777 | if (!XT_PREAD_RR_FILE(ot->ot_rec_file, xt_rec_id_to_rec_offset(tab, rec_id), tab->tab_dic.dic_rec_size, 0, ext_rec, &red_size, &self->st_statistics.st_rec, self)) { | 777 | if (!check_index && !tab->tab_dic.dic_blob_count && record->fr.fr_status_1 != XT_LOG_ENT_REC_REMOVED_EXT) |
4039 | 778 | xt_log_and_clear_exception_ns(); | 778 | goto do_rec_freed; |
4040 | 779 | goto do_rec_freed; | 779 | |
4041 | 780 | } | 780 | ext_rec = (XTTabRecExtDPtr) ot->ot_row_rbuffer; |
4042 | 781 | 781 | ||
4043 | 782 | if (red_size < sizeof(XTTabRecHeadDRec)) | 782 | if (!XT_PREAD_RR_FILE(ot->ot_rec_file, xt_rec_id_to_rec_offset(tab, rec_id), tab->tab_dic.dic_rec_size, 0, ext_rec, &red_size, &self->st_statistics.st_rec, self)) { |
4044 | 783 | goto do_rec_freed; | 783 | xt_log_and_clear_exception_ns(); |
4045 | 784 | 784 | goto do_rec_freed; | |
4046 | 785 | /* Check that the record is the same as the one originally removed. | 785 | } |
4047 | 786 | * This can be different if recovery is repeated. | 786 | |
4048 | 787 | * For example: | 787 | if (red_size < sizeof(XTTabRecHeadDRec)) |
4049 | 788 | * | 788 | goto do_rec_freed; |
4050 | 789 | * log=21 offset=6304472 REMOVED-X REC op=360616 tab=7 rec=25874 | 789 | |
4051 | 790 | * log=21 offset=6309230 UPDATE-FL op=360618 tab=7 rec=25874 row=26667 log=1 offset=26503077 xact=209 | 790 | /* Check that the record is the same as the one originally removed. |
4052 | 791 | * log=21 offset=6317500 CLEAN REC op=360631 tab=7 rec=25874 | 791 | * This can be different if recovery is repeated. |
4053 | 792 | * | 792 | * For example: |
4054 | 793 | * If this recovery sequence is repeated, then the REMOVED-X will free the | 793 | * |
4055 | 794 | * extended record belonging to the update that came afterwards! | 794 | * log=21 offset=6304472 REMOVED-X REC op=360616 tab=7 rec=25874 |
4056 | 795 | * | 795 | * log=21 offset=6309230 UPDATE-FL op=360618 tab=7 rec=25874 row=26667 log=1 offset=26503077 xact=209 |
4057 | 796 | * Additional situation to consider: | 796 | * log=21 offset=6317500 CLEAN REC op=360631 tab=7 rec=25874 |
4058 | 797 | * | 797 | * |
4059 | 798 | * - A record "x" is created, and index entries created. | 798 | * If this recovery sequence is repeated, then the REMOVED-X will free the |
4060 | 799 | * - A checkpoint is made done. | 799 | * extended record belonging to the update that came afterwards! |
4061 | 800 | * - Record "x" is deleted due to UPDATE. | 800 | * |
4062 | 801 | * - The index entries are removed, but the index is not | 801 | * Additional situation to consider: |
4063 | 802 | * flushed. | 802 | * |
4064 | 803 | * - This deletion is written to disk by the writer. | 803 | * - A record "x" is created, and index entries created. |
4065 | 804 | * So we have the situation that the remove is on disk, | 804 | * - A checkpoint is made done. |
4066 | 805 | * but the index changes have not been made. | 805 | * - Record "x" is deleted due to UPDATE. |
4067 | 806 | * | 806 | * - The index entries are removed, but the index is not |
4068 | 807 | * In this case, skipping to "do_rec_freed" is incorrect. | 807 | * flushed. |
4069 | 808 | */ | 808 | * - This deletion is written to disk by the writer. |
4070 | 809 | if (record->fr.fr_stat_id_1 != ext_rec->tr_stat_id_1 || | 809 | * So we have the situation that the remove is on disk, |
4071 | 810 | XT_GET_DISK_4(record->fr.fr_xact_id_4) != XT_GET_DISK_4(ext_rec->tr_xact_id_4)) | 810 | * but the index changes have not been made. |
4072 | 811 | goto dont_remove_x_record; | 811 | * |
4073 | 812 | 812 | * In this case, skipping to "do_rec_freed" is incorrect. | |
4074 | 813 | if (record->xl.xl_status_1 == XT_LOG_ENT_REC_REMOVED_EXT) { | 813 | */ |
4075 | 814 | if (!XT_REC_IS_EXT_DLOG(ext_rec->tr_rec_type_1)) | 814 | if (record->fr.fr_stat_id_1 != ext_rec->tr_stat_id_1 || |
4076 | 815 | goto dont_remove_x_record; | 815 | XT_GET_DISK_4(record->fr.fr_xact_id_4) != XT_GET_DISK_4(ext_rec->tr_xact_id_4)) |
4077 | 816 | if (red_size < offsetof(XTTabRecExtDRec, re_data)) | 816 | goto dont_remove_x_record; |
4078 | 817 | goto dont_remove_x_record; | 817 | |
4079 | 818 | 818 | if (record->xl.xl_status_1 == XT_LOG_ENT_REC_REMOVED_EXT) { | |
4080 | 819 | /* Save this for later (can be overwritten by xres_load_record(): */ | 819 | if (!XT_REC_IS_EXT_DLOG(ext_rec->tr_rec_type_1)) |
4081 | 820 | data_log_id = XT_GET_DISK_2(ext_rec->re_log_id_2); | 820 | goto dont_remove_x_record; |
4082 | 821 | data_log_offset = XT_GET_DISK_6(ext_rec->re_log_offs_6); | 821 | if (red_size < offsetof(XTTabRecExtDRec, re_data)) |
4083 | 822 | log_over_size = XT_GET_DISK_4(ext_rec->re_log_dat_siz_4); | 822 | goto dont_remove_x_record; |
4084 | 823 | } | 823 | |
4085 | 824 | dont_remove_x_record: | 824 | /* Save this for later (can be overwritten by xres_load_record(): */ |
4086 | 825 | 825 | data_log_id = XT_GET_DISK_2(ext_rec->re_log_id_2); | |
4087 | 826 | record_loaded = FALSE; | 826 | data_log_offset = XT_GET_DISK_6(ext_rec->re_log_offs_6); |
4088 | 827 | 827 | log_over_size = XT_GET_DISK_4(ext_rec->re_log_dat_siz_4); | |
4089 | 828 | if (check_index) { | 828 | } |
4090 | 829 | cols_required = tab->tab_dic.dic_ind_cols_req; | 829 | dont_remove_x_record: |
4091 | 830 | if (tab->tab_dic.dic_blob_cols_req > cols_required) | 830 | |
4092 | 831 | cols_required = tab->tab_dic.dic_blob_cols_req; | 831 | record_loaded = FALSE; |
4093 | 832 | if (!(rec_data = xres_load_record(self, ot, rec_id, ot->ot_row_rbuffer, red_size, rec_buf, cols_required))) | 832 | |
4094 | 833 | goto do_rec_freed; | 833 | if (check_index) { |
4095 | 834 | record_loaded = TRUE; | 834 | cols_required = tab->tab_dic.dic_ind_cols_req; |
4096 | 835 | xres_remove_index_entries(ot, rec_id, rec_data); | 835 | if (tab->tab_dic.dic_blob_cols_req > cols_required) |
4097 | 836 | } | 836 | cols_required = tab->tab_dic.dic_blob_cols_req; |
4098 | 837 | 837 | if (!(rec_data = xres_load_record(self, ot, rec_id, ot->ot_row_rbuffer, red_size, rec_buf, cols_required))) | |
4099 | 838 | if (tab->tab_dic.dic_blob_count) { | 838 | goto do_rec_freed; |
4100 | 839 | if (!record_loaded) { | 839 | record_loaded = TRUE; |
4101 | 840 | if (tab->tab_dic.dic_blob_cols_req > cols_required) | 840 | xres_remove_index_entries(ot, rec_id, rec_data); |
4102 | 841 | cols_required = tab->tab_dic.dic_blob_cols_req; | 841 | } |
4103 | 842 | if (!(rec_data = xres_load_record(self, ot, rec_id, ot->ot_row_rbuffer, red_size, rec_buf, cols_required))) | 842 | |
4104 | 843 | /* [(7)] REMOVE is followed by FREE: | 843 | if (tab->tab_dic.dic_blob_count) { |
4105 | 844 | goto get_rec_offset; | 844 | if (!record_loaded) { |
4106 | 845 | */ | 845 | if (tab->tab_dic.dic_blob_cols_req > cols_required) |
4107 | 846 | goto do_rec_freed; | 846 | cols_required = tab->tab_dic.dic_blob_cols_req; |
4108 | 847 | record_loaded = TRUE; | 847 | if (!(rec_data = xres_load_record(self, ot, rec_id, ot->ot_row_rbuffer, red_size, rec_buf, cols_required))) |
4109 | 848 | } | 848 | /* [(7)] REMOVE is followed by FREE: |
4110 | 849 | #ifdef XT_STREAMING | 849 | goto get_rec_offset; |
4111 | 850 | myxt_release_blobs(ot, rec_data, rec_id); | 850 | */ |
4112 | 851 | #endif | 851 | goto do_rec_freed; |
4113 | 852 | } | 852 | record_loaded = TRUE; |
4114 | 853 | 853 | } | |
4115 | 854 | if (record->xl.xl_status_1 == XT_LOG_ENT_REC_REMOVED_EXT) { | 854 | #ifdef XT_STREAMING |
4116 | 855 | /* Note: dlb_delete_log() may be repeated, but should handle this: | 855 | myxt_release_blobs(ot, rec_data, rec_id); |
4117 | 856 | * | 856 | #endif |
4118 | 857 | * Example: | 857 | } |
4119 | 858 | * log=5 offset=213334 CLEAN REC op=28175 tab=1 rec=317428 | 858 | |
4120 | 859 | * ... | 859 | if (record->xl.xl_status_1 == XT_LOG_ENT_REC_REMOVED_EXT) { |
4121 | 860 | * log=6 offset=321063 REMOVED-X REC op=33878 tab=1 rec=317428 | 860 | /* Note: dlb_delete_log() may be repeated, but should handle this: |
4122 | 861 | * | 861 | * |
4123 | 862 | * When this sequence is repeated during recovery, then CLEAN REC | 862 | * Example: |
4124 | 863 | * will reset the status byte of the record so that it | 863 | * log=5 offset=213334 CLEAN REC op=28175 tab=1 rec=317428 |
4125 | 864 | * comes back to here! | 864 | * ... |
4126 | 865 | * | 865 | * log=6 offset=321063 REMOVED-X REC op=33878 tab=1 rec=317428 |
4127 | 866 | * The check for zero is probably not required here. | 866 | * |
4128 | 867 | */ | 867 | * When this sequence is repeated during recovery, then CLEAN REC |
4129 | 868 | if (data_log_id && data_log_offset && log_over_size) { | 868 | * will reset the status byte of the record so that it |
4130 | 869 | if (!ot->ot_thread->st_dlog_buf.dlb_delete_log(data_log_id, data_log_offset, log_over_size, tab->tab_id, rec_id, self)) { | 869 | * comes back to here! |
4131 | 870 | if (ot->ot_thread->t_exception.e_xt_err != XT_ERR_BAD_EXT_RECORD && | 870 | * |
4132 | 871 | ot->ot_thread->t_exception.e_xt_err != XT_ERR_DATA_LOG_NOT_FOUND) | 871 | * The check for zero is probably not required here. |
4133 | 872 | xt_log_and_clear_exception_ns(); | 872 | */ |
4134 | 873 | } | 873 | if (data_log_id && data_log_offset && log_over_size) { |
4135 | 874 | } | 874 | if (!ot->ot_thread->st_dlog_buf.dlb_delete_log(data_log_id, data_log_offset, log_over_size, tab->tab_id, rec_id, self)) { |
4136 | 875 | } | 875 | if (ot->ot_thread->t_exception.e_xt_err != XT_ERR_BAD_EXT_RECORD && |
4137 | 876 | 876 | ot->ot_thread->t_exception.e_xt_err != XT_ERR_DATA_LOG_NOT_FOUND) | |
4138 | 877 | goto do_rec_freed; | 877 | xt_log_and_clear_exception_ns(); |
4139 | 878 | } | 878 | } |
4140 | 879 | case XT_LOG_ENT_REC_REMOVED_BI: { | 879 | } |
4141 | 880 | /* | 880 | } |
4142 | 881 | * For deletion we need the complete before image because of the following problem. | 881 | |
4143 | 882 | * | 882 | goto do_rec_freed; |
4144 | 883 | * DROP TABLE IF EXISTS t1; | 883 | } |
4145 | 884 | * CREATE TABLE t1 (ID int primary key auto_increment, value int, index (value)) engine=pbxt; | 884 | case XT_LOG_ENT_REC_REMOVED_BI: { |
4146 | 885 | * | 885 | /* |
4147 | 886 | * insert t1(value) values(50); | 886 | * For deletion we need the complete before image because of the following problem. |
4148 | 887 | * | 887 | * |
4149 | 888 | * -- CHECKPOINT -- | 888 | * DROP TABLE IF EXISTS t1; |
4150 | 889 | * | 889 | * CREATE TABLE t1 (ID int primary key auto_increment, value int, index (value)) engine=pbxt; |
4151 | 890 | * update t1 set value = 60; | 890 | * |
4152 | 891 | * | 891 | * insert t1(value) values(50); |
4153 | 892 | * -- PAUSE -- | 892 | * |
4154 | 893 | * | 893 | * -- CHECKPOINT -- |
4155 | 894 | * update t1 set value = 70; | 894 | * |
4156 | 895 | * | 895 | * update t1 set value = 60; |
4157 | 896 | * -- CRASH -- | 896 | * |
4158 | 897 | * | 897 | * -- PAUSE -- |
4159 | 898 | * select value from t1; | 898 | * |
4160 | 899 | * select * from t1; | 899 | * update t1 set value = 70; |
4161 | 900 | * | 900 | * |
4162 | 901 | * 081203 12:11:46 [Note] PBXT: Recovering from 1-148, bytes to read: 33554284 | 901 | * -- CRASH -- |
4163 | 902 | * log=1 offset=148 UPDATE-BG op=5 tab=1 rec=2 row=1 xact=3 | 902 | * |
4164 | 903 | * log=1 offset=188 REC ADD ROW op=6 tab=1 row=1 | 903 | * select value from t1; |
4165 | 904 | * log=1 offset=206 COMMIT xact=3 | 904 | * select * from t1; |
4166 | 905 | * log=1 offset=216 REMOVED REC op=7 tab=1 rec=1 xact=2 | 905 | * |
4167 | 906 | * log=1 offset=241 CLEAN REC op=8 tab=1 rec=2 | 906 | * 081203 12:11:46 [Note] PBXT: Recovering from 1-148, bytes to read: 33554284 |
4168 | 907 | * log=1 offset=261 CLEANUP xact=3 | 907 | * log=1 offset=148 UPDATE-BG op=5 tab=1 rec=2 row=1 xact=3 |
4169 | 908 | * log=1 offset=267 UPDATE-FL-BG op=9 tab=1 rec=1 row=1 xact=4 | 908 | * log=1 offset=188 REC ADD ROW op=6 tab=1 row=1 |
4170 | 909 | * log=1 offset=311 REC ADD ROW op=10 tab=1 row=1 | 909 | * log=1 offset=206 COMMIT xact=3 |
4171 | 910 | * log=1 offset=329 COMMIT xact=4 | 910 | * log=1 offset=216 REMOVED REC op=7 tab=1 rec=1 xact=2 |
4172 | 911 | * log=1 offset=339 REMOVED REC op=11 tab=1 rec=2 xact=3 | 911 | * log=1 offset=241 CLEAN REC op=8 tab=1 rec=2 |
4173 | 912 | * log=1 offset=364 CLEAN REC op=12 tab=1 rec=1 | 912 | * log=1 offset=261 CLEANUP xact=3 |
4174 | 913 | * log=1 offset=384 CLEANUP xact=4 | 913 | * log=1 offset=267 UPDATE-FL-BG op=9 tab=1 rec=1 row=1 xact=4 |
4175 | 914 | * 081203 12:12:15 [Note] PBXT: Recovering complete at 1-390, bytes read: 33554284 | 914 | * log=1 offset=311 REC ADD ROW op=10 tab=1 row=1 |
4176 | 915 | * | 915 | * log=1 offset=329 COMMIT xact=4 |
4177 | 916 | * mysql> select value from t1; | 916 | * log=1 offset=339 REMOVED REC op=11 tab=1 rec=2 xact=3 |
4178 | 917 | * +-------+ | 917 | * log=1 offset=364 CLEAN REC op=12 tab=1 rec=1 |
4179 | 918 | * | value | | 918 | * log=1 offset=384 CLEANUP xact=4 |
4180 | 919 | * +-------+ | 919 | * 081203 12:12:15 [Note] PBXT: Recovering complete at 1-390, bytes read: 33554284 |
4181 | 920 | * | 50 | | 920 | * |
4182 | 921 | * | 70 | | 921 | * mysql> select value from t1; |
4183 | 922 | * +-------+ | 922 | * +-------+ |
4184 | 923 | * 2 rows in set (55.99 sec) | 923 | * | value | |
4185 | 924 | * | 924 | * +-------+ |
4186 | 925 | * mysql> select * from t1; | 925 | * | 50 | |
4187 | 926 | * +----+-------+ | 926 | * | 70 | |
4188 | 927 | * | ID | value | | 927 | * +-------+ |
4189 | 928 | * +----+-------+ | 928 | * 2 rows in set (55.99 sec) |
4190 | 929 | * | 1 | 70 | | 929 | * |
4191 | 930 | * +----+-------+ | 930 | * mysql> select * from t1; |
4192 | 931 | * 1 row in set (0.00 sec) | 931 | * +----+-------+ |
4193 | 932 | */ | 932 | * | ID | value | |
4194 | 933 | XTTabRecExtDPtr ext_rec; | 933 | * +----+-------+ |
4195 | 934 | xtWord4 log_over_size = 0; | 934 | * | 1 | 70 | |
4196 | 935 | xtLogID data_log_id = 0; | 935 | * +----+-------+ |
4197 | 936 | xtLogOffset data_log_offset = 0; | 936 | * 1 row in set (0.00 sec) |
4198 | 937 | u_int cols_required = 0; | 937 | */ |
4199 | 938 | xtBool record_loaded; | 938 | XTTabRecExtDPtr ext_rec; |
4200 | 939 | size_t rec_size; | 939 | xtWord4 log_over_size = 0; |
4201 | 940 | 940 | xtLogID data_log_id = 0; | |
4202 | 941 | rec_id = XT_GET_DISK_4(record->rb.rb_rec_id_4); | 941 | xtLogOffset data_log_offset = 0; |
4203 | 942 | rec_size = XT_GET_DISK_2(record->rb.rb_size_2); | 942 | u_int cols_required = 0; |
4204 | 943 | 943 | xtBool record_loaded; | |
4205 | 944 | ext_rec = (XTTabRecExtDPtr) &record->rb.rb_rec_type_1; | 944 | size_t rec_size; |
4206 | 945 | 945 | ||
4207 | 946 | if (XT_REC_IS_EXT_DLOG(record->rb.rb_rec_type_1)) { | 946 | rec_id = XT_GET_DISK_4(record->rb.rb_rec_id_4); |
4208 | 947 | /* Save this for later (can be overwritten by xres_load_record(): */ | 947 | rec_size = XT_GET_DISK_2(record->rb.rb_size_2); |
4209 | 948 | data_log_id = XT_GET_DISK_2(ext_rec->re_log_id_2); | 948 | |
4210 | 949 | data_log_offset = XT_GET_DISK_6(ext_rec->re_log_offs_6); | 949 | ext_rec = (XTTabRecExtDPtr) &record->rb.rb_rec_type_1; |
4211 | 950 | log_over_size = XT_GET_DISK_4(ext_rec->re_log_dat_siz_4); | 950 | |
4212 | 951 | } | 951 | if (XT_REC_IS_EXT_DLOG(record->rb.rb_rec_type_1)) { |
4213 | 952 | 952 | /* Save this for later (can be overwritten by xres_load_record(): */ | |
4214 | 953 | record_loaded = FALSE; | 953 | data_log_id = XT_GET_DISK_2(ext_rec->re_log_id_2); |
4215 | 954 | 954 | data_log_offset = XT_GET_DISK_6(ext_rec->re_log_offs_6); | |
4216 | 955 | if (check_index) { | 955 | log_over_size = XT_GET_DISK_4(ext_rec->re_log_dat_siz_4); |
4217 | 956 | cols_required = tab->tab_dic.dic_ind_cols_req; | 956 | } |
4218 | 957 | #ifdef XT_STREAMING | 957 | |
4219 | 958 | if (tab->tab_dic.dic_blob_cols_req > cols_required) | 958 | record_loaded = FALSE; |
4220 | 959 | cols_required = tab->tab_dic.dic_blob_cols_req; | 959 | |
4221 | 960 | #endif | 960 | if (check_index) { |
4222 | 961 | if (!(rec_data = xres_load_record(self, ot, rec_id, &record->rb.rb_rec_type_1, rec_size, rec_buf, cols_required))) | 961 | cols_required = tab->tab_dic.dic_ind_cols_req; |
4223 | 962 | goto go_on_to_free; | 962 | #ifdef XT_STREAMING |
4224 | 963 | record_loaded = TRUE; | 963 | if (tab->tab_dic.dic_blob_cols_req > cols_required) |
4225 | 964 | xres_remove_index_entries(ot, rec_id, rec_data); | 964 | cols_required = tab->tab_dic.dic_blob_cols_req; |
4226 | 965 | } | 965 | #endif |
4227 | 966 | 966 | if (!(rec_data = xres_load_record(self, ot, rec_id, &record->rb.rb_rec_type_1, rec_size, rec_buf, cols_required))) | |
4228 | 967 | #ifdef XT_STREAMING | 967 | goto go_on_to_free; |
4229 | 968 | if (tab->tab_dic.dic_blob_count) { | 968 | record_loaded = TRUE; |
4230 | 969 | if (!record_loaded) { | 969 | xres_remove_index_entries(ot, rec_id, rec_data); |
4231 | 970 | cols_required = tab->tab_dic.dic_blob_cols_req; | 970 | } |
4232 | 971 | if (!(rec_data = xres_load_record(self, ot, rec_id, &record->rb.rb_rec_type_1, rec_size, rec_buf, cols_required))) | 971 | |
4233 | 972 | /* [(7)] REMOVE is followed by FREE: | 972 | #ifdef XT_STREAMING |
4234 | 973 | goto get_rec_offset; | 973 | if (tab->tab_dic.dic_blob_count) { |
4235 | 974 | */ | 974 | if (!record_loaded) { |
4236 | 975 | goto go_on_to_free; | 975 | cols_required = tab->tab_dic.dic_blob_cols_req; |
4237 | 976 | record_loaded = TRUE; | 976 | if (!(rec_data = xres_load_record(self, ot, rec_id, &record->rb.rb_rec_type_1, rec_size, rec_buf, cols_required))) |
4238 | 977 | } | 977 | /* [(7)] REMOVE is followed by FREE: |
4239 | 978 | myxt_release_blobs(ot, rec_data, rec_id); | 978 | goto get_rec_offset; |
4240 | 979 | } | 979 | */ |
4241 | 980 | #endif | 980 | goto go_on_to_free; |
4242 | 981 | 981 | record_loaded = TRUE; | |
4243 | 982 | if (data_log_id && data_log_offset && log_over_size) { | 982 | } |
4244 | 983 | if (!ot->ot_thread->st_dlog_buf.dlb_delete_log(data_log_id, data_log_offset, log_over_size, tab->tab_id, rec_id, self)) { | 983 | myxt_release_blobs(ot, rec_data, rec_id); |
4245 | 984 | if (ot->ot_thread->t_exception.e_xt_err != XT_ERR_BAD_EXT_RECORD && | 984 | } |
4246 | 985 | ot->ot_thread->t_exception.e_xt_err != XT_ERR_DATA_LOG_NOT_FOUND) | 985 | #endif |
4247 | 986 | xt_log_and_clear_exception_ns(); | 986 | |
4248 | 987 | } | 987 | if (data_log_id && data_log_offset && log_over_size) { |
4249 | 988 | } | 988 | if (!ot->ot_thread->st_dlog_buf.dlb_delete_log(data_log_id, data_log_offset, log_over_size, tab->tab_id, rec_id, self)) { |
4250 | 989 | 989 | if (ot->ot_thread->t_exception.e_xt_err != XT_ERR_BAD_EXT_RECORD && | |
4251 | 990 | go_on_to_free: | 990 | ot->ot_thread->t_exception.e_xt_err != XT_ERR_DATA_LOG_NOT_FOUND) |
4252 | 991 | /* Use the new record type: */ | 991 | xt_log_and_clear_exception_ns(); |
4253 | 992 | record->rb.rb_rec_type_1 = record->rb.rb_new_rec_type_1; | 992 | } |
4254 | 993 | free_data = (XTTabRecFreeDPtr) &record->rb.rb_rec_type_1; | 993 | } |
4255 | 994 | goto do_rec_freed; | 994 | |
4256 | 995 | } | 995 | go_on_to_free: |
4257 | 996 | case XT_LOG_ENT_REC_FREED: | 996 | /* Use the new record type: */ |
4258 | 997 | rec_id = XT_GET_DISK_4(record->fr.fr_rec_id_4); | 997 | record->rb.rb_rec_type_1 = record->rb.rb_new_rec_type_1; |
4259 | 998 | free_data = (XTTabRecFreeDPtr) &record->fr.fr_rec_type_1; | 998 | free_data = (XTTabRecFreeDPtr) &record->rb.rb_rec_type_1; |
4260 | 999 | do_rec_freed: | 999 | goto do_rec_freed; |
4261 | 1000 | if (!in_sequence) { | 1000 | } |
4262 | 1001 | size_t red_size; | 1001 | case XT_LOG_ENT_REC_FREED: |
4263 | 1002 | 1002 | rec_id = XT_GET_DISK_4(record->fr.fr_rec_id_4); | |
4264 | 1003 | /* Free the record. | 1003 | free_data = (XTTabRecFreeDPtr) &record->fr.fr_rec_type_1; |
4265 | 1004 | * We place the record on front of the current | 1004 | do_rec_freed: |
4266 | 1005 | * free list. | 1005 | if (!in_sequence) { |
4267 | 1006 | * | 1006 | size_t red_size; |
4268 | 1007 | * However, before we do this, we remove the record | 1007 | |
4269 | 1008 | * from its row list, if the record is on a row list. | 1008 | /* Free the record. |
4270 | 1009 | * | 1009 | * We place the record on front of the current |
4271 | 1010 | * We do this here, because in the normal removal | 1010 | * free list. |
4272 | 1011 | * from the row list uses the operations: | 1011 | * |
4273 | 1012 | * | 1012 | * However, before we do this, we remove the record |
4274 | 1013 | * XT_LOG_ENT_REC_UNLINKED, XT_LOG_ENT_ROW_SET and | 1013 | * from its row list, if the record is on a row list. |
4275 | 1014 | * XT_LOG_ENT_ROW_FREED. | 1014 | * |
4276 | 1015 | * | 1015 | * We do this here, because in the normal removal |
4277 | 1016 | * When operations are performed out of sequence, | 1016 | * from the row list uses the operations: |
4278 | 1017 | * these operations are ignored for the purpose | 1017 | * |
4279 | 1018 | * of removing the record from the row. | 1018 | * XT_LOG_ENT_REC_UNLINKED, XT_LOG_ENT_ROW_SET and |
4280 | 1019 | */ | 1019 | * XT_LOG_ENT_ROW_FREED. |
4281 | 1020 | if (!XT_PREAD_RR_FILE(ot->ot_rec_file, xt_rec_id_to_rec_offset(tab, rec_id), sizeof(XTTabRecHeadDRec), sizeof(XTTabRecHeadDRec), (xtWord1 *) &rec_head, NULL, &self->st_statistics.st_rec, self)) | 1020 | * |
4282 | 1021 | xt_throw(self); | 1021 | * When operations are performed out of sequence, |
4283 | 1022 | /* The record is already free: */ | 1022 | * these operations are ignored for the purpose |
4284 | 1023 | if (XT_REC_IS_FREE(rec_head.tr_rec_type_1)) | 1023 | * of removing the record from the row. |
4285 | 1024 | goto free_done; | 1024 | */ |
4286 | 1025 | row_id = XT_GET_DISK_4(rec_head.tr_row_id_4); | 1025 | if (!XT_PREAD_RR_FILE(ot->ot_rec_file, xt_rec_id_to_rec_offset(tab, rec_id), sizeof(XTTabRecHeadDRec), sizeof(XTTabRecHeadDRec), (xtWord1 *) &rec_head, NULL, &self->st_statistics.st_rec, self)) |
4287 | 1026 | 1026 | xt_throw(self); | |
4288 | 1027 | /* Search the row for this record: */ | 1027 | /* The record is already free: */ |
4289 | 1028 | if (!XT_PREAD_RR_FILE(ot->ot_row_file, xt_row_id_to_row_offset(tab, row_id), sizeof(XTTabRowRefDRec), sizeof(XTTabRowRefDRec), (xtWord1 *) &row_buf, NULL, &self->st_statistics.st_rec, self)) | 1028 | if (XT_REC_IS_FREE(rec_head.tr_rec_type_1)) |
4290 | 1029 | xt_throw(self); | 1029 | goto free_done; |
4291 | 1030 | link_rec_id = XT_GET_DISK_4(row_buf.rr_ref_id_4); | 1030 | row_id = XT_GET_DISK_4(rec_head.tr_row_id_4); |
4292 | 1031 | prev_link_rec_id = 0; | 1031 | |
4293 | 1032 | while (link_rec_id) { | 1032 | /* Search the row for this record: */ |
4294 | 1033 | if (!XT_PREAD_RR_FILE(ot->ot_rec_file, xt_rec_id_to_rec_offset(tab, link_rec_id), sizeof(XTTabRecHeadDRec), 0, (xtWord1 *) &rec_head, &red_size, &self->st_statistics.st_rec, self)) { | 1033 | if (!XT_PREAD_RR_FILE(ot->ot_row_file, xt_row_id_to_row_offset(tab, row_id), sizeof(XTTabRowRefDRec), sizeof(XTTabRowRefDRec), (xtWord1 *) &row_buf, NULL, &self->st_statistics.st_rec, self)) |
4295 | 1034 | xt_log_and_clear_exception(self); | 1034 | xt_throw(self); |
4296 | 1035 | break; | 1035 | link_rec_id = XT_GET_DISK_4(row_buf.rr_ref_id_4); |
4297 | 1036 | } | 1036 | prev_link_rec_id = 0; |
4298 | 1037 | if (red_size < sizeof(XTTabRecHeadDRec)) | 1037 | while (link_rec_id) { |
4299 | 1038 | break; | 1038 | if (!XT_PREAD_RR_FILE(ot->ot_rec_file, xt_rec_id_to_rec_offset(tab, link_rec_id), sizeof(XTTabRecHeadDRec), 0, (xtWord1 *) &rec_head, &red_size, &self->st_statistics.st_rec, self)) { |
4300 | 1039 | if (link_rec_id == rec_id) | 1039 | xt_log_and_clear_exception(self); |
4301 | 1040 | break; | 1040 | break; |
4302 | 1041 | if (XT_GET_DISK_4(rec_head.tr_row_id_4) != row_id) | 1041 | } |
4303 | 1042 | break; | 1042 | if (red_size < sizeof(XTTabRecHeadDRec)) |
4304 | 1043 | switch (rec_head.tr_rec_type_1 & XT_TAB_STATUS_MASK) { | 1043 | break; |
4305 | 1044 | case XT_TAB_STATUS_FREED: | 1044 | if (link_rec_id == rec_id) |
4306 | 1045 | break; | 1045 | break; |
4307 | 1046 | case XT_TAB_STATUS_DELETE: | 1046 | if (XT_GET_DISK_4(rec_head.tr_row_id_4) != row_id) |
4308 | 1047 | case XT_TAB_STATUS_FIXED: | 1047 | break; |
4309 | 1048 | case XT_TAB_STATUS_VARIABLE: | 1048 | switch (rec_head.tr_rec_type_1 & XT_TAB_STATUS_MASK) { |
4310 | 1049 | case XT_TAB_STATUS_EXT_DLOG: | 1049 | case XT_TAB_STATUS_FREED: |
4311 | 1050 | break; | 1050 | break; |
4312 | 1051 | default: | 1051 | case XT_TAB_STATUS_DELETE: |
4313 | 1052 | ASSERT(FALSE); | 1052 | case XT_TAB_STATUS_FIXED: |
4314 | 1053 | goto exit_loop; | 1053 | case XT_TAB_STATUS_VARIABLE: |
4315 | 1054 | } | 1054 | case XT_TAB_STATUS_EXT_DLOG: |
4316 | 1055 | if (rec_head.tr_rec_type_1 & ~(XT_TAB_STATUS_CLEANED_BIT | XT_TAB_STATUS_MASK)) { | 1055 | break; |
4317 | 1056 | ASSERT(FALSE); | 1056 | default: |
4318 | 1057 | break; | 1057 | ASSERT(FALSE); |
4319 | 1058 | } | 1058 | goto exit_loop; |
4320 | 1059 | prev_link_rec_id = link_rec_id; | 1059 | } |
4321 | 1060 | link_rec_id = XT_GET_DISK_4(rec_head.tr_prev_rec_id_4); | 1060 | if (rec_head.tr_rec_type_1 & ~(XT_TAB_STATUS_CLEANED_BIT | XT_TAB_STATUS_MASK)) { |
4322 | 1061 | } | 1061 | ASSERT(FALSE); |
4323 | 1062 | 1062 | break; | |
4324 | 1063 | exit_loop: | 1063 | } |
4325 | 1064 | if (link_rec_id == rec_id) { | 1064 | prev_link_rec_id = link_rec_id; |
4326 | 1065 | /* The record was found on the row list, remove it: */ | 1065 | link_rec_id = XT_GET_DISK_4(rec_head.tr_prev_rec_id_4); |
4327 | 1066 | if (prev_link_rec_id) { | 1066 | } |
4328 | 1067 | /* We write the previous variation pointer from position 'link_rec_id' into | 1067 | |
4329 | 1068 | * variation pointer of the 'prev_link_rec_id' record. This unlinks 'link_rec_id'! | 1068 | exit_loop: |
4330 | 1069 | */ | 1069 | if (link_rec_id == rec_id) { |
4331 | 1070 | if (!XT_PWRITE_RR_FILE(ot->ot_rec_file, xt_rec_id_to_rec_offset(tab, prev_link_rec_id) + offsetof(XTTabRecHeadDRec, tr_prev_rec_id_4), XT_RECORD_ID_SIZE, (xtWord1 *) &rec_head.tr_prev_rec_id_4, &ot->ot_thread->st_statistics.st_rec, ot->ot_thread)) | 1070 | /* The record was found on the row list, remove it: */ |
4332 | 1071 | xt_throw(self); | 1071 | if (prev_link_rec_id) { |
4333 | 1072 | tab->tab_bytes_to_flush += XT_RECORD_ID_SIZE; | 1072 | /* We write the previous variation pointer from position 'link_rec_id' into |
4334 | 1073 | } | 1073 | * variation pointer of the 'prev_link_rec_id' record. This unlinks 'link_rec_id'! |
4335 | 1074 | else { | 1074 | */ |
4336 | 1075 | /* The record is at the front of the row list: */ | 1075 | if (!XT_PWRITE_RR_FILE(ot->ot_rec_file, xt_rec_id_to_rec_offset(tab, prev_link_rec_id) + offsetof(XTTabRecHeadDRec, tr_prev_rec_id_4), XT_RECORD_ID_SIZE, (xtWord1 *) &rec_head.tr_prev_rec_id_4, &ot->ot_thread->st_statistics.st_rec, ot->ot_thread)) |
4337 | 1076 | xtRefID ref_id = XT_GET_DISK_4(rec_head.tr_prev_rec_id_4); | 1076 | xt_throw(self); |
4338 | 1077 | XT_SET_DISK_4(row_buf.rr_ref_id_4, ref_id); | 1077 | tab->tab_bytes_to_flush += XT_RECORD_ID_SIZE; |
4339 | 1078 | if (!XT_PWRITE_RR_FILE(ot->ot_row_file, xt_row_id_to_row_offset(tab, row_id), sizeof(XTTabRowRefDRec), (xtWord1 *) &row_buf, &ot->ot_thread->st_statistics.st_rec, ot->ot_thread)) | 1078 | } |
4340 | 1079 | xt_throw(self); | 1079 | else { |
4341 | 1080 | tab->tab_bytes_to_flush += sizeof(XTTabRowRefDRec); | 1080 | /* The record is at the front of the row list: */ |
4342 | 1081 | } | 1081 | xtRefID ref_id = XT_GET_DISK_4(rec_head.tr_prev_rec_id_4); |
4343 | 1082 | } | 1082 | XT_SET_DISK_4(row_buf.rr_ref_id_4, ref_id); |
4344 | 1083 | 1083 | if (!XT_PWRITE_RR_FILE(ot->ot_row_file, xt_row_id_to_row_offset(tab, row_id), sizeof(XTTabRowRefDRec), (xtWord1 *) &row_buf, &ot->ot_thread->st_statistics.st_rec, ot->ot_thread)) | |
4345 | 1084 | /* Now we free the record, by placing it at the front of | 1084 | xt_throw(self); |
4346 | 1085 | * the free list: | 1085 | tab->tab_bytes_to_flush += sizeof(XTTabRowRefDRec); |
4347 | 1086 | */ | 1086 | } |
4348 | 1087 | XT_SET_DISK_4(free_data->rf_next_rec_id_4, tab->tab_head_rec_free_id); | 1087 | } |
4349 | 1088 | } | 1088 | |
4350 | 1089 | tab->tab_head_rec_free_id = rec_id; | 1089 | /* Now we free the record, by placing it at the front of |
4351 | 1090 | tab->tab_head_rec_fnum++; | 1090 | * the free list: |
4352 | 1091 | if (!XT_PWRITE_RR_FILE(ot->ot_rec_file, xt_rec_id_to_rec_offset(tab, rec_id), sizeof(XTTabRecFreeDRec), (xtWord1 *) free_data, &ot->ot_thread->st_statistics.st_rec, ot->ot_thread)) | 1091 | */ |
4353 | 1092 | xt_throw(self); | 1092 | XT_SET_DISK_4(free_data->rf_next_rec_id_4, tab->tab_head_rec_free_id); |
4354 | 1093 | tab->tab_bytes_to_flush += sizeof(XTTabRecFreeDRec); | 1093 | } |
4355 | 1094 | tab->tab_flush_pending = TRUE; | 1094 | tab->tab_head_rec_free_id = rec_id; |
4356 | 1095 | free_done: | 1095 | tab->tab_head_rec_fnum++; |
4357 | 1096 | break; | 1096 | if (!XT_PWRITE_RR_FILE(ot->ot_rec_file, xt_rec_id_to_rec_offset(tab, rec_id), sizeof(XTTabRecFreeDRec), (xtWord1 *) free_data, &ot->ot_thread->st_statistics.st_rec, ot->ot_thread)) |
4358 | 1097 | case XT_LOG_ENT_REC_MOVED: | 1097 | xt_throw(self); |
4359 | 1098 | len = 8; | 1098 | tab->tab_bytes_to_flush += sizeof(XTTabRecFreeDRec); |
4360 | 1099 | rec_id = XT_GET_DISK_4(record->xw.xw_rec_id_4); | 1099 | tab->tab_flush_pending = TRUE; |
4361 | 1100 | if (!XT_PWRITE_RR_FILE(ot->ot_rec_file, xt_rec_id_to_rec_offset(tab, rec_id) + offsetof(XTTabRecExtDRec, re_log_id_2), len, (xtWord1 *) &record->xw.xw_rec_type_1, &ot->ot_thread->st_statistics.st_rec, ot->ot_thread)) | 1100 | free_done: |
4362 | 1101 | xt_throw(self); | 1101 | break; |
4363 | 1102 | tab->tab_bytes_to_flush += len; | 1102 | case XT_LOG_ENT_REC_MOVED: |
4364 | 1103 | tab->tab_flush_pending = TRUE; | 1103 | len = 8; |
4365 | 1104 | break; | 1104 | rec_id = XT_GET_DISK_4(record->xw.xw_rec_id_4); |
4366 | 1105 | case XT_LOG_ENT_REC_CLEANED: | 1105 | if (!XT_PWRITE_RR_FILE(ot->ot_rec_file, xt_rec_id_to_rec_offset(tab, rec_id) + offsetof(XTTabRecExtDRec, re_log_id_2), len, (xtWord1 *) &record->xw.xw_rec_type_1, &ot->ot_thread->st_statistics.st_rec, ot->ot_thread)) |
4367 | 1106 | len = offsetof(XTTabRecHeadDRec, tr_prev_rec_id_4) + XT_RECORD_ID_SIZE; | 1106 | xt_throw(self); |
4368 | 1107 | goto get_rec_offset; | 1107 | tab->tab_bytes_to_flush += len; |
4369 | 1108 | case XT_LOG_ENT_REC_CLEANED_1: | 1108 | tab->tab_flush_pending = TRUE; |
4370 | 1109 | len = 1; | 1109 | break; |
4371 | 1110 | goto get_rec_offset; | 1110 | case XT_LOG_ENT_REC_CLEANED: |
4372 | 1111 | case XT_LOG_ENT_REC_UNLINKED: | 1111 | len = offsetof(XTTabRecHeadDRec, tr_prev_rec_id_4) + XT_RECORD_ID_SIZE; |
4373 | 1112 | if (!in_sequence) { | 1112 | goto get_rec_offset; |
4374 | 1113 | /* Unlink the record. | 1113 | case XT_LOG_ENT_REC_CLEANED_1: |
4375 | 1114 | * This is done when the record is freed. | 1114 | len = 1; |
4376 | 1115 | */ | 1115 | goto get_rec_offset; |
4377 | 1116 | break; | 1116 | case XT_LOG_ENT_REC_UNLINKED: |
4378 | 1117 | } | 1117 | if (!in_sequence) { |
4379 | 1118 | len = offsetof(XTTabRecHeadDRec, tr_prev_rec_id_4) + XT_RECORD_ID_SIZE; | 1118 | /* Unlink the record. |
4380 | 1119 | get_rec_offset: | 1119 | * This is done when the record is freed. |
4381 | 1120 | rec_id = XT_GET_DISK_4(record->xw.xw_rec_id_4); | 1120 | */ |
4382 | 1121 | if (!XT_PWRITE_RR_FILE(ot->ot_rec_file, xt_rec_id_to_rec_offset(tab, rec_id), len, (xtWord1 *) &record->xw.xw_rec_type_1, &ot->ot_thread->st_statistics.st_rec, ot->ot_thread)) | 1121 | break; |
4383 | 1122 | xt_throw(self); | 1122 | } |
4384 | 1123 | tab->tab_bytes_to_flush += len; | 1123 | len = offsetof(XTTabRecHeadDRec, tr_prev_rec_id_4) + XT_RECORD_ID_SIZE; |
4385 | 1124 | tab->tab_flush_pending = TRUE; | 1124 | get_rec_offset: |
4386 | 1125 | break; | 1125 | rec_id = XT_GET_DISK_4(record->xw.xw_rec_id_4); |
4387 | 1126 | case XT_LOG_ENT_ROW_NEW: | 1126 | if (!XT_PWRITE_RR_FILE(ot->ot_rec_file, xt_rec_id_to_rec_offset(tab, rec_id), len, (xtWord1 *) &record->xw.xw_rec_type_1, &ot->ot_thread->st_statistics.st_rec, ot->ot_thread)) |
4388 | 1127 | len = offsetof(XTactRowAddedEntryDRec, xa_free_list_4); | 1127 | xt_throw(self); |
4389 | 1128 | row_id = XT_GET_DISK_4(record->xa.xa_row_id_4); | 1128 | tab->tab_bytes_to_flush += len; |
4390 | 1129 | if (!in_sequence) { | 1129 | tab->tab_flush_pending = TRUE; |
4391 | 1130 | /* A row was allocated from the EOF. Because operations are missing. | 1130 | break; |
4392 | 1131 | * The blocks between the current EOF and the new EOF need to be | 1131 | case XT_LOG_ENT_ROW_NEW: |
4393 | 1132 | * place on the free list! | 1132 | len = offsetof(XTactRowAddedEntryDRec, xa_free_list_4); |
4394 | 1133 | */ | 1133 | row_id = XT_GET_DISK_4(record->xa.xa_row_id_4); |
4395 | 1134 | while (tab->tab_head_row_eof_id < row_id) { | 1134 | if (!in_sequence) { |
4396 | 1135 | XT_SET_DISK_4(row_buf.rr_ref_id_4, tab->tab_head_row_free_id); | 1135 | /* A row was allocated from the EOF. Because operations are missing. |
4397 | 1136 | if (!XT_PWRITE_RR_FILE(ot->ot_row_file, xt_row_id_to_row_offset(tab, tab->tab_head_row_eof_id), sizeof(XTTabRowRefDRec), (xtWord1 *) &row_buf, &ot->ot_thread->st_statistics.st_rec, ot->ot_thread)) | 1136 | * The blocks between the current EOF and the new EOF need to be |
4398 | 1137 | xt_throw(self); | 1137 | * place on the free list! |
4399 | 1138 | tab->tab_bytes_to_flush += sizeof(XTTabRowRefDRec); | 1138 | */ |
4400 | 1139 | tab->tab_head_row_free_id = tab->tab_head_row_eof_id; | 1139 | while (tab->tab_head_row_eof_id < row_id) { |
4401 | 1140 | tab->tab_head_row_eof_id++; | 1140 | XT_SET_DISK_4(row_buf.rr_ref_id_4, tab->tab_head_row_free_id); |
4402 | 1141 | } | 1141 | if (!XT_PWRITE_RR_FILE(ot->ot_row_file, xt_row_id_to_row_offset(tab, tab->tab_head_row_eof_id), sizeof(XTTabRowRefDRec), (xtWord1 *) &row_buf, &ot->ot_thread->st_statistics.st_rec, ot->ot_thread)) |
4403 | 1142 | } | 1142 | xt_throw(self); |
4404 | 1143 | if (tab->tab_head_row_eof_id < row_id + 1) | 1143 | tab->tab_bytes_to_flush += sizeof(XTTabRowRefDRec); |
4405 | 1144 | tab->tab_head_row_eof_id = row_id + 1; | 1144 | tab->tab_head_row_free_id = tab->tab_head_row_eof_id; |
4406 | 1145 | tab->tab_flush_pending = TRUE; | 1145 | tab->tab_head_row_eof_id++; |
4407 | 1146 | break; | 1146 | } |
4408 | 1147 | case XT_LOG_ENT_ROW_NEW_FL: | 1147 | } |
4409 | 1148 | len = sizeof(XTactRowAddedEntryDRec); | 1148 | if (tab->tab_head_row_eof_id < row_id + 1) |
4410 | 1149 | row_id = XT_GET_DISK_4(record->xa.xa_row_id_4); | 1149 | tab->tab_head_row_eof_id = row_id + 1; |
4411 | 1150 | free_ref_id = XT_GET_DISK_4(record->xa.xa_free_list_4); | 1150 | tab->tab_flush_pending = TRUE; |
4412 | 1151 | if (!in_sequence) { | 1151 | break; |
4413 | 1152 | size_t red_size; | 1152 | case XT_LOG_ENT_ROW_NEW_FL: |
4414 | 1153 | /* The record was taken from the free list. | 1153 | len = sizeof(XTactRowAddedEntryDRec); |
4415 | 1154 | * If the operations were in sequence, then this would be | 1154 | row_id = XT_GET_DISK_4(record->xa.xa_row_id_4); |
4416 | 1155 | * the front of the free list now. | 1155 | free_ref_id = XT_GET_DISK_4(record->xa.xa_free_list_4); |
4417 | 1156 | * However, because operations are missing, it may no | 1156 | if (!in_sequence) { |
4418 | 1157 | * longer be the front of the free list! | 1157 | size_t red_size; |
4419 | 1158 | * Search and remove: | 1158 | /* The record was taken from the free list. |
4420 | 1159 | */ | 1159 | * If the operations were in sequence, then this would be |
4421 | 1160 | link_rec_id = tab->tab_head_row_free_id; | 1160 | * the front of the free list now. |
4422 | 1161 | prev_link_rec_id = 0; | 1161 | * However, because operations are missing, it may no |
4423 | 1162 | while (link_rec_id) { | 1162 | * longer be the front of the free list! |
4424 | 1163 | if (!XT_PREAD_RR_FILE(ot->ot_row_file, xt_row_id_to_row_offset(tab, link_rec_id), sizeof(XTTabRowRefDRec), 0, (xtWord1 *) &row_buf, &red_size, &self->st_statistics.st_rec, self)) { | 1163 | * Search and remove: |
4425 | 1164 | xt_log_and_clear_exception(self); | 1164 | */ |
4426 | 1165 | break; | 1165 | link_rec_id = tab->tab_head_row_free_id; |
4427 | 1166 | } | 1166 | prev_link_rec_id = 0; |
4428 | 1167 | if (red_size < sizeof(XTTabRowRefDRec)) | 1167 | while (link_rec_id) { |
4429 | 1168 | break; | 1168 | if (!XT_PREAD_RR_FILE(ot->ot_row_file, xt_row_id_to_row_offset(tab, link_rec_id), sizeof(XTTabRowRefDRec), 0, (xtWord1 *) &row_buf, &red_size, &self->st_statistics.st_rec, self)) { |
4430 | 1169 | if (link_rec_id == row_id) | 1169 | xt_log_and_clear_exception(self); |
4431 | 1170 | break; | 1170 | break; |
4432 | 1171 | prev_link_rec_id = link_rec_id; | 1171 | } |
4433 | 1172 | link_rec_id = XT_GET_DISK_4(row_buf.rr_ref_id_4); | 1172 | if (red_size < sizeof(XTTabRowRefDRec)) |
4434 | 1173 | } | 1173 | break; |
4435 | 1174 | if (link_rec_id == row_id) { | 1174 | if (link_rec_id == row_id) |
4436 | 1175 | /* The block was found on the free list, remove it: */ | 1175 | break; |
4437 | 1176 | if (prev_link_rec_id) { | 1176 | prev_link_rec_id = link_rec_id; |
4438 | 1177 | /* We write the record from position 'link_rec_id' into | 1177 | link_rec_id = XT_GET_DISK_4(row_buf.rr_ref_id_4); |
4439 | 1178 | * position 'prev_link_rec_id'. This unlinks 'link_rec_id'! | 1178 | } |
4440 | 1179 | */ | 1179 | if (link_rec_id == row_id) { |
4441 | 1180 | if (!XT_PWRITE_RR_FILE(ot->ot_row_file, xt_row_id_to_row_offset(tab, prev_link_rec_id), sizeof(XTTabRowRefDRec), (xtWord1 *) &row_buf, &ot->ot_thread->st_statistics.st_rec, ot->ot_thread)) | 1180 | /* The block was found on the free list, remove it: */ |
4442 | 1181 | xt_throw(self); | 1181 | if (prev_link_rec_id) { |
4443 | 1182 | tab->tab_bytes_to_flush += sizeof(XTTabRowRefDRec); | 1182 | /* We write the record from position 'link_rec_id' into |
4444 | 1183 | free_ref_id = tab->tab_head_row_free_id; | 1183 | * position 'prev_link_rec_id'. This unlinks 'link_rec_id'! |
4445 | 1184 | } | 1184 | */ |
4446 | 1185 | else | 1185 | if (!XT_PWRITE_RR_FILE(ot->ot_row_file, xt_row_id_to_row_offset(tab, prev_link_rec_id), sizeof(XTTabRowRefDRec), (xtWord1 *) &row_buf, &ot->ot_thread->st_statistics.st_rec, ot->ot_thread)) |
4447 | 1186 | /* The block is at the front of the free list: */ | 1186 | xt_throw(self); |
4448 | 1187 | free_ref_id = XT_GET_DISK_4(row_buf.rr_ref_id_4); | 1187 | tab->tab_bytes_to_flush += sizeof(XTTabRowRefDRec); |
4449 | 1188 | } | 1188 | free_ref_id = tab->tab_head_row_free_id; |
4450 | 1189 | else { | 1189 | } |
4451 | 1190 | /* Not found? */ | 1190 | else |
4452 | 1191 | if (tab->tab_head_row_eof_id < row_id + 1) | 1191 | /* The block is at the front of the free list: */ |
4453 | 1192 | tab->tab_head_row_eof_id = row_id + 1; | 1192 | free_ref_id = XT_GET_DISK_4(row_buf.rr_ref_id_4); |
4454 | 1193 | break; | 1193 | } |
4455 | 1194 | } | 1194 | else { |
4456 | 1195 | 1195 | /* Not found? */ | |
4457 | 1196 | } | 1196 | if (tab->tab_head_row_eof_id < row_id + 1) |
4458 | 1197 | if (tab->tab_head_row_eof_id < row_id + 1) | 1197 | tab->tab_head_row_eof_id = row_id + 1; |
4459 | 1198 | tab->tab_head_row_eof_id = row_id + 1; | 1198 | break; |
4460 | 1199 | tab->tab_head_row_free_id = free_ref_id; | 1199 | } |
4461 | 1200 | tab->tab_head_row_fnum--; | 1200 | |
4462 | 1201 | tab->tab_flush_pending = TRUE; | 1201 | } |
4463 | 1202 | break; | 1202 | if (tab->tab_head_row_eof_id < row_id + 1) |
4464 | 1203 | case XT_LOG_ENT_ROW_FREED: | 1203 | tab->tab_head_row_eof_id = row_id + 1; |
4465 | 1204 | row_id = XT_GET_DISK_4(record->wr.wr_row_id_4); | 1204 | tab->tab_head_row_free_id = free_ref_id; |
4466 | 1205 | if (!in_sequence) { | 1205 | tab->tab_head_row_fnum--; |
4467 | 1206 | /* Free the row. | 1206 | tab->tab_flush_pending = TRUE; |
4468 | 1207 | * Since this operation is being performed out of sequence, we | 1207 | break; |
4469 | 1208 | * must assume that some other free and allocation operations | 1208 | case XT_LOG_ENT_ROW_FREED: |
4470 | 1209 | * must be missing. | 1209 | row_id = XT_GET_DISK_4(record->wr.wr_row_id_4); |
4471 | 1210 | * For this reason, we add the row to the front of the | 1210 | if (!in_sequence) { |
4472 | 1211 | * existing free list. | 1211 | /* Free the row. |
4473 | 1212 | */ | 1212 | * Since this operation is being performed out of sequence, we |
4474 | 1213 | XT_SET_DISK_4(record->wr.wr_ref_id_4, tab->tab_head_row_free_id); | 1213 | * must assume that some other free and allocation operations |
4475 | 1214 | } | 1214 | * must be missing. |
4476 | 1215 | tab->tab_head_row_free_id = row_id; | 1215 | * For this reason, we add the row to the front of the |
4477 | 1216 | tab->tab_head_row_fnum++; | 1216 | * existing free list. |
4478 | 1217 | goto write_row_data; | 1217 | */ |
4479 | 1218 | case XT_LOG_ENT_ROW_ADD_REC: | 1218 | XT_SET_DISK_4(record->wr.wr_ref_id_4, tab->tab_head_row_free_id); |
4480 | 1219 | row_id = XT_GET_DISK_4(record->wr.wr_row_id_4); | 1219 | } |
4481 | 1220 | if (!in_sequence) { | 1220 | tab->tab_head_row_free_id = row_id; |
4482 | 1221 | if (!XT_PREAD_RR_FILE(ot->ot_row_file, xt_row_id_to_row_offset(tab, row_id), sizeof(XTTabRowRefDRec), 0, (xtWord1 *) &row_buf, &tfer, &self->st_statistics.st_rec, self)) | 1221 | tab->tab_head_row_fnum++; |
4483 | 1222 | xt_throw(self); | 1222 | goto write_row_data; |
4484 | 1223 | if (tfer == sizeof(XTTabRowRefDRec)) { | 1223 | case XT_LOG_ENT_ROW_ADD_REC: |
4485 | 1224 | /* Add a record to the front of the row. | 1224 | row_id = XT_GET_DISK_4(record->wr.wr_row_id_4); |
4486 | 1225 | * This is easy, but we have to make sure that the next | 1225 | if (!in_sequence) { |
4487 | 1226 | * pointer in the record is correct. | 1226 | if (!XT_PREAD_RR_FILE(ot->ot_row_file, xt_row_id_to_row_offset(tab, row_id), sizeof(XTTabRowRefDRec), 0, (xtWord1 *) &row_buf, &tfer, &self->st_statistics.st_rec, self)) |
4488 | 1227 | */ | 1227 | xt_throw(self); |
4489 | 1228 | rec_id = XT_GET_DISK_4(record->wr.wr_ref_id_4); | 1228 | if (tfer == sizeof(XTTabRowRefDRec)) { |
4490 | 1229 | if (!XT_PREAD_RR_FILE(ot->ot_rec_file, xt_rec_id_to_rec_offset(tab, rec_id), sizeof(XTTabRecHeadDRec), 0, (xtWord1 *) &rec_head, &tfer, &self->st_statistics.st_rec, self)) | 1229 | /* Add a record to the front of the row. |
4491 | 1230 | xt_throw(self); | 1230 | * This is easy, but we have to make sure that the next |
4492 | 1231 | if (tfer == sizeof(XTTabRecHeadDRec) && XT_GET_DISK_4(rec_head.tr_row_id_4) == row_id) { | 1231 | * pointer in the record is correct. |
4493 | 1232 | /* This is now the correct next pointer: */ | 1232 | */ |
4494 | 1233 | xtRecordID next_ref_id = XT_GET_DISK_4(row_buf.rr_ref_id_4); | 1233 | rec_id = XT_GET_DISK_4(record->wr.wr_ref_id_4); |
4495 | 1234 | if (XT_GET_DISK_4(rec_head.tr_prev_rec_id_4) != next_ref_id && | 1234 | if (!XT_PREAD_RR_FILE(ot->ot_rec_file, xt_rec_id_to_rec_offset(tab, rec_id), sizeof(XTTabRecHeadDRec), 0, (xtWord1 *) &rec_head, &tfer, &self->st_statistics.st_rec, self)) |
4496 | 1235 | rec_id != next_ref_id) { | 1235 | xt_throw(self); |
4497 | 1236 | XT_SET_DISK_4(rec_head.tr_prev_rec_id_4, next_ref_id); | 1236 | if (tfer == sizeof(XTTabRecHeadDRec) && XT_GET_DISK_4(rec_head.tr_row_id_4) == row_id) { |
4498 | 1237 | if (!XT_PWRITE_RR_FILE(ot->ot_rec_file, xt_rec_id_to_rec_offset(tab, rec_id), sizeof(XTTabRecHeadDRec), (xtWord1 *) &rec_head, &ot->ot_thread->st_statistics.st_rec, ot->ot_thread)) | 1237 | /* This is now the correct next pointer: */ |
4499 | 1238 | xt_throw(self); | 1238 | xtRecordID next_ref_id = XT_GET_DISK_4(row_buf.rr_ref_id_4); |
4500 | 1239 | tab->tab_bytes_to_flush += sizeof(XTTabRecHeadDRec); | 1239 | if (XT_GET_DISK_4(rec_head.tr_prev_rec_id_4) != next_ref_id && |
4501 | 1240 | } | 1240 | rec_id != next_ref_id) { |
4502 | 1241 | } | 1241 | XT_SET_DISK_4(rec_head.tr_prev_rec_id_4, next_ref_id); |
4503 | 1242 | } | 1242 | if (!XT_PWRITE_RR_FILE(ot->ot_rec_file, xt_rec_id_to_rec_offset(tab, rec_id), sizeof(XTTabRecHeadDRec), (xtWord1 *) &rec_head, &ot->ot_thread->st_statistics.st_rec, ot->ot_thread)) |
4504 | 1243 | 1243 | xt_throw(self); | |
4505 | 1244 | } | 1244 | tab->tab_bytes_to_flush += sizeof(XTTabRecHeadDRec); |
4506 | 1245 | goto write_row_data; | 1245 | } |
4507 | 1246 | case XT_LOG_ENT_ROW_SET: | 1246 | } |
4508 | 1247 | if (!in_sequence) | 1247 | } |
4509 | 1248 | /* This operation is ignored when out of sequence! | 1248 | |
4510 | 1249 | * The operation is used to remove a record from a row. | 1249 | } |
4511 | 1250 | * This is done automatically when the record is freed. | 1250 | goto write_row_data; |
4512 | 1251 | */ | 1251 | case XT_LOG_ENT_ROW_SET: |
4513 | 1252 | break; | 1252 | if (!in_sequence) |
4514 | 1253 | row_id = XT_GET_DISK_4(record->wr.wr_row_id_4); | 1253 | /* This operation is ignored when out of sequence! |
4515 | 1254 | write_row_data: | 1254 | * The operation is used to remove a record from a row. |
4516 | 1255 | ASSERT_NS(XT_GET_DISK_4(record->wr.wr_ref_id_4) < tab->tab_head_rec_eof_id); | 1255 | * This is done automatically when the record is freed. |
4517 | 1256 | if (!XT_PWRITE_RR_FILE(ot->ot_row_file, xt_row_id_to_row_offset(tab, row_id), sizeof(XTTabRowRefDRec), (xtWord1 *) &record->wr.wr_ref_id_4, &ot->ot_thread->st_statistics.st_rec, self)) | 1256 | */ |
4518 | 1257 | xt_throw(self); | 1257 | break; |
4519 | 1258 | tab->tab_bytes_to_flush += sizeof(XTTabRowRefDRec); | 1258 | row_id = XT_GET_DISK_4(record->wr.wr_row_id_4); |
4520 | 1259 | if (tab->tab_head_row_eof_id < row_id + 1) | 1259 | write_row_data: |
4521 | 1260 | tab->tab_head_row_eof_id = row_id + 1; | 1260 | ASSERT_NS(XT_GET_DISK_4(record->wr.wr_ref_id_4) < tab->tab_head_rec_eof_id); |
4522 | 1261 | tab->tab_flush_pending = TRUE; | 1261 | if (!XT_PWRITE_RR_FILE(ot->ot_row_file, xt_row_id_to_row_offset(tab, row_id), sizeof(XTTabRowRefDRec), (xtWord1 *) &record->wr.wr_ref_id_4, &ot->ot_thread->st_statistics.st_rec, self)) |
4523 | 1262 | break; | 1262 | xt_throw(self); |
4524 | 1263 | case XT_LOG_ENT_NO_OP: | 1263 | tab->tab_bytes_to_flush += sizeof(XTTabRowRefDRec); |
4525 | 1264 | case XT_LOG_ENT_END_OF_LOG: | 1264 | if (tab->tab_head_row_eof_id < row_id + 1) |
4526 | 1265 | break; | 1265 | tab->tab_head_row_eof_id = row_id + 1; |
4527 | 1266 | } | 1266 | tab->tab_flush_pending = TRUE; |
4528 | 1267 | } | 1267 | break; |
4529 | 1268 | 1268 | case XT_LOG_ENT_NO_OP: | |
4530 | 1269 | /* | 1269 | case XT_LOG_ENT_END_OF_LOG: |
4531 | 1270 | * Apply all operations that have been buffered | 1270 | break; |
4532 | 1271 | * for a particular table. | 1271 | } |
4533 | 1272 | * Operations are buffered if they are | 1272 | } |
4534 | 1273 | * read from the log out of sequence. | 1273 | |
4535 | 1274 | * | 1274 | /* |
4536 | 1275 | * In this case we buffer, and wait for the | 1275 | * Apply all operations that have been buffered |
4537 | 1276 | * out of sequence operations to arrive. | 1276 | * for a particular table. |
4538 | 1277 | * | 1277 | * Operations are buffered if they are |
4539 | 1278 | * When the server is running, this will always be | 1278 | * read from the log out of sequence. |
4540 | 1279 | * the case. A delay occurs while a transaction | 1279 | * |
4541 | 1280 | * fills its private log buffer. | 1280 | * In this case we buffer, and wait for the |
4542 | 1281 | */ | 1281 | * out of sequence operations to arrive. |
4543 | 1282 | static void xres_apply_operations(XTThreadPtr self, XTWriterStatePtr ws, xtBool in_sequence) | 1282 | * |
4544 | 1283 | { | 1283 | * When the server is running, this will always be |
4545 | 1284 | XTTableHPtr tab = ws->ws_ot->ot_table; | 1284 | * the case. A delay occurs while a transaction |
4546 | 1285 | u_int i = 0; | 1285 | * fills its private log buffer. |
4547 | 1286 | XTOperationPtr op; | 1286 | */ |
4548 | 1287 | xtBool check_index; | 1287 | static void xres_apply_operations(XTThreadPtr self, XTWriterStatePtr ws, xtBool in_sequence) |
4549 | 1288 | 1288 | { | |
4550 | 1289 | // XTDatabaseHPtr db, XTOpenTablePtr ot, XTXactSeqReadPtr sr, XTDataBufferPtr databuf | 1289 | XTTableHPtr tab = ws->ws_ot->ot_table; |
4551 | 1290 | xt_sl_lock(self, tab->tab_op_list); | 1290 | u_int i = 0; |
4552 | 1291 | for (;;) { | 1291 | XTOperationPtr op; |
4553 | 1292 | op = (XTOperationPtr) xt_sl_item_at(tab->tab_op_list, i); | 1292 | xtBool check_index; |
4554 | 1293 | if (!op) | 1293 | |
4555 | 1294 | break; | 1294 | // XTDatabaseHPtr db, XTOpenTablePtr ot, XTXactSeqReadPtr sr, XTDataBufferPtr databuf |
4556 | 1295 | if (in_sequence && tab->tab_head_op_seq+1 != op->or_op_seq) | 1295 | xt_sl_lock(self, tab->tab_op_list); |
4557 | 1296 | break; | 1296 | for (;;) { |
4558 | 1297 | xt_db_set_size(self, &ws->ws_databuf, (size_t) op->or_op_len); | 1297 | op = (XTOperationPtr) xt_sl_item_at(tab->tab_op_list, i); |
4559 | 1298 | if (!ws->ws_db->db_xlog.xlog_rnd_read(&ws->ws_seqread, op->or_log_id, op->or_log_offset, (size_t) op->or_op_len, ws->ws_databuf.db_data, NULL, self)) | 1298 | if (!op) |
4560 | 1299 | xt_throw(self); | 1299 | break; |
4561 | 1300 | check_index = ws->ws_in_recover && xt_comp_log_pos(op->or_log_id, op->or_log_offset, ws->ws_ind_rec_log_id, ws->ws_ind_rec_log_offset) >= 0; | 1300 | if (in_sequence && tab->tab_head_op_seq+1 != op->or_op_seq) |
4562 | 1301 | xres_apply_change(self, ws->ws_ot, (XTXactLogBufferDPtr) ws->ws_databuf.db_data, in_sequence, check_index, &ws->ws_rec_buf); | 1301 | break; |
4563 | 1302 | tab->tab_head_op_seq = op->or_op_seq; | 1302 | xt_db_set_size(self, &ws->ws_databuf, (size_t) op->or_op_len); |
4564 | 1303 | if (tab->tab_wr_wake_freeer) { | 1303 | if (!ws->ws_db->db_xlog.xlog_rnd_read(&ws->ws_seqread, op->or_log_id, op->or_log_offset, (size_t) op->or_op_len, ws->ws_databuf.db_data, NULL, self)) |
4565 | 1304 | if (!XTTableSeq::xt_op_is_before(tab->tab_head_op_seq, tab->tab_wake_freeer_op)) | 1304 | xt_throw(self); |
4566 | 1305 | xt_wr_wake_freeer(self); | 1305 | check_index = ws->ws_in_recover && xt_comp_log_pos(op->or_log_id, op->or_log_offset, ws->ws_ind_rec_log_id, ws->ws_ind_rec_log_offset) >= 0; |
4567 | 1306 | } | 1306 | xres_apply_change(self, ws->ws_ot, (XTXactLogBufferDPtr) ws->ws_databuf.db_data, in_sequence, check_index, &ws->ws_rec_buf); |
4568 | 1307 | i++; | 1307 | tab->tab_head_op_seq = op->or_op_seq; |
4569 | 1308 | } | 1308 | if (tab->tab_wr_wake_freeer) { |
4570 | 1309 | xt_sl_remove_from_front(self, tab->tab_op_list, i); | 1309 | if (!XTTableSeq::xt_op_is_before(tab->tab_head_op_seq, tab->tab_wake_freeer_op)) |
4571 | 1310 | xt_sl_unlock(self, tab->tab_op_list); | 1310 | xt_wr_wake_freeer(self); |
4572 | 1311 | } | 1311 | } |
4573 | 1312 | 1312 | i++; | |
4574 | 1313 | /* Check for operations still remaining on tables. | 1313 | } |
4575 | 1314 | * These operations are applied even though operations | 1314 | xt_sl_remove_from_front(self, tab->tab_op_list, i); |
4576 | 1315 | * in sequence are missing. | 1315 | xt_sl_unlock(self, tab->tab_op_list); |
4577 | 1316 | */ | 1316 | } |
4578 | 1317 | xtBool xres_sync_operations(XTThreadPtr self, XTDatabaseHPtr db, XTWriterStatePtr ws) | 1317 | |
4579 | 1318 | { | 1318 | /* Check for operations still remaining on tables. |
4580 | 1319 | u_int edx; | 1319 | * These operations are applied even though operations |
4581 | 1320 | XTTableEntryPtr te_ptr; | 1320 | * in sequence are missing. |
4582 | 1321 | XTTableHPtr tab; | 1321 | */ |
4583 | 1322 | xtBool op_synced = FALSE; | 1322 | xtBool xres_sync_operations(XTThreadPtr self, XTDatabaseHPtr db, XTWriterStatePtr ws) |
4584 | 1323 | 1323 | { | |
4585 | 1324 | xt_enum_tables_init(&edx); | 1324 | u_int edx; |
4586 | 1325 | while ((te_ptr = xt_enum_tables_next(self, db, &edx))) { | 1325 | XTTableEntryPtr te_ptr; |
4587 | 1326 | /* Dirty read of tab_op_list OK, here because this is the | 1326 | XTTableHPtr tab; |
4588 | 1327 | * only thread that updates the list! | 1327 | xtBool op_synced = FALSE; |
4589 | 1328 | */ | 1328 | |
4590 | 1329 | if ((tab = te_ptr->te_table)) { | 1329 | xt_enum_tables_init(&edx); |
4591 | 1330 | if (xt_sl_get_size(tab->tab_op_list)) { | 1330 | while ((te_ptr = xt_enum_tables_next(self, db, &edx))) { |
4592 | 1331 | op_synced = TRUE; | 1331 | /* Dirty read of tab_op_list OK, here because this is the |
4593 | 1332 | if (xres_open_table(self, ws, te_ptr->te_tab_id)) | 1332 | * only thread that updates the list! |
4594 | 1333 | xres_apply_operations(self, ws, FALSE); | 1333 | */ |
4595 | 1334 | } | 1334 | if ((tab = te_ptr->te_table)) { |
4596 | 1335 | 1335 | if (xt_sl_get_size(tab->tab_op_list)) { | |
4597 | 1336 | /* Update the pointer cache: */ | 1336 | op_synced = TRUE; |
4598 | 1337 | tab->tab_seq.xt_op_seq_set(self, tab->tab_head_op_seq+1); | 1337 | if (xres_open_table(self, ws, te_ptr->te_tab_id)) |
4599 | 1338 | tab->tab_row_eof_id = tab->tab_head_row_eof_id; | 1338 | xres_apply_operations(self, ws, FALSE); |
4600 | 1339 | tab->tab_row_free_id = tab->tab_head_row_free_id; | 1339 | } |
4601 | 1340 | tab->tab_row_fnum = tab->tab_head_row_fnum; | 1340 | |
4602 | 1341 | tab->tab_rec_eof_id = tab->tab_head_rec_eof_id; | 1341 | /* Update the pointer cache: */ |
4603 | 1342 | tab->tab_rec_free_id = tab->tab_head_rec_free_id; | 1342 | tab->tab_seq.xt_op_seq_set(self, tab->tab_head_op_seq+1); |
4604 | 1343 | tab->tab_rec_fnum = tab->tab_head_rec_fnum; | 1343 | tab->tab_row_eof_id = tab->tab_head_row_eof_id; |
4605 | 1344 | } | 1344 | tab->tab_row_free_id = tab->tab_head_row_free_id; |
4606 | 1345 | } | 1345 | tab->tab_row_fnum = tab->tab_head_row_fnum; |
4607 | 1346 | return op_synced; | 1346 | tab->tab_rec_eof_id = tab->tab_head_rec_eof_id; |
4608 | 1347 | } | 1347 | tab->tab_rec_free_id = tab->tab_head_rec_free_id; |
4609 | 1348 | 1348 | tab->tab_rec_fnum = tab->tab_head_rec_fnum; | |
4610 | 1349 | /* | 1349 | } |
4611 | 1350 | * Operations from the log are applied in sequence order. | 1350 | } |
4612 | 1351 | * If the operations are out of sequence, they are buffered | 1351 | return op_synced; |
4613 | 1352 | * until the missing operations appear. | 1352 | } |
4614 | 1353 | * | 1353 | |
4615 | 1354 | * NOTE: No lock is required because there should only be | 1354 | /* |
4616 | 1355 | * one thread that does this! | 1355 | * Operations from the log are applied in sequence order. |
4617 | 1356 | */ | 1356 | * If the operations are out of sequence, they are buffered |
4618 | 1357 | xtPublic void xt_xres_apply_in_order(XTThreadPtr self, XTWriterStatePtr ws, xtLogID log_id, xtLogOffset log_offset, XTXactLogBufferDPtr record) | 1357 | * until the missing operations appear. |
4619 | 1358 | { | 1358 | * |
4620 | 1359 | xtOpSeqNo op_seq; | 1359 | * NOTE: No lock is required because there should only be |
4621 | 1360 | xtTableID tab_id; | 1360 | * one thread that does this! |
4622 | 1361 | size_t len; | 1361 | */ |
4623 | 1362 | xtBool check_index; | 1362 | xtPublic void xt_xres_apply_in_order(XTThreadPtr self, XTWriterStatePtr ws, xtLogID log_id, xtLogOffset log_offset, XTXactLogBufferDPtr record) |
4624 | 1363 | 1363 | { | |
4625 | 1364 | // XTDatabaseHPtr db, XTOpenTablePtr *ot, XTXactSeqReadPtr sr, XTDataBufferPtr databuf | 1364 | xtOpSeqNo op_seq; |
4626 | 1365 | switch (record->xl.xl_status_1) { | 1365 | xtTableID tab_id; |
4627 | 1366 | case XT_LOG_ENT_REC_MODIFIED: | 1366 | size_t len; |
4628 | 1367 | case XT_LOG_ENT_UPDATE: | 1367 | xtBool check_index; |
4629 | 1368 | case XT_LOG_ENT_INSERT: | 1368 | |
4630 | 1369 | case XT_LOG_ENT_DELETE: | 1369 | // XTDatabaseHPtr db, XTOpenTablePtr *ot, XTXactSeqReadPtr sr, XTDataBufferPtr databuf |
4631 | 1370 | case XT_LOG_ENT_UPDATE_BG: | 1370 | switch (record->xl.xl_status_1) { |
4632 | 1371 | case XT_LOG_ENT_INSERT_BG: | 1371 | case XT_LOG_ENT_REC_MODIFIED: |
4633 | 1372 | case XT_LOG_ENT_DELETE_BG: | 1372 | case XT_LOG_ENT_UPDATE: |
4634 | 1373 | len = offsetof(XTactUpdateEntryDRec, xu_rec_type_1) + (size_t) XT_GET_DISK_2(record->xu.xu_size_2); | 1373 | case XT_LOG_ENT_INSERT: |
4635 | 1374 | op_seq = XT_GET_DISK_4(record->xu.xu_op_seq_4); | 1374 | case XT_LOG_ENT_DELETE: |
4636 | 1375 | tab_id = XT_GET_DISK_4(record->xu.xu_tab_id_4); | 1375 | case XT_LOG_ENT_UPDATE_BG: |
4637 | 1376 | break; | 1376 | case XT_LOG_ENT_INSERT_BG: |
4638 | 1377 | case XT_LOG_ENT_UPDATE_FL: | 1377 | case XT_LOG_ENT_DELETE_BG: |
4639 | 1378 | case XT_LOG_ENT_INSERT_FL: | 1378 | len = offsetof(XTactUpdateEntryDRec, xu_rec_type_1) + (size_t) XT_GET_DISK_2(record->xu.xu_size_2); |
4640 | 1379 | case XT_LOG_ENT_DELETE_FL: | 1379 | op_seq = XT_GET_DISK_4(record->xu.xu_op_seq_4); |
4641 | 1380 | case XT_LOG_ENT_UPDATE_FL_BG: | 1380 | tab_id = XT_GET_DISK_4(record->xu.xu_tab_id_4); |
4642 | 1381 | case XT_LOG_ENT_INSERT_FL_BG: | 1381 | break; |
4643 | 1382 | case XT_LOG_ENT_DELETE_FL_BG: | 1382 | case XT_LOG_ENT_UPDATE_FL: |
4644 | 1383 | len = offsetof(XTactUpdateFLEntryDRec, xf_rec_type_1) + (size_t) XT_GET_DISK_2(record->xf.xf_size_2); | 1383 | case XT_LOG_ENT_INSERT_FL: |
4645 | 1384 | op_seq = XT_GET_DISK_4(record->xf.xf_op_seq_4); | 1384 | case XT_LOG_ENT_DELETE_FL: |
4646 | 1385 | tab_id = XT_GET_DISK_4(record->xf.xf_tab_id_4); | 1385 | case XT_LOG_ENT_UPDATE_FL_BG: |
4647 | 1386 | break; | 1386 | case XT_LOG_ENT_INSERT_FL_BG: |
4648 | 1387 | case XT_LOG_ENT_REC_FREED: | 1387 | case XT_LOG_ENT_DELETE_FL_BG: |
4649 | 1388 | case XT_LOG_ENT_REC_REMOVED: | 1388 | len = offsetof(XTactUpdateFLEntryDRec, xf_rec_type_1) + (size_t) XT_GET_DISK_2(record->xf.xf_size_2); |
4650 | 1389 | case XT_LOG_ENT_REC_REMOVED_EXT: | 1389 | op_seq = XT_GET_DISK_4(record->xf.xf_op_seq_4); |
4651 | 1390 | /* [(7)] REMOVE is now a extended version of FREE! */ | 1390 | tab_id = XT_GET_DISK_4(record->xf.xf_tab_id_4); |
4652 | 1391 | len = offsetof(XTactFreeRecEntryDRec, fr_rec_type_1) + sizeof(XTTabRecFreeDRec); | 1391 | break; |
4653 | 1392 | goto fixed_len_data; | 1392 | case XT_LOG_ENT_REC_FREED: |
4654 | 1393 | case XT_LOG_ENT_REC_REMOVED_BI: | 1393 | case XT_LOG_ENT_REC_REMOVED: |
4655 | 1394 | len = offsetof(XTactRemoveBIEntryDRec, rb_rec_type_1) + (size_t) XT_GET_DISK_2(record->rb.rb_size_2); | 1394 | case XT_LOG_ENT_REC_REMOVED_EXT: |
4656 | 1395 | op_seq = XT_GET_DISK_4(record->rb.rb_op_seq_4); | 1395 | /* [(7)] REMOVE is now a extended version of FREE! */ |
4657 | 1396 | tab_id = XT_GET_DISK_4(record->rb.rb_tab_id_4); | 1396 | len = offsetof(XTactFreeRecEntryDRec, fr_rec_type_1) + sizeof(XTTabRecFreeDRec); |
4658 | 1397 | break; | 1397 | goto fixed_len_data; |
4659 | 1398 | case XT_LOG_ENT_REC_MOVED: | 1398 | case XT_LOG_ENT_REC_REMOVED_BI: |
4660 | 1399 | len = offsetof(XTactWriteRecEntryDRec, xw_rec_type_1) + 8; | 1399 | len = offsetof(XTactRemoveBIEntryDRec, rb_rec_type_1) + (size_t) XT_GET_DISK_2(record->rb.rb_size_2); |
4661 | 1400 | goto fixed_len_data; | 1400 | op_seq = XT_GET_DISK_4(record->rb.rb_op_seq_4); |
4662 | 1401 | case XT_LOG_ENT_REC_CLEANED: | 1401 | tab_id = XT_GET_DISK_4(record->rb.rb_tab_id_4); |
4663 | 1402 | len = offsetof(XTactWriteRecEntryDRec, xw_rec_type_1) + offsetof(XTTabRecHeadDRec, tr_prev_rec_id_4) + XT_RECORD_ID_SIZE; | 1402 | break; |
4664 | 1403 | goto fixed_len_data; | 1403 | case XT_LOG_ENT_REC_MOVED: |
4665 | 1404 | case XT_LOG_ENT_REC_CLEANED_1: | 1404 | len = offsetof(XTactWriteRecEntryDRec, xw_rec_type_1) + 8; |
4666 | 1405 | len = offsetof(XTactWriteRecEntryDRec, xw_rec_type_1) + 1; | 1405 | goto fixed_len_data; |
4667 | 1406 | goto fixed_len_data; | 1406 | case XT_LOG_ENT_REC_CLEANED: |
4668 | 1407 | case XT_LOG_ENT_REC_UNLINKED: | 1407 | len = offsetof(XTactWriteRecEntryDRec, xw_rec_type_1) + offsetof(XTTabRecHeadDRec, tr_prev_rec_id_4) + XT_RECORD_ID_SIZE; |
4669 | 1408 | len = offsetof(XTactWriteRecEntryDRec, xw_rec_type_1) + offsetof(XTTabRecHeadDRec, tr_prev_rec_id_4) + XT_RECORD_ID_SIZE; | 1408 | goto fixed_len_data; |
4670 | 1409 | fixed_len_data: | 1409 | case XT_LOG_ENT_REC_CLEANED_1: |
4671 | 1410 | op_seq = XT_GET_DISK_4(record->xw.xw_op_seq_4); | 1410 | len = offsetof(XTactWriteRecEntryDRec, xw_rec_type_1) + 1; |
4672 | 1411 | tab_id = XT_GET_DISK_4(record->xw.xw_tab_id_4); | 1411 | goto fixed_len_data; |
4673 | 1412 | break; | 1412 | case XT_LOG_ENT_REC_UNLINKED: |
4674 | 1413 | case XT_LOG_ENT_ROW_NEW: | 1413 | len = offsetof(XTactWriteRecEntryDRec, xw_rec_type_1) + offsetof(XTTabRecHeadDRec, tr_prev_rec_id_4) + XT_RECORD_ID_SIZE; |
4675 | 1414 | len = sizeof(XTactRowAddedEntryDRec) - 4; | 1414 | fixed_len_data: |
4676 | 1415 | goto new_row; | 1415 | op_seq = XT_GET_DISK_4(record->xw.xw_op_seq_4); |
4677 | 1416 | case XT_LOG_ENT_ROW_NEW_FL: | 1416 | tab_id = XT_GET_DISK_4(record->xw.xw_tab_id_4); |
4678 | 1417 | len = sizeof(XTactRowAddedEntryDRec); | 1417 | break; |
4679 | 1418 | new_row: | 1418 | case XT_LOG_ENT_ROW_NEW: |
4680 | 1419 | op_seq = XT_GET_DISK_4(record->xa.xa_op_seq_4); | 1419 | len = sizeof(XTactRowAddedEntryDRec) - 4; |
4681 | 1420 | tab_id = XT_GET_DISK_4(record->xa.xa_tab_id_4); | 1420 | goto new_row; |
4682 | 1421 | break; | 1421 | case XT_LOG_ENT_ROW_NEW_FL: |
4683 | 1422 | case XT_LOG_ENT_ROW_ADD_REC: | 1422 | len = sizeof(XTactRowAddedEntryDRec); |
4684 | 1423 | case XT_LOG_ENT_ROW_SET: | 1423 | new_row: |
4685 | 1424 | case XT_LOG_ENT_ROW_FREED: | 1424 | op_seq = XT_GET_DISK_4(record->xa.xa_op_seq_4); |
4686 | 1425 | len = offsetof(XTactWriteRowEntryDRec, wr_ref_id_4) + sizeof(XTTabRowRefDRec); | 1425 | tab_id = XT_GET_DISK_4(record->xa.xa_tab_id_4); |
4687 | 1426 | op_seq = XT_GET_DISK_4(record->wr.wr_op_seq_4); | 1426 | break; |
4688 | 1427 | tab_id = XT_GET_DISK_4(record->wr.wr_tab_id_4); | 1427 | case XT_LOG_ENT_ROW_ADD_REC: |
4689 | 1428 | break; | 1428 | case XT_LOG_ENT_ROW_SET: |
4690 | 1429 | case XT_LOG_ENT_NO_OP: | 1429 | case XT_LOG_ENT_ROW_FREED: |
4691 | 1430 | case XT_LOG_ENT_END_OF_LOG: | 1430 | len = offsetof(XTactWriteRowEntryDRec, wr_ref_id_4) + sizeof(XTTabRowRefDRec); |
4692 | 1431 | return; | 1431 | op_seq = XT_GET_DISK_4(record->wr.wr_op_seq_4); |
4693 | 1432 | default: | 1432 | tab_id = XT_GET_DISK_4(record->wr.wr_tab_id_4); |
4694 | 1433 | return; | 1433 | break; |
4695 | 1434 | } | 1434 | case XT_LOG_ENT_NO_OP: |
4696 | 1435 | 1435 | case XT_LOG_ENT_END_OF_LOG: | |
4697 | 1436 | if (!xres_open_table(self, ws, tab_id)) | 1436 | return; |
4698 | 1437 | return; | 1437 | default: |
4699 | 1438 | 1438 | return; | |
4700 | 1439 | XTTableHPtr tab = ws->ws_ot->ot_table; | 1439 | } |
4701 | 1440 | 1440 | ||
4702 | 1441 | /* NOTE: | 1441 | if (!xres_open_table(self, ws, tab_id)) |
4703 | 1442 | * | 1442 | return; |
4704 | 1443 | * During normal operation this is actually given. | 1443 | |
4705 | 1444 | * | 1444 | XTTableHPtr tab = ws->ws_ot->ot_table; |
4706 | 1445 | * During recovery, it only applies to the record/row files | 1445 | |
4707 | 1446 | * The index file is flushed indepently, and changes may | 1446 | /* NOTE: |
4708 | 1447 | * have been applied to the index (due to a call to flush index, | 1447 | * |
4709 | 1448 | * which comes as a result of out of memory) that have not been | 1448 | * During normal operation this is actually given. |
4710 | 1449 | * applied to the record/row files. | 1449 | * |
4711 | 1450 | * | 1450 | * During recovery, it only applies to the record/row files |
4712 | 1451 | * As a result we need to do the index checks that apply to this | 1451 | * The index file is flushed indepently, and changes may |
4713 | 1452 | * change. | 1452 | * have been applied to the index (due to a call to flush index, |
4714 | 1453 | * | 1453 | * which comes as a result of out of memory) that have not been |
4715 | 1454 | * At the moment, I will just do everything, which should not | 1454 | * applied to the record/row files. |
4716 | 1455 | * hurt! | 1455 | * |
4717 | 1456 | * | 1456 | * As a result we need to do the index checks that apply to this |
4718 | 1457 | * This error can be repeated by running the test | 1457 | * change. |
4719 | 1458 | * runTest(OUT_OF_CACHE_UPDATE_TEST, 32, OUT_OF_CACHE_UPDATE_TEST_UPDATE_COUNT, OUT_OF_CACHE_UPDATE_TEST_SET_SIZE) | 1458 | * |
4720 | 1459 | * and crashing after a while. | 1459 | * At the moment, I will just do everything, which should not |
4721 | 1460 | * | 1460 | * hurt! |
4722 | 1461 | * Do this by setting not_this to NULL. This will cause the test to | 1461 | * |
4723 | 1462 | * hang after a while. After a restart the indexes are corrupt if the | 1462 | * This error can be repeated by running the test |
4724 | 1463 | * ws->ws_in_recover condition is not present here. | 1463 | * runTest(OUT_OF_CACHE_UPDATE_TEST, 32, OUT_OF_CACHE_UPDATE_TEST_UPDATE_COUNT, OUT_OF_CACHE_UPDATE_TEST_SET_SIZE) |
4725 | 1464 | */ | 1464 | * and crashing after a while. |
4726 | 1465 | if (ws->ws_in_recover) { | 1465 | * |
4727 | 1466 | if (!tab->tab_recovery_done) { | 1466 | * Do this by setting not_this to NULL. This will cause the test to |
4728 | 1467 | /* op_seq <= tab_head_op_seq + 1: */ | 1467 | * hang after a while. After a restart the indexes are corrupt if the |
4729 | 1468 | ASSERT(XTTableSeq::xt_op_is_before(op_seq, tab->tab_head_op_seq+2)); | 1468 | * ws->ws_in_recover condition is not present here. |
4730 | 1469 | if (XTTableSeq::xt_op_is_before(op_seq-1, tab->tab_head_op_seq)) | 1469 | */ |
4731 | 1470 | /* Adjust the operation sequence number: */ | 1470 | if (ws->ws_in_recover) { |
4732 | 1471 | tab->tab_head_op_seq = op_seq-1; | 1471 | if (!tab->tab_recovery_done) { |
4733 | 1472 | tab->tab_recovery_done = TRUE; | 1472 | /* op_seq <= tab_head_op_seq + 1: */ |
4734 | 1473 | } | 1473 | ASSERT(XTTableSeq::xt_op_is_before(op_seq, tab->tab_head_op_seq+2)); |
4735 | 1474 | } | 1474 | if (XTTableSeq::xt_op_is_before(op_seq-1, tab->tab_head_op_seq)) |
4736 | 1475 | 1475 | /* Adjust the operation sequence number: */ | |
4737 | 1476 | if (!XTTableSeq::xt_op_is_before(tab->tab_head_op_seq, op_seq)) | 1476 | tab->tab_head_op_seq = op_seq-1; |
4738 | 1477 | return; | 1477 | tab->tab_recovery_done = TRUE; |
4739 | 1478 | 1478 | } | |
4740 | 1479 | if (tab->tab_head_op_seq+1 == op_seq) { | 1479 | } |
4741 | 1480 | /* I could use tab_ind_rec_log_id, but this may be a problem, if | 1480 | |
4742 | 1481 | * recovery does not recover up to the last committed transaction. | 1481 | if (!XTTableSeq::xt_op_is_before(tab->tab_head_op_seq, op_seq)) |
4743 | 1482 | */ | 1482 | return; |
4744 | 1483 | check_index = ws->ws_in_recover && xt_comp_log_pos(log_id, log_offset, ws->ws_ind_rec_log_id, ws->ws_ind_rec_log_offset) >= 0; | 1483 | |
4745 | 1484 | xres_apply_change(self, ws->ws_ot, record, TRUE, check_index, &ws->ws_rec_buf); | 1484 | if (tab->tab_head_op_seq+1 == op_seq) { |
4746 | 1485 | tab->tab_head_op_seq = op_seq; | 1485 | /* I could use tab_ind_rec_log_id, but this may be a problem, if |
4747 | 1486 | if (tab->tab_wr_wake_freeer) { | 1486 | * recovery does not recover up to the last committed transaction. |
4748 | 1487 | if (!XTTableSeq::xt_op_is_before(tab->tab_head_op_seq, tab->tab_wake_freeer_op)) | 1487 | */ |
4749 | 1488 | xt_wr_wake_freeer(self); | 1488 | check_index = ws->ws_in_recover && xt_comp_log_pos(log_id, log_offset, ws->ws_ind_rec_log_id, ws->ws_ind_rec_log_offset) >= 0; |
4750 | 1489 | } | 1489 | xres_apply_change(self, ws->ws_ot, record, TRUE, check_index, &ws->ws_rec_buf); |
4751 | 1490 | 1490 | tab->tab_head_op_seq = op_seq; | |
4752 | 1491 | /* Apply any operations in the list that now follow on... | 1491 | if (tab->tab_wr_wake_freeer) { |
4753 | 1492 | * NOTE: the tab_op_list only has be locked for modification. | 1492 | if (!XTTableSeq::xt_op_is_before(tab->tab_head_op_seq, tab->tab_wake_freeer_op)) |
4754 | 1493 | * This is because only one thread ever changes the list | 1493 | xt_wr_wake_freeer(self); |
4755 | 1494 | * (on startup and the writer), but the checkpoint thread | 1494 | } |
4756 | 1495 | * reads it. | 1495 | |
4757 | 1496 | */ | 1496 | /* Apply any operations in the list that now follow on... |
4758 | 1497 | XTOperationPtr op; | 1497 | * NOTE: the tab_op_list only has be locked for modification. |
4759 | 1498 | if ((op = (XTOperationPtr) xt_sl_first_item(tab->tab_op_list))) { | 1498 | * This is because only one thread ever changes the list |
4760 | 1499 | if (tab->tab_head_op_seq+1 == op->or_op_seq) { | 1499 | * (on startup and the writer), but the checkpoint thread |
4761 | 1500 | xres_apply_operations(self, ws, TRUE); | 1500 | * reads it. |
4762 | 1501 | } | 1501 | */ |
4763 | 1502 | } | 1502 | XTOperationPtr op; |
4764 | 1503 | } | 1503 | if ((op = (XTOperationPtr) xt_sl_first_item(tab->tab_op_list))) { |
4765 | 1504 | else { | 1504 | if (tab->tab_head_op_seq+1 == op->or_op_seq) { |
4766 | 1505 | /* Add the operation to the list: */ | 1505 | xres_apply_operations(self, ws, TRUE); |
4767 | 1506 | XTOperationRec op; | 1506 | } |
4768 | 1507 | 1507 | } | |
4769 | 1508 | op.or_op_seq = op_seq; | 1508 | } |
4770 | 1509 | op.or_op_len = len; | 1509 | else { |
4771 | 1510 | op.or_log_id = log_id; | 1510 | /* Add the operation to the list: */ |
4772 | 1511 | op.or_log_offset = log_offset; | 1511 | XTOperationRec op; |
4773 | 1512 | xt_sl_lock(self, tab->tab_op_list); | 1512 | |
4774 | 1513 | xt_sl_insert(self, tab->tab_op_list, &op_seq, &op); | 1513 | op.or_op_seq = op_seq; |
4775 | 1514 | ASSERT(tab->tab_op_list->sl_usage_count < 1000000); | 1514 | op.or_op_len = len; |
4776 | 1515 | xt_sl_unlock(self, tab->tab_op_list); | 1515 | op.or_log_id = log_id; |
4777 | 1516 | } | 1516 | op.or_log_offset = log_offset; |
4778 | 1517 | } | 1517 | xt_sl_lock(self, tab->tab_op_list); |
4779 | 1518 | 1518 | xt_sl_insert(self, tab->tab_op_list, &op_seq, &op); | |
4780 | 1519 | /* ---------------------------------------------------------------------- | 1519 | ASSERT(tab->tab_op_list->sl_usage_count < 1000000); |
4781 | 1520 | * CHECKPOINTING FUNCTIONALITY | 1520 | xt_sl_unlock(self, tab->tab_op_list); |
4782 | 1521 | */ | 1521 | } |
4783 | 1522 | 1522 | } | |
4784 | 1523 | static xtBool xres_delete_data_log(XTDatabaseHPtr db, xtLogID log_id) | 1523 | |
4785 | 1524 | { | 1524 | /* ---------------------------------------------------------------------- |
4786 | 1525 | XTDataLogFilePtr data_log; | 1525 | * CHECKPOINTING FUNCTIONALITY |
4787 | 1526 | char path[PATH_MAX]; | 1526 | */ |
4788 | 1527 | 1527 | ||
4789 | 1528 | db->db_datalogs.dlc_name(PATH_MAX, path, log_id); | 1528 | static xtBool xres_delete_data_log(XTDatabaseHPtr db, xtLogID log_id) |
4790 | 1529 | 1529 | { | |
4791 | 1530 | if (!db->db_datalogs.dlc_remove_data_log(log_id, TRUE)) | 1530 | XTDataLogFilePtr data_log; |
4792 | 1531 | return FAILED; | 1531 | char path[PATH_MAX]; |
4793 | 1532 | 1532 | ||
4794 | 1533 | if (xt_fs_exists(path)) { | 1533 | db->db_datalogs.dlc_name(PATH_MAX, path, log_id); |
4795 | 1534 | #ifdef DEBUG_LOG_DELETE | 1534 | |
4796 | 1535 | printf("-- delete log: %s\n", path); | 1535 | if (!db->db_datalogs.dlc_remove_data_log(log_id, TRUE)) |
4797 | 1536 | #endif | 1536 | return FAILED; |
4798 | 1537 | if (!xt_fs_delete(NULL, path)) | 1537 | |
4799 | 1538 | return FAILED; | 1538 | if (xt_fs_exists(path)) { |
4800 | 1539 | } | 1539 | #ifdef DEBUG_LOG_DELETE |
4801 | 1540 | /* The log was deleted: */ | 1540 | printf("-- delete log: %s\n", path); |
4802 | 1541 | if (!db->db_datalogs.dlc_get_data_log(&data_log, log_id, TRUE, NULL)) | 1541 | #endif |
4803 | 1542 | return FAILED; | 1542 | if (!xt_fs_delete(NULL, path)) |
4804 | 1543 | if (data_log) { | 1543 | return FAILED; |
4805 | 1544 | if (!db->db_datalogs.dls_set_log_state(data_log, XT_DL_DELETED)) | 1544 | } |
4806 | 1545 | return FAILED; | 1545 | /* The log was deleted: */ |
4807 | 1546 | } | 1546 | if (!db->db_datalogs.dlc_get_data_log(&data_log, log_id, TRUE, NULL)) |
4808 | 1547 | return OK; | 1547 | return FAILED; |
4809 | 1548 | } | 1548 | if (data_log) { |
4810 | 1549 | 1549 | if (!db->db_datalogs.dls_set_log_state(data_log, XT_DL_DELETED)) | |
4811 | 1550 | static int xres_comp_flush_tabs(XTThreadPtr XT_UNUSED(self), register const void *XT_UNUSED(thunk), register const void *a, register const void *b) | 1550 | return FAILED; |
4812 | 1551 | { | 1551 | } |
4813 | 1552 | xtTableID tab_id = *((xtTableID *) a); | 1552 | return OK; |
4814 | 1553 | XTCheckPointTablePtr cp_tab = (XTCheckPointTablePtr) b; | 1553 | } |
4815 | 1554 | 1554 | ||
4816 | 1555 | if (tab_id < cp_tab->cpt_tab_id) | 1555 | static int xres_comp_flush_tabs(XTThreadPtr XT_UNUSED(self), register const void *XT_UNUSED(thunk), register const void *a, register const void *b) |
4817 | 1556 | return -1; | 1556 | { |
4818 | 1557 | if (tab_id > cp_tab->cpt_tab_id) | 1557 | xtTableID tab_id = *((xtTableID *) a); |
4819 | 1558 | return 1; | 1558 | XTCheckPointTablePtr cp_tab = (XTCheckPointTablePtr) b; |
4820 | 1559 | return 0; | 1559 | |
4821 | 1560 | } | 1560 | if (tab_id < cp_tab->cpt_tab_id) |
4822 | 1561 | 1561 | return -1; | |
4823 | 1562 | static void xres_init_checkpoint_state(XTThreadPtr self, XTCheckPointStatePtr cp) | 1562 | if (tab_id > cp_tab->cpt_tab_id) |
4824 | 1563 | { | 1563 | return 1; |
4825 | 1564 | xt_init_mutex_with_autoname(self, &cp->cp_state_lock); | 1564 | return 0; |
4826 | 1565 | } | 1565 | } |
4827 | 1566 | 1566 | ||
4828 | 1567 | static void xres_free_checkpoint_state(XTThreadPtr self, XTCheckPointStatePtr cp) | 1567 | static void xres_init_checkpoint_state(XTThreadPtr self, XTCheckPointStatePtr cp) |
4829 | 1568 | { | 1568 | { |
4830 | 1569 | xt_free_mutex(&cp->cp_state_lock); | 1569 | xt_init_mutex_with_autoname(self, &cp->cp_state_lock); |
4831 | 1570 | if (cp->cp_table_ids) { | 1570 | } |
4832 | 1571 | xt_free_sortedlist(self, cp->cp_table_ids); | 1571 | |
4833 | 1572 | cp->cp_table_ids = NULL; | 1572 | static void xres_free_checkpoint_state(XTThreadPtr self, XTCheckPointStatePtr cp) |
4834 | 1573 | } | 1573 | { |
4835 | 1574 | } | 1574 | xt_free_mutex(&cp->cp_state_lock); |
4836 | 1575 | 1575 | if (cp->cp_table_ids) { | |
4837 | 1576 | /* | 1576 | xt_free_sortedlist(self, cp->cp_table_ids); |
4838 | 1577 | * Remove the deleted logs so that they can be re-used. | 1577 | cp->cp_table_ids = NULL; |
4839 | 1578 | * This is only possible after a checkpoint has been | 1578 | } |
4840 | 1579 | * written that does _not_ include these logs as logs | 1579 | } |
4841 | 1580 | * to be deleted! | 1580 | |
4842 | 1581 | */ | 1581 | /* |
4843 | 1582 | static xtBool xres_remove_data_logs(XTDatabaseHPtr db) | 1582 | * Remove the deleted logs so that they can be re-used. |
4844 | 1583 | { | 1583 | * This is only possible after a checkpoint has been |
4845 | 1584 | u_int no_of_logs = xt_sl_get_size(db->db_datalogs.dlc_deleted); | 1584 | * written that does _not_ include these logs as logs |
4846 | 1585 | xtLogID *log_id_ptr; | 1585 | * to be deleted! |
4847 | 1586 | 1586 | */ | |
4848 | 1587 | for (u_int i=0; i<no_of_logs; i++) { | 1587 | static xtBool xres_remove_data_logs(XTDatabaseHPtr db) |
4849 | 1588 | log_id_ptr = (xtLogID *) xt_sl_item_at(db->db_datalogs.dlc_deleted, i); | 1588 | { |
4850 | 1589 | if (!db->db_datalogs.dlc_remove_data_log(*log_id_ptr, FALSE)) | 1589 | u_int no_of_logs = xt_sl_get_size(db->db_datalogs.dlc_deleted); |
4851 | 1590 | return FAILED; | 1590 | xtLogID *log_id_ptr; |
4852 | 1591 | } | 1591 | |
4853 | 1592 | xt_sl_set_size(db->db_datalogs.dlc_deleted, 0); | 1592 | for (u_int i=0; i<no_of_logs; i++) { |
4854 | 1593 | return OK; | 1593 | log_id_ptr = (xtLogID *) xt_sl_item_at(db->db_datalogs.dlc_deleted, i); |
4855 | 1594 | } | 1594 | if (!db->db_datalogs.dlc_remove_data_log(*log_id_ptr, FALSE)) |
4856 | 1595 | 1595 | return FAILED; | |
4857 | 1596 | /* ---------------------------------------------------------------------- | 1596 | } |
4858 | 1597 | * INIT & EXIT | 1597 | xt_sl_set_size(db->db_datalogs.dlc_deleted, 0); |
4859 | 1598 | */ | 1598 | return OK; |
4860 | 1599 | 1599 | } | |
4861 | 1600 | xtPublic void xt_xres_init(XTThreadPtr self, XTDatabaseHPtr db) | 1600 | |
4862 | 1601 | { | 1601 | /* ---------------------------------------------------------------------- |
4863 | 1602 | xtLogID max_log_id; | 1602 | * INIT & EXIT |
4864 | 1603 | 1603 | */ | |
4865 | 1604 | xt_init_mutex_with_autoname(self, &db->db_cp_lock); | 1604 | |
4866 | 1605 | xt_init_cond(self, &db->db_cp_cond); | 1605 | xtPublic void xt_xres_init(XTThreadPtr self, XTDatabaseHPtr db) |
4867 | 1606 | 1606 | { | |
4868 | 1607 | xres_init_checkpoint_state(self, &db->db_cp_state); | 1607 | xtLogID max_log_id; |
4869 | 1608 | db->db_restart.xres_init(self, db, &db->db_wr_log_id, &db->db_wr_log_offset, &max_log_id); | 1608 | |
4870 | 1609 | 1609 | xt_init_mutex_with_autoname(self, &db->db_cp_lock); | |
4871 | 1610 | /* It is also the position where transactions will start writing the | 1610 | xt_init_cond(self, &db->db_cp_cond); |
4872 | 1611 | * log: | 1611 | |
4873 | 1612 | */ | 1612 | xres_init_checkpoint_state(self, &db->db_cp_state); |
4874 | 1613 | if (!db->db_xlog.xlog_set_write_offset(db->db_wr_log_id, db->db_wr_log_offset, max_log_id, self)) | 1613 | db->db_restart.xres_init(self, db, &db->db_wr_log_id, &db->db_wr_log_offset, &max_log_id); |
4875 | 1614 | xt_throw(self); | 1614 | |
4876 | 1615 | } | 1615 | /* It is also the position where transactions will start writing the |
4877 | 1616 | 1616 | * log: | |
4878 | 1617 | xtPublic void xt_xres_exit(XTThreadPtr self, XTDatabaseHPtr db) | 1617 | */ |
4879 | 1618 | { | 1618 | if (!db->db_xlog.xlog_set_write_offset(db->db_wr_log_id, db->db_wr_log_offset, max_log_id, self)) |
4880 | 1619 | db->db_restart.xres_exit(self); | 1619 | xt_throw(self); |
4881 | 1620 | xres_free_checkpoint_state(self, &db->db_cp_state); | 1620 | } |
4882 | 1621 | xt_free_mutex(&db->db_cp_lock); | 1621 | |
4883 | 1622 | xt_free_cond(&db->db_cp_cond); | 1622 | xtPublic void xt_xres_exit(XTThreadPtr self, XTDatabaseHPtr db) |
4884 | 1623 | } | 1623 | { |
4885 | 1624 | 1624 | db->db_restart.xres_exit(self); | |
4886 | 1625 | /* ---------------------------------------------------------------------- | 1625 | xres_free_checkpoint_state(self, &db->db_cp_state); |
4887 | 1626 | * RESTART FUNCTIONALITY | 1626 | xt_free_mutex(&db->db_cp_lock); |
4888 | 1627 | */ | 1627 | xt_free_cond(&db->db_cp_cond); |
4889 | 1628 | 1628 | } | |
4890 | 1629 | /* | 1629 | |
4891 | 1630 | * Restart the database. This function loads the restart position, and | 1630 | /* ---------------------------------------------------------------------- |
4892 | 1631 | * applies all changes in the logs, until the end of the log, or | 1631 | * RESTART FUNCTIONALITY |
4893 | 1632 | * a corrupted record is found. | 1632 | */ |
4894 | 1633 | * | 1633 | |
4895 | 1634 | * The restart position is the position in the log where we know that | 1634 | /* |
4896 | 1635 | * all the changes up to that point have been flushed to the | 1635 | * Restart the database. This function loads the restart position, and |
4897 | 1636 | * database. | 1636 | * applies all changes in the logs, until the end of the log, or |
4898 | 1637 | * | 1637 | * a corrupted record is found. |
4899 | 1638 | * This is called the checkpoint position. The checkpoint position | 1638 | * |
4900 | 1639 | * is written alternatively to 2 restart files. | 1639 | * The restart position is the position in the log where we know that |
4901 | 1640 | * | 1640 | * all the changes up to that point have been flushed to the |
4902 | 1641 | * To make a checkpoint: | 1641 | * database. |
4903 | 1642 | * Get the current log writer log offset. | 1642 | * |
4904 | 1643 | * For each table: | 1643 | * This is called the checkpoint position. The checkpoint position |
4905 | 1644 | * Get the log offset of the next operation on the table, if an | 1644 | * is written alternatively to 2 restart files. |
4906 | 1645 | * operation is queued for the table. | 1645 | * |
4907 | 1646 | * Flush that table, and the operation sequence to the table. | 1646 | * To make a checkpoint: |
4908 | 1647 | * For each unclean transaction: | 1647 | * Get the current log writer log offset. |
4909 | 1648 | * Get the log offset of the begin of the transaction. | 1648 | * For each table: |
4910 | 1649 | * Write the lowest of all log offsets to the restart file! | 1649 | * Get the log offset of the next operation on the table, if an |
4911 | 1650 | */ | 1650 | * operation is queued for the table. |
4912 | 1651 | 1651 | * Flush that table, and the operation sequence to the table. | |
4913 | 1652 | void XTXactRestart::xres_init(XTThreadPtr self, XTDatabaseHPtr db, xtLogID *log_id, xtLogOffset *log_offset, xtLogID *max_log_id) | 1652 | * For each unclean transaction: |
4914 | 1653 | { | 1653 | * Get the log offset of the begin of the transaction. |
4915 | 1654 | char path[PATH_MAX]; | 1654 | * Write the lowest of all log offsets to the restart file! |
4916 | 1655 | XTOpenFilePtr of = NULL; | 1655 | */ |
4917 | 1656 | XTXlogCheckpointDPtr res_1_buffer = NULL; | 1656 | |
4918 | 1657 | XTXlogCheckpointDPtr res_2_buffer = NULL; | 1657 | void XTXactRestart::xres_init(XTThreadPtr self, XTDatabaseHPtr db, xtLogID *log_id, xtLogOffset *log_offset, xtLogID *max_log_id) |
4919 | 1658 | XTXlogCheckpointDPtr use_buffer; | 1658 | { |
4920 | 1659 | xtLogID ind_rec_log_id = 0; | 1659 | char path[PATH_MAX]; |
4921 | 1660 | xtLogOffset ind_rec_log_offset = 0; | 1660 | XTOpenFilePtr of = NULL; |
4922 | 1661 | 1661 | XTXlogCheckpointDPtr res_1_buffer = NULL; | |
4923 | 1662 | enter_(); | 1662 | XTXlogCheckpointDPtr res_2_buffer = NULL; |
4924 | 1663 | xres_db = db; | 1663 | XTXlogCheckpointDPtr use_buffer; |
4925 | 1664 | 1664 | xtLogID ind_rec_log_id = 0; | |
4926 | 1665 | ASSERT(!self->st_database); | 1665 | xtLogOffset ind_rec_log_offset = 0; |
4927 | 1666 | /* The following call stack: | 1666 | |
4928 | 1667 | * XTDatabaseLog::xlog_flush_pending() | 1667 | enter_(); |
4929 | 1668 | * XTDatabaseLog::xlog_flush() | 1668 | xres_db = db; |
4930 | 1669 | * xt_xlog_flush_log() | 1669 | |
4931 | 1670 | * xt_flush_indices() | 1670 | ASSERT(!self->st_database); |
4932 | 1671 | * idx_out_of_memory_failure() | 1671 | /* The following call stack: |
4933 | 1672 | * xt_idx_delete() | 1672 | * XTDatabaseLog::xlog_flush_pending() |
4934 | 1673 | * xres_remove_index_entries() | 1673 | * XTDatabaseLog::xlog_flush() |
4935 | 1674 | * xres_apply_change() | 1674 | * xt_xlog_flush_log() |
4936 | 1675 | * xt_xres_apply_in_order() | 1675 | * xt_flush_indices() |
4937 | 1676 | * XTXactRestart::xres_restart() | 1676 | * idx_out_of_memory_failure() |
4938 | 1677 | * XTXactRestart::xres_init() | 1677 | * xt_idx_delete() |
4939 | 1678 | * Leads to st_database being used! | 1678 | * xres_remove_index_entries() |
4940 | 1679 | */ | 1679 | * xres_apply_change() |
4941 | 1680 | self->st_database = db; | 1680 | * xt_xres_apply_in_order() |
4942 | 1681 | 1681 | * XTXactRestart::xres_restart() | |
4943 | 1682 | #ifdef SKIP_STARTUP_CHECKPOINT | 1682 | * XTXactRestart::xres_init() |
4944 | 1683 | /* When debugging, we do not checkpoint immediately, just in case | 1683 | * Leads to st_database being used! |
4945 | 1684 | * we detect a problem during recovery. | 1684 | */ |
4946 | 1685 | */ | 1685 | self->st_database = db; |
4947 | 1686 | xres_cp_required = FALSE; | 1686 | |
4948 | 1687 | #else | 1687 | #ifdef SKIP_STARTUP_CHECKPOINT |
4949 | 1688 | xres_cp_required = TRUE; | 1688 | /* When debugging, we do not checkpoint immediately, just in case |
4950 | 1689 | #endif | 1689 | * we detect a problem during recovery. |
4951 | 1690 | xres_cp_number = 0; | 1690 | */ |
4952 | 1691 | try_(a) { | 1691 | xres_cp_required = FALSE; |
4953 | 1692 | 1692 | #else | |
4954 | 1693 | /* Figure out which restart file to use. | 1693 | xres_cp_required = TRUE; |
4955 | 1694 | */ | 1694 | #endif |
4956 | 1695 | xres_name(PATH_MAX, path, 1); | 1695 | xres_cp_number = 0; |
4957 | 1696 | if ((of = xt_open_file(self, path, XT_FS_MISSING_OK))) { | 1696 | try_(a) { |
4958 | 1697 | size_t res_1_size; | 1697 | |
4959 | 1698 | 1698 | /* Figure out which restart file to use. | |
4960 | 1699 | res_1_size = (size_t) xt_seek_eof_file(self, of); | 1699 | */ |
4961 | 1700 | res_1_buffer = (XTXlogCheckpointDPtr) xt_malloc(self, res_1_size); | 1700 | xres_name(PATH_MAX, path, 1); |
4962 | 1701 | if (!xt_pread_file(of, 0, res_1_size, res_1_size, res_1_buffer, NULL, &self->st_statistics.st_x, self)) | 1701 | if ((of = xt_open_file(self, path, XT_FS_MISSING_OK))) { |
4963 | 1702 | xt_throw(self); | 1702 | size_t res_1_size; |
4964 | 1703 | xt_close_file(self, of); | 1703 | |
4965 | 1704 | of = NULL; | 1704 | res_1_size = (size_t) xt_seek_eof_file(self, of); |
4966 | 1705 | if (!xres_check_checksum(res_1_buffer, res_1_size)) { | 1705 | res_1_buffer = (XTXlogCheckpointDPtr) xt_malloc(self, res_1_size); |
4967 | 1706 | xt_free(self, res_1_buffer); | 1706 | if (!xt_pread_file(of, 0, res_1_size, res_1_size, res_1_buffer, NULL, &self->st_statistics.st_x, self)) |
4968 | 1707 | res_1_buffer = NULL; | 1707 | xt_throw(self); |
4969 | 1708 | } | 1708 | xt_close_file(self, of); |
4970 | 1709 | } | 1709 | of = NULL; |
4971 | 1710 | 1710 | if (!xres_check_checksum(res_1_buffer, res_1_size)) { | |
4972 | 1711 | xres_name(PATH_MAX, path, 2); | 1711 | xt_free(self, res_1_buffer); |
4973 | 1712 | if ((of = xt_open_file(self, path, XT_FS_MISSING_OK))) { | 1712 | res_1_buffer = NULL; |
4974 | 1713 | size_t res_2_size; | 1713 | } |
4975 | 1714 | 1714 | } | |
4976 | 1715 | res_2_size = (size_t) xt_seek_eof_file(self, of); | 1715 | |
4977 | 1716 | res_2_buffer = (XTXlogCheckpointDPtr) xt_malloc(self, res_2_size); | 1716 | xres_name(PATH_MAX, path, 2); |
4978 | 1717 | if (!xt_pread_file(of, 0, res_2_size, res_2_size, res_2_buffer, NULL, &self->st_statistics.st_x, self)) | 1717 | if ((of = xt_open_file(self, path, XT_FS_MISSING_OK))) { |
4979 | 1718 | xt_throw(self); | 1718 | size_t res_2_size; |
4980 | 1719 | xt_close_file(self, of); | 1719 | |
4981 | 1720 | of = NULL; | 1720 | res_2_size = (size_t) xt_seek_eof_file(self, of); |
4982 | 1721 | if (!xres_check_checksum(res_2_buffer, res_2_size)) { | 1721 | res_2_buffer = (XTXlogCheckpointDPtr) xt_malloc(self, res_2_size); |
4983 | 1722 | xt_free(self, res_2_buffer); | 1722 | if (!xt_pread_file(of, 0, res_2_size, res_2_size, res_2_buffer, NULL, &self->st_statistics.st_x, self)) |
4984 | 1723 | res_2_buffer = NULL; | 1723 | xt_throw(self); |
4985 | 1724 | } | 1724 | xt_close_file(self, of); |
4986 | 1725 | } | 1725 | of = NULL; |
4987 | 1726 | 1726 | if (!xres_check_checksum(res_2_buffer, res_2_size)) { | |
4988 | 1727 | if (res_1_buffer && res_2_buffer) { | 1727 | xt_free(self, res_2_buffer); |
4989 | 1728 | if (xt_comp_log_pos( | 1728 | res_2_buffer = NULL; |
4990 | 1729 | XT_GET_DISK_4(res_1_buffer->xcp_log_id_4), | 1729 | } |
4991 | 1730 | XT_GET_DISK_6(res_1_buffer->xcp_log_offs_6), | 1730 | } |
4992 | 1731 | XT_GET_DISK_4(res_2_buffer->xcp_log_id_4), | 1731 | |
4993 | 1732 | XT_GET_DISK_6(res_2_buffer->xcp_log_offs_6)) > 0) { | 1732 | if (res_1_buffer && res_2_buffer) { |
4994 | 1733 | /* The first log is the further along than the second: */ | 1733 | if (xt_comp_log_pos( |
4995 | 1734 | xt_free(self, res_2_buffer); | 1734 | XT_GET_DISK_4(res_1_buffer->xcp_log_id_4), |
4996 | 1735 | res_2_buffer = NULL; | 1735 | XT_GET_DISK_6(res_1_buffer->xcp_log_offs_6), |
4997 | 1736 | } | 1736 | XT_GET_DISK_4(res_2_buffer->xcp_log_id_4), |
4998 | 1737 | else { | 1737 | XT_GET_DISK_6(res_2_buffer->xcp_log_offs_6)) > 0) { |
4999 | 1738 | if (XT_GET_DISK_6(res_1_buffer->xcp_chkpnt_no_6) > | 1738 | /* The first log is the further along than the second: */ |
5000 | 1739 | XT_GET_DISK_6(res_2_buffer->xcp_chkpnt_no_6)) { | 1739 | xt_free(self, res_2_buffer); |
1802 | 1740 | xt_free(self, res_2_buffer); | ||
1803 | 1741 | res_2_buffer = NULL; | ||
1804 | 1742 | } | ||
1805 | 1743 | else { | ||
1806 | 1744 | xt_free(self, res_1_buffer); | ||
1807 | 1745 | res_1_buffer = NULL; | ||
1808 | 1746 | } | ||
1809 | 1747 | } | ||
1810 | 1748 | } | ||
1811 | 1749 | |||
1812 | 1750 | if (res_1_buffer) { | ||
1813 | 1751 | use_buffer = res_1_buffer; | ||
1814 | 1752 | xres_next_res_no = 2; | ||
1815 | 1753 | } | ||
1816 | 1754 | else { | ||
1817 | 1755 | use_buffer = res_2_buffer; | ||
1818 | 1756 | xres_next_res_no = 1; | ||
1819 | 1757 | } | ||
1820 | 1758 | |||
1821 | 1759 | /* Read the checkpoint data: */ | ||
1822 | 1760 | if (use_buffer) { | ||
1823 | 1761 | u_int no_of_logs; | ||
1824 | 1762 | xtLogID xt_log_id; | ||
1825 | 1763 | xtTableID xt_tab_id; | ||
1826 | 1764 | |||
1827 | 1765 | xres_cp_number = XT_GET_DISK_6(use_buffer->xcp_chkpnt_no_6); | ||
1828 | 1766 | xres_cp_log_id = XT_GET_DISK_4(use_buffer->xcp_log_id_4); | ||
1829 | 1767 | xres_cp_log_offset = XT_GET_DISK_6(use_buffer->xcp_log_offs_6); | ||
1830 | 1768 | xt_tab_id = XT_GET_DISK_4(use_buffer->xcp_tab_id_4); | ||
1831 | 1769 | if (xt_tab_id > db->db_curr_tab_id) | ||
1832 | 1770 | db->db_curr_tab_id = xt_tab_id; | ||
1833 | 1771 | db->db_xn_curr_id = XT_GET_DISK_4(use_buffer->xcp_xact_id_4); | ||
1834 | 1772 | ind_rec_log_id = XT_GET_DISK_4(use_buffer->xcp_ind_rec_log_id_4); | ||
1835 | 1773 | ind_rec_log_offset = XT_GET_DISK_6(use_buffer->xcp_ind_rec_log_offs_6); | ||
1836 | 1774 | no_of_logs = XT_GET_DISK_2(use_buffer->xcp_log_count_2); | ||
1837 | 1775 | |||
1838 | 1776 | #ifdef DEBUG_PRINT | ||
1839 | 1777 | printf("CHECKPOINT log=%d offset=%d ", (int) xres_cp_log_id, (int) xres_cp_log_offset); | ||
1840 | 1778 | if (no_of_logs) | ||
1841 | 1779 | printf("DELETED LOGS: "); | ||
1842 | 1780 | #endif | ||
1843 | 1781 | |||
1844 | 1782 | /* Logs that are deleted are locked until _after_ the next | ||
1845 | 1783 | * checkpoint. | ||
1846 | 1784 | * | ||
1847 | 1785 | * To prevent the following problem from occuring: | ||
1848 | 1786 | * - Recovery is performed, and log X is deleted | ||
1849 | 1787 | * - After delete a log is free for re-use. | ||
1850 | 1788 | * New data is writen to log X. | ||
1851 | 1789 | * - Server crashes. | ||
1852 | 1790 | * - Recovery is performed from previous checkpoint, | ||
1853 | 1791 | * and log X is deleted again. | ||
1854 | 1792 | * | ||
1855 | 1793 | * To lock the logs the are placed on the deleted list. | ||
1856 | 1794 | * After the next checkpoint, all logs on this list | ||
1857 | 1795 | * will be removed. | ||
1858 | 1796 | */ | ||
1859 | 1797 | for (u_int i=0; i<no_of_logs; i++) { | ||
1860 | 1798 | xt_log_id = (xtLogID) XT_GET_DISK_2(use_buffer->xcp_del_log[i]); | ||
1861 | 1799 | #ifdef DEBUG_PRINT | ||
1862 | 1800 | if (i != 0) | ||
1863 | 1801 | printf(", "); | ||
1864 | 1802 | printf("%d", (int) xt_log_id); | ||
1865 | 1803 | #endif | ||
1866 | 1804 | #ifdef DEBUG_KEEP_LOGS | ||
1867 | 1805 | xt_dl_set_to_delete(self, db, xt_log_id); | ||
1868 | 1806 | #else | ||
1869 | 1807 | if (!xres_delete_data_log(db, xt_log_id)) | ||
1870 | 1808 | xt_throw(self); | ||
1871 | 1809 | #endif | ||
1872 | 1810 | } | ||
1873 | 1811 | |||
1874 | 1812 | #ifdef DEBUG_PRINT | ||
1875 | 1813 | printf("\n"); | ||
1876 | 1814 | #endif | ||
1877 | 1815 | } | ||
1878 | 1816 | else { | ||
1879 | 1817 | /* Try to determine the correct start point. */ | ||
1880 | 1818 | xres_cp_number = 0; | ||
1881 | 1819 | xres_cp_log_id = xt_xlog_get_min_log(self, db); | ||
1882 | 1820 | xres_cp_log_offset = 0; | ||
1883 | 1821 | ind_rec_log_id = xres_cp_log_id; | ||
1884 | 1822 | ind_rec_log_offset = xres_cp_log_offset; | ||
1885 | 1823 | |||
1886 | 1824 | #ifdef DEBUG_PRINT | ||
1887 | 1825 | printf("CHECKPOINT log=1 offset=0\n"); | ||
1888 | 1826 | #endif | ||
1889 | 1827 | } | ||
1890 | 1828 | |||
1891 | 1829 | if (res_1_buffer) { | ||
1892 | 1830 | xt_free(self, res_1_buffer); | ||
1893 | 1831 | res_1_buffer = NULL; | ||
1894 | 1832 | } | ||
1895 | 1833 | if (res_2_buffer) { | ||
1896 | 1834 | xt_free(self, res_2_buffer); | ||
1897 | 1835 | res_2_buffer = NULL; | ||
1898 | 1836 | } | ||
1899 | 1837 | |||
1900 | 1838 | if (!xres_restart(self, log_id, log_offset, ind_rec_log_id, ind_rec_log_offset, max_log_id)) | ||
1901 | 1839 | xt_throw(self); | ||
1902 | 1840 | } | ||
1903 | 1841 | catch_(a) { | ||
1904 | 1842 | self->st_database = NULL; | ||
1905 | 1843 | if (of) | ||
1906 | 1844 | xt_close_file(self, of); | ||
1907 | 1845 | if (res_1_buffer) | ||
1908 | 1846 | xt_free(self, res_1_buffer); | ||
1909 | 1847 | if (res_2_buffer) | ||
1910 | 1848 | xt_free(self, res_2_buffer); | ||
1911 | 1849 | xres_exit(self); | ||
1912 | 1850 | throw_(); | ||
1913 | 1851 | } | ||
1914 | 1852 | cont_(a); | ||
1915 | 1853 | self->st_database = NULL; | ||
1916 | 1854 | |||
1917 | 1855 | exit_(); | ||
1918 | 1856 | } | ||
1919 | 1857 | |||
1920 | 1858 | void XTXactRestart::xres_exit(XTThreadPtr XT_UNUSED(self)) | ||
1921 | 1859 | { | ||
1922 | 1860 | } | ||
1923 | 1861 | |||
1924 | 1862 | void XTXactRestart::xres_name(size_t size, char *path, xtLogID log_id) | ||
1925 | 1863 | { | ||
1926 | 1864 | char name[50]; | ||
1927 | 1865 | |||
1928 | 1866 | sprintf(name, "restart-%lu.xt", (u_long) log_id); | ||
1929 | 1867 | xt_strcpy(size, path, xres_db->db_main_path); | ||
1930 | 1868 | xt_add_system_dir(size, path); | ||
1931 | 1869 | xt_add_dir_char(size, path); | ||
1932 | 1870 | xt_strcat(size, path, name); | ||
1933 | 1871 | } | ||
1934 | 1872 | |||
1935 | 1873 | xtBool XTXactRestart::xres_check_checksum(XTXlogCheckpointDPtr buffer, size_t size) | ||
1936 | 1874 | { | ||
1937 | 1875 | size_t head_size; | ||
1938 | 1876 | |||
1939 | 1877 | /* The minimum size: */ | ||
1940 | 1878 | if (size < offsetof(XTXlogCheckpointDRec, xcp_head_size_4) + 4) | ||
1941 | 1879 | return FAILED; | ||
1942 | 1880 | |||
1943 | 1881 | /* Check the sizes: */ | ||
1944 | 1882 | head_size = XT_GET_DISK_4(buffer->xcp_head_size_4); | ||
1945 | 1883 | if (size < head_size) | ||
1946 | 1884 | return FAILED; | ||
1947 | 1885 | |||
1948 | 1886 | if (XT_GET_DISK_2(buffer->xcp_checksum_2) != xt_get_checksum(((xtWord1 *) buffer) + 2, size - 2, 1)) | ||
1949 | 1887 | return FAILED; | ||
1950 | 1888 | |||
1951 | 1889 | if (XT_GET_DISK_2(buffer->xcp_version_2) != XT_CHECKPOINT_VERSION) | ||
1952 | 1890 | return FAILED; | ||
1953 | 1891 | |||
1954 | 1892 | return OK; | ||
1955 | 1893 | } | ||
1956 | 1894 | |||
1957 | 1895 | void XTXactRestart::xres_recover_progress(XTThreadPtr self, XTOpenFilePtr *of, int perc) | ||
1958 | 1896 | { | ||
1959 | 1897 | #ifdef XT_USE_GLOBAL_DB | ||
1960 | 1898 | if (!perc) { | ||
1961 | 1899 | char file_path[PATH_MAX]; | ||
1962 | 1900 | |||
1963 | 1901 | xt_strcpy(PATH_MAX, file_path, xres_db->db_main_path); | ||
1964 | 1902 | xt_add_pbxt_file(PATH_MAX, file_path, "recovery-progress"); | ||
1965 | 1903 | *of = xt_open_file(self, file_path, XT_FS_CREATE | XT_FS_MAKE_PATH); | ||
1966 | 1904 | xt_set_eof_file(self, *of, 0); | ||
1967 | 1905 | } | ||
1968 | 1906 | |||
1969 | 1907 | if (perc > 100) { | ||
1970 | 1908 | char file_path[PATH_MAX]; | ||
1971 | 1909 | |||
1972 | 1910 | if (*of) { | ||
1973 | 1911 | xt_close_file(self, *of); | ||
1974 | 1912 | *of = NULL; | ||
1975 | 1913 | } | ||
1976 | 1914 | xt_strcpy(PATH_MAX, file_path, xres_db->db_main_path); | ||
1977 | 1915 | xt_add_pbxt_file(PATH_MAX, file_path, "recovery-progress"); | ||
1978 | 1916 | if (xt_fs_exists(file_path)) | ||
1979 | 1917 | xt_fs_delete(self, file_path); | ||
1980 | 1918 | } | ||
1981 | 1919 | else { | ||
1982 | 1920 | char number[40]; | ||
1983 | 1921 | |||
1984 | 1922 | sprintf(number, "%d", perc); | ||
1985 | 1923 | if (!xt_pwrite_file(*of, 0, strlen(number), number, &self->st_statistics.st_x, self)) | ||
1986 | 1924 | xt_throw(self); | ||
1987 | 1925 | if (!xt_flush_file(*of, &self->st_statistics.st_x, self)) | ||
1988 | 1926 | xt_throw(self); | ||
1989 | 1927 | } | ||
1990 | 1928 | #endif | ||
1991 | 1929 | } | ||
1992 | 1930 | |||
1993 | 1931 | xtBool XTXactRestart::xres_restart(XTThreadPtr self, xtLogID *log_id, xtLogOffset *log_offset, xtLogID ind_rec_log_id, xtLogOffset ind_rec_log_offset, xtLogID *max_log_id) | ||
1994 | 1932 | { | ||
1995 | 1933 | xtBool ok = TRUE; | ||
1996 | 1934 | XTDatabaseHPtr db = xres_db; | ||
1997 | 1935 | XTXactLogBufferDPtr record; | ||
1998 | 1936 | xtXactID xn_id; | ||
1999 | 1937 | XTXactDataPtr xact; | ||
2000 | 1938 | xtTableID tab_id; | ||
2001 | 1939 | XTWriterStateRec ws; | ||
2002 | 1940 | off_t bytes_read = 0; | ||
2003 | 1941 | off_t bytes_to_read; | ||
2004 | 1942 | volatile xtBool print_progress = FALSE; | ||
2005 | 1943 | volatile off_t perc_size = 0, next_goal = 0; | ||
2006 | 1944 | int perc_complete = 1; | ||
2007 | 1945 | XTOpenFilePtr progress_file = NULL; | ||
2008 | 1946 | xtBool min_ram_xn_id_set = FALSE; | ||
2009 | 1947 | u_int log_count; | ||
2010 | 1948 | |||
2011 | 1949 | memset(&ws, 0, sizeof(ws)); | ||
2012 | 1950 | |||
2013 | 1951 | ws.ws_db = db; | ||
2014 | 1952 | ws.ws_in_recover = TRUE; | ||
2015 | 1953 | ws.ws_ind_rec_log_id = ind_rec_log_id; | ||
2016 | 1954 | ws.ws_ind_rec_log_offset = ind_rec_log_offset; | ||
2017 | 1955 | |||
2018 | 1956 | /* Initialize the data log buffer (required if extended data is | ||
2019 | 1957 | * referenced). | ||
2020 | 1958 | * Note: this buffer is freed later. It is part of the thread | ||
2021 | 1959 | * "open database" state, and this means that a thread | ||
2022 | 1960 | * may not have another database open (in use) when | ||
2023 | 1961 | * it calls this functions. | ||
2024 | 1962 | */ | ||
2025 | 1963 | self->st_dlog_buf.dlb_init(db, xt_db_log_buffer_size); | ||
2026 | 1964 | |||
2027 | 1965 | if (!db->db_xlog.xlog_seq_init(&ws.ws_seqread, xt_db_log_buffer_size, TRUE)) | ||
2028 | 1966 | return FAILED; | ||
2029 | 1967 | |||
2030 | 1968 | bytes_to_read = xres_bytes_to_read(self, db, &log_count, max_log_id); | ||
2031 | 1969 | /* Don't print anything about recovering an empty database: */ | ||
2032 | 1970 | if (bytes_to_read != 0) | ||
2033 | 1971 | xt_logf(XT_NT_INFO, "PBXT: Recovering from %lu-%llu, bytes to read: %llu\n", (u_long) xres_cp_log_id, (u_llong) xres_cp_log_offset, (u_llong) bytes_to_read); | ||
2034 | 1972 | if (bytes_to_read >= 10*1024*1024) { | ||
2035 | 1973 | print_progress = TRUE; | ||
2036 | 1974 | perc_size = bytes_to_read / 100; | ||
2037 | 1975 | next_goal = perc_size; | ||
2038 | 1976 | xres_recover_progress(self, &progress_file, 0); | ||
2039 | 1977 | } | ||
2040 | 1978 | |||
2041 | 1979 | if (!db->db_xlog.xlog_seq_start(&ws.ws_seqread, xres_cp_log_id, xres_cp_log_offset, FALSE)) { | ||
2042 | 1980 | ok = FALSE; | ||
2043 | 1981 | goto failed; | ||
2044 | 1982 | } | ||
2045 | 1983 | |||
2046 | 1984 | try_(a) { | ||
2047 | 1985 | for (;;) { | ||
2048 | 1986 | if (!db->db_xlog.xlog_seq_next(&ws.ws_seqread, &record, TRUE, self)) { | ||
2049 | 1987 | ok = FALSE; | ||
2050 | 1988 | break; | ||
2051 | 1989 | } | ||
2052 | 1990 | /* Increment before. If record is NULL then xseq_record_len will be zero, | ||
2053 | 1991 | * UNLESS the last record was of type XT_LOG_ENT_END_OF_LOG | ||
2054 | 1992 | * which fills the log to align to block of size 512. | ||
2055 | 1993 | */ | ||
2056 | 1994 | bytes_read += ws.ws_seqread.xseq_record_len; | ||
2057 | 1995 | if (!record) | ||
2058 | 1996 | break; | ||
2059 | 1997 | #ifdef PRINT_LOG_ON_RECOVERY | ||
2060 | 1998 | xt_print_log_record(ws.ws_seqread.xseq_rec_log_id, ws.ws_seqread.xseq_rec_log_offset, record); | ||
2061 | 1999 | #endif | ||
2062 | 2000 | if (print_progress && bytes_read > next_goal) { | ||
2063 | 2001 | if (((perc_complete - 1) % 25) == 0) | ||
2064 | 2002 | xt_logf(XT_NT_INFO, "PBXT: "); | ||
2065 | 2003 | if ((perc_complete % 25) == 0) | ||
2066 | 2004 | xt_logf(XT_NT_INFO, "%2d\n", (int) perc_complete); | ||
2067 | 2005 | else | ||
2068 | 2006 | xt_logf(XT_NT_INFO, "%2d ", (int) perc_complete); | ||
2069 | 2007 | xt_log_flush(self); | ||
2070 | 2008 | xres_recover_progress(self, &progress_file, perc_complete); | ||
2071 | 2009 | next_goal += perc_size; | ||
2072 | 2010 | perc_complete++; | ||
2073 | 2011 | } | ||
2074 | 2012 | switch (record->xl.xl_status_1) { | ||
2075 | 2013 | case XT_LOG_ENT_HEADER: | ||
2076 | 2014 | break; | ||
2077 | 2015 | case XT_LOG_ENT_NEW_LOG: { | ||
2078 | 2016 | /* Adjust the bytes read for the fact that logs are written | ||
2079 | 2017 | * on 512 byte boundaries. | ||
2080 | 2018 | */ | ||
2081 | 2019 | off_t offs, eof = ws.ws_seqread.xseq_log_eof; | ||
2082 | 2020 | |||
2083 | 2021 | offs = ws.ws_seqread.xseq_rec_log_offset + ws.ws_seqread.xseq_record_len; | ||
2084 | 2022 | if (eof > offs) | ||
2085 | 2023 | bytes_read += eof - offs; | ||
2086 | 2024 | if (!db->db_xlog.xlog_seq_start(&ws.ws_seqread, XT_GET_DISK_4(record->xl.xl_log_id_4), 0, TRUE)) | ||
2087 | 2025 | xt_throw(self); | ||
2088 | 2026 | break; | ||
2089 | 2027 | } | ||
2090 | 2028 | case XT_LOG_ENT_NEW_TAB: | ||
2091 | 2029 | tab_id = XT_GET_DISK_4(record->xt.xt_tab_id_4); | ||
2092 | 2030 | if (tab_id > db->db_curr_tab_id) | ||
2093 | 2031 | db->db_curr_tab_id = tab_id; | ||
2094 | 2032 | break; | ||
2095 | 2033 | case XT_LOG_ENT_UPDATE_BG: | ||
2096 | 2034 | case XT_LOG_ENT_INSERT_BG: | ||
2097 | 2035 | case XT_LOG_ENT_DELETE_BG: | ||
2098 | 2036 | xn_id = XT_GET_DISK_4(record->xu.xu_xact_id_4); | ||
2099 | 2037 | goto start_xact; | ||
2100 | 2038 | case XT_LOG_ENT_UPDATE_FL_BG: | ||
2101 | 2039 | case XT_LOG_ENT_INSERT_FL_BG: | ||
2102 | 2040 | case XT_LOG_ENT_DELETE_FL_BG: | ||
2103 | 2041 | xn_id = XT_GET_DISK_4(record->xf.xf_xact_id_4); | ||
2104 | 2042 | start_xact: | ||
2105 | 2043 | if (xt_xn_is_before(db->db_xn_curr_id, xn_id)) | ||
2106 | 2044 | db->db_xn_curr_id = xn_id; | ||
2107 | 2045 | |||
2108 | 2046 | if (!(xact = xt_xn_add_old_xact(db, xn_id, self))) | ||
2109 | 2047 | xt_throw(self); | ||
2110 | 2048 | |||
2111 | 2049 | xact->xd_begin_log = ws.ws_seqread.xseq_rec_log_id; | ||
2112 | 2050 | xact->xd_begin_offset = ws.ws_seqread.xseq_rec_log_offset; | ||
2113 | 2051 | |||
2114 | 2052 | xact->xd_end_xn_id = xn_id; | ||
2115 | 2053 | xact->xd_end_time = db->db_xn_end_time; | ||
2116 | 2054 | xact->xd_flags = (XT_XN_XAC_LOGGED | XT_XN_XAC_ENDED | XT_XN_XAC_RECOVERED | XT_XN_XAC_SWEEP); | ||
2117 | 2055 | |||
2118 | 2056 | /* This may affect the "minimum RAM transaction": */ | ||
2119 | 2057 | if (!min_ram_xn_id_set || xt_xn_is_before(xn_id, db->db_xn_min_ram_id)) { | ||
2120 | 2058 | min_ram_xn_id_set = TRUE; | ||
2121 | 2059 | db->db_xn_min_ram_id = xn_id; | ||
2122 | 2060 | } | ||
2123 | 2061 | xt_xres_apply_in_order(self, &ws, ws.ws_seqread.xseq_rec_log_id, ws.ws_seqread.xseq_rec_log_offset, record); | ||
2124 | 2062 | break; | ||
2125 | 2063 | case XT_LOG_ENT_COMMIT: | ||
2126 | 2064 | case XT_LOG_ENT_ABORT: | ||
2127 | 2065 | xn_id = XT_GET_DISK_4(record->xe.xe_xact_id_4); | ||
2128 | 2066 | if ((xact = xt_xn_get_xact(db, xn_id, self))) { | ||
2129 | 2067 | xact->xd_end_xn_id = xn_id; | ||
2130 | 2068 | xact->xd_flags |= XT_XN_XAC_ENDED | XT_XN_XAC_SWEEP; | ||
2131 | 2069 | xact->xd_flags &= ~XT_XN_XAC_RECOVERED; // We can expect an end record on cleanup! | ||
2132 | 2070 | if (record->xl.xl_status_1 == XT_LOG_ENT_COMMIT) | ||
2133 | 2071 | xact->xd_flags |= XT_XN_XAC_COMMITTED; | ||
2134 | 2072 | } | ||
2135 | 2073 | break; | ||
2136 | 2074 | case XT_LOG_ENT_CLEANUP: | ||
2137 | 2075 | /* The transaction was cleaned up: */ | ||
2138 | 2076 | xn_id = XT_GET_DISK_4(record->xc.xc_xact_id_4); | ||
2139 | 2077 | xt_xn_delete_xact(db, xn_id, self); | ||
2140 | 2078 | break; | ||
2141 | 2079 | case XT_LOG_ENT_OP_SYNC: | ||
2142 | 2080 | xres_sync_operations(self, db, &ws); | ||
2143 | 2081 | break; | ||
2144 | 2082 | case XT_LOG_ENT_DEL_LOG: | ||
2145 | 2083 | xtLogID rec_log_id; | ||
2146 | 2084 | |||
2147 | 2085 | rec_log_id = XT_GET_DISK_4(record->xl.xl_log_id_4); | ||
2148 | 2086 | xt_dl_set_to_delete(self, db, rec_log_id); | ||
2149 | 2087 | break; | ||
2150 | 2088 | default: | ||
2151 | 2089 | xt_xres_apply_in_order(self, &ws, ws.ws_seqread.xseq_rec_log_id, ws.ws_seqread.xseq_rec_log_offset, record); | ||
2152 | 2090 | break; | ||
2153 | 2091 | } | ||
2154 | 2092 | } | ||
2155 | 2093 | |||
2156 | 2094 | if (xres_sync_operations(self, db, &ws)) { | ||
2157 | 2095 | XTactOpSyncEntryDRec op_sync; | ||
2158 | 2096 | time_t now = time(NULL); | ||
2159 | 2097 | |||
2160 | 2098 | op_sync.os_status_1 = XT_LOG_ENT_OP_SYNC; | ||
2161 | 2099 | op_sync.os_checksum_1 = XT_CHECKSUM_1(now) ^ XT_CHECKSUM_1(ws.ws_seqread.xseq_rec_log_id); | ||
2162 | 2100 | XT_SET_DISK_4(op_sync.os_time_4, (xtWord4) now); | ||
2163 | 2101 | /* TODO: If this is done, check to see that | ||
2164 | 2102 | * the byte written here are read back by the writter. | ||
2165 | 2103 | * This is in order to be in sync with 'xl_log_bytes_written'. | ||
2166 | 2104 | * i.e. xl_log_bytes_written == xl_log_bytes_read | ||
2167 | 2105 | */ | ||
2168 | 2106 | if (!db->db_xlog.xlog_write_thru(&ws.ws_seqread, sizeof(XTactOpSyncEntryDRec), (xtWord1 *) &op_sync, self)) | ||
2169 | 2107 | xt_throw(self); | ||
2170 | 2108 | } | ||
2171 | 2109 | } | ||
2172 | 2110 | catch_(a) { | ||
2173 | 2111 | ok = FALSE; | ||
2174 | 2112 | } | ||
2175 | 2113 | cont_(a); | ||
2176 | 2114 | |||
2177 | 2115 | if (ok) { | ||
2178 | 2116 | if (print_progress) { | ||
2179 | 2117 | while (perc_complete <= 100) { | ||
2180 | 2118 | if (((perc_complete - 1) % 25) == 0) | ||
2181 | 2119 | xt_logf(XT_NT_INFO, "PBXT: "); | ||
2182 | 2120 | if ((perc_complete % 25) == 0) | ||
2183 | 2121 | xt_logf(XT_NT_INFO, "%2d\n", (int) perc_complete); | ||
2184 | 2122 | else | ||
2185 | 2123 | xt_logf(XT_NT_INFO, "%2d ", (int) perc_complete); | ||
2186 | 2124 | xt_log_flush(self); | ||
2187 | 2125 | xres_recover_progress(self, &progress_file, perc_complete); | ||
2188 | 2126 | perc_complete++; | ||
2189 | 2127 | } | ||
2190 | 2128 | } | ||
2191 | 2129 | if (bytes_to_read != 0) | ||
2192 | 2130 | xt_logf(XT_NT_INFO, "PBXT: Recovering complete at %lu-%llu, bytes read: %llu\n", (u_long) ws.ws_seqread.xseq_rec_log_id, (u_llong) ws.ws_seqread.xseq_rec_log_offset, (u_llong) bytes_read); | ||
2193 | 2131 | |||
2194 | 2132 | *log_id = ws.ws_seqread.xseq_rec_log_id; | ||
2195 | 2133 | *log_offset = ws.ws_seqread.xseq_rec_log_offset; | ||
2196 | 2134 | |||
2197 | 2135 | if (!min_ram_xn_id_set) | ||
2198 | 2136 | /* This is true because if no transaction was placed in RAM then | ||
2199 | 2137 | * the next transaction in RAM will have the next ID: */ | ||
2200 | 2138 | db->db_xn_min_ram_id = db->db_xn_curr_id + 1; | ||
2201 | 2139 | } | ||
2202 | 2140 | |||
2203 | 2141 | failed: | ||
2204 | 2142 | xt_free_writer_state(self, &ws); | ||
2205 | 2143 | self->st_dlog_buf.dlb_exit(self); | ||
2206 | 2144 | xres_recover_progress(self, &progress_file, 101); | ||
2207 | 2145 | return ok; | ||
2208 | 2146 | } | ||
2209 | 2147 | |||
2210 | 2148 | xtBool XTXactRestart::xres_is_checkpoint_pending(xtLogID curr_log_id, xtLogOffset curr_log_offset) | ||
2211 | 2149 | { | ||
2212 | 2150 | return xt_bytes_since_last_checkpoint(xres_db, curr_log_id, curr_log_offset) >= xt_db_checkpoint_frequency / 2; | ||
2213 | 2151 | } | ||
2214 | 2152 | |||
2215 | 2153 | /* | ||
2216 | 2154 | * Calculate the bytes to be read for recovery. | ||
2217 | 2155 | * This is only an estimate of the number of bytes that | ||
2218 | 2156 | * will be read. | ||
2219 | 2157 | */ | ||
2220 | 2158 | off_t XTXactRestart::xres_bytes_to_read(XTThreadPtr self, XTDatabaseHPtr db, u_int *log_count, xtLogID *max_log_id) | ||
2221 | 2159 | { | ||
2222 | 2160 | off_t to_read = 0, eof; | ||
2223 | 2161 | xtLogID log_id = xres_cp_log_id; | ||
2224 | 2162 | char log_path[PATH_MAX]; | ||
2225 | 2163 | XTOpenFilePtr of; | ||
2226 | 2164 | XTXactLogHeaderDRec log_head; | ||
2227 | 2165 | size_t head_size; | ||
2228 | 2166 | size_t red_size; | ||
2229 | 2167 | |||
2230 | 2168 | *max_log_id = log_id; | ||
2231 | 2169 | *log_count = 0; | ||
2232 | 2170 | for (;;) { | ||
2233 | 2171 | db->db_xlog.xlog_name(PATH_MAX, log_path, log_id); | ||
2234 | 2172 | of = NULL; | ||
2235 | 2173 | if (!xt_open_file_ns(&of, log_path, XT_FS_MISSING_OK)) | ||
2236 | 2174 | xt_throw(self); | ||
2237 | 2175 | if (!of) | ||
2238 | 2176 | break; | ||
2239 | 2177 | pushr_(xt_close_file, of); | ||
2240 | 2178 | |||
2241 | 2179 | /* Check the first record of the log, to see if it is valid. */ | ||
2242 | 2180 | if (!xt_pread_file(of, 0, sizeof(XTXactLogHeaderDRec), 0, (xtWord1 *) &log_head, &red_size, &self->st_statistics.st_xlog, self)) | ||
2243 | 2181 | xt_throw(self); | ||
2244 | 2182 | /* The minimum size (old log size): */ | ||
2245 | 2183 | if (red_size < XT_MIN_LOG_HEAD_SIZE) | ||
2246 | 2184 | goto done; | ||
2247 | 2185 | head_size = XT_GET_DISK_4(log_head.xh_size_4); | ||
2248 | 2186 | if (log_head.xh_status_1 != XT_LOG_ENT_HEADER) | ||
2249 | 2187 | goto done; | ||
2250 | 2188 | if (log_head.xh_checksum_1 != XT_CHECKSUM_1(log_id)) | ||
2251 | 2189 | goto done; | ||
2252 | 2190 | if (XT_LOG_HEAD_MAGIC(&log_head, head_size) != XT_LOG_FILE_MAGIC) | ||
2253 | 2191 | goto done; | ||
2254 | 2192 | if (head_size > offsetof(XTXactLogHeaderDRec, xh_log_id_4) + 4) { | ||
2255 | 2193 | if (XT_GET_DISK_4(log_head.xh_log_id_4) != log_id) | ||
2256 | 2194 | goto done; | ||
2257 | 2195 | } | ||
2258 | 2196 | if (head_size > offsetof(XTXactLogHeaderDRec, xh_version_2) + 4) { | ||
2259 | 2197 | if (XT_GET_DISK_2(log_head.xh_version_2) > XT_LOG_VERSION_NO) | ||
2260 | 2198 | xt_throw_ulxterr(XT_CONTEXT, XT_ERR_NEW_TYPE_OF_XLOG, (u_long) log_id); | ||
2261 | 2199 | } | ||
2262 | 2200 | |||
2263 | 2201 | eof = xt_seek_eof_file(self, of); | ||
2264 | 2202 | freer_(); // xt_close_file(of) | ||
2265 | 2203 | if (log_id == xres_cp_log_id) | ||
2266 | 2204 | to_read += (eof - xres_cp_log_offset); | ||
2267 | 2205 | else | ||
2268 | 2206 | to_read += eof; | ||
2269 | 2207 | (*log_count)++; | ||
2270 | 2208 | *max_log_id = log_id; | ||
2271 | 2209 | log_id++; | ||
2272 | 2210 | } | ||
2273 | 2211 | return to_read; | ||
2274 | 2212 | |||
2275 | 2213 | done: | ||
2276 | 2214 | freer_(); // xt_close_file(of) | ||
2277 | 2215 | return to_read; | ||
2278 | 2216 | } | ||
2279 | 2217 | |||
2280 | 2218 | |||
2281 | 2219 | /* ---------------------------------------------------------------------- | ||
2282 | 2220 | * C H E C K P O I N T P R O C E S S | ||
2283 | 2221 | */ | ||
2284 | 2222 | |||
2285 | 2223 | typedef enum XTFileType { | ||
2286 | 2224 | XT_FT_RECROW_FILE, | ||
2287 | 2225 | XT_FT_INDEX_FILE | ||
2288 | 2226 | } XTFileType; | ||
2289 | 2227 | |||
2290 | 2228 | typedef struct XTDirtyFile { | ||
2291 | 2229 | xtTableID df_tab_id; | ||
2292 | 2230 | XTFileType df_file_type; | ||
2293 | 2231 | } XTDirtyFileRec, *XTDirtyFilePtr; | ||
2294 | 2232 | |||
2295 | 2233 | #define XT_MAX_FLUSH_FILES 200 | ||
2296 | 2234 | #define XT_FLUSH_THRESHOLD (2 * 1024 * 1024) | ||
2297 | 2235 | |||
2298 | 2236 | /* Sort files to be flused. */ | ||
2299 | 2237 | #ifdef USE_LATER | ||
2300 | 2238 | static void xres_cp_flush_files(XTThreadPtr self, XTDatabaseHPtr db) | ||
2301 | 2239 | { | ||
2302 | 2240 | u_int edx; | ||
2303 | 2241 | XTTableEntryPtr te; | ||
2304 | 2242 | XTDirtyFileRec flush_list[XT_MAX_FLUSH_FILES]; | ||
2305 | 2243 | u_int file_count = 0; | ||
2306 | 2244 | XTIndexPtr *iptr; | ||
2307 | 2245 | u_int dirty_blocks; | ||
2308 | 2246 | XTOpenTablePtr ot; | ||
2309 | 2247 | XTTableHPtr tab; | ||
2310 | 2248 | |||
2311 | 2249 | retry: | ||
2312 | 2250 | xt_enum_tables_init(&edx); | ||
2313 | 2251 | xt_ht_lock(self, db->db_tables); | ||
2314 | 2252 | pushr_(xt_ht_unlock, db->db_tables); | ||
2315 | 2253 | while (file_count < XT_MAX_FLUSH_FILES && | ||
2316 | 2254 | (te = xt_enum_tables_next(self, db, &edx))) { | ||
2317 | 2255 | if ((tab = te->te_table)) { | ||
2318 | 2256 | if (tab->tab_bytes_to_flush >= XT_FLUSH_THRESHOLD) { | ||
2319 | 2257 | flush_list[file_count].df_tab_id = te->te_tab_id; | ||
2320 | 2258 | flush_list[file_count].df_file_type = XT_FT_RECROW_FILE; | ||
2321 | 2259 | file_count++; | ||
2322 | 2260 | } | ||
2323 | 2261 | if (file_count == XT_MAX_FLUSH_FILES) | ||
2324 | 2262 | break; | ||
2325 | 2263 | iptr = tab->tab_dic.dic_keys; | ||
2326 | 2264 | dirty_blocks = 0; | ||
2327 | 2265 | for (u_int i=0;i<tab->tab_dic.dic_key_count; i++) { | ||
2328 | 2266 | dirty_blocks += (*iptr)->mi_dirty_blocks; | ||
2329 | 2267 | iptr++; | ||
2330 | 2268 | } | ||
2331 | 2269 | if ((dirty_blocks * XT_INDEX_PAGE_SIZE) >= XT_FLUSH_THRESHOLD) { | ||
2332 | 2270 | flush_list[file_count].df_tab_id = te->te_tab_id; | ||
2333 | 2271 | flush_list[file_count].df_file_type = XT_FT_INDEX_FILE; | ||
2334 | 2272 | file_count++; | ||
2335 | 2273 | } | ||
2336 | 2274 | } | ||
2337 | 2275 | } | ||
2338 | 2276 | freer_(); // xt_ht_unlock(db->db_tables) | ||
2339 | 2277 | |||
2340 | 2278 | for (u_int i=0;i<file_count && !self->t_quit; i++) { | ||
2341 | 2279 | /* We want to flush about once a second: */ | ||
2342 | 2280 | xt_sleep_milli_second(400); | ||
2343 | 2281 | if ((ot = xt_db_open_pool_table(self, db, flush_list[i].df_tab_id, NULL, TRUE))) { | ||
2344 | 2282 | pushr_(xt_db_return_table_to_pool, ot); | ||
2345 | 2283 | |||
2346 | 2284 | if (flush_list[i].df_file_type == XT_FT_RECROW_FILE) { | ||
2347 | 2285 | if (!xt_flush_record_row(ot, NULL)) | ||
2348 | 2286 | xt_throw(self); | ||
2349 | 2287 | } | ||
2350 | 2288 | else { | ||
2351 | 2289 | if (!xt_flush_indices(ot, NULL)) | ||
2352 | 2290 | xt_throw(self); | ||
2353 | 2291 | } | ||
2354 | 2292 | |||
2355 | 2293 | freer_(); // xt_db_return_table_to_pool(ot) | ||
2356 | 2294 | } | ||
2357 | 2295 | } | ||
2358 | 2296 | |||
2359 | 2297 | if (file_count == 100) | ||
2360 | 2298 | goto retry; | ||
2361 | 2299 | } | ||
2362 | 2300 | #endif | ||
2363 | 2301 | |||
2364 | 2302 | #ifdef xxx | ||
2365 | 2303 | void XTXactRestart::xres_checkpoint_pending(xtLogID log_id, xtLogOffset log_offset) | ||
2366 | 2304 | { | ||
2367 | 2305 | #ifdef TRACE_CHECKPOINT_ACTIVITY | ||
2368 | 2306 | xtBool tmp = xres_cp_pending; | ||
2369 | 2307 | #endif | ||
2370 | 2308 | xres_cp_pending = xres_is_checkpoint_pending(log_id, log_offset); | ||
2371 | 2309 | #ifdef TRACE_CHECKPOINT_ACTIVITY | ||
2372 | 2310 | if (tmp) { | ||
2373 | 2311 | if (!xres_cp_pending) | ||
2374 | 2312 | printf("%s xres_cp_pending = FALSE\n", xt_get_self()->t_name); | ||
2375 | 2313 | } | ||
2376 | 2314 | else { | ||
2377 | 2315 | if (xres_cp_pending) | ||
2378 | 2316 | printf("%s xres_cp_pending = TRUE\n", xt_get_self()->t_name); | ||
2379 | 2317 | } | ||
2380 | 2318 | #endif | ||
2381 | 2319 | } | ||
2382 | 2320 | |||
2383 | 2321 | |||
2384 | 2322 | xres_checkpoint_pending(); | ||
2385 | 2323 | |||
2386 | 2324 | if (!xres_cp_required && | ||
2387 | 2325 | !xres_cp_pending && | ||
2388 | 2326 | xt_sl_get_size(db->db_datalogs.dlc_to_delete) == 0 && | ||
2389 | 2327 | xt_sl_get_size(db->db_datalogs.dlc_deleted) == 0) | ||
2390 | 2328 | return FALSE; | ||
2391 | 2329 | #endif | ||
2392 | 2330 | |||
2393 | 2331 | #ifdef NEVER_CHECKPOINT | ||
2394 | 2332 | xtBool no_checkpoint = TRUE; | ||
2395 | 2333 | #endif | ||
2396 | 2334 | |||
2397 | 2335 | #define XT_CHECKPOINT_IF_NO_ACTIVITY 0 | ||
2398 | 2336 | #define XT_CHECKPOINT_PAUSE_IF_ACTIVITY 1 | ||
2399 | 2337 | #define XT_CHECKPOINT_NO_PAUSE 2 | ||
2400 | 2338 | |||
2401 | 2339 | /* | ||
2402 | 2340 | * This function performs table flush, as long as the system is idle. | ||
2403 | 2341 | */ | ||
2404 | 2342 | static xtBool xres_cp_checkpoint(XTThreadPtr self, XTDatabaseHPtr db, u_int curr_writer_total, xtBool force_checkpoint) | ||
2405 | 2343 | { | ||
2406 | 2344 | XTCheckPointStatePtr cp = &db->db_cp_state; | ||
2407 | 2345 | XTOpenTablePtr ot; | ||
2408 | 2346 | XTCheckPointTablePtr to_flush_ptr; | ||
2409 | 2347 | XTCheckPointTableRec to_flush; | ||
2410 | 2348 | u_int table_count = 0; | ||
2411 | 2349 | xtBool checkpoint_done; | ||
2412 | 2350 | off_t bytes_flushed = 0; | ||
2413 | 2351 | int check_type; | ||
2414 | 2352 | |||
2415 | 2353 | #ifdef NEVER_CHECKPOINT | ||
2416 | 2354 | if (no_checkpoint) | ||
2417 | 2355 | return FALSE; | ||
2418 | 2356 | #endif | ||
2419 | 2357 | if (force_checkpoint) { | ||
2420 | 2358 | if (db->db_restart.xres_cp_required) | ||
2421 | 2359 | check_type = XT_CHECKPOINT_NO_PAUSE; | ||
2422 | 2360 | else | ||
2423 | 2361 | check_type = XT_CHECKPOINT_PAUSE_IF_ACTIVITY; | ||
2424 | 2362 | } | ||
2425 | 2363 | else | ||
2426 | 2364 | check_type = XT_CHECKPOINT_IF_NO_ACTIVITY; | ||
2427 | 2365 | |||
2428 | 2366 | to_flush.cpt_tab_id = 0; | ||
2429 | 2367 | to_flush.cpt_flushed = 0; | ||
2430 | 2368 | |||
2431 | 2369 | /* Start a checkpoint: */ | ||
2432 | 2370 | if (!xt_begin_checkpoint(db, FALSE, self)) | ||
2433 | 2371 | xt_throw(self); | ||
2434 | 2372 | |||
2435 | 2373 | while (!self->t_quit) { | ||
2436 | 2374 | xt_lock_mutex_ns(&cp->cp_state_lock); | ||
2437 | 2375 | table_count = 0; | ||
2438 | 2376 | if (cp->cp_table_ids) | ||
2439 | 2377 | table_count = xt_sl_get_size(cp->cp_table_ids); | ||
2440 | 2378 | if (!cp->cp_running || cp->cp_flush_count >= table_count) { | ||
2441 | 2379 | xt_unlock_mutex_ns(&cp->cp_state_lock); | ||
2442 | 2380 | break; | ||
2443 | 2381 | } | ||
2444 | 2382 | if (cp->cp_next_to_flush > table_count) | ||
2445 | 2383 | cp->cp_next_to_flush = 0; | ||
2446 | 2384 | |||
2447 | 2385 | to_flush_ptr = (XTCheckPointTablePtr) xt_sl_item_at(cp->cp_table_ids, cp->cp_next_to_flush); | ||
2448 | 2386 | if (to_flush_ptr) | ||
2449 | 2387 | to_flush = *to_flush_ptr; | ||
2450 | 2388 | xt_unlock_mutex_ns(&cp->cp_state_lock); | ||
2451 | 2389 | |||
2452 | 2390 | if (to_flush_ptr) { | ||
2453 | 2391 | if ((ot = xt_db_open_pool_table(self, db, to_flush.cpt_tab_id, NULL, TRUE))) { | ||
2454 | 2392 | pushr_(xt_db_return_table_to_pool, ot); | ||
2455 | 2393 | |||
2456 | 2394 | if (!(to_flush.cpt_flushed & XT_CPT_REC_ROW_FLUSHED)) { | ||
2457 | 2395 | if (!xt_flush_record_row(ot, &bytes_flushed, FALSE)) | ||
2458 | 2396 | xt_throw(self); | ||
2459 | 2397 | } | ||
2460 | 2398 | |||
2461 | 2399 | xt_lock_mutex_ns(&cp->cp_state_lock); | ||
2462 | 2400 | to_flush_ptr = NULL; | ||
2463 | 2401 | if (cp->cp_running) | ||
2464 | 2402 | to_flush_ptr = (XTCheckPointTablePtr) xt_sl_item_at(cp->cp_table_ids, cp->cp_next_to_flush); | ||
2465 | 2403 | if (to_flush_ptr) | ||
2466 | 2404 | to_flush = *to_flush_ptr; | ||
2467 | 2405 | xt_unlock_mutex_ns(&cp->cp_state_lock); | ||
2468 | 2406 | |||
2469 | 2407 | if (to_flush_ptr && !self->t_quit) { | ||
2470 | 2408 | if (!(to_flush.cpt_flushed & XT_CPT_INDEX_FLUSHED)) { | ||
2471 | 2409 | switch (check_type) { | ||
2472 | 2410 | case XT_CHECKPOINT_IF_NO_ACTIVITY: | ||
2473 | 2411 | if (bytes_flushed > 0 && curr_writer_total != db->db_xn_total_writer_count) { | ||
2474 | 2412 | freer_(); // xt_db_return_table_to_pool(ot) | ||
2475 | 2413 | goto end_checkpoint; | ||
2476 | 2414 | } | ||
2477 | 2415 | break; | ||
2478 | 2416 | case XT_CHECKPOINT_PAUSE_IF_ACTIVITY: | ||
2479 | 2417 | if (bytes_flushed > 2 * 1024 * 1024 && curr_writer_total != db->db_xn_total_writer_count) { | ||
2480 | 2418 | curr_writer_total = db->db_xn_total_writer_count; | ||
2481 | 2419 | bytes_flushed = 0; | ||
2482 | 2420 | xt_sleep_milli_second(400); | ||
2483 | 2421 | } | ||
2484 | 2422 | break; | ||
2485 | 2423 | case XT_CHECKPOINT_NO_PAUSE: | ||
2486 | 2424 | break; | ||
2487 | 2425 | } | ||
2488 | 2426 | |||
2489 | 2427 | if (!self->t_quit) { | ||
2490 | 2428 | if (!xt_flush_indices(ot, &bytes_flushed, FALSE)) | ||
2491 | 2429 | xt_throw(self); | ||
2492 | 2430 | to_flush.cpt_flushed |= XT_CPT_INDEX_FLUSHED; | ||
2493 | 2431 | } | ||
2494 | 2432 | } | ||
2495 | 2433 | } | ||
2496 | 2434 | |||
2497 | 2435 | freer_(); // xt_db_return_table_to_pool(ot) | ||
2498 | 2436 | } | ||
2499 | 2437 | |||
2500 | 2438 | if ((to_flush.cpt_flushed & XT_CPT_ALL_FLUSHED) == XT_CPT_ALL_FLUSHED) | ||
2501 | 2439 | cp->cp_next_to_flush++; | ||
2502 | 2440 | } | ||
2503 | 2441 | else | ||
2504 | 2442 | cp->cp_next_to_flush++; | ||
2505 | 2443 | |||
2506 | 2444 | if (self->t_quit) | ||
2507 | 2445 | break; | ||
2508 | 2446 | |||
2509 | 2447 | switch (check_type) { | ||
2510 | 2448 | case XT_CHECKPOINT_IF_NO_ACTIVITY: | ||
2511 | 2449 | if (bytes_flushed > 0 && curr_writer_total != db->db_xn_total_writer_count) | ||
2512 | 2450 | goto end_checkpoint; | ||
2513 | 2451 | break; | ||
2514 | 2452 | case XT_CHECKPOINT_PAUSE_IF_ACTIVITY: | ||
2515 | 2453 | if (bytes_flushed > 2 * 1024 * 1024 && curr_writer_total != db->db_xn_total_writer_count) { | ||
2516 | 2454 | curr_writer_total = db->db_xn_total_writer_count; | ||
2517 | 2455 | bytes_flushed = 0; | ||
2518 | 2456 | xt_sleep_milli_second(400); | ||
2519 | 2457 | } | ||
2520 | 2458 | break; | ||
2521 | 2459 | case XT_CHECKPOINT_NO_PAUSE: | ||
2522 | 2460 | break; | ||
2523 | 2461 | } | ||
2524 | 2462 | } | ||
2525 | 2463 | |||
2526 | 2464 | end_checkpoint: | ||
2527 | 2465 | if (!xt_end_checkpoint(db, self, &checkpoint_done)) | ||
2528 | 2466 | xt_throw(self); | ||
2529 | 2467 | return checkpoint_done; | ||
2530 | 2468 | } | ||
2531 | 2469 | |||
2532 | 2470 | |||
2533 | 2471 | /* Wait for the log writer to tell us to do something. | ||
2534 | 2472 | */ | ||
2535 | 2473 | static void xres_cp_wait_for_log_writer(XTThreadPtr self, XTDatabaseHPtr db, u_long milli_secs) | ||
2536 | 2474 | { | ||
2537 | 2475 | xt_lock_mutex(self, &db->db_cp_lock); | ||
2538 | 2476 | pushr_(xt_unlock_mutex, &db->db_cp_lock); | ||
2539 | 2477 | if (!self->t_quit) | ||
2540 | 2478 | xt_timed_wait_cond(self, &db->db_cp_cond, &db->db_cp_lock, milli_secs); | ||
2541 | 2479 | freer_(); // xt_unlock_mutex(&db->db_cp_lock) | ||
2542 | 2480 | } | ||
2543 | 2481 | |||
2544 | 2482 | /* | ||
2545 | 2483 | * This is the way checkpoint works: | ||
2546 | 2484 | * | ||
2547 | 2485 | * To write a checkpoint we need to flush all tables in | ||
2548 | 2486 | * the database. | ||
2549 | 2487 | * | ||
2550 | 2488 | * Before flushing the first table we get the checkpoint | ||
2551 | 2489 | * log position. | ||
2552 | 2490 | * | ||
2553 | 2491 | * After flushing all files we write of the checkpoint | ||
2554 | 2492 | * log position. | ||
2555 | 2493 | */ | ||
2556 | 2494 | static void xres_cp_main(XTThreadPtr self) | ||
2557 | 2495 | { | ||
2558 | 2496 | XTDatabaseHPtr db = self->st_database; | ||
2559 | 2497 | u_int curr_writer_total; | ||
2560 | 2498 | time_t now; | ||
2561 | 2499 | |||
2562 | 2500 | xt_set_low_priority(self); | ||
2563 | 2501 | |||
2564 | 2502 | |||
2565 | 2503 | while (!self->t_quit) { | ||
2566 | 2504 | /* Wait 2 seconds: */ | ||
2567 | 2505 | curr_writer_total = db->db_xn_total_writer_count; | ||
2568 | 2506 | xt_db_approximate_time = time(NULL); | ||
2569 | 2507 | now = xt_db_approximate_time; | ||
2570 | 2508 | while (!self->t_quit && xt_db_approximate_time < now + 2 && !db->db_restart.xres_cp_required) { | ||
2571 | 2509 | xres_cp_wait_for_log_writer(self, db, 400); | ||
2572 | 2510 | xt_db_approximate_time = time(NULL); | ||
2573 | 2511 | xt_db_free_unused_open_tables(self, db); | ||
2574 | 2512 | } | ||
2575 | 2513 | |||
2576 | 2514 | if (self->t_quit) | ||
2577 | 2515 | break; | ||
2578 | 2516 | |||
2579 | 2517 | if (curr_writer_total == db->db_xn_total_writer_count) | ||
2580 | 2518 | /* No activity in 2 seconds: */ | ||
2581 | 2519 | xres_cp_checkpoint(self, db, curr_writer_total, FALSE); | ||
2582 | 2520 | else { | ||
2583 | 2521 | /* There server is busy, check if we need to | ||
2584 | 2522 | * write a checkpoint anyway... | ||
2585 | 2523 | */ | ||
2586 | 2524 | if (db->db_restart.xres_cp_required || | ||
2587 | 2525 | db->db_restart.xres_is_checkpoint_pending(db->db_xlog.xl_write_log_id, db->db_xlog.xl_write_log_offset)) { | ||
2588 | 2526 | /* Flush tables, until the checkpoint is complete. */ | ||
2589 | 2527 | xres_cp_checkpoint(self, db, curr_writer_total, TRUE); | ||
2590 | 2528 | } | ||
2591 | 2529 | } | ||
2592 | 2530 | |||
2593 | 2531 | if (curr_writer_total == db->db_xn_total_writer_count) { | ||
2594 | 2532 | /* We did a checkpoint, and still, nothing has | ||
2595 | 2533 | * happened.... | ||
2596 | 2534 | * | ||
2597 | 2535 | * Wait for something to happen: | ||
2598 | 2536 | */ | ||
2599 | 2537 | xtLogID log_id; | ||
2600 | 2538 | xtLogOffset log_offset; | ||
2601 | 2539 | |||
2602 | 2540 | while (!self->t_quit && curr_writer_total == db->db_xn_total_writer_count) { | ||
2603 | 2541 | /* The writer position: */ | ||
2604 | 2542 | xt_lock_mutex(self, &db->db_wr_lock); | ||
2605 | 2543 | pushr_(xt_unlock_mutex, &db->db_wr_lock); | ||
2606 | 2544 | log_id = db->db_wr_log_id; | ||
2607 | 2545 | log_offset = db->db_wr_log_offset; | ||
2608 | 2546 | freer_(); // xt_unlock_mutex(&db->db_wr_lock) | ||
2609 | 2547 | |||
2610 | 2548 | /* This condition means we could checkpoint: */ | ||
2611 | 2549 | if (!(xt_sl_get_size(db->db_datalogs.dlc_to_delete) == 0 && | ||
2612 | 2550 | xt_sl_get_size(db->db_datalogs.dlc_deleted) == 0 && | ||
2613 | 2551 | xt_comp_log_pos(log_id, log_offset, db->db_restart.xres_cp_log_id, db->db_restart.xres_cp_log_offset) <= 0)) | ||
2614 | 2552 | break; | ||
2615 | 2553 | |||
2616 | 2554 | xres_cp_wait_for_log_writer(self, db, 400); | ||
2617 | 2555 | xt_db_approximate_time = time(NULL); | ||
2618 | 2556 | xt_db_free_unused_open_tables(self, db); | ||
2619 | 2557 | } | ||
2620 | 2558 | } | ||
2621 | 2559 | } | ||
2622 | 2560 | } | ||
2623 | 2561 | |||
2624 | 2562 | static void *xres_cp_run_thread(XTThreadPtr self) | ||
2625 | 2563 | { | ||
2626 | 2564 | XTDatabaseHPtr db = (XTDatabaseHPtr) self->t_data; | ||
2627 | 2565 | int count; | ||
2628 | 2566 | void *mysql_thread; | ||
2629 | 2567 | |||
2630 | 2568 | mysql_thread = myxt_create_thread(); | ||
2631 | 2569 | |||
2632 | 2570 | while (!self->t_quit) { | ||
2633 | 2571 | try_(a) { | ||
2634 | 2572 | /* | ||
2635 | 2573 | * The garbage collector requires that the database | ||
2636 | 2574 | * is in use because. | ||
2637 | 2575 | */ | ||
2638 | 2576 | xt_use_database(self, db, XT_FOR_CHECKPOINTER); | ||
2639 | 2577 | |||
2640 | 2578 | /* This action is both safe and required (see details elsewhere) */ | ||
2641 | 2579 | xt_heap_release(self, self->st_database); | ||
2642 | 2580 | |||
2643 | 2581 | xres_cp_main(self); | ||
2644 | 2582 | } | ||
2645 | 2583 | catch_(a) { | ||
2646 | 2584 | /* This error is "normal"! */ | ||
2647 | 2585 | if (self->t_exception.e_xt_err != XT_ERR_NO_DICTIONARY && | ||
2648 | 2586 | !(self->t_exception.e_xt_err == XT_SIGNAL_CAUGHT && | ||
2649 | 2587 | self->t_exception.e_sys_err == SIGTERM)) | ||
2650 | 2588 | xt_log_and_clear_exception(self); | ||
2651 | 2589 | } | ||
2652 | 2590 | cont_(a); | ||
2653 | 2591 | |||
2654 | 2592 | /* Avoid releasing the database (done above) */ | ||
2655 | 2593 | self->st_database = NULL; | ||
2656 | 2594 | xt_unuse_database(self, self); | ||
2657 | 2595 | |||
2658 | 2596 | /* After an exception, pause before trying again... */ | ||
2659 | 2597 | /* Number of seconds */ | ||
2660 | 2598 | count = 60; | ||
2661 | 2599 | while (!self->t_quit && count > 0) { | ||
2662 | 2600 | sleep(1); | ||
2663 | 2601 | count--; | ||
2664 | 2602 | } | ||
2665 | 2603 | } | ||
2666 | 2604 | |||
2667 | 2605 | myxt_destroy_thread(mysql_thread, TRUE); | ||
2668 | 2606 | return NULL; | ||
2669 | 2607 | } | ||
2670 | 2608 | |||
2671 | 2609 | static void xres_cp_free_thread(XTThreadPtr self, void *data) | ||
2672 | 2610 | { | ||
2673 | 2611 | XTDatabaseHPtr db = (XTDatabaseHPtr) data; | ||
2674 | 2612 | |||
2675 | 2613 | if (db->db_cp_thread) { | ||
2676 | 2614 | xt_lock_mutex(self, &db->db_cp_lock); | ||
2677 | 2615 | pushr_(xt_unlock_mutex, &db->db_cp_lock); | ||
2678 | 2616 | db->db_cp_thread = NULL; | ||
2679 | 2617 | freer_(); // xt_unlock_mutex(&db->db_cp_lock) | ||
2680 | 2618 | } | ||
2681 | 2619 | } | ||
2682 | 2620 | |||
2683 | 2621 | /* Start a checkpoint, if none has been started. */ | ||
2684 | 2622 | xtPublic xtBool xt_begin_checkpoint(XTDatabaseHPtr db, xtBool have_table_lock, XTThreadPtr thread) | ||
2685 | 2623 | { | ||
2686 | 2624 | XTCheckPointStatePtr cp = &db->db_cp_state; | ||
2687 | 2625 | xtLogID log_id; | ||
2688 | 2626 | xtLogOffset log_offset; | ||
2689 | 2627 | xtLogID ind_rec_log_id; | ||
2690 | 2628 | xtLogOffset ind_rec_log_offset; | ||
2691 | 2629 | u_int edx; | ||
2692 | 2630 | XTTableEntryPtr te_ptr; | ||
2693 | 2631 | XTTableHPtr tab; | ||
2694 | 2632 | XTOperationPtr op; | ||
2695 | 2633 | XTCheckPointTableRec cpt; | ||
2696 | 2634 | XTSortedListPtr tables = NULL; | ||
2697 | 2635 | |||
2698 | 2636 | /* First check if a checkpoint is already running: */ | ||
2699 | 2637 | xt_lock_mutex_ns(&cp->cp_state_lock); | ||
2700 | 2638 | if (cp->cp_running) { | ||
2701 | 2639 | xt_unlock_mutex_ns(&cp->cp_state_lock); | ||
2702 | 2640 | return OK; | ||
2703 | 2641 | } | ||
2704 | 2642 | if (cp->cp_table_ids) { | ||
2705 | 2643 | xt_free_sortedlist(NULL, cp->cp_table_ids); | ||
2706 | 2644 | cp->cp_table_ids = NULL; | ||
2707 | 2645 | } | ||
2708 | 2646 | xt_unlock_mutex_ns(&cp->cp_state_lock); | ||
2709 | 2647 | |||
2710 | 2648 | /* Flush the log before we continue. This is to ensure that | ||
2711 | 2649 | * before we write a checkpoint, that the changes | ||
2712 | 2650 | * done by the sweeper and the compactor, have been | ||
2713 | 2651 | * applied. | ||
2714 | 2652 | * | ||
2715 | 2653 | * Note, the sweeper does not flush the log, so this is | ||
2716 | 2654 | * necessary! | ||
2717 | 2655 | * | ||
2718 | 2656 | * --- I have removed this flush. It is actually just a | ||
2719 | 2657 | * minor optimisation, which pushes the flush position | ||
2720 | 2658 | * below ahead. | ||
2721 | 2659 | * | ||
2722 | 2660 | * Note that the writer position used for the checkpoint | ||
2723 | 2661 | * _will_ be behind the current log flush position. | ||
2724 | 2662 | * | ||
2725 | 2663 | * This is because the writer cannot apply log changes | ||
2726 | 2664 | * until they are flushed. | ||
2727 | 2665 | */ | ||
2728 | 2666 | /* This is an alternative to the above. | ||
2729 | 2667 | if (!xt_xlog_flush_log(self)) | ||
2730 | 2668 | xt_throw(self); | ||
2731 | 2669 | */ | ||
2732 | 2670 | xt_lock_mutex_ns(&db->db_wr_lock); | ||
2733 | 2671 | |||
2734 | 2672 | /* The theoretical maximum restart log postion, is the | ||
2735 | 2673 | * position of the writer thread: | ||
2736 | 2674 | */ | ||
2737 | 2675 | log_id = db->db_wr_log_id; | ||
2738 | 2676 | log_offset = db->db_wr_log_offset; | ||
2739 | 2677 | |||
2740 | 2678 | ind_rec_log_id = db->db_xlog.xl_flush_log_id; | ||
2741 | 2679 | ind_rec_log_offset = db->db_xlog.xl_flush_log_offset; | ||
2742 | 2680 | |||
2743 | 2681 | xt_unlock_mutex_ns(&db->db_wr_lock); | ||
2744 | 2682 | |||
2745 | 2683 | /* Go through all the transactions, and find | ||
2746 | 2684 | * the lowest log start position of all the transactions. | ||
2747 | 2685 | */ | ||
2748 | 2686 | for (u_int i=0; i<XT_XN_NO_OF_SEGMENTS; i++) { | ||
2749 | 2687 | XTXactSegPtr seg; | ||
2750 | 2688 | |||
2751 | 2689 | seg = &db->db_xn_idx[i]; | ||
2752 | 2690 | XT_XACT_READ_LOCK(&seg->xs_tab_lock, self); | ||
2753 | 2691 | for (u_int j=0; j<XT_XN_HASH_TABLE_SIZE; j++) { | ||
2754 | 2692 | XTXactDataPtr xact; | ||
2755 | 2693 | |||
2756 | 2694 | xact = seg->xs_table[j]; | ||
2757 | 2695 | while (xact) { | ||
2758 | 2696 | /* If the transaction is logged, but not cleaned: */ | ||
2759 | 2697 | if ((xact->xd_flags & (XT_XN_XAC_LOGGED | XT_XN_XAC_CLEANED)) == XT_XN_XAC_LOGGED) { | ||
2760 | 2698 | if (xt_comp_log_pos(log_id, log_offset, xact->xd_begin_log, xact->xd_begin_offset) > 0) { | ||
2761 | 2699 | log_id = xact->xd_begin_log; | ||
2762 | 2700 | log_offset = xact->xd_begin_offset; | ||
2763 | 2701 | } | ||
2764 | 2702 | } | ||
2765 | 2703 | xact = xact->xd_next_xact; | ||
2766 | 2704 | } | ||
2767 | 2705 | } | ||
2768 | 2706 | XT_XACT_UNLOCK(&seg->xs_tab_lock, self, FALSE); | ||
2769 | 2707 | } | ||
2770 | 2708 | |||
2771 | 2709 | #ifdef TRACE_CHECKPOINT | ||
2772 | 2710 | printf("BEGIN CHECKPOINT %d-%llu\n", (int) log_id, (u_llong) log_offset); | ||
2773 | 2711 | #endif | ||
2774 | 2712 | /* Go through all tables, and find the lowest log position. | ||
2775 | 2713 | * The log position stored by each table shows the position of | ||
2776 | 2714 | * the next operation that still needs to be applied. | ||
2777 | 2715 | * | ||
2778 | 2716 | * This comes from the list of operations which are | ||
2779 | 2717 | * queued for the table. | ||
2780 | 2718 | * | ||
2781 | 2719 | * This function also builds a list of tables! | ||
2782 | 2720 | */ | ||
2783 | 2721 | |||
2784 | 2722 | if (!(tables = xt_new_sortedlist_ns(sizeof(XTCheckPointTableRec), 20, xres_comp_flush_tabs, NULL, NULL))) | ||
2785 | 2723 | return FAILED; | ||
2786 | 2724 | |||
2787 | 2725 | xt_enum_tables_init(&edx); | ||
2788 | 2726 | if (!have_table_lock) | ||
2789 | 2727 | xt_ht_lock(NULL, db->db_tables); | ||
2790 | 2728 | while ((te_ptr = xt_enum_tables_next(NULL, db, &edx))) { | ||
2791 | 2729 | if ((tab = te_ptr->te_table)) { | ||
2792 | 2730 | xt_sl_lock_ns(tab->tab_op_list, thread); | ||
2793 | 2731 | if ((op = (XTOperationPtr) xt_sl_first_item(tab->tab_op_list))) { | ||
2794 | 2732 | if (xt_comp_log_pos(log_id, log_offset, op->or_log_id, op->or_log_offset) > 0) { | ||
2795 | 2733 | log_id = op->or_log_id; | ||
2796 | 2734 | log_offset = op->or_log_offset; | ||
2797 | 2735 | } | ||
2798 | 2736 | } | ||
2799 | 2737 | xt_sl_unlock(NULL, tab->tab_op_list); | ||
2800 | 2738 | cpt.cpt_flushed = 0; | ||
2801 | 2739 | cpt.cpt_tab_id = tab->tab_id; | ||
2802 | 2740 | #ifdef TRACE_CHECKPOINT | ||
2803 | 2741 | printf("to flush: %d %s\n", (int) tab->tab_id, tab->tab_name->ps_path); | ||
2804 | 2742 | #endif | ||
2805 | 2743 | if (!xt_sl_insert(NULL, tables, &tab->tab_id, &cpt)) { | ||
2806 | 2744 | if (!have_table_lock) | ||
2807 | 2745 | xt_ht_unlock(NULL, db->db_tables); | ||
2808 | 2746 | xt_free_sortedlist(NULL, tables); | ||
2809 | 2747 | return FAILED; | ||
2810 | 2748 | } | ||
2811 | 2749 | } | ||
2812 | 2750 | } | ||
2813 | 2751 | if (!have_table_lock) | ||
2814 | 2752 | xt_ht_unlock(NULL, db->db_tables); | ||
2815 | 2753 | |||
2816 | 2754 | xt_lock_mutex_ns(&cp->cp_state_lock); | ||
2817 | 2755 | /* If there is a table list, then someone was faster than me! */ | ||
2818 | 2756 | if (!cp->cp_running && log_id && log_offset) { | ||
2819 | 2757 | cp->cp_running = TRUE; | ||
2820 | 2758 | cp->cp_log_id = log_id; | ||
2821 | 2759 | cp->cp_log_offset = log_offset; | ||
2822 | 2760 | |||
2823 | 2761 | cp->cp_ind_rec_log_id = ind_rec_log_id; | ||
2824 | 2762 | cp->cp_ind_rec_log_offset = ind_rec_log_offset; | ||
2825 | 2763 | |||
2826 | 2764 | cp->cp_flush_count = 0; | ||
2827 | 2765 | cp->cp_next_to_flush = 0; | ||
2828 | 2766 | cp->cp_table_ids = tables; | ||
2829 | 2767 | } | ||
2830 | 2768 | else | ||
2831 | 2769 | xt_free_sortedlist(NULL, tables); | ||
2832 | 2770 | xt_unlock_mutex_ns(&cp->cp_state_lock); | ||
2833 | 2771 | |||
2834 | 2772 | /* At this point, log flushing can begin... */ | ||
2835 | 2773 | return OK; | ||
2836 | 2774 | } | ||
2837 | 2775 | |||
2838 | 2776 | /* End a checkpoint, if a checkpoint has been started, | ||
2839 | 2777 | * and all checkpoint tables have been flushed | ||
2840 | 2778 | */ | ||
2841 | 2779 | xtPublic xtBool xt_end_checkpoint(XTDatabaseHPtr db, XTThreadPtr thread, xtBool *checkpoint_done) | ||
2842 | 2780 | { | ||
2843 | 2781 | XTCheckPointStatePtr cp = &db->db_cp_state; | ||
2844 | 2782 | XTXlogCheckpointDPtr cp_buf = NULL; | ||
2845 | 2783 | char path[PATH_MAX]; | ||
2846 | 2784 | XTOpenFilePtr of; | ||
2847 | 2785 | u_int table_count; | ||
2848 | 2786 | size_t chk_size = 0; | ||
2849 | 2787 | u_int no_of_logs = 0; | ||
2850 | 2788 | |||
2851 | 2789 | #ifdef NEVER_CHECKPOINT | ||
2852 | 2790 | return OK; | ||
2853 | 2791 | #endif | ||
2854 | 2792 | /* Lock the checkpoint state so that only on thread can do this! */ | ||
2855 | 2793 | xt_lock_mutex_ns(&cp->cp_state_lock); | ||
2856 | 2794 | if (!cp->cp_running) | ||
2857 | 2795 | goto checkpoint_done; | ||
2858 | 2796 | |||
2859 | 2797 | table_count = 0; | ||
2860 | 2798 | if (cp->cp_table_ids) | ||
2861 | 2799 | table_count = xt_sl_get_size(cp->cp_table_ids); | ||
2862 | 2800 | if (cp->cp_flush_count < table_count) { | ||
2863 | 2801 | /* Checkpoint is not done, yet! */ | ||
2864 | 2802 | xt_unlock_mutex_ns(&cp->cp_state_lock); | ||
2865 | 2803 | if (checkpoint_done) | ||
2866 | 2804 | *checkpoint_done = FALSE; | ||
2867 | 2805 | return OK; | ||
2868 | 2806 | } | ||
2869 | 2807 | |||
2870 | 2808 | /* Check if anything has changed since the last checkpoint, | ||
2871 | 2809 | * if not, there is no need to write a new checkpoint! | ||
2872 | 2810 | */ | ||
2873 | 2811 | if (xt_sl_get_size(db->db_datalogs.dlc_to_delete) == 0 && | ||
2874 | 2812 | xt_sl_get_size(db->db_datalogs.dlc_deleted) == 0 && | ||
2875 | 2813 | xt_comp_log_pos(cp->cp_log_id, cp->cp_log_offset, db->db_restart.xres_cp_log_id, db->db_restart.xres_cp_log_offset) <= 0) { | ||
2876 | 2814 | /* A checkpoint is required if the size of the deleted | ||
2877 | 2815 | * list is not zero. The reason is, I cannot remove the | ||
2878 | 2816 | * logs from the deleted list BEFORE a checkpoint has been | ||
2879 | 2817 | * done which does NOT include these logs. | ||
2880 | 2818 | * | ||
2881 | 2819 | * Even though the logs have already been deleted. They | ||
2882 | 2820 | * remain on the deleted list to ensure that they are NOT | ||
2883 | 2821 | * reused during this time, until the next checkpoint. | ||
2884 | 2822 | * | ||
2885 | 2823 | * This is done because if they are used, then on restart | ||
2886 | 2824 | * they would be deleted! | ||
2887 | 2825 | */ | ||
2888 | 2826 | #ifdef TRACE_CHECKPOINT | ||
2889 | 2827 | printf("--- END CHECKPOINT - no write\n"); | ||
2890 | 2828 | #endif | ||
2891 | 2829 | goto checkpoint_done; | ||
2892 | 2830 | } | ||
2893 | 2831 | |||
2894 | 2832 | #ifdef TRACE_CHECKPOINT | ||
2895 | 2833 | printf("--- END CHECKPOINT - write start point\n"); | ||
2896 | 2834 | #endif | ||
2897 | 2835 | xt_lock_mutex_ns(&db->db_datalogs.dlc_lock); | ||
2898 | 2836 | |||
2899 | 2837 | no_of_logs = xt_sl_get_size(db->db_datalogs.dlc_to_delete); | ||
2900 | 2838 | chk_size = offsetof(XTXlogCheckpointDRec, xcp_del_log) + no_of_logs * 2; | ||
2901 | 2839 | xtLogID *log_id_ptr; | ||
2902 | 2840 | |||
2903 | 2841 | if (!(cp_buf = (XTXlogCheckpointDPtr) xt_malloc_ns(chk_size))) { | ||
2904 | 2842 | xt_unlock_mutex_ns(&db->db_datalogs.dlc_lock); | ||
2905 | 2843 | goto failed_0; | ||
2906 | 2844 | } | ||
2907 | 2845 | |||
2908 | 2846 | /* Increment the checkpoint number. This value is used if 2 checkpoint have the | ||
2909 | 2847 | * same log number. In this case checkpoints may differ in the log files | ||
2910 | 2848 | * that should be deleted. Here it is important to use the most recent | ||
2911 | 2849 | * log file! | ||
2912 | 2850 | */ | ||
2913 | 2851 | db->db_restart.xres_cp_number++; | ||
2914 | 2852 | |||
2915 | 2853 | /* Create the checkpoint record: */ | ||
2916 | 2854 | XT_SET_DISK_4(cp_buf->xcp_head_size_4, chk_size); | ||
2917 | 2855 | XT_SET_DISK_2(cp_buf->xcp_version_2, XT_CHECKPOINT_VERSION); | ||
2918 | 2856 | XT_SET_DISK_6(cp_buf->xcp_chkpnt_no_6, db->db_restart.xres_cp_number); | ||
2919 | 2857 | XT_SET_DISK_4(cp_buf->xcp_log_id_4, cp->cp_log_id); | ||
2920 | 2858 | XT_SET_DISK_6(cp_buf->xcp_log_offs_6, cp->cp_log_offset); | ||
2921 | 2859 | XT_SET_DISK_4(cp_buf->xcp_tab_id_4, db->db_curr_tab_id); | ||
2922 | 2860 | XT_SET_DISK_4(cp_buf->xcp_xact_id_4, db->db_xn_curr_id); | ||
2923 | 2861 | XT_SET_DISK_4(cp_buf->xcp_ind_rec_log_id_4, cp->cp_ind_rec_log_id); | ||
2924 | 2862 | XT_SET_DISK_6(cp_buf->xcp_ind_rec_log_offs_6, cp->cp_ind_rec_log_offset); | ||
2925 | 2863 | XT_SET_DISK_2(cp_buf->xcp_log_count_2, no_of_logs); | ||
2926 | 2864 | |||
2927 | 2865 | for (u_int i=0; i<no_of_logs; i++) { | ||
2928 | 2866 | log_id_ptr = (xtLogID *) xt_sl_item_at(db->db_datalogs.dlc_to_delete, i); | ||
2929 | 2867 | XT_SET_DISK_2(cp_buf->xcp_del_log[i], (xtWord2) *log_id_ptr); | ||
2930 | 2868 | } | ||
2931 | 2869 | |||
2932 | 2870 | XT_SET_DISK_2(cp_buf->xcp_checksum_2, xt_get_checksum(((xtWord1 *) cp_buf) + 2, chk_size - 2, 1)); | ||
2933 | 2871 | |||
2934 | 2872 | xt_unlock_mutex_ns(&db->db_datalogs.dlc_lock); | ||
2935 | 2873 | |||
2936 | 2874 | /* Write the checkpoint: */ | ||
2937 | 2875 | db->db_restart.xres_name(PATH_MAX, path, db->db_restart.xres_next_res_no); | ||
2938 | 2876 | if (!(of = xt_open_file_ns(path, XT_FS_CREATE | XT_FS_MAKE_PATH))) | ||
2939 | 2877 | goto failed_1; | ||
2940 | 2878 | |||
2941 | 2879 | if (!xt_set_eof_file(NULL, of, 0)) | ||
2942 | 2880 | goto failed_2; | ||
2943 | 2881 | if (!xt_pwrite_file(of, 0, chk_size, (xtWord1 *) cp_buf, &thread->st_statistics.st_x, thread)) | ||
2944 | 2882 | goto failed_2; | ||
2945 | 2883 | if (!xt_flush_file(of, &thread->st_statistics.st_x, thread)) | ||
2946 | 2884 | goto failed_2; | ||
2947 | 2885 | |||
2948 | 2886 | xt_close_file_ns(of); | ||
2949 | 2887 | |||
2950 | 2888 | /* Next time write the other restart file: */ | ||
2951 | 2889 | db->db_restart.xres_next_res_no = (db->db_restart.xres_next_res_no % 2) + 1; | ||
2952 | 2890 | db->db_restart.xres_cp_log_id = cp->cp_log_id; | ||
2953 | 2891 | db->db_restart.xres_cp_log_offset = cp->cp_log_offset; | ||
2954 | 2892 | db->db_restart.xres_cp_required = FALSE; | ||
2955 | 2893 | |||
2956 | 2894 | /* | ||
2957 | 2895 | * Remove all the data logs that were deleted on the | ||
2958 | 2896 | * last checkpoint: | ||
2959 | 2897 | */ | ||
2960 | 2898 | if (!xres_remove_data_logs(db)) | ||
2961 | 2899 | goto failed_0; | ||
2962 | 2900 | |||
2963 | 2901 | #ifndef DEBUG_KEEP_LOGS | ||
2964 | 2902 | /* After checkpoint, we can delete transaction logs that will no longer be required | ||
2965 | 2903 | * for recovery... | ||
2966 | 2904 | */ | ||
2967 | 2905 | if (cp->cp_log_id > 1) { | ||
2968 | 2906 | xtLogID current_log_id = cp->cp_log_id; | ||
2969 | 2907 | xtLogID del_log_id; | ||
2970 | 2908 | |||
2971 | 2909 | #ifdef XT_NUMBER_OF_LOGS_TO_SAVE | ||
2972 | 2910 | if (pbxt_crash_debug) { | ||
2973 | 2911 | /* To save the logs, we just consider them in use: */ | ||
2974 | 2912 | if (current_log_id > XT_NUMBER_OF_LOGS_TO_SAVE) | ||
2975 | 2913 | current_log_id -= XT_NUMBER_OF_LOGS_TO_SAVE; | ||
2976 | 2914 | else | ||
2977 | 2915 | current_log_id = 1; | ||
2978 | 2916 | } | ||
2979 | 2917 | #endif | ||
2980 | 2918 | |||
2981 | 2919 | del_log_id = current_log_id - 1; | ||
2982 | 2920 | |||
2983 | 2921 | while (del_log_id > 0) { | ||
2984 | 2922 | db->db_xlog.xlog_name(PATH_MAX, path, del_log_id); | ||
2985 | 2923 | if (!xt_fs_exists(path)) | ||
2986 | 2924 | break; | ||
2987 | 2925 | del_log_id--; | ||
2988 | 2926 | } | ||
2989 | 2927 | |||
2990 | 2928 | /* This was the lowest log ID that existed: */ | ||
2991 | 2929 | del_log_id++; | ||
2992 | 2930 | |||
2993 | 2931 | /* Delete all logs that still exist, that come before | ||
2994 | 2932 | * the current log: | ||
2995 | 2933 | * | ||
2996 | 2934 | * Do this from least to greatest to ensure no "holes" appear. | ||
2997 | 2935 | */ | ||
2998 | 2936 | while (del_log_id < current_log_id) { | ||
2999 | 2937 | switch (db->db_xlog.xlog_delete_log(del_log_id, thread)) { | ||
3000 | 2938 | case OK: | ||
3001 | 2939 | break; | ||
3002 | 2940 | case FAILED: | ||
3003 | 2941 | goto exit_loop; | ||
3004 | 2942 | case XT_ERR: | ||
3005 | 2943 | goto failed_0; | ||
3006 | 2944 | } | ||
3007 | 2945 | del_log_id++; | ||
3008 | 2946 | } | ||
3009 | 2947 | exit_loop:; | ||
3010 | 2948 | } | ||
3011 | 2949 | |||
3012 | 2950 | /* And we can delete data logs in the list, and place them | ||
3013 | 2951 | * on the deleted list. | ||
3014 | 2952 | */ | ||
3015 | 2953 | xtLogID log_id; | ||
3016 | 2954 | for (u_int i=0; i<no_of_logs; i++) { | ||
3017 | 2955 | log_id = (xtLogID) XT_GET_DISK_2(cp_buf->xcp_del_log[i]); | ||
3018 | 2956 | if (!xres_delete_data_log(db, log_id)) | ||
3019 | 2957 | goto failed_0; | ||
3020 | 2958 | } | ||
3021 | 2959 | #endif | ||
3022 | 2960 | |||
3023 | 2961 | xt_free_ns(cp_buf); | ||
3024 | 2962 | cp_buf = NULL; | ||
3025 | 2963 | |||
3026 | 2964 | checkpoint_done: | ||
3027 | 2965 | cp->cp_running = FALSE; | ||
3028 | 2966 | if (cp->cp_table_ids) { | ||
3029 | 2967 | xt_free_sortedlist(NULL, cp->cp_table_ids); | ||
3030 | 2968 | cp->cp_table_ids = NULL; | ||
3031 | 2969 | } | ||
3032 | 2970 | cp->cp_flush_count = 0; | ||
3033 | 2971 | cp->cp_next_to_flush = 0; | ||
3034 | 2972 | db->db_restart.xres_cp_required = FALSE; | ||
3035 | 2973 | xt_unlock_mutex_ns(&cp->cp_state_lock); | ||
3036 | 2974 | if (checkpoint_done) | ||
3037 | 2975 | *checkpoint_done = TRUE; | ||
3038 | 2976 | return OK; | ||
3039 | 2977 | |||
3040 | 2978 | failed_2: | ||
3041 | 2979 | xt_close_file_ns(of); | ||
3042 | 2980 | |||
3043 | 2981 | failed_1: | ||
3044 | 2982 | xt_free_ns(cp_buf); | ||
3045 | 2983 | |||
3046 | 2984 | failed_0: | ||
3047 | 2985 | if (cp_buf) | ||
3048 | 2986 | xt_free_ns(cp_buf); | ||
3049 | 2987 | xt_unlock_mutex_ns(&cp->cp_state_lock); | ||
3050 | 2988 | return FAILED; | ||
3051 | 2989 | } | ||
3052 | 2990 | |||
3053 | 2991 | xtPublic xtWord8 xt_bytes_since_last_checkpoint(XTDatabaseHPtr db, xtLogID curr_log_id, xtLogOffset curr_log_offset) | ||
3054 | 2992 | { | ||
3055 | 2993 | xtLogID log_id; | ||
3056 | 2994 | xtLogOffset log_offset; | ||
3057 | 2995 | size_t byte_count = 0; | ||
3058 | 2996 | |||
3059 | 2997 | log_id = db->db_restart.xres_cp_log_id; | ||
3060 | 2998 | log_offset = db->db_restart.xres_cp_log_offset; | ||
3061 | 2999 | |||
3062 | 3000 | /* Assume the logs have the threshold: */ | ||
3063 | 3001 | if (log_id < curr_log_id) { | ||
3064 | 3002 | if (log_offset < xt_db_log_file_threshold) | ||
3065 | 3003 | byte_count = (size_t) (xt_db_log_file_threshold - log_offset); | ||
3066 | 3004 | log_offset = 0; | ||
3067 | 3005 | log_id++; | ||
3068 | 3006 | } | ||
3069 | 3007 | while (log_id < curr_log_id) { | ||
3070 | 3008 | byte_count += (size_t) xt_db_log_file_threshold; | ||
3071 | 3009 | log_id++; | ||
3072 | 3010 | } | ||
3073 | 3011 | if (log_offset < curr_log_offset) | ||
3074 | 3012 | byte_count += (size_t) (curr_log_offset - log_offset); | ||
3075 | 3013 | |||
3076 | 3014 | return byte_count; | ||
3077 | 3015 | } | ||
3078 | 3016 | |||
3079 | 3017 | xtPublic void xt_start_checkpointer(XTThreadPtr self, XTDatabaseHPtr db) | ||
3080 | 3018 | { | ||
3081 | 3019 | char name[PATH_MAX]; | ||
3082 | 3020 | |||
3083 | 3021 | sprintf(name, "CP-%s", xt_last_directory_of_path(db->db_main_path)); | ||
3084 | 3022 | xt_remove_dir_char(name); | ||
3085 | 3023 | db->db_cp_thread = xt_create_daemon(self, name); | ||
3086 | 3024 | xt_set_thread_data(db->db_cp_thread, db, xres_cp_free_thread); | ||
3087 | 3025 | xt_run_thread(self, db->db_cp_thread, xres_cp_run_thread); | ||
3088 | 3026 | } | ||
3089 | 3027 | |||
3090 | 3028 | xtPublic void xt_wait_for_checkpointer(XTThreadPtr self, XTDatabaseHPtr db) | ||
3091 | 3029 | { | ||
3092 | 3030 | time_t then, now; | ||
3093 | 3031 | xtBool message = FALSE; | ||
3094 | 3032 | xtLogID log_id; | ||
3095 | 3033 | xtLogOffset log_offset; | ||
3096 | 3034 | |||
3097 | 3035 | if (db->db_cp_thread) { | ||
3098 | 3036 | then = time(NULL); | ||
3099 | 3037 | for (;;) { | ||
3100 | 3038 | xt_lock_mutex(self, &db->db_wr_lock); | ||
3101 | 3039 | pushr_(xt_unlock_mutex, &db->db_wr_lock); | ||
3102 | 3040 | log_id = db->db_wr_log_id; | ||
3103 | 3041 | log_offset = db->db_wr_log_offset; | ||
3104 | 3042 | freer_(); // xt_unlock_mutex(&db->db_wr_lock) | ||
3105 | 3043 | |||
3106 | 3044 | if (xt_sl_get_size(db->db_datalogs.dlc_to_delete) == 0 && | ||
3107 | 3045 | xt_sl_get_size(db->db_datalogs.dlc_deleted) == 0 && | ||
3108 | 3046 | xt_comp_log_pos(log_id, log_offset, db->db_restart.xres_cp_log_id, db->db_restart.xres_cp_log_offset) <= 0) | ||
3109 | 3047 | break; | ||
3110 | 3048 | |||
3111 | 3049 | /* Do a final checkpoint before shutdown: */ | ||
3112 | 3050 | db->db_restart.xres_cp_required = TRUE; | ||
3113 | 3051 | |||
3114 | 3052 | xt_lock_mutex(self, &db->db_cp_lock); | ||
3115 | 3053 | pushr_(xt_unlock_mutex, &db->db_cp_lock); | ||
3116 | 3054 | if (!xt_broadcast_cond_ns(&db->db_cp_cond)) { | ||
3117 | 3055 | xt_log_and_clear_exception_ns(); | ||
3118 | 3056 | break; | ||
3119 | 3057 | } | ||
3120 | 3058 | freer_(); // xt_unlock_mutex(&db->db_cp_lock) | ||
3121 | 3059 | |||
3122 | 3060 | xt_sleep_milli_second(10); | ||
3123 | 3061 | |||
3124 | 3062 | now = time(NULL); | ||
3125 | 3063 | if (now >= then + 16) { | ||
3126 | 3064 | xt_logf(XT_NT_INFO, "Aborting wait for '%s' checkpointer\n", db->db_name); | ||
3127 | 3065 | message = FALSE; | ||
3128 | 3066 | break; | ||
3129 | 3067 | } | ||
3130 | 3068 | if (now >= then + 2) { | ||
3131 | 3069 | if (!message) { | ||
3132 | 3070 | message = TRUE; | ||
3133 | 3071 | xt_logf(XT_NT_INFO, "Waiting for '%s' checkpointer...\n", db->db_name); | ||
3134 | 3072 | } | ||
3135 | 3073 | } | ||
3136 | 3074 | } | ||
3137 | 3075 | |||
3138 | 3076 | if (message) | ||
3139 | 3077 | xt_logf(XT_NT_INFO, "Checkpointer '%s' done.\n", db->db_name); | ||
3140 | 3078 | } | ||
3141 | 3079 | } | ||
3142 | 3080 | |||
3143 | 3081 | xtPublic void xt_stop_checkpointer(XTThreadPtr self, XTDatabaseHPtr db) | ||
3144 | 3082 | { | ||
3145 | 3083 | XTThreadPtr thr_wr; | ||
3146 | 3084 | |||
3147 | 3085 | if (db->db_cp_thread) { | ||
3148 | 3086 | xt_lock_mutex(self, &db->db_cp_lock); | ||
3149 | 3087 | pushr_(xt_unlock_mutex, &db->db_cp_lock); | ||
3150 | 3088 | |||
3151 | 3089 | /* This pointer is safe as long as you have the transaction lock. */ | ||
3152 | 3090 | if ((thr_wr = db->db_cp_thread)) { | ||
3153 | 3091 | xtThreadID tid = thr_wr->t_id; | ||
3154 | 3092 | |||
3155 | 3093 | /* Make sure the thread quits when woken up. */ | ||
3156 | 3094 | xt_terminate_thread(self, thr_wr); | ||
3157 | 3095 | |||
3158 | 3096 | xt_wake_checkpointer(self, db); | ||
3159 | 3097 | |||
3160 | 3098 | freer_(); // xt_unlock_mutex(&db->db_cp_lock) | ||
3161 | 3099 | |||
3162 | 3100 | /* | ||
3163 | 3101 | * GOTCHA: This is a wierd thing but the SIGTERM directed | ||
3164 | 3102 | * at a particular thread (in this case the sweeper) was | ||
3165 | 3103 | * being caught by a different thread and killing the server | ||
3166 | 3104 | * sometimes. Disconcerting. | ||
3167 | 3105 | * (this may only be a problem on Mac OS X) | ||
3168 | 3106 | xt_kill_thread(thread); | ||
3169 | 3107 | */ | ||
3170 | 3108 | xt_wait_for_thread(tid, FALSE); | ||
3171 | 3109 | |||
3172 | 3110 | /* PMC - This should not be necessary to set the signal here, but in the | ||
3173 | 3111 | * debugger the handler is not called!!? | ||
3174 | 3112 | thr_wr->t_delayed_signal = SIGTERM; | ||
3175 | 3113 | xt_kill_thread(thread); | ||
3176 | 3114 | */ | ||
3177 | 3115 | db->db_cp_thread = NULL; | ||
3178 | 3116 | } | ||
3179 | 3117 | else | ||
3180 | 3118 | freer_(); // xt_unlock_mutex(&db->db_cp_lock) | ||
3181 | 3119 | } | ||
3182 | 3120 | } | ||
3183 | 3121 | |||
3184 | 3122 | xtPublic void xt_wake_checkpointer(XTThreadPtr self, XTDatabaseHPtr db) | ||
3185 | 3123 | { | ||
3186 | 3124 | if (!xt_broadcast_cond_ns(&db->db_cp_cond)) | ||
3187 | 3125 | xt_log_and_clear_exception(self); | ||
3188 | 3126 | } | ||
3189 | 3127 | |||
3190 | 3128 | xtPublic void xt_free_writer_state(struct XTThread *self, XTWriterStatePtr ws) | ||
3191 | 3129 | { | ||
3192 | 3130 | if (ws->ws_db) | ||
3193 | 3131 | ws->ws_db->db_xlog.xlog_seq_exit(&ws->ws_seqread); | ||
3194 | 3132 | xt_db_set_size(self, &ws->ws_databuf, 0); | ||
3195 | 3133 | xt_ib_free(self, &ws->ws_rec_buf); | ||
3196 | 3134 | if (ws->ws_ot) { | ||
3197 | 3135 | xt_db_return_table_to_pool(self, ws->ws_ot); | ||
3198 | 3136 | ws->ws_ot = NULL; | ||
3199 | 3137 | } | ||
3200 | 3138 | } | ||
3201 | 3139 | |||
3202 | 3140 | xtPublic void xt_dump_xlogs(XTDatabaseHPtr db, xtLogID start_log) | ||
3203 | 3141 | { | ||
3204 | 3142 | XTXactSeqReadRec seq; | ||
3205 | 3143 | XTXactLogBufferDPtr record; | ||
3206 | 3144 | xtLogID log_id = db->db_restart.xres_cp_log_id; | ||
3207 | 3145 | char log_path[PATH_MAX]; | ||
3208 | 3146 | XTThreadPtr thread = xt_get_self(); | ||
3209 | 3147 | |||
3210 | 3148 | /* Find the first log that still exists:*/ | ||
3211 | 3149 | for (;;) { | ||
3212 | 3150 | log_id--; | ||
3213 | 3151 | db->db_xlog.xlog_name(PATH_MAX, log_path, log_id); | ||
3214 | 3152 | if (!xt_fs_exists(log_path)) | ||
3215 | 3153 | break; | ||
3216 | 3154 | } | ||
3217 | 3155 | log_id++; | ||
3218 | 3156 | |||
3219 | 3157 | if (!db->db_xlog.xlog_seq_init(&seq, xt_db_log_buffer_size, FALSE)) | ||
3220 | 3158 | return; | ||
3221 | 3159 | |||
3222 | 3160 | if (log_id < start_log) | ||
3223 | 3161 | log_id = start_log; | ||
3224 | 3162 | |||
3225 | 3163 | for (;;) { | ||
3226 | 3164 | db->db_xlog.xlog_name(PATH_MAX, log_path, log_id); | ||
3227 | 3165 | if (!xt_fs_exists(log_path)) | ||
3228 | 3166 | break; | ||
3229 | 3167 | |||
3230 | 3168 | if (!db->db_xlog.xlog_seq_start(&seq, log_id, 0, FALSE)) | ||
3231 | 3169 | goto done; | ||
3232 | 3170 | |||
3233 | 3171 | PRINTF("---------- DUMP LOG %d\n", (int) log_id); | ||
3234 | 3172 | for (;;) { | ||
3235 | 3173 | if (!db->db_xlog.xlog_seq_next(&seq, &record, TRUE, thread)) { | ||
3236 | 3174 | PRINTF("---------- DUMP LOG %d ERROR\n", (int) log_id); | ||
3237 | 3175 | xt_log_and_clear_exception_ns(); | ||
3238 | 3176 | break; | ||
3239 | 3177 | } | ||
3240 | 3178 | if (!record) { | ||
3241 | 3179 | PRINTF("---------- DUMP LOG %d DONE\n", (int) log_id); | ||
3242 | 3180 | break; | ||
3243 | 3181 | } | ||
3244 | 3182 | xt_print_log_record(seq.xseq_rec_log_id, seq.xseq_rec_log_offset, record); | ||
3245 | 3183 | } | ||
3246 | 3184 | |||
3247 | 3185 | log_id++; | ||
3248 | 3186 | } | ||
3249 | 3187 | |||
3250 | 3188 | done: | ||
3251 | 3189 | db->db_xlog.xlog_seq_exit(&seq); | ||
3252 | 3190 | } | ||
3253 | 3191 | |||
3254 | 3192 | /* ---------------------------------------------------------------------- | ||
3255 | 3193 | * D A T A B A S E R E C O V E R Y T H R E A D | ||
3256 | 3194 | */ | ||
3257 | 3195 | |||
3258 | 3196 | extern XTDatabaseHPtr pbxt_database; | ||
3259 | 3197 | |||
3260 | 3198 | static void *xn_xres_run_recovery_thread(XTThreadPtr self) | ||
3261 | 3199 | { |
The diff has been truncated for viewing.