~percona-dev/percona-server/5.1.57-12-rnt

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
# name       : innodb_extra_rseg.patch
# introduced : 11 or before
# maintainer : Yasufumi
#
#!!! notice !!!
# Any small change to this file in the main branch
# should be done or reviewed by the maintainer!
diff -ruN a/storage/innodb_plugin/handler/ha_innodb.cc b/storage/innodb_plugin/handler/ha_innodb.cc
--- a/storage/innodb_plugin/handler/ha_innodb.cc	2010-08-27 15:56:27.388990435 +0900
+++ b/storage/innodb_plugin/handler/ha_innodb.cc	2010-08-27 15:57:21.943242617 +0900
@@ -11177,6 +11177,11 @@
   "Enable/Disable unsafe group commit when support_xa=OFF and use with binlog or other XA storage engine.",
   NULL, NULL, 0, 0, 1, 0);
 
+static MYSQL_SYSVAR_ULONG(extra_rsegments, srv_extra_rsegments,
+  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
+  "Number of extra user rollback segments when create new database.",
+  NULL, NULL, 0, 0, 126, 0);
+
 static struct st_mysql_sys_var* innobase_system_variables[]= {
   MYSQL_SYSVAR(additional_mem_pool_size),
   MYSQL_SYSVAR(autoextend_increment),
@@ -11242,6 +11247,7 @@
   MYSQL_SYSVAR(adaptive_checkpoint),
   MYSQL_SYSVAR(flush_log_at_trx_commit_session),
   MYSQL_SYSVAR(enable_unsafe_group_commit),
+  MYSQL_SYSVAR(extra_rsegments),
   MYSQL_SYSVAR(use_sys_malloc),
   MYSQL_SYSVAR(change_buffering),
 #if defined UNIV_DEBUG || defined UNIV_IBUF_DEBUG
@@ -11267,6 +11273,7 @@
   innobase_system_variables, /* system variables */
   NULL /* reserved */
 },
+i_s_innodb_rseg,
 i_s_innodb_buffer_pool_pages,
 i_s_innodb_buffer_pool_pages_index,
 i_s_innodb_buffer_pool_pages_blob,
diff -ruN a/storage/innodb_plugin/handler/i_s.cc b/storage/innodb_plugin/handler/i_s.cc
--- a/storage/innodb_plugin/handler/i_s.cc	2010-08-27 15:55:39.396056760 +0900
+++ b/storage/innodb_plugin/handler/i_s.cc	2010-08-27 15:57:21.946209184 +0900
@@ -43,6 +43,8 @@
 #include "ha_prototypes.h" /* for innobase_convert_name() */
 #include "srv0start.h" /* for srv_was_started */
 #include "btr0btr.h" /* for btr_page_get_index_id */
+#include "trx0rseg.h" /* for trx_rseg_struct */
+#include "trx0sys.h" /* for trx_sys */
 }
 
 static const char plugin_author[] = "Innobase Oy";
@@ -2435,3 +2437,166 @@
 
 	DBUG_RETURN(0);
 }
