Merge lp:~vkolesnikov/pbxt/pbxt-mem-debugger-and-leaks into lp:pbxt

Proposed by Vladimir Kolesnikov
Status: Merged
Merged at revision: not available
Proposed branch: lp:~vkolesnikov/pbxt/pbxt-mem-debugger-and-leaks
Merge into: lp:pbxt
Diff against target: None lines
To merge this branch: bzr merge lp:~vkolesnikov/pbxt/pbxt-mem-debugger-and-leaks
Reviewer Review Type Date Requested Status
PBXT Core Pending
Review via email: mp+4378@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Paul McCullagh (paul-mccullagh) wrote :

Hi Vlad,

I am wondering why this is necessary!

Surely "fkey->co_name" should be freed by: key->release(self).

key->release(self) should call XTDDConstraint::finalize():

 virtual void finalize(XTThreadPtr self) {
  if (co_name)
   xt_free(self, co_name);
  if (co_ind_name)
   xt_free(self, co_ind_name);
  co_cols.deleteAll(self);
  XTObject::finalize(self);
 }

fkey is a XTDDForeignKey which is a XTDDIndex which is a XTDDConstraint.

On Mar 11, 2009, at 4:45 PM, Vladimir Kolesnikov wrote:

> === modified file 'src/datadic_xt.cc'
> --- src/datadic_xt.cc 2009-01-21 13:55:57 +0000
> +++ src/datadic_xt.cc 2009-03-11 15:38:29 +0000
> @@ -1513,6 +1513,7 @@
> for (i=0; i<ct_curr_table->dt_fkeys.size(); i++) {
> fkey = ct_curr_table->dt_fkeys.itemAt(i);
> if (fkey->co_name && myxt_strcasecmp(con_name, fkey->co_name) ==
> 0) {
> + xt_free(self, fkey->co_name);
> ct_curr_table->dt_fkeys.remove(fkey);
> fkey->release(self);
> }

--
Paul McCullagh
PrimeBase Technologies
www.primebase.org
www.blobstreaming.org
pbxt.blogspot.com

Revision history for this message
Vladimir Kolesnikov (vkolesnikov) wrote :

Hi Paul,

please ignore the change to src/datadic_xt.cc. I think I made it prior to making the real fix (in the ha_pbxt.cc) and then forgot to recheck it. I just retested it and no leaks are reported w/o that line.

582. By Vladimir Kolesnikov

merge from upstream

583. By Vladimir Kolesnikov

removed unneeded change

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ChangeLog'
2--- ChangeLog 2009-03-05 15:28:42 +0000
3+++ ChangeLog 2009-03-10 17:43:39 +0000
4@@ -3,6 +3,10 @@
5
6 ------- 1.0.08 RC - Not yet released
7
8+RN226: Fixed bug #340316: Issue with bigint unsigned auto-increment field
9+
10+RN225: Fixed bug #308557: UPDATE fails to match all rows in a transactional scenario
11+
12 RN224: Fixed a deadlock which could occur during table scans.
13
14 RN223: Index scans now use handles to cache buffers instead of making a copy of the index page. The handles are "copy-on-write".
15
16=== modified file 'src/datadic_xt.cc'
17--- src/datadic_xt.cc 2009-01-21 13:55:57 +0000
18+++ src/datadic_xt.cc 2009-03-11 15:38:29 +0000
19@@ -1513,6 +1513,7 @@
20 for (i=0; i<ct_curr_table->dt_fkeys.size(); i++) {
21 fkey = ct_curr_table->dt_fkeys.itemAt(i);
22 if (fkey->co_name && myxt_strcasecmp(con_name, fkey->co_name) == 0) {
23+ xt_free(self, fkey->co_name);
24 ct_curr_table->dt_fkeys.remove(fkey);
25 fkey->release(self);
26 }
27
28=== modified file 'src/ha_pbxt.cc'
29--- src/ha_pbxt.cc 2009-02-27 09:22:44 +0000
30+++ src/ha_pbxt.cc 2009-03-11 15:38:29 +0000
31@@ -2065,7 +2065,7 @@
32 MX_ULONGLONG_T *nb_reserved_values __attribute__((unused)))
33 {
34 register XTTableHPtr tab;
35- MX_ULONGLONG_T nr;
36+ MX_ULONGLONG_T nr, nr_plus_inc;
37
38 ASSERT_NS(pb_ex_in_use);
39
40@@ -2077,7 +2077,11 @@
41 nr = offset;
42 else if (increment > 1 && ((nr - offset) % increment) != 0)
43 nr += increment - ((nr - offset) % increment);
44- tab->tab_auto_inc = (xtWord8) (nr + increment);
45+ nr_plus_inc = nr + increment;
46+ if (table->next_number_field->cmp((const unsigned char *)&nr, (const unsigned char *)&nr_plus_inc) < 0)
47+ tab->tab_auto_inc = (xtWord8) (nr_plus_inc);
48+ else
49+ nr = ~0; /* indicate error to the caller */
50 xt_spinlock_unlock(&tab->tab_ainc_lock);
51
52 *first_value = nr;
53@@ -2091,25 +2095,34 @@
54 * insert into t1 values (-1);
55 * insert into t1 values (NULL);
56 */
57-void ha_pbxt::set_auto_increment(MX_LONGLONG_T nr)
58+void ha_pbxt::set_auto_increment(Field *nr)
59 {
60 register XTTableHPtr tab;
61+ MX_ULONGLONG_T nr_int_val;
62+
63+ nr_int_val = nr->val_int();
64+ tab = pb_open_tab->ot_table;
65
66- tab = pb_open_tab->ot_table;
67- if ((MX_LONGLONG_T) tab->tab_auto_inc <= nr) {
68+ if (nr->cmp((const unsigned char *)&tab->tab_auto_inc) > 0) {
69 xt_spinlock_lock(&tab->tab_ainc_lock);
70- if ((MX_LONGLONG_T) tab->tab_auto_inc <= nr && nr > 0)
71- tab->tab_auto_inc = nr + 1;
72+
73+ if (nr->cmp((const unsigned char *)&tab->tab_auto_inc) > 0) {
74+ MX_ULONGLONG_T nr_int_val_plus_one = nr_int_val + 1;
75+ if (nr->cmp((const unsigned char *)&nr_int_val_plus_one) < 0)
76+ tab->tab_auto_inc = nr_int_val_plus_one;
77+ else
78+ tab->tab_auto_inc = nr_int_val;
79+ }
80 xt_spinlock_unlock(&tab->tab_ainc_lock);
81 }
82
83 if (xt_db_auto_increment_mode == 1) {
84- if (nr > (MX_LONGLONG_T) tab->tab_dic.dic_min_auto_inc) {
85+ if (nr_int_val > (MX_ULONGLONG_T) tab->tab_dic.dic_min_auto_inc) {
86 /* Do this every 100 calls: */
87 #ifdef DEBUG
88- tab->tab_dic.dic_min_auto_inc = nr + 5;
89+ tab->tab_dic.dic_min_auto_inc = nr_int_val + 5;
90 #else
91- tab->tab_dic.dic_min_auto_inc = nr + 100;
92+ tab->tab_dic.dic_min_auto_inc = nr_int_val + 100;
93 #endif
94 pb_open_tab->ot_thread = xt_get_self();
95 if (!xt_tab_write_min_auto_inc(pb_open_tab))
96@@ -2187,8 +2200,12 @@
97 table->timestamp_field->set_time();
98
99 if (table->next_number_field && buf == table->record[0]) {
100- update_auto_increment();
101- set_auto_increment(table->next_number_field->val_int());
102+ int err = update_auto_increment();
103+ if (err) {
104+ ha_log_pbxt_thread_error_for_mysql(pb_ignore_dup_key);
105+ return err;
106+ }
107+ set_auto_increment(table->next_number_field);
108 }
109
110 if (!xt_tab_new_record(pb_open_tab, (xtWord1 *) buf))
111@@ -2281,8 +2298,8 @@
112
113 old_map = mx_tmp_use_all_columns(table, table->read_set);
114 nr = table->found_next_number_field->val_int();
115+ set_auto_increment(table->found_next_number_field);
116 mx_tmp_restore_column_map(table, old_map);
117- set_auto_increment(nr);
118 }
119
120 if (!xt_tab_update_record(pb_open_tab, (xtWord1 *) old_data, (xtWord1 *) new_data))
121@@ -4788,6 +4805,8 @@
122 xt_create_table(self, (XTPathStrPtr) table_path, &dic);
123 }
124 catch_(a) {
125+ if (tab_def)
126+ tab_def->finalize(self);
127 err = xt_ha_pbxt_thread_error_for_mysql(thd, self, pb_ignore_dup_key);
128 }
129 cont_(a);
130
131=== modified file 'src/ha_pbxt.h'
132--- src/ha_pbxt.h 2008-12-10 20:34:30 +0000
133+++ src/ha_pbxt.h 2009-03-10 17:43:39 +0000
134@@ -171,7 +171,7 @@
135 MX_ULONGLONG_T nb_desired_values,
136 MX_ULONGLONG_T *first_value,
137 MX_ULONGLONG_T *nb_reserved_values);
138- void set_auto_increment(MX_LONGLONG_T nr);
139+ void set_auto_increment(Field *nr);
140
141 int write_row(byte * buf);
142 int update_row(const byte * old_data, byte * new_data);
143
144=== modified file 'src/index_xt.cc'
145--- src/index_xt.cc 2009-03-06 13:40:00 +0000
146+++ src/index_xt.cc 2009-03-10 08:28:54 +0000
147@@ -2327,7 +2327,9 @@
148 #endif
149 ASSERT_NS(ot->ot_ind_rhandle);
150 xt_ind_lock_handle(ot->ot_ind_rhandle);
151- if (!ot->ot_ind_state.i_node_ref_size && ot->ot_ind_state.i_item_offset < ot->ot_ind_state.i_total_size) {
152+ if (!ot->ot_ind_state.i_node_ref_size &&
153+ ot->ot_ind_state.i_item_offset < ot->ot_ind_state.i_total_size &&
154+ ot->ot_ind_rhandle->ih_cache_reference) {
155 key_value.sv_key = &ot->ot_ind_rhandle->ih_branch->tb_data[ot->ot_ind_state.i_item_offset];
156 key_value.sv_length = ot->ot_ind_state.i_item_size - XT_RECORD_REF_SIZE;
157
158
159=== modified file 'src/memory_xt.cc'
160--- src/memory_xt.cc 2009-02-05 11:30:34 +0000
161+++ src/memory_xt.cc 2009-03-11 15:38:29 +0000
162@@ -376,7 +376,7 @@
163 /* Not enough space, add more: */
164 MissingMemoryRec *new_addresses;
165
166- new_addresses = (MissingMemoryRec *) malloc(sizeof(MissingMemoryRec) * (mm_total_allocated + ADD_TOTAL_ALLOCS));
167+ new_addresses = (MissingMemoryRec *) xt_calloc_ns(sizeof(MissingMemoryRec) * (mm_total_allocated + ADD_TOTAL_ALLOCS));
168 if (!new_addresses)
169 return(-1);
170
171
172=== modified file 'test/mysql-test/r/pbxt_bugs.result'
173--- test/mysql-test/r/pbxt_bugs.result 2008-12-16 13:39:34 +0000
174+++ test/mysql-test/r/pbxt_bugs.result 2009-03-11 11:18:00 +0000
175@@ -986,3 +986,62 @@
176 insert into t1 values ("1");
177 insert into t2 values ("1");
178 DROP TABLE IF EXISTS t2,t1;
179+DROP TABLE IF EXISTS t5;
180+CREATE TABLE t5 (
181+c1 BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
182+c2 BIGINT SIGNED NULL,
183+c3 BIGINT SIGNED NOT NULL,
184+c4 TINYINT, c5 SMALLINT,
185+c6 MEDIUMINT,
186+c7 INT,
187+c8 INTEGER,
188+PRIMARY KEY(c1,c2), UNIQUE INDEX(c3));
189+INSERT INTO t5 VALUES
190+(0,-9223372036854775808,1,2,3,4,5,5),
191+(255,-2147483648,6,7,8,9,10,10),
192+(65535,-8388608,11,12,13,14,15,15),
193+(16777215,-32768,16,17,18,19,20,20),
194+(4294967295,-128,21,22,23,24,25,25),
195+(18446744073709551615,9223372036854775807,26,27,28,29,30,30);
196+INSERT INTO t5(c2,c3) VALUES(33,34) /* tries to increment out of range */;
197+ERROR HY000: Failed to read auto-increment value from storage engine
198+INSERT INTO t5(c2,c3) VALUES(33,34);
199+ERROR HY000: Failed to read auto-increment value from storage engine
200+SELECT * FROM t5;
201+c1 c2 c3 c4 c5 c6 c7 c8
202+1 -9223372036854775808 1 2 3 4 5 5
203+255 -2147483648 6 7 8 9 10 10
204+65535 -8388608 11 12 13 14 15 15
205+16777215 -32768 16 17 18 19 20 20
206+4294967295 -128 21 22 23 24 25 25
207+18446744073709551615 9223372036854775807 26 27 28 29 30 30
208+DROP TABLE t5;
209+/* same test as above with signed bigint */
210+CREATE TABLE t5 (
211+c1 BIGINT SIGNED NOT NULL AUTO_INCREMENT,
212+c2 BIGINT SIGNED NULL,
213+c3 BIGINT SIGNED NOT NULL,
214+c4 TINYINT, c5 SMALLINT,
215+c6 MEDIUMINT,
216+c7 INT,
217+c8 INTEGER,
218+PRIMARY KEY(c1,c2), UNIQUE INDEX(c3));
219+INSERT INTO t5 VALUES
220+(0,-9223372036854775808,1,2,3,4,5,5),
221+(255,-2147483648,6,7,8,9,10,10),
222+(65535,-8388608,11,12,13,14,15,15),
223+(16777215,-32768,16,17,18,19,20,20),
224+(4294967295,-128,21,22,23,24,25,25),
225+(9223372036854775807,9223372036854775807,26,27,28,29,30,30);
226+INSERT INTO t5(c2,c3) VALUES(33,34) /* tries to increment out of range */;
227+ERROR HY000: Failed to read auto-increment value from storage engine
228+INSERT INTO t5(c2,c3) VALUES(33,34);
229+ERROR HY000: Failed to read auto-increment value from storage engine
230+SELECT * FROM t5;
231+c1 c2 c3 c4 c5 c6 c7 c8
232+1 -9223372036854775808 1 2 3 4 5 5
233+255 -2147483648 6 7 8 9 10 10
234+65535 -8388608 11 12 13 14 15 15
235+16777215 -32768 16 17 18 19 20 20
236+4294967295 -128 21 22 23 24 25 25
237+9223372036854775807 9223372036854775807 26 27 28 29 30 30
238
239=== modified file 'test/mysql-test/t/pbxt_bugs.test'
240--- test/mysql-test/t/pbxt_bugs.test 2008-12-16 13:39:34 +0000
241+++ test/mysql-test/t/pbxt_bugs.test 2009-03-11 11:18:00 +0000
242@@ -807,3 +807,61 @@
243 insert into t2 values ("1");
244
245 DROP TABLE IF EXISTS t2,t1;
246+
247+# bug 340316: Issue with bigint unsigned auto-increment field
248+
249+--disable_warnings
250+DROP TABLE IF EXISTS t5;
251+--enable_warnings
252+CREATE TABLE t5 (
253+ c1 BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
254+ c2 BIGINT SIGNED NULL,
255+ c3 BIGINT SIGNED NOT NULL,
256+ c4 TINYINT, c5 SMALLINT,
257+ c6 MEDIUMINT,
258+ c7 INT,
259+ c8 INTEGER,
260+ PRIMARY KEY(c1,c2), UNIQUE INDEX(c3));
261+
262+INSERT INTO t5 VALUES
263+ (0,-9223372036854775808,1,2,3,4,5,5),
264+ (255,-2147483648,6,7,8,9,10,10),
265+ (65535,-8388608,11,12,13,14,15,15),
266+ (16777215,-32768,16,17,18,19,20,20),
267+ (4294967295,-128,21,22,23,24,25,25),
268+ (18446744073709551615,9223372036854775807,26,27,28,29,30,30);
269+
270+--error 1467
271+INSERT INTO t5(c2,c3) VALUES(33,34) /* tries to increment out of range */;
272+--error 1467
273+INSERT INTO t5(c2,c3) VALUES(33,34);
274+
275+SELECT * FROM t5;
276+
277+DROP TABLE t5;
278+
279+/* same test as above with signed bigint */
280+CREATE TABLE t5 (
281+ c1 BIGINT SIGNED NOT NULL AUTO_INCREMENT,
282+ c2 BIGINT SIGNED NULL,
283+ c3 BIGINT SIGNED NOT NULL,
284+ c4 TINYINT, c5 SMALLINT,
285+ c6 MEDIUMINT,
286+ c7 INT,
287+ c8 INTEGER,
288+ PRIMARY KEY(c1,c2), UNIQUE INDEX(c3));
289+
290+INSERT INTO t5 VALUES
291+ (0,-9223372036854775808,1,2,3,4,5,5),
292+ (255,-2147483648,6,7,8,9,10,10),
293+ (65535,-8388608,11,12,13,14,15,15),
294+ (16777215,-32768,16,17,18,19,20,20),
295+ (4294967295,-128,21,22,23,24,25,25),
296+ (9223372036854775807,9223372036854775807,26,27,28,29,30,30);
297+
298+--error 1467
299+INSERT INTO t5(c2,c3) VALUES(33,34) /* tries to increment out of range */;
300+--error 1467
301+INSERT INTO t5(c2,c3) VALUES(33,34);
302+
303+SELECT * FROM t5;

Subscribers

People subscribed via source and target branches