~drizzle-trunk/drizzle/development

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
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
--- a/storage/innobase/btr/btr0btr.c	2011-03-11 06:29:45.000000000 -0800
+++ b/storage/innobase/btr/btr0btr.c	2011-03-11 06:30:17.000000000 -0800
@@ -515,7 +515,7 @@
 
 /****************************************************************
 Returns the child page of a node pointer and x-latches it. */
-static
+//static
 page_t*
 btr_node_ptr_get_child(
 /*===================*/
--- a/storage/innobase/buf/buf0buf.c	2011-03-11 06:29:45.000000000 -0800
+++ b/storage/innobase/buf/buf0buf.c	2011-03-11 06:30:17.000000000 -0800
@@ -317,7 +317,7 @@
 		return(TRUE);
 	}
 
-#ifndef UNIV_HOTBACKUP
+#ifdef UNDEFINED
 	if (recv_lsn_checks_on && log_peek_lsn(&current_lsn)) {
 		if (ut_dulint_cmp(current_lsn,
 				  mach_read_from_8(read_buf + FIL_PAGE_LSN))
@@ -2083,7 +2083,7 @@
 					  block->space, block->offset);
 		}
 
-		if (!recv_no_ibuf_operations) {
+		if (!recv_no_ibuf_operations && !srv_fake_write) {
 			ibuf_merge_or_delete_for_page(
 				block->frame, block->space, block->offset,
 				TRUE);
--- a/storage/innobase/buf/buf0flu.c	2011-03-11 06:29:45.000000000 -0800
+++ b/storage/innobase/buf/buf0flu.c	2011-03-11 06:30:17.000000000 -0800
@@ -81,6 +81,22 @@
 	prev_b = NULL;
 	b = UT_LIST_GET_FIRST(buf_pool->flush_list);
 
+	if (srv_fast_recovery) {
+	/* speed hack */
+	if (b == NULL || (ut_dulint_cmp(b->oldest_modification,
+					block->oldest_modification) < 0)) {
+		UT_LIST_ADD_FIRST(flush_list, buf_pool->flush_list, block);
+	} else {
+		b = UT_LIST_GET_LAST(buf_pool->flush_list);
+		if (ut_dulint_cmp(b->oldest_modification,
+					block->oldest_modification) < 0) {
+			/* align oldest_modification not to sort */
+			block->oldest_modification = b->oldest_modification;
+		}
+		UT_LIST_ADD_LAST(flush_list, buf_pool->flush_list, block);
+	}
+	} else {
+	/* normal */
 	while (b && (ut_dulint_cmp(b->oldest_modification,
 				   block->oldest_modification) > 0)) {
 		prev_b = b;
@@ -93,6 +109,7 @@
 		UT_LIST_INSERT_AFTER(flush_list, buf_pool->flush_list, prev_b,
 				     block);
 	}
+	}
 
 	ut_ad(buf_flush_validate_low());
 }
--- a/storage/innobase/buf/buf0rea.c	2011-03-11 06:29:45.000000000 -0800
+++ b/storage/innobase/buf/buf0rea.c	2011-03-11 06:30:17.000000000 -0800
@@ -114,6 +114,45 @@
 	block = buf_page_init_for_read(err, mode, space, tablespace_version,
 				       offset);
 	if (block == NULL) {
+		if (recv_recovery_is_on() && *err == DB_TABLESPACE_DELETED) {
+			/* hashed log recs must be treated here */
+			recv_addr_t*    recv_addr;
+
+			mutex_enter(&(recv_sys->mutex));
+
+			if (recv_sys->apply_log_recs == FALSE) {
+				mutex_exit(&(recv_sys->mutex));
+				goto not_to_recover;
+			}
+
+			/* recv_get_fil_addr_struct() */
+			recv_addr = HASH_GET_FIRST(recv_sys->addr_hash,
+					hash_calc_hash(ut_fold_ulint_pair(space, offset),
+						recv_sys->addr_hash));
+			while (recv_addr) {
+				if ((recv_addr->space == space)
+					&& (recv_addr->page_no == offset)) {
+					break;
+				}
+				recv_addr = HASH_GET_NEXT(addr_hash, recv_addr);
+			}
+
+			if ((recv_addr == NULL)
+			    || (recv_addr->state == RECV_BEING_PROCESSED)
+			    || (recv_addr->state == RECV_PROCESSED)) {
+				mutex_exit(&(recv_sys->mutex));
+				goto not_to_recover;
+			}
+
+			fprintf(stderr, " (cannot find space: %lu)", space);
+			recv_addr->state = RECV_PROCESSED;
+
+			ut_a(recv_sys->n_addrs);
+			recv_sys->n_addrs--;
+
+			mutex_exit(&(recv_sys->mutex));
+		}
+not_to_recover:
 
 		return(0);
 	}
@@ -677,11 +716,11 @@
 		while (buf_pool->n_pend_reads >= recv_n_pool_free_frames / 2) {
 
 			os_aio_simulated_wake_handler_threads();
-			os_thread_sleep(500000);
+			os_thread_sleep(10000);
 
 			count++;
 
-			if (count > 100) {
+			if (count > 5000) {
 				fprintf(stderr,
 					"InnoDB: Error: InnoDB has waited for"
 					" 50 seconds for pending\n"
--- a/storage/innobase/fil/fil0fil.c	2011-03-11 06:29:45.000000000 -0800
+++ b/storage/innobase/fil/fil0fil.c	2011-03-11 06:30:17.000000000 -0800
@@ -26,6 +26,9 @@
 #include "mtr0mtr.h"
 #include "mtr0log.h"
 #include "dict0dict.h"
+#include "trx0trx.h"
+#include "trx0sys.h"
+#include "pars0pars.h"
 
 
 /*
@@ -604,9 +607,9 @@
 		}
 
 		if (size_bytes >= FSP_EXTENT_SIZE * UNIV_PAGE_SIZE) {
-			node->size = (ulint)
-				((size_bytes / (1024 * 1024))
-				 * ((1024 * 1024) / UNIV_PAGE_SIZE));
+
+			/* The size should be exact for after applying .delta */
+			node->size = (ulint) (size_bytes / UNIV_PAGE_SIZE);
 		} else {
 			node->size = (ulint) (size_bytes / UNIV_PAGE_SIZE);
 		}
@@ -1957,7 +1960,7 @@
 			if (fil_create_new_single_table_tablespace(
 				    &space_id, name, FALSE,
 				    FIL_IBD_FILE_INITIAL_SIZE) != DB_SUCCESS) {
-				ut_error;
+				//ut_error;
 			}
 		}
 	}
@@ -2116,7 +2119,7 @@
 	}
 
 	if (success) {
-#ifndef UNIV_HOTBACKUP
+#ifdef UNDEFINED
 		/* Write a log record about the deletion of the .ibd
 		file, so that ibbackup can replay it in the
 		--apply-log phase. We use a dummy mtr and the familiar
@@ -2392,7 +2395,7 @@
 
 	mutex_exit(&(system->mutex));
 
-#ifndef UNIV_HOTBACKUP
+#ifdef UNDEFINED
 	if (success) {
 		mtr_t		mtr;
 
@@ -2568,7 +2571,7 @@
 
 	fil_node_create(path, size, *space_id, FALSE);
 
-#ifndef UNIV_HOTBACKUP
+#ifdef UNDEFINED
 	{
 		mtr_t		mtr;
 
@@ -2786,20 +2789,99 @@
 		      "InnoDB: open the tablespace file ", stderr);
 		ut_print_filename(stderr, filepath);
 		fputs("!\n"
-		      "InnoDB: Have you moved InnoDB .ibd files around"
-		      " without using the\n"
-		      "InnoDB: commands DISCARD TABLESPACE and"
-		      " IMPORT TABLESPACE?\n"
-		      "InnoDB: It is also possible that this is"
-		      " a temporary table #sql...,\n"
-		      "InnoDB: and MySQL removed the .ibd file for this.\n"
-		      "InnoDB: Please refer to\n"
-		      "InnoDB: http://dev.mysql.com/doc/refman/5.1/en/"
-		      "innodb-troubleshooting-datadict.html\n"
-		      "InnoDB: for how to resolve the issue.\n", stderr);
+		      "InnoDB: It will be removed from data dictionary.\n"
+		      , stderr);
 
 		mem_free(filepath);
 
+		/* removing from data dictionary */
+		{
+			trx_t*		trx;
+			pars_info_t*	info = NULL;
+
+			trx = trx_allocate_for_mysql();
+
+			trx->op_info = "removing invalid table from data dictionary";
+
+			info = pars_info_create();
+
+			pars_info_add_str_literal(info, "table_name", name);
+
+			que_eval_sql(info,
+			   "PROCEDURE DROP_TABLE_PROC () IS\n"
+			   "sys_foreign_id CHAR;\n"
+			   "table_id CHAR;\n"
+			   "index_id CHAR;\n"
+			   "foreign_id CHAR;\n"
+			   "found INT;\n"
+			   "BEGIN\n"
+			   "SELECT ID INTO table_id\n"
+			   "FROM SYS_TABLES\n"
+			   "WHERE NAME = :table_name\n"
+			   "LOCK IN SHARE MODE;\n"
+			   "IF (SQL % NOTFOUND) THEN\n"
+			   "       COMMIT WORK;\n"
+			   "       RETURN;\n"
+			   "END IF;\n"
+			   "found := 1;\n"
+			   "SELECT ID INTO sys_foreign_id\n"
+			   "FROM SYS_TABLES\n"
+			   "WHERE NAME = 'SYS_FOREIGN'\n"
+			   "LOCK IN SHARE MODE;\n"
+			   "IF (SQL % NOTFOUND) THEN\n"
+			   "       found := 0;\n"
+			   "END IF;\n"
+			   "IF (:table_name = 'SYS_FOREIGN') THEN\n"
+			   "       found := 0;\n"
+			   "END IF;\n"
+			   "IF (:table_name = 'SYS_FOREIGN_COLS') THEN\n"
+			   "       found := 0;\n"
+			   "END IF;\n"
+			   "WHILE found = 1 LOOP\n"
+			   "       SELECT ID INTO foreign_id\n"
+			   "       FROM SYS_FOREIGN\n"
+			   "       WHERE FOR_NAME = :table_name\n"
+			   "               AND TO_BINARY(FOR_NAME)\n"
+			   "                 = TO_BINARY(:table_name)\n"
+			   "               LOCK IN SHARE MODE;\n"
+			   "       IF (SQL % NOTFOUND) THEN\n"
+			   "               found := 0;\n"
+			   "       ELSE\n"
+			   "               DELETE FROM SYS_FOREIGN_COLS\n"
+			   "               WHERE ID = foreign_id;\n"
+			   "               DELETE FROM SYS_FOREIGN\n"
+			   "               WHERE ID = foreign_id;\n"
+			   "       END IF;\n"
+			   "END LOOP;\n"
+			   "found := 1;\n"
+			   "WHILE found = 1 LOOP\n"
+			   "       SELECT ID INTO index_id\n"
+			   "       FROM SYS_INDEXES\n"
+			   "       WHERE TABLE_ID = table_id\n"
+			   "       LOCK IN SHARE MODE;\n"
+			   "       IF (SQL % NOTFOUND) THEN\n"
+			   "               found := 0;\n"
+			   "       ELSE\n"
+			   "               DELETE FROM SYS_FIELDS\n"
+			   "               WHERE INDEX_ID = index_id;\n"
+			   "               DELETE FROM SYS_INDEXES\n"
+			   "               WHERE ID = index_id\n"
+			   "               AND TABLE_ID = table_id;\n"
+			   "       END IF;\n"
+			   "END LOOP;\n"
+			   "DELETE FROM SYS_COLUMNS\n"
+			   "WHERE TABLE_ID = table_id;\n"
+			   "DELETE FROM SYS_TABLES\n"
+			   "WHERE ID = table_id;\n"
+			   "COMMIT WORK;\n"
+			   "END;\n"
+			   , FALSE, trx);
+
+			trx_commit_for_mysql(trx);
+
+			trx_free_for_mysql(trx);
+		}
+
 		return(FALSE);
 	}
 
@@ -3025,7 +3107,7 @@
 	cannot be ok. */
 
 	size = (((ib_longlong)size_high) << 32) + (ib_longlong)size_low;
-#ifndef UNIV_HOTBACKUP
+#ifdef UNDEFINED
 	if (size < FIL_IBD_FILE_INITIAL_SIZE * UNIV_PAGE_SIZE) {
 		fprintf(stderr,
 			"InnoDB: Error: the size of single-table tablespace"
@@ -3152,7 +3234,7 @@
 A fault-tolerant function that tries to read the next file name in the
 directory. We retry 100 times if os_file_readdir_next_file() returns -1. The
 idea is to read as much good data as we can and jump over bad data. */
-static
+//static
 int
 fil_file_readdir_next_file(
 /*=======================*/
@@ -3500,15 +3582,100 @@
 				"InnoDB: in InnoDB data dictionary"
 				" has tablespace id %lu,\n"
 				"InnoDB: but tablespace with that id"
-				" or name does not exist. Have\n"
-				"InnoDB: you deleted or moved .ibd files?\n"
-				"InnoDB: This may also be a table created with"
-				" CREATE TEMPORARY TABLE\n"
-				"InnoDB: whose .ibd and .frm files"
-				" MySQL automatically removed, but the\n"
-				"InnoDB: table still exists in the"
-				" InnoDB internal data dictionary.\n",
+				" or name does not exist. It will be removed from data dictionary.\n"
+				,
 				(ulong) id);
+			mem_free(path);
+			mutex_exit(&(system->mutex));
+			/* removing from data dictionary */
+			{
+				trx_t*		trx;
+				pars_info_t*	info = NULL;
+
+				trx = trx_allocate_for_mysql();
+
+				trx->op_info = "removing invalid table from data dictionary";
+
+				info = pars_info_create();
+
+				pars_info_add_str_literal(info, "table_name", name);
+
+
+				que_eval_sql(info,
+				   "PROCEDURE DROP_TABLE_PROC () IS\n"
+				   "sys_foreign_id CHAR;\n"
+				   "table_id CHAR;\n"
+				   "index_id CHAR;\n"
+				   "foreign_id CHAR;\n"
+				   "found INT;\n"
+				   "BEGIN\n"
+				   "SELECT ID INTO table_id\n"
+				   "FROM SYS_TABLES\n"
+				   "WHERE NAME = :table_name\n"
+				   "LOCK IN SHARE MODE;\n"
+				   "IF (SQL % NOTFOUND) THEN\n"
+				   "       COMMIT WORK;\n"
+				   "       RETURN;\n"
+				   "END IF;\n"
+				   "found := 1;\n"
+				   "SELECT ID INTO sys_foreign_id\n"
+				   "FROM SYS_TABLES\n"
+				   "WHERE NAME = 'SYS_FOREIGN'\n"
+				   "LOCK IN SHARE MODE;\n"
+				   "IF (SQL % NOTFOUND) THEN\n"
+				   "       found := 0;\n"
+				   "END IF;\n"
+				   "IF (:table_name = 'SYS_FOREIGN') THEN\n"
+				   "       found := 0;\n"
+				   "END IF;\n"
+				   "IF (:table_name = 'SYS_FOREIGN_COLS') THEN\n"
+				   "       found := 0;\n"
+				   "END IF;\n"
+				   "WHILE found = 1 LOOP\n"
+				   "       SELECT ID INTO foreign_id\n"
+				   "       FROM SYS_FOREIGN\n"
+				   "       WHERE FOR_NAME = :table_name\n"
+				   "               AND TO_BINARY(FOR_NAME)\n"
+				   "                 = TO_BINARY(:table_name)\n"
+				   "               LOCK IN SHARE MODE;\n"
+				   "       IF (SQL % NOTFOUND) THEN\n"
+				   "               found := 0;\n"
+				   "       ELSE\n"
+				   "               DELETE FROM SYS_FOREIGN_COLS\n"
+				   "               WHERE ID = foreign_id;\n"
+				   "               DELETE FROM SYS_FOREIGN\n"
+				   "               WHERE ID = foreign_id;\n"
+				   "       END IF;\n"
+				   "END LOOP;\n"
+				   "found := 1;\n"
+				   "WHILE found = 1 LOOP\n"
+				   "       SELECT ID INTO index_id\n"
+				   "       FROM SYS_INDEXES\n"
+				   "       WHERE TABLE_ID = table_id\n"
+				   "       LOCK IN SHARE MODE;\n"
+				   "       IF (SQL % NOTFOUND) THEN\n"
+				   "               found := 0;\n"
+				   "       ELSE\n"
+				   "               DELETE FROM SYS_FIELDS\n"
+				   "               WHERE INDEX_ID = index_id;\n"
+				   "               DELETE FROM SYS_INDEXES\n"
+				   "               WHERE ID = index_id\n"
+				   "               AND TABLE_ID = table_id;\n"
+				   "       END IF;\n"
+				   "END LOOP;\n"
+				   "DELETE FROM SYS_COLUMNS\n"
+				   "WHERE TABLE_ID = table_id;\n"
+				   "DELETE FROM SYS_TABLES\n"
+				   "WHERE ID = table_id;\n"
+				   "COMMIT WORK;\n"
+				   "END;\n"
+				   , FALSE, trx);
+
+				trx_commit_for_mysql(trx);
+
+				trx_free_for_mysql(trx);
+			}
+			return(FALSE);
 		} else {
 			ut_print_timestamp(stderr);
 			fputs("  InnoDB: Error: table ", stderr);
@@ -4112,6 +4279,16 @@
 
 	ut_ad((mode != OS_AIO_IBUF) || (space->purpose == FIL_TABLESPACE));
 
+	if (space->size <= block_offset) {
+		ulint	actual_size;
+
+		mutex_exit(&(system->mutex));
+		fil_extend_space_to_desired_size(&actual_size, space->id,
+						 ((block_offset + 1) / 64 + 1) * 64);
+		mutex_enter(&(system->mutex));
+		/* should retry? but it may safe for xtrabackup for now. */
+	}
+
 	node = UT_LIST_GET_FIRST(space->chain);
 
 	for (;;) {
--- a/storage/innobase/ibuf/ibuf0ibuf.c	2011-03-11 06:29:45.000000000 -0800
+++ b/storage/innobase/ibuf/ibuf0ibuf.c	2011-03-11 06:30:17.000000000 -0800
@@ -984,7 +984,7 @@
 	mtr_t	mtr;
 	ibool	ret;
 
-	if (recv_no_ibuf_operations) {
+	if (recv_no_ibuf_operations || srv_fake_write) {
 		/* Recovery is running: no ibuf operations should be
 		performed */
 
@@ -2234,6 +2234,9 @@
 	ulint	n_bytes;
 	ulint	n_pag2;
 
+	if (srv_fake_write)
+		return(0);
+
 	while (sum_pages < n_pages) {
 		n_bytes = ibuf_contract_ext(&n_pag2, sync);
 
--- a/storage/innobase/include/mem0mem.h	2011-03-11 06:29:45.000000000 -0800
+++ b/storage/innobase/include/mem0mem.h	2011-03-11 06:30:17.000000000 -0800
@@ -401,6 +401,7 @@
 			allocated buffer frame, which can be appended as a
 			free block to the heap, if we need more space;
 			otherwise, this is NULL */
+	ulint	sum_len;	/* sum of all blocks' len belong to the base node */
 #ifdef MEM_PERIODIC_CHECK
 	UT_LIST_NODE_T(mem_block_t) mem_block_list;
 			/* List of all mem blocks allocated; protected
--- a/storage/innobase/include/mem0mem.ic	2011-03-11 06:29:45.000000000 -0800
+++ b/storage/innobase/include/mem0mem.ic	2011-03-11 06:30:17.000000000 -0800
@@ -452,6 +452,7 @@
 
 	/* Add the created block itself as the first block in the list */
 	UT_LIST_ADD_FIRST(list, block->base, block);
+	block->sum_len = block->len;
 
 #ifdef UNIV_MEM_DEBUG
 
@@ -573,6 +574,7 @@
 
 	ut_ad(mem_heap_check(heap));
 
+/*
 	block = heap;
 
 	while (block != NULL) {
@@ -580,6 +582,8 @@
 		size += mem_block_get_len(block);
 		block = UT_LIST_GET_NEXT(list, block);
 	}
+*/
+	size = heap->sum_len;
 
 	if (heap->free_block) {
 		size += UNIV_PAGE_SIZE;
--- a/storage/innobase/include/srv0srv.h	2011-03-11 06:29:45.000000000 -0800
+++ b/storage/innobase/include/srv0srv.h	2011-03-11 06:30:17.000000000 -0800
@@ -60,6 +60,8 @@
 extern ibool	srv_file_per_table;
 extern ibool	srv_locks_unsafe_for_binlog;
 
+extern ibool	srv_fast_recovery;
+
 extern ulint	srv_n_data_files;
 extern char**	srv_data_file_names;
 extern ulint*	srv_data_file_sizes;
@@ -84,6 +86,7 @@
 
 extern byte	srv_latin1_ordering[256];/* The sort order table of the latin1
 					character set */
+extern ibool	srv_use_sys_malloc;
 extern ulint	srv_pool_size;
 extern ulint	srv_awe_window_size;
 extern ulint	srv_mem_pool_size;
@@ -133,6 +136,10 @@
 extern ulong	srv_max_purge_lag;
 extern ibool	srv_use_awe;
 extern ibool	srv_use_adaptive_hash_indexes;
+
+extern ibool	srv_read_only;
+extern ibool	srv_fake_write;
+extern ibool	srv_apply_log_only;
 /*-------------------------------------------*/
 
 extern ulint	srv_n_rows_inserted;
--- a/storage/innobase/include/srv0start.h	2011-03-11 06:29:45.000000000 -0800
+++ b/storage/innobase/include/srv0start.h	2011-03-11 06:30:17.000000000 -0800
@@ -80,6 +80,7 @@
 				/* out: DB_SUCCESS or error code */
 extern	dulint	srv_shutdown_lsn;
 extern	dulint	srv_start_lsn;
+extern	dulint	srv_oldest_lsn;
 
 #ifdef __NETWARE__
 void set_panic_flag_for_netware(void);
--- a/storage/innobase/include/ut0byte.ic	2011-03-11 06:29:45.000000000 -0800
+++ b/storage/innobase/include/ut0byte.ic	2011-03-11 06:30:17.000000000 -0800
@@ -152,6 +152,14 @@
 	dulint	a,	/* in: dulint */
 	ulint	b)	/* in: ulint */
 {
+	if (sizeof(ulint) != 4) {
+		ulint	b_h;
+
+		b_h = b >> 32;
+		b &= 0xFFFFFFFFUL;
+		a.high += b_h;
+	}
+
 	if (0xFFFFFFFFUL - b >= a.low) {
 		a.low += b;
 
@@ -175,6 +183,14 @@
 	dulint	a,	/* in: dulint */
 	ulint	b)	/* in: ulint, b <= a */
 {
+	if (sizeof(ulint) != 4) {
+		ulint	b_h;
+
+		b_h = b >> 32;
+		b &= 0xFFFFFFFFUL;
+		a.high -= b_h;
+	}
+
 	if (a.low >= b) {
 		a.low -= b;
 
@@ -219,6 +235,10 @@
 
 	ut_ad(diff > a.low);
 
+	if (sizeof(ulint) != 4) {
+		diff += (a.high - b.high - 1) << 32;
+	}
+
 	return(diff);
 }
 
--- a/storage/innobase/include/ut0mem.h	2011-03-11 06:29:45.000000000 -0800
+++ b/storage/innobase/include/ut0mem.h	2011-03-11 06:30:17.000000000 -0800
@@ -30,6 +30,13 @@
 
 
 /**************************************************************************
+Initializes the mem block list at database startup. */
+
+void
+ut_mem_block_list_init(void);
+/*========================*/
+
+/**************************************************************************
 Allocates memory. Sets it also to zero if UNIV_SET_MEM_TO_ZERO is
 defined and set_to_zero is TRUE. */
 
--- a/storage/innobase/log/log0log.c	2011-03-11 06:29:45.000000000 -0800
+++ b/storage/innobase/log/log0log.c	2011-03-11 06:30:17.000000000 -0800
@@ -538,7 +538,9 @@
 
 	offset = (gr_lsn_size_offset + difference) % group_size;
 
+	if (sizeof(ulint) == 4) {
 	ut_a(offset < (((ib_longlong) 1) << 32)); /* offset must be < 4 GB */
+	}
 
 	/* fprintf(stderr,
 	"Offset is %lu gr_lsn_offset is %lu difference is %lu\n",
@@ -1301,7 +1303,7 @@
 #endif /* UNIV_DEBUG */
 	ulint		unlock;
 
-	if (recv_no_ibuf_operations) {
+	if (recv_no_ibuf_operations || srv_fake_write) {
 		/* Recovery is running and no operations on the log files are
 		allowed yet (the variable name .._no_ibuf_.. is misleading) */
 
@@ -3056,6 +3058,7 @@
 	for the 'very fast' shutdown, because the InnoDB layer may have
 	committed or prepared transactions and we don't want to lose them. */
 
+	if (!srv_apply_log_only) {
 	if (trx_n_mysql_transactions > 0
 	    || UT_LIST_GET_LEN(trx_sys->trx_list) > 0) {
 
@@ -3063,6 +3066,7 @@
 
 		goto loop;
 	}
+	}
 
 	if (srv_fast_shutdown == 2) {
 		/* In this fastest shutdown we do not flush the buffer pool:
--- a/storage/innobase/log/log0recv.c	2011-03-11 06:29:45.000000000 -0800
+++ b/storage/innobase/log/log0recv.c	2011-03-11 06:30:17.000000000 -0800
@@ -35,19 +35,19 @@
 #include "fil0fil.h"
 #include "sync0sync.h"
 
-#ifdef UNIV_HOTBACKUP
+//#ifdef UNIV_HOTBACKUP
 /* This is set to FALSE if the backup was originally taken with the
 ibbackup --include regexp option: then we do not want to create tables in
 directories which were not included */
 ibool	recv_replay_file_ops	= TRUE;
-#endif /* UNIV_HOTBACKUP */
+//#endif /* UNIV_HOTBACKUP */
 
 /* Log records are stored in the hash table in chunks at most of this size;
 this must be less than UNIV_PAGE_SIZE as it is stored in the buffer pool */
 #define RECV_DATA_BLOCK_SIZE	(MEM_MAX_ALLOC_IN_BUF - sizeof(recv_data_t))
 
 /* Read-ahead area in applying log records to file pages */
-#define RECV_READ_AHEAD_AREA	32
+#define RECV_READ_AHEAD_AREA	128
 
 recv_sys_t*	recv_sys = NULL;
 ibool		recv_recovery_on = FALSE;
@@ -101,7 +101,7 @@
 use these free frames to read in pages when we start applying the
 log records to the database. */
 
-ulint	recv_n_pool_free_frames		= 256;
+ulint	recv_n_pool_free_frames		= 1024;
 
 /* The maximum lsn we see for a page during the recovery process. If this
 is bigger than the lsn we are able to scan up to, that is an indication that
@@ -452,7 +452,7 @@
 
 /***************************************************************************
 Checks the consistency of the checkpoint info */
-static
+//static
 ibool
 recv_check_cp_is_consistent(
 /*========================*/
@@ -481,7 +481,7 @@
 
 /************************************************************
 Looks for the maximum consistent checkpoint from the log groups. */
-static
+//static
 ulint
 recv_find_max_checkpoint(
 /*=====================*/
@@ -654,7 +654,7 @@
 Checks the 4-byte checksum to the trailer checksum field of a log block.
 We also accept a log block in the old format < InnoDB-3.23.52 where the
 checksum field contains the log block number. */
-static
+//static
 ibool
 log_block_checksum_is_ok_or_old_format(
 /*===================================*/
@@ -1171,6 +1171,7 @@
 	recv_addr = recv_get_fil_addr_struct(space, page_no);
 
 	if ((recv_addr == NULL)
+	    || (recv_addr->state == RECV_BEING_READ && !just_read_in)
 	    || (recv_addr->state == RECV_BEING_PROCESSED)
 	    || (recv_addr->state == RECV_PROCESSED)) {
 
@@ -1926,7 +1927,7 @@
 		} else if (store_to_hash && (type == MLOG_FILE_CREATE
 					     || type == MLOG_FILE_RENAME
 					     || type == MLOG_FILE_DELETE)) {
-#ifdef UNIV_HOTBACKUP
+//#ifdef UNIV_HOTBACKUP
 			if (recv_replay_file_ops) {
 
 				/* In ibbackup --apply-log, replay an .ibd file
@@ -1949,7 +1950,7 @@
 					ut_a(0);
 				}
 			}
-#endif
+//#endif
 			/* In normal mysqld crash recovery we do not try to
 			replay file operations */
 		} else if (store_to_hash) {
@@ -2360,9 +2361,12 @@
 
 			fprintf(stderr,
 				"InnoDB: Doing recovery: scanned up to"
-				" log sequence number %lu %lu\n",
+				" log sequence number %lu %lu (%lu %)\n",
 				(ulong) ut_dulint_get_high(*group_scanned_lsn),
-				(ulong) ut_dulint_get_low(*group_scanned_lsn));
+				(ulong) ut_dulint_get_low(*group_scanned_lsn),
+				(ulong) ut_dulint_minus(*group_scanned_lsn, srv_oldest_lsn)
+				/ (8 * log_group_get_capacity(UT_LIST_GET_FIRST(log_sys->log_groups))/900)
+			);
 		}
 	}
 
@@ -2471,12 +2475,14 @@
 
 	if (srv_force_recovery < SRV_FORCE_NO_LOG_REDO) {
 
+#ifdef UNDEFINED
 		fprintf(stderr,
 			"InnoDB: Restoring possible"
 			" half-written data pages from"
 			" the doublewrite\n"
 			"InnoDB: buffer...\n");
-		trx_sys_doublewrite_init_or_restore_pages(TRUE);
+#endif
+		trx_sys_doublewrite_init_or_restore_pages(FALSE);
 	}
 }
 
@@ -2611,6 +2617,7 @@
 		recv_sys->recovered_lsn = checkpoint_lsn;
 
 		srv_start_lsn = checkpoint_lsn;
+		srv_oldest_lsn = checkpoint_lsn;
 	}
 
 	contiguous_lsn = ut_dulint_align_down(recv_sys->scanned_lsn,
@@ -2910,6 +2917,7 @@
 	/* Switch latching order checks on in sync0sync.c */
 	sync_order_checks_on = TRUE;
 #endif
+	if (!srv_apply_log_only) {
 	if (srv_force_recovery < SRV_FORCE_NO_TRX_UNDO) {
 		/* Rollback the uncommitted transactions which have no user
 		session */
@@ -2917,6 +2925,7 @@
 		os_thread_create(trx_rollback_or_clean_all_without_sess,
 				 (void *)&i, NULL);
 	}
+	}
 }
 
 /**********************************************************
--- a/storage/innobase/mem/mem0dbg.c	2011-03-11 06:29:45.000000000 -0800
+++ b/storage/innobase/mem/mem0dbg.c	2011-03-11 06:30:17.000000000 -0800
@@ -133,6 +133,14 @@
 	mem_hash_initialized = TRUE;
 #endif
 
+	if (UNIV_LIKELY(srv_use_sys_malloc)) {
+		/* When innodb_use_sys_malloc is set, the
+		mem_comm_pool won't be used for any allocations.  We
+		create a dummy mem_comm_pool, because some statistics
+		and debugging code relies on it being initialized. */
+		size = 1;
+	}
+
 	mem_comm_pool = mem_pool_create(size);
 }
 
--- a/storage/innobase/mem/mem0mem.c	2011-03-11 06:29:45.000000000 -0800
+++ b/storage/innobase/mem/mem0mem.c	2011-03-11 06:30:17.000000000 -0800
@@ -472,6 +472,7 @@
 	/* Add the new block as the last block */
 
 	UT_LIST_INSERT_AFTER(list, heap->base, block, new_block);
+	heap->sum_len += new_block->len;
 
 	return(new_block);
 }
@@ -494,6 +495,7 @@
 	}
 
 	UT_LIST_REMOVE(list, heap->base, block);
+	heap->sum_len -= block->len;
 
 #ifdef MEM_PERIODIC_CHECK
 	mem_pool_mutex_enter();
@@ -507,6 +509,7 @@
 	init_block = block->init_block;
 	block->magic_n = MEM_FREED_BLOCK_MAGIC_N;
 
+	if (!srv_use_sys_malloc) {
 #ifdef UNIV_MEM_DEBUG
 	/* In the debug version we set the memory to a random combination
 	of hex 0xDE and 0xAD. */
@@ -515,6 +518,7 @@
 #else /* UNIV_MEM_DEBUG */
 	UNIV_MEM_ASSERT_AND_FREE(block, len);
 #endif /* UNIV_MEM_DEBUG */
+	}
 
 	if (init_block) {
 		/* Do not have to free: do nothing */
--- a/storage/innobase/mem/mem0pool.c	2011-03-11 06:29:45.000000000 -0800
+++ b/storage/innobase/mem/mem0pool.c	2011-03-11 06:30:17.000000000 -0800
@@ -11,6 +11,7 @@
 #include "mem0pool.ic"
 #endif
 
+#include "srv0srv.h"
 #include "sync0sync.h"
 #include "ut0mem.h"
 #include "ut0lst.h"
@@ -192,8 +193,6 @@
 	ulint		i;
 	ulint		used;
 
-	ut_a(size > 10000);
-
 	pool = ut_malloc(sizeof(mem_pool_t));
 
 	/* We do not set the memory to zero (FALSE) in the pool,
@@ -333,6 +332,10 @@
 	ulint		n;
 	ibool		ret;
 
+	if (UNIV_LIKELY(srv_use_sys_malloc)) {
+		return(malloc(size));
+	}
+
 	n = ut_2_log(ut_max(size + MEM_AREA_EXTRA_SIZE, MEM_AREA_MIN_SIZE));
 
 	mutex_enter(&(pool->mutex));
@@ -465,6 +468,11 @@
 	ulint		size;
 	ulint		n;
 
+	if (UNIV_LIKELY(srv_use_sys_malloc)) {
+		free(ptr);
+		return;
+	}
+
 	/* It may be that the area was really allocated from the OS with
 	regular malloc: check if ptr points within our memory pool */
 
--- a/storage/innobase/os/os0file.c	2011-03-11 06:29:45.000000000 -0800
+++ b/storage/innobase/os/os0file.c	2011-03-11 06:30:17.000000000 -0800
@@ -466,7 +466,7 @@
 }
 
 #undef USE_FILE_LOCK
-#define USE_FILE_LOCK
+//#define USE_FILE_LOCK
 #if defined(UNIV_HOTBACKUP) || defined(__WIN__) || defined(__NETWARE__)
 /* InnoDB Hot Backup does not lock the data files.
  * On Windows, mandatory locking is used.
@@ -1268,8 +1268,9 @@
 		attributes = 0;
 		ut_error;
 	}
-
+	share_mode |= FILE_SHARE_WRITE; /* Why? */
 	file = CreateFile((LPCTSTR) name,
+			  (srv_read_only && create_flag == OPEN_EXISTING) ? GENERIC_READ :
 			  GENERIC_READ | GENERIC_WRITE, /* read and write
 							access */
 			  share_mode,	/* File can be read also by other
@@ -1324,7 +1325,11 @@
 	if (create_mode == OS_FILE_OPEN || create_mode == OS_FILE_OPEN_RAW
 	    || create_mode == OS_FILE_OPEN_RETRY) {
 		mode_str = "OPEN";
-		create_flag = O_RDWR;
+		if (srv_read_only) {
+			create_flag = O_RDONLY;
+		} else {
+			create_flag = O_RDWR;
+		}
 	} else if (create_mode == OS_FILE_CREATE) {
 		mode_str = "CREATE";
 		create_flag = O_RDWR | O_CREAT | O_EXCL;
@@ -2458,6 +2463,9 @@
 	ut_a((offset & 0xFFFFFFFFUL) == offset);
 	ut_a((n & 0xFFFFFFFFUL) == n);
 
+	if (srv_fake_write)
+		return(TRUE);
+
 	os_n_file_writes++;
 
 	ut_ad(file);
@@ -2578,6 +2586,9 @@
 #else
 	ssize_t	ret;
 
+	if (srv_fake_write)
+		return(TRUE);
+
 	ret = os_file_pwrite(file, buf, n, offset, offset_high);
 
 	if ((ulint)ret == n) {
@@ -3255,6 +3266,8 @@
 {
 	os_aio_slot_t*	slot;
 	ulint		i;
+	ulint		prim_segment;
+	ulint		n;
 #ifdef WIN_ASYNC_IO
 	OVERLAPPED*	control;
 
@@ -3264,6 +3277,10 @@
 	struct aiocb*	control;
 #endif
 
+	n = array->n_slots / array->n_segments;
+	/* 64 blocks' striping ( aligning max(BUF_READ_AHEAD_AREA) ) */
+	prim_segment = ( offset >> (UNIV_PAGE_SIZE_SHIFT + 6) ) % (array->n_segments);
+
 loop:
 	os_mutex_enter(array->mutex);
 
@@ -3282,6 +3299,16 @@
 		goto loop;
 	}
 
+	for (i = prim_segment * n; i < array->n_slots; i++) {
+		slot = os_aio_array_get_nth_slot(array, i);
+
+		if (slot->reserved == FALSE) {
+			break;
+		}
+	}
+
+	if (slot->reserved == TRUE){
+		/* Not found after the intended segment. So we should search before. */
 	for (i = 0;; i++) {
 		slot = os_aio_array_get_nth_slot(array, i);
 
@@ -3289,6 +3316,7 @@
 			break;
 		}
 	}
+	}
 
 	array->n_reserved++;
 
--- a/storage/innobase/os/os0thread.c	2011-03-11 06:29:45.000000000 -0800
+++ b/storage/innobase/os/os0thread.c	2011-03-11 06:30:17.000000000 -0800
@@ -273,12 +273,17 @@
 #elif defined(__NETWARE__)
 	delay(tm / 1000);
 #else
+	/* select() simetimes hang up from xtrabackup */
+	/* change to use usleep() for now */
+	usleep(tm);
+/*
 	struct timeval	t;
 
 	t.tv_sec = tm / 1000000;
 	t.tv_usec = tm % 1000000;
 
 	select(0, NULL, NULL, NULL, &t);
+*/
 #endif
 }
 
--- a/storage/innobase/srv/srv0srv.c	2011-03-11 06:29:45.000000000 -0800
+++ b/storage/innobase/srv/srv0srv.c	2011-03-11 06:30:17.000000000 -0800
@@ -94,6 +94,8 @@
 						duplicate key checking
 						and foreign key
 						checking */
+ibool	srv_fast_recovery = TRUE;
+
 ulint	srv_n_data_files = 0;
 char**	srv_data_file_names = NULL;
 ulint*	srv_data_file_sizes = NULL;	/* size in database pages */
@@ -171,6 +173,8 @@
 , 0xD8, 0x55, 0x55, 0x55, 0x59, 0x59, 0xDE, 0xFF
 };
 
+ibool	srv_use_sys_malloc	= TRUE;
+
 ulint	srv_pool_size		= ULINT_MAX;	/* size in pages; MySQL inits
 						this to size in kilobytes but
 						we normalize this to pages in
@@ -358,6 +362,9 @@
 ibool	srv_use_awe			= FALSE;
 ibool	srv_use_adaptive_hash_indexes	= TRUE;
 
+ibool	srv_read_only	= FALSE;
+ibool	srv_fake_write	= FALSE;
+ibool	srv_apply_log_only = FALSE;
 /*-------------------------------------------*/
 ulong	srv_n_spin_wait_rounds	= 20;
 ulong	srv_n_free_tickets_to_enter = 500;
@@ -980,6 +987,7 @@
 srv_general_init(void)
 /*==================*/
 {
+	ut_mem_block_list_init();
 	os_sync_init();
 	sync_init();
 	mem_init(srv_mem_pool_size);
--- a/storage/innobase/srv/srv0start.c	2011-03-11 06:29:45.000000000 -0800
+++ b/storage/innobase/srv/srv0start.c	2011-03-11 06:30:17.000000000 -0800
@@ -61,6 +61,8 @@
 /* Log sequence number at shutdown */
 dulint		srv_shutdown_lsn;
 
+dulint		srv_oldest_lsn;
+
 #ifdef HAVE_DARWIN_THREADS
 # include <sys/utsname.h>
 ibool		srv_have_fullfsync = FALSE;
@@ -519,7 +521,7 @@
 
 /*************************************************************************
 Creates or opens the log files and closes them. */
-static
+//static
 ulint
 open_or_create_log_file(
 /*====================*/
@@ -672,7 +674,7 @@
 
 /*************************************************************************
 Creates or opens database data files and closes them. */
-static
+//static
 ulint
 open_or_create_data_files(
 /*======================*/
@@ -1037,6 +1039,11 @@
 	fprintf(stderr,
 		"InnoDB: !!!!!!!! UNIV_SIMULATE_AWE switched on !!!!!!!!!\n");
 #endif
+	if (UNIV_LIKELY(srv_use_sys_malloc)) {
+		fprintf(stderr,
+			"InnoDB: The InnoDB memory heap is disabled\n");
+	}
+
 	if (srv_sizeof_trx_t_in_ha_innodb_cc != (ulint)sizeof(trx_t)) {
 		fprintf(stderr,
 			"InnoDB: Error: trx_t size is %lu in ha_innodb.cc"
@@ -1232,12 +1239,12 @@
 
 	if (!os_aio_use_native_aio) {
 		/* In simulated aio we currently have use only for 4 threads */
-		srv_n_file_io_threads = 4;
+		/*srv_n_file_io_threads = 4;*/
 
 		os_aio_init(8 * SRV_N_PENDING_IOS_PER_THREAD
 			    * srv_n_file_io_threads,
 			    srv_n_file_io_threads,
-			    SRV_MAX_N_PENDING_SYNC_IOS);
+			    SRV_MAX_N_PENDING_SYNC_IOS * 8);
 	} else {
 		os_aio_init(SRV_N_PENDING_IOS_PER_THREAD
 			    * srv_n_file_io_threads,
@@ -1321,7 +1328,7 @@
 	}
 #endif /* UNIV_LOG_ARCHIVE */
 
-	if (srv_n_log_files * srv_log_file_size >= 262144) {
+	if (sizeof(ulint) == 4 && srv_n_log_files * srv_log_file_size >= 262144) {
 		fprintf(stderr,
 			"InnoDB: Error: combined size of log files"
 			" must be < 4 GB\n");
@@ -1563,6 +1570,11 @@
 		are initialized in trx_sys_init_at_db_start(). */
 
 		recv_recovery_from_checkpoint_finish();
+
+		if (srv_apply_log_only) {
+			srv_was_started = TRUE;
+			goto skip_processes;
+		}
 	}
 
 	if (!create_new_db && sum_of_new_sizes > 0) {
@@ -1682,7 +1694,18 @@
 
 	if (srv_auto_extend_last_data_file
 	    && sum_of_data_file_sizes < tablespace_size_in_header) {
+		/* extend table space size aligning with header */
+		ulint	actual_size;
+		fil_extend_space_to_desired_size(&actual_size, 0, tablespace_size_in_header);
+		if (actual_size < tablespace_size_in_header) {
+			fprintf(stderr,
+"InnoDB: Warning: To extend tablespace size aligning with header seems to be failed.\n"
+"InnoDB: The acutual size %lu must be larger than %lu.\n",
+				(ulong) actual_size,
+				(ulong) tablespace_size_in_header);
+		}
 
+#ifdef UNDEFINED
 		fprintf(stderr,
 			"InnoDB: Error: tablespace size stored in header"
 			" is %lu pages, but\n"
@@ -1707,6 +1730,7 @@
 
 			return(DB_ERROR);
 		}
+#endif
 	}
 
 	/* Check that os_fast_mutexes work as expected */
@@ -1803,6 +1827,7 @@
 		ibuf_update_max_tablespace_id();
 	}
 
+skip_processes:
 	srv_file_per_table = srv_file_per_table_original_value;
 
 	return((int) DB_SUCCESS);
--- a/storage/innobase/trx/trx0purge.c	2011-03-11 06:29:45.000000000 -0800
+++ b/storage/innobase/trx/trx0purge.c	2011-03-11 06:30:17.000000000 -0800
@@ -1024,6 +1024,9 @@
 	/*	que_thr_t*	thr2; */
 	ulint		old_pages_handled;
 
+	if (srv_fake_write)
+		return(0);
+
 	mutex_enter(&(purge_sys->mutex));
 
 	if (purge_sys->trx->n_active_thrs > 0) {
--- a/storage/innobase/trx/trx0trx.c	2011-03-11 06:29:45.000000000 -0800
+++ b/storage/innobase/trx/trx0trx.c	2011-03-11 06:30:17.000000000 -0800
@@ -478,8 +478,8 @@
 						ut_dulint_get_low(trx->id));
 
 					if (srv_force_recovery == 0) {
-
-						trx->conc_state = TRX_PREPARED;
+						/* xtrabackup should rollback it */
+						trx->conc_state = TRX_ACTIVE;
 					} else {
 						fprintf(stderr,
 							"InnoDB: Since"
@@ -555,9 +555,9 @@
 								trx->id));
 
 						if (srv_force_recovery == 0) {
-
+							/* xtrabackup should rollback it */
 							trx->conc_state
-								= TRX_PREPARED;
+								= TRX_ACTIVE;
 						} else {
 							fprintf(stderr,
 								"InnoDB: Since"
--- a/storage/innobase/ut/ut0mem.c	2011-03-11 06:29:45.000000000 -0800
+++ b/storage/innobase/ut/ut0mem.c	2011-03-11 06:30:17.000000000 -0800
@@ -15,6 +15,7 @@
 #include "mem0mem.h"
 #include "os0sync.h"
 #include "os0thread.h"
+#include "srv0srv.h"
 
 /* This struct is placed first in every allocated memory block */
 typedef struct ut_mem_block_struct ut_mem_block_t;
@@ -43,7 +44,7 @@
 
 /**************************************************************************
 Initializes the mem block list at database startup. */
-static
+
 void
 ut_mem_block_list_init(void)
 /*========================*/
@@ -71,11 +72,22 @@
 	ulint	retry_count	= 0;
 	void*	ret;
 
-	ut_ad((sizeof(ut_mem_block_t) % 8) == 0); /* check alignment ok */
+	if (UNIV_LIKELY(srv_use_sys_malloc)) {
+		ret = malloc(n);
+		ut_a(ret || !assert_on_error);
 
-	if (!ut_mem_block_list_inited) {
-		ut_mem_block_list_init();
+#ifdef UNIV_SET_MEM_TO_ZERO
+		if (set_to_zero) {
+			memset(ret, '\0', n);
+			UNIV_MEM_ALLOC(ret, n);
+		}
+#endif
+		return(ret);
 	}
+
+	ut_ad((sizeof(ut_mem_block_t) % 8) == 0); /* check alignment ok */
+	ut_a(ut_mem_block_list_inited);
+
 retry:
 	os_fast_mutex_lock(&ut_list_mutex);
 
@@ -239,6 +251,11 @@
 {
 	ut_mem_block_t* block;
 
+	if (UNIV_LIKELY(srv_use_sys_malloc)) {
+		free(ptr);
+		return;
+	}
+
 	block = (ut_mem_block_t*)((byte*)ptr - sizeof(ut_mem_block_t));
 
 	os_fast_mutex_lock(&ut_list_mutex);
@@ -291,6 +308,10 @@
 	ulint		min_size;
 	void*		new_ptr;
 
+	if (UNIV_LIKELY(srv_use_sys_malloc)) {
+		return(realloc(ptr, size));
+	}
+
 	if (ptr == NULL) {
 
 		return(ut_malloc(size));
@@ -338,6 +359,8 @@
 {
 	ut_mem_block_t* block;
 
+	ut_mem_block_list_inited = FALSE;
+
 	os_fast_mutex_free(&ut_list_mutex);
 
 	while ((block = UT_LIST_GET_FIRST(ut_mem_block_list))) {