+
+/***********************************************************************
+*/
+static ST_FIELD_INFO	i_s_innodb_rseg_fields_info[] =
+{
+	{STRUCT_FLD(field_name,		"rseg_id"),
+	 STRUCT_FLD(field_length,	MY_INT64_NUM_DECIMAL_DIGITS),
+	 STRUCT_FLD(field_type,		MYSQL_TYPE_LONGLONG),
+	 STRUCT_FLD(value,		0),
+	 STRUCT_FLD(field_flags,	MY_I_S_UNSIGNED),
+	 STRUCT_FLD(old_name,		""),
+	 STRUCT_FLD(open_method,	SKIP_OPEN_TABLE)},
+
+	{STRUCT_FLD(field_name,		"space_id"),
+	 STRUCT_FLD(field_length,	MY_INT64_NUM_DECIMAL_DIGITS),
+	 STRUCT_FLD(field_type,		MYSQL_TYPE_LONGLONG),
+	 STRUCT_FLD(value,		0),
+	 STRUCT_FLD(field_flags,	MY_I_S_UNSIGNED),
+	 STRUCT_FLD(old_name,		""),
+	 STRUCT_FLD(open_method,	SKIP_OPEN_TABLE)},
+
+	{STRUCT_FLD(field_name,		"zip_size"),
+	 STRUCT_FLD(field_length,	MY_INT64_NUM_DECIMAL_DIGITS),
+	 STRUCT_FLD(field_type,		MYSQL_TYPE_LONGLONG),
+	 STRUCT_FLD(value,		0),
+	 STRUCT_FLD(field_flags,	MY_I_S_UNSIGNED),
+	 STRUCT_FLD(old_name,		""),
+	 STRUCT_FLD(open_method,	SKIP_OPEN_TABLE)},
+
+	{STRUCT_FLD(field_name,		"page_no"),
+	 STRUCT_FLD(field_length,	MY_INT64_NUM_DECIMAL_DIGITS),
+	 STRUCT_FLD(field_type,		MYSQL_TYPE_LONGLONG),
+	 STRUCT_FLD(value,		0),
+	 STRUCT_FLD(field_flags,	MY_I_S_UNSIGNED),
+	 STRUCT_FLD(old_name,		""),
+	 STRUCT_FLD(open_method,	SKIP_OPEN_TABLE)},
+
+	{STRUCT_FLD(field_name,		"max_size"),
+	 STRUCT_FLD(field_length,	MY_INT64_NUM_DECIMAL_DIGITS),
+	 STRUCT_FLD(field_type,		MYSQL_TYPE_LONGLONG),
+	 STRUCT_FLD(value,		0),
+	 STRUCT_FLD(field_flags,	MY_I_S_UNSIGNED),
+	 STRUCT_FLD(old_name,		""),
+	 STRUCT_FLD(open_method,	SKIP_OPEN_TABLE)},
+
+	{STRUCT_FLD(field_name,		"curr_size"),
+	 STRUCT_FLD(field_length,	MY_INT64_NUM_DECIMAL_DIGITS),
+	 STRUCT_FLD(field_type,		MYSQL_TYPE_LONGLONG),
+	 STRUCT_FLD(value,		0),
+	 STRUCT_FLD(field_flags,	MY_I_S_UNSIGNED),
+	 STRUCT_FLD(old_name,		""),
+	 STRUCT_FLD(open_method,	SKIP_OPEN_TABLE)},
+
+	END_OF_ST_FIELD_INFO
+};
+
+static
+int
+i_s_innodb_rseg_fill(
+/*=================*/
+	THD*		thd,	/* in: thread */
+	TABLE_LIST*	tables,	/* in/out: tables to fill */
+	COND*		cond)	/* in: condition (ignored) */
+{
+	TABLE*	table	= (TABLE *) tables->table;
+	int	status	= 0;
+	trx_rseg_t*	rseg;
+
+	DBUG_ENTER("i_s_innodb_rseg_fill");
+
+	/* deny access to non-superusers */
+	if (check_global_access(thd, PROCESS_ACL)) {
+
+		DBUG_RETURN(0);
+	}
+
+	RETURN_IF_INNODB_NOT_STARTED(tables->schema_table_name);
+
+	rseg = UT_LIST_GET_FIRST(trx_sys->rseg_list);
+
+	while (rseg) {
+		table->field[0]->store(rseg->id);
+		table->field[1]->store(rseg->space);
+		table->field[2]->store(rseg->zip_size);
+		table->field[3]->store(rseg->page_no);
+		table->field[4]->store(rseg->max_size);
+		table->field[5]->store(rseg->curr_size);
+
+		if (schema_table_store_record(thd, table)) {
+			status = 1;
+			break;
+		}
+
+		rseg = UT_LIST_GET_NEXT(rseg_list, rseg);
+	}
+
+	DBUG_RETURN(status);
+}
+
+static
+int
+i_s_innodb_rseg_init(
+/*=================*/
+			/* out: 0 on success */
+	void*	p)	/* in/out: table schema object */
+{
+	DBUG_ENTER("i_s_innodb_rseg_init");
+	ST_SCHEMA_TABLE* schema = (ST_SCHEMA_TABLE*) p;
+
+	schema->fields_info = i_s_innodb_rseg_fields_info;
+	schema->fill_table = i_s_innodb_rseg_fill;
+
+	DBUG_RETURN(0);
+}
+
+UNIV_INTERN struct st_mysql_plugin	i_s_innodb_rseg =
+{
+	/* the plugin type (a MYSQL_XXX_PLUGIN value) */
+	/* int */
+	STRUCT_FLD(type, MYSQL_INFORMATION_SCHEMA_PLUGIN),
+
+	/* pointer to type-specific plugin descriptor */
+	/* void* */
+	STRUCT_FLD(info, &i_s_info),
+
+	/* plugin name */
+	/* const char* */
+	STRUCT_FLD(name, "INNODB_RSEG"),
+
+	/* plugin author (for SHOW PLUGINS) */
+	/* const char* */
+	STRUCT_FLD(author, "Percona"),
+
+	/* general descriptive text (for SHOW PLUGINS) */
+	/* const char* */
+	STRUCT_FLD(descr, "InnoDB rollback segment information"),
+
+	/* the plugin license (PLUGIN_LICENSE_XXX) */
+	/* int */
+	STRUCT_FLD(license, PLUGIN_LICENSE_GPL),
+
+	/* the function to invoke when plugin is loaded */
+	/* int (*)(void*); */
+	STRUCT_FLD(init, i_s_innodb_rseg_init),
+
+	/* the function to invoke when plugin is unloaded */
+	/* int (*)(void*); */
+	STRUCT_FLD(deinit, i_s_common_deinit),
+
+	/* plugin version (for SHOW PLUGINS) */
+	/* unsigned int */
+	STRUCT_FLD(version, 0x0100 /* 1.0 */),
+
+	/* struct st_mysql_show_var* */
+	STRUCT_FLD(status_vars, NULL),
+
+	/* struct st_mysql_sys_var** */
+	STRUCT_FLD(system_vars, NULL),
+
+	/* reserved for dependency checking */
+	/* void* */
+	STRUCT_FLD(__reserved1, NULL)
+};
diff -ruN a/storage/innodb_plugin/handler/i_s.h b/storage/innodb_plugin/handler/i_s.h
--- a/storage/innodb_plugin/handler/i_s.h	2010-08-27 15:55:39.398061420 +0900
+++ b/storage/innodb_plugin/handler/i_s.h	2010-08-27 15:57:21.948402335 +0900
@@ -37,5 +37,6 @@
 extern struct st_mysql_plugin	i_s_innodb_cmpmem;
 extern struct st_mysql_plugin	i_s_innodb_cmpmem_reset;
 extern struct st_mysql_plugin	i_s_innodb_patches;
