Merge lp:~vkolesnikov/pbxt/pbxt-ilog-out-of-disk into lp:pbxt

Proposed by Vladimir Kolesnikov
Status: Merged
Merged at revision: not available
Proposed branch: lp:~vkolesnikov/pbxt/pbxt-ilog-out-of-disk
Merge into: lp:pbxt
Diff against target: 205 lines (+44/-16)
9 files modified
ChangeLog (+2/-0)
src/cache_xt.h (+1/-1)
src/index_xt.cc (+28/-10)
src/index_xt.h (+1/-1)
src/myxt_xt.cc (+2/-1)
src/restart_xt.cc (+6/-0)
src/restart_xt.h (+1/-0)
src/table_xt.h (+1/-1)
src/thread_xt.cc (+2/-2)
To merge this branch: bzr merge lp:~vkolesnikov/pbxt/pbxt-ilog-out-of-disk
Reviewer Review Type Date Requested Status
PBXT Core Pending
Review via email: mp+20461@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Vladimir Kolesnikov (vkolesnikov) wrote :

this patch should fix index corruption problems when running out of disk space

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ChangeLog'
2--- ChangeLog 2010-02-25 20:19:49 +0000
3+++ ChangeLog 2010-03-02 17:45:27 +0000
4@@ -5,6 +5,8 @@
5
6 RN310: Fixed Windows atomic INC/DEC operations, which lead to atomic R/W lock not working correctly. The result was that some index entries were not foound.
7
8+RN310: Fixed ilog corruption when running out of disk space.
9+
10 RN309: Fixed a bug that caused a crash when the index was corrupted. The crash occurs if the index page in not completely written, and an item in the index has a bad length.
11
12 RN308: Fixed bug #509803: can't run tpcc (cannot compare FKs that rely on indexes of different length).
13
14=== modified file 'src/cache_xt.h'
15--- src/cache_xt.h 2009-11-23 14:03:48 +0000
16+++ src/cache_xt.h 2010-03-02 17:45:27 +0000
17@@ -105,7 +105,7 @@
18 XT_IPAGE_LOCK_TYPE cb_lock;
19 xtWord1 cb_state; /* Block status. */
20 xtWord2 cb_handle_count; /* TRUE if this page is referenced by a handle. */
21- xtWord2 cp_flush_seq;
22+ xtWord4 cp_flush_seq;
23 xtWord2 cp_del_count; /* Number of deleted entries. */
24 #ifdef XT_USE_DIRECT_IO_ON_INDEX
25 xtWord1 *cb_data;
26
27=== modified file 'src/index_xt.cc'
28--- src/index_xt.cc 2010-02-17 16:18:57 +0000
29+++ src/index_xt.cc 2010-03-02 17:45:27 +0000
30@@ -3762,7 +3762,8 @@
31 static xtBool idx_flush_dirty_list(XTIndexLogPtr il, XTOpenTablePtr ot, u_int *flush_count, XTIndBlockPtr *flush_list)
32 {
33 for (u_int i=0; i<*flush_count; i++)
34- il->il_write_block(ot, flush_list[i]);
35+ if (!il->il_write_block(ot, flush_list[i]))
36+ return FAILED;
37 *flush_count = 0;
38 return OK;
39 }
40@@ -3815,7 +3816,7 @@
41 xtIndexNodeID ind_free;
42 xtBool something_to_free = FALSE;
43 xtIndexNodeID last_address, next_address;
44- xtWord2 curr_flush_seq;
45+ xtWord4 curr_flush_seq;
46 XTIndFreeListPtr list_ptr;
47 u_int dirty_blocks;
48 XTCheckPointTablePtr cp_tab;
49@@ -3832,7 +3833,8 @@
50 if (!tab->tab_db->db_indlogs.ilp_get_log(&il, ot->ot_thread))
51 goto failed_3;
52
53- il->il_reset(tab->tab_id);
54+ if (!il->il_reset(ot))
55+ goto failed_2;
56 if (!il->il_write_byte(ot, XT_DT_FREE_LIST))
57 goto failed_2;
58 if (!il->il_write_word4(ot, tab->tab_id))
59@@ -3871,7 +3873,7 @@
60 wrote_something = TRUE;
61 while (block) {
62 ASSERT_NS(block->cb_state == IDX_CAC_BLOCK_DIRTY);
63- ASSERT_NS(block->cp_flush_seq == curr_flush_seq);
64+ ASSERT_NS((block->cp_flush_seq == curr_flush_seq) || xt_xn_is_before(block->cp_flush_seq, curr_flush_seq));
65 if (!ind_add_to_dirty_list(il, ot, &flush_count, flush_list, block))
66 goto failed;
67 block = block->cb_dirty_next;
68@@ -4045,7 +4047,7 @@
69 fblock = block;
70 block = block->cb_dirty_next;
71 ASSERT_NS(fblock->cb_state == IDX_CAC_BLOCK_DIRTY);
72- if (fblock->cp_flush_seq == curr_flush_seq) {
73+ if (fblock->cp_flush_seq == curr_flush_seq || xt_xn_is_before(fblock->cp_flush_seq, curr_flush_seq)) {
74 /* Take the block off the dirty list: */
75 if (fblock->cb_dirty_next)
76 fblock->cb_dirty_next->cb_dirty_prev = fblock->cb_dirty_prev;
77@@ -4276,12 +4278,28 @@
78 xt_unlock_mutex_ns(&ilp_lock);
79 }
80
81-void XTIndexLog::il_reset(xtTableID tab_id)
82+xtBool XTIndexLog::il_reset(XTOpenTable *ot)
83 {
84- il_tab_id = tab_id;
85- il_log_eof = 0;
86- il_buffer_len = 0;
87- il_buffer_offset = 0;
88+ il_tab_id = ot->ot_table->tab_id;
89+ il_log_eof = 0;
90+ il_buffer_len = 0;
91+ il_buffer_offset = 0;
92+
93+ if (!il_write_byte(ot, XT_DT_FREE_LIST))
94+ return FAILED;
95+ if (!il_write_word4(ot, 0))
96+ return FAILED;
97+ if (!il_write_word4(ot, 0))
98+ return FAILED;
99+ if (!xt_flush_file(il_of, &ot->ot_thread->st_statistics.st_ilog, ot->ot_thread))
100+ return FAILED;
101+
102+ il_tab_id = ot->ot_table->tab_id;
103+ il_log_eof = 0;
104+ il_buffer_len = 0;
105+ il_buffer_offset = 0;
106+
107+ return OK;
108 }
109
110 void XTIndexLog::il_close(xtBool delete_it)
111
112=== modified file 'src/index_xt.h'
113--- src/index_xt.h 2010-01-22 13:24:35 +0000
114+++ src/index_xt.h 2010-03-02 17:45:27 +0000
115@@ -407,7 +407,7 @@
116 off_t il_buffer_offset;
117
118
119- void il_reset(xtTableID tab_id);
120+ xtBool il_reset(XTOpenTable *ot);
121 void il_close(xtBool delete_it);
122 void il_release();
123
124
125=== modified file 'src/myxt_xt.cc'
126--- src/myxt_xt.cc 2010-02-16 10:06:24 +0000
127+++ src/myxt_xt.cc 2010-03-02 17:45:27 +0000
128@@ -2132,7 +2132,8 @@
129 {
130 enter_();
131 /* The dirty list of cache pages should be empty here! */
132- ASSERT(!mi->mi_dirty_list);
133+ /* This is not the case if we were not able to flush data. E.g. when running out of disk space */
134+ //ASSERT(!mi->mi_dirty_list);
135 ASSERT(!mi->mi_free_list);
136
137 xt_spinlock_free(self, &mi->mi_dirty_lock);
138
139=== modified file 'src/restart_xt.cc'
140--- src/restart_xt.cc 2010-01-28 11:01:12 +0000
141+++ src/restart_xt.cc 2010-03-02 17:45:28 +0000
142@@ -1575,10 +1575,12 @@
143 static void xres_init_checkpoint_state(XTThreadPtr self, XTCheckPointStatePtr cp)
144 {
145 xt_init_mutex_with_autoname(self, &cp->cp_state_lock);
146+ cp->cp_inited = TRUE;
147 }
148
149 static void xres_free_checkpoint_state(XTThreadPtr self, XTCheckPointStatePtr cp)
150 {
151+ cp->cp_inited = FALSE;
152 xt_free_mutex(&cp->cp_state_lock);
153 if (cp->cp_table_ids) {
154 xt_free_sortedlist(self, cp->cp_table_ids);
155@@ -2674,6 +2676,10 @@
156 XTOperationPtr op;
157 XTCheckPointTableRec cpt;
158 XTSortedListPtr tables = NULL;
159+
160+ /* during startup we can get an error before the checkpointer is inited */
161+ if (!cp->cp_inited)
162+ return FAILED;
163
164 /* First check if a checkpoint is already running: */
165 xt_lock_mutex_ns(&cp->cp_state_lock);
166
167=== modified file 'src/restart_xt.h'
168--- src/restart_xt.h 2009-12-07 11:15:02 +0000
169+++ src/restart_xt.h 2010-03-02 17:45:28 +0000
170@@ -92,6 +92,7 @@
171 } XTXactRestartRec, *XTXactRestartPtr;
172
173 typedef struct XTCheckPointState {
174+ xtBool cp_inited; /* TRUE if structure was inited */
175 xt_mutex_type cp_state_lock; /* Lock and the entire checkpoint state. */
176 xtBool cp_running; /* TRUE if a checkpoint is running. */
177 xtLogID cp_log_id;
178
179=== modified file 'src/table_xt.h'
180--- src/table_xt.h 2010-02-02 10:06:03 +0000
181+++ src/table_xt.h 2010-03-02 17:45:28 +0000
182@@ -375,7 +375,7 @@
183 xtIndexNodeID tab_ind_free; /* The start of the free page list of the index. */
184 XTIndFreeListPtr tab_ind_free_list; /* A cache of the free list (if exists, don't go to disk!) */
185 xt_mutex_type tab_ind_lock; /* Lock for reading and writing the index free list. */
186- xtWord2 tab_ind_flush_seq;
187+ xtWord4 tab_ind_flush_seq;
188 } XTTableHRec, *XTTableHPtr; /* Heap pointer */
189
190 /* Used for an in-memory list of the tables, ordered by ID. */
191
192=== modified file 'src/thread_xt.cc'
193--- src/thread_xt.cc 2010-01-19 15:08:28 +0000
194+++ src/thread_xt.cc 2010-03-02 17:45:28 +0000
195@@ -413,8 +413,8 @@
196 vsnprintf(e->e_err_msg, XT_ERR_MSG_SIZE, fmt, ap);
197
198 /* Make the first character of the message upper case: */
199- if (isalpha(e->e_err_msg[0]) && islower(e->e_err_msg[0]))
200- e->e_err_msg[0] = (char) toupper(e->e_err_msg[0]);
201+ //if (isalpha(e->e_err_msg[0]) && islower(e->e_err_msg[0]))
202+ // e->e_err_msg[0] = (char) toupper(e->e_err_msg[0]);
203
204 if (func && *func && *func != '-')
205 xt_strcpy_term(XT_MAX_FUNC_NAME_SIZE, e->e_func_name, func, '(');

Subscribers

People subscribed via source and target branches