+extern struct st_mysql_plugin	i_s_innodb_rseg;
 
 #endif /* i_s_h */
diff -ruN a/storage/innodb_plugin/handler/innodb_patch_info.h b/storage/innodb_plugin/handler/innodb_patch_info.h
--- a/storage/innodb_plugin/handler/innodb_patch_info.h	2010-08-27 15:56:27.390020919 +0900
+++ b/storage/innodb_plugin/handler/innodb_patch_info.h	2010-08-27 15:57:21.943242617 +0900
@@ -29,5 +29,6 @@
 {"innodb_opt_lru_count","Fix of buffer_pool mutex","Decreases contention on buffer_pool mutex on LRU operations","http://www.percona.com/docs/wiki/percona-xtradb"},
 {"innodb_buffer_pool_pages","Information of buffer pool content","","http://www.percona.com/docs/wiki/percona-xtradb"},
 {"innodb_expand_undo_slots","expandable maximum number of undo slots","from 1024 (default) to about 4000","http://www.percona.com/docs/wiki/percona-xtradb"},
+{"innodb_extra_rseg","allow to create extra rollback segments","When create new db, the new parameter allows to create more rollback segments","http://www.percona.com/docs/wiki/percona-xtradb"},
 {NULL, NULL, NULL, NULL}
 };
diff -ruN a/storage/innodb_plugin/include/srv0srv.h b/storage/innodb_plugin/include/srv0srv.h
--- a/storage/innodb_plugin/include/srv0srv.h	2010-08-27 15:56:27.391059197 +0900
+++ b/storage/innodb_plugin/include/srv0srv.h	2010-08-27 15:57:21.949178913 +0900
@@ -216,6 +216,8 @@
 extern ulint	srv_read_ahead;
 extern ulint	srv_adaptive_checkpoint;
 
+extern ulint	srv_extra_rsegments;
+
 /*-------------------------------------------*/
 
 extern ulint	srv_n_rows_inserted;
diff -ruN a/storage/innodb_plugin/include/trx0rseg.h b/storage/innodb_plugin/include/trx0rseg.h
--- a/storage/innodb_plugin/include/trx0rseg.h	2010-08-27 15:56:27.392056954 +0900
+++ b/storage/innodb_plugin/include/trx0rseg.h	2010-08-27 15:57:21.951103043 +0900
@@ -114,6 +114,17 @@
 /*=========================*/
 	trx_sysf_t*	sys_header,	/*!< in: trx system header */
 	mtr_t*		mtr);		/*!< in: mtr */
+/****************************************************************//**
+Creates a new rollback segment to the database.
+@return	the created segment object, NULL if fail */
+UNIV_INTERN
+trx_rseg_t*
+trx_rseg_create(
+/*============*/
+	ulint	space,		/*!< in: space id */
+	ulint	max_size,	/*!< in: max size in pages */
+	ulint*	id,		/*!< out: rseg id */
+	mtr_t*	mtr);		/*!< in: mtr */
 /***************************************************************************
 Free's an instance of the rollback segment in memory. */
 UNIV_INTERN
diff -ruN a/storage/innodb_plugin/include/trx0sys.h b/storage/innodb_plugin/include/trx0sys.h
--- a/storage/innodb_plugin/include/trx0sys.h	2010-08-04 02:24:19.000000000 +0900
+++ b/storage/innodb_plugin/include/trx0sys.h	2010-08-27 15:57:21.952410637 +0900
@@ -134,6 +134,13 @@
 void
 trx_sys_create(void);
 /*================*/
+/*********************************************************************
+Create extra rollback segments when create_new_db */
+UNIV_INTERN
+void
+trx_sys_create_extra_rseg(
+/*======================*/
+	ulint	num);	/* in: number of extra user rollback segments */
 /****************************************************************//**
 Looks for a free slot for a rollback segment in the trx system file copy.
 @return	slot index or ULINT_UNDEFINED if not found */
diff -ruN a/storage/innodb_plugin/srv/srv0srv.c b/storage/innodb_plugin/srv/srv0srv.c
--- a/storage/innodb_plugin/srv/srv0srv.c	2010-08-27 15:56:27.393071672 +0900
+++ b/storage/innodb_plugin/srv/srv0srv.c	2010-08-27 15:57:21.956058333 +0900
@@ -388,6 +388,8 @@
 UNIV_INTERN ulint	srv_enable_unsafe_group_commit = 0; /* 0:disable 1:enable */
 UNIV_INTERN ulint	srv_read_ahead = 3; /* 1: random  2: linear  3: Both */
 UNIV_INTERN ulint	srv_adaptive_checkpoint = 0; /* 0: none  1: reflex  2: estimate */
+
+UNIV_INTERN ulint	srv_extra_rsegments = 0; /* extra rseg for users */
 /*-------------------------------------------*/
 UNIV_INTERN ulong	srv_n_spin_wait_rounds	= 30;
 UNIV_INTERN ulong	srv_n_free_tickets_to_enter = 500;
diff -ruN a/storage/innodb_plugin/srv/srv0start.c b/storage/innodb_plugin/srv/srv0start.c
--- a/storage/innodb_plugin/srv/srv0start.c	2010-08-27 15:54:18.103988092 +0900
+++ b/storage/innodb_plugin/srv/srv0start.c	2010-08-27 15:57:21.959058733 +0900
@@ -1533,6 +1533,14 @@
 		dict_create();
 		srv_startup_is_before_trx_rollback_phase = FALSE;
 
+		if (trx_doublewrite == NULL) {
+			/* Create the doublewrite buffer here to avoid assertion error
+			   about page_no of doublewrite_buf */
+			trx_sys_create_doublewrite_buf();
+		}
+
+		if (srv_extra_rsegments)
+			trx_sys_create_extra_rseg(srv_extra_rsegments);
 #ifdef UNIV_LOG_ARCHIVE
 	} else if (srv_archive_recovery) {
 		fprintf(stderr,
diff -ruN a/storage/innodb_plugin/trx/trx0rseg.c b/storage/innodb_plugin/trx/trx0rseg.c
--- a/storage/innodb_plugin/trx/trx0rseg.c	2010-08-04 02:24:20.000000000 +0900
+++ b/storage/innodb_plugin/trx/trx0rseg.c	2010-08-27 15:57:21.961059126 +0900
@@ -286,3 +286,39 @@
 		}
 	}
 }
+
+/****************************************************************//**
+Creates a new rollback segment to the database.
+@return	the created segment object, NULL if fail */
+UNIV_INTERN
+trx_rseg_t*
+trx_rseg_create(
+/*============*/
+	ulint	space,		/*!< in: space id */
+	ulint	max_size,	/*!< in: max size in pages */
+	ulint*	id,		/*!< out: rseg id */
+	mtr_t*	mtr)		/*!< in: mtr */
+{
+	ulint		flags;
+	ulint		zip_size;
+	ulint		page_no;
+	trx_rseg_t*	rseg;
+
+	mtr_x_lock(fil_space_get_latch(space, &flags), mtr);
+	zip_size = dict_table_flags_to_zip_size(flags);
+	mutex_enter(&kernel_mutex);
+
+	page_no = trx_rseg_header_create(space, zip_size, max_size, id, mtr);
+
+	if (page_no == FIL_NULL) {
+
+		mutex_exit(&kernel_mutex);
+		return(NULL);
+	}
+
+	rseg = trx_rseg_mem_create(*id, space, zip_size, page_no, mtr);
+
+	mutex_exit(&kernel_mutex);
+
+	return(rseg);
+}
diff -ruN a/storage/innodb_plugin/trx/trx0sys.c b/storage/innodb_plugin/trx/trx0sys.c
--- a/storage/innodb_plugin/trx/trx0sys.c	2010-08-04 02:24:20.000000000 +0900
+++ b/storage/innodb_plugin/trx/trx0sys.c	2010-08-27 15:57:21.963058358 +0900
@@ -1044,6 +1044,31 @@
 	trx_sys_init_at_db_start();
 }
 
+/*********************************************************************
+Create extra rollback segments when create_new_db */
+UNIV_INTERN
+void
+trx_sys_create_extra_rseg(
+/*======================*/
+	ulint	num)	/* in: number of extra user rollback segments */
+{
+	mtr_t	mtr;
+	ulint	slot_no;
+	ulint	i;
+
+	/* Craete extra rollback segments */
+	mtr_start(&mtr);
+	for (i = 1; i < num + 1; i++) {
+		if(!trx_rseg_create(TRX_SYS_SPACE, ULINT_MAX, &slot_no, &mtr)) {
+			fprintf(stderr,
+"InnoDB: Warning: Failed to create extra rollback segments.\n");
+			break;
+		}
+		ut_a(slot_no == i);
+	}
+	mtr_commit(&mtr);
+}
+
 /*****************************************************************//**
 Update the file format tag.
 @return	always TRUE */