~percona-dev/percona-server/release-5.1.50-12

« back to all changes in this revision

Viewing changes to innodb_buffer_pool_shm.patch

- New static bool option innodb_buffer_pool_shm_checksum for bug643650
- Fix should be for bug643724 and bug649408
- Fix for bug649393

Show diffs side-by-side

added added

removed removed

Lines of Context:
96
96
 /********************************************************************//**
97
97
 Allocates a chunk of buffer frames.
98
98
 @return        chunk, or NULL on failure */
99
 
@@ -768,26 +835,174 @@
 
99
@@ -768,26 +835,184 @@
100
100
 {
101
101
        buf_block_t*    block;
102
102
        byte*           frame;
161
161
+               if (UNIV_UNLIKELY(chunk->mem == NULL)) {
162
162
+                       return(NULL);
163
163
+               }
164
 
+
 
164
+init_again:
165
165
+#ifdef UNIV_SET_MEM_TO_ZERO
166
166
+               if (is_new) {
167
167
+                       memset(chunk->mem, '\0', chunk->mem_size);
204
204
+                               "InnoDB: Error: The shared memory was not initialized yet.\n");
205
205
+                               return(NULL);
206
206
+                       }
207
 
+                       if (!shm_info->clean) {
208
 
+                               fprintf(stderr,
209
 
+                               "InnoDB: Error: The shared memory was not shut down cleanly.\n");
210
 
+                               return(NULL);
211
 
+                       }
212
 
+                       if (!shm_info->reusable) {
213
 
+                               fprintf(stderr,
214
 
+                               "InnoDB: Error: The shared memory has unrecoverable contents.\n");
215
 
+                               return(NULL);
216
 
+                       }
217
207
+                       if (shm_info->buf_pool_size != srv_buf_pool_size) {
218
208
+                               fprintf(stderr,
219
209
+                               "InnoDB: Error: srv_buf_pool_size is different (shm=%lu current=%lu).\n",
226
216
+                               shm_info->page_size, srv_page_size);
227
217
+                               return(NULL);
228
218
+                       }
 
219
+                       if (!shm_info->reusable) {
 
220
+                               fprintf(stderr,
 
221
+                               "InnoDB: Warning: The shared memory has unrecoverable contents.\n"
 
222
+                               "InnoDB: The shared memory segment is initialized.\n");
 
223
+                               is_new = TRUE;
 
224
+                               goto init_again;
 
225
+                       }
 
226
+                       if (!shm_info->clean) {
 
227
+                               fprintf(stderr,
 
228
+                               "InnoDB: Warning: The shared memory was not shut down cleanly.\n"
 
229
+                               "InnoDB: The shared memory segment is initialized.\n");
 
230
+                               is_new = TRUE;
 
231
+                               goto init_again;
 
232
+                       }
229
233
+
230
234
+                       ut_a(shm_info->zip_hash_offset == chunk->mem_size - zip_hash_mem_size);
231
235
+                       ut_a(shm_info->zip_hash_n == zip_hash_n);
232
236
+
233
237
+                       /* check checksum */
234
 
+                       checksum = ut_fold_binary_32((byte*)chunk->mem + sizeof(buf_shm_info_t),
235
 
+                                                 chunk->mem_size - sizeof(buf_shm_info_t));
236
 
+                       if (shm_info->checksum != checksum) {
 
238
+                       if (srv_buffer_pool_shm_checksum) {
 
239
+                               checksum = ut_fold_binary_32((byte*)chunk->mem + sizeof(buf_shm_info_t),
 
240
+                                                            chunk->mem_size - sizeof(buf_shm_info_t));
 
241
+                       } else {
 
242
+                               checksum = BUF_NO_CHECKSUM_MAGIC;
 
243
+                       }
 
244
+
 
245
+                       if (shm_info->checksum != BUF_NO_CHECKSUM_MAGIC
 
246
+                           && shm_info->checksum != checksum) {
237
247
+                               fprintf(stderr,
238
248
+                               "InnoDB: Error: checksum of the shared memory is not match. "
239
249
+                               "(stored=%lu calculated=%lu)\n",
271
281
 
272
282
        /* Align a pointer to the first frame.  Note that when
273
283
        os_large_page_size is smaller than UNIV_PAGE_SIZE,
274
 
@@ -795,8 +1010,13 @@
 
284
@@ -795,8 +1020,13 @@
275
285
        it is bigger, we may allocate more blocks than requested. */
276
286
 
277
287
        frame = ut_align(chunk->mem, UNIV_PAGE_SIZE);
285
295
 
286
296
        /* Subtract the space needed for block descriptors. */
287
297
        {
288
 
@@ -810,6 +1030,98 @@
 
298
@@ -810,6 +1040,98 @@
289
299
                chunk->size = size;
290
300
        }
291
301
 
305
315
+               }
306
316
+
307
317
+               chunk->size = shm_info->chunk_backup.size;
308
 
+               phys_offset = frame - (byte*)chunk->mem + shm_info->frame_offset;
 
318
+               phys_offset = frame - ((byte*)chunk->mem + shm_info->frame_offset);
309
319
+               logi_offset = frame - chunk->blocks[0].frame;
310
320
+               previous_frame_address = chunk->blocks[0].frame;
311
321
+               blocks_offset = (byte*)chunk->blocks - (byte*)shm_info->chunk_backup.blocks;
339
349
+                       " Done.\n");
340
350
+               }
341
351
+
 
352
+               /* buf_block_t */
 
353
+               block = chunk->blocks;
 
354
+               for (i = chunk->size; i--; ) {
 
355
+                       buf_block_reuse(block, logi_offset);
 
356
+                       block++;
 
357
+               }
 
358
+
342
359
+               if (logi_offset || blocks_offset) {
343
360
+                       fprintf(stderr,
344
361
+                       "InnoDB: Aligning logical offset...");
345
362
+
346
 
+                       /* buf_block_t */
347
 
+                       block = chunk->blocks;
348
 
+
349
 
+                       for (i = chunk->size; i--; ) {
350
 
+                               buf_block_reuse(block, logi_offset);
351
 
+                               block++;
352
 
+                       }
353
363
+
354
364
+                       /* buf_pool_t buf_pool_backup */
355
365
+                       UT_LIST_OFFSET(flush_list, buf_page_t, shm_info->buf_pool_backup.flush_list,
384
394
        /* Init block structs and assign frames for them. Then we
385
395
        assign the frames to the first blocks (we already mapped the
386
396
        memory above). */
387
 
@@ -833,6 +1145,11 @@
 
397
@@ -833,6 +1155,11 @@
388
398
                block++;
389
399
                frame += UNIV_PAGE_SIZE;
390
400
        }
396
406
 
397
407
        return(chunk);
398
408
 }
399
 
@@ -1014,6 +1331,8 @@
 
409
@@ -1014,6 +1341,8 @@
400
410
                UNIV_MEM_UNDESC(block);
401
411
        }
402
412
 
405
415
        os_mem_free_large(chunk->mem, chunk->mem_size);
406
416
 }
407
417
 
408
 
@@ -1063,7 +1382,10 @@
 
418
@@ -1063,7 +1392,10 @@
409
419
        srv_buf_pool_curr_size = buf_pool->curr_size * UNIV_PAGE_SIZE;
410
420
 
411
421
        buf_pool->page_hash = hash_create(2 * buf_pool->curr_size);
416
426
 
417
427
        buf_pool->last_printout_time = time(NULL);
418
428
 
419
 
@@ -1078,6 +1400,86 @@
 
429
@@ -1078,6 +1410,86 @@
420
430
        --------------------------- */
421
431
        /* All fields are initialized by mem_zalloc(). */
422
432
 
503
513
        mutex_exit(&LRU_list_mutex);
504
514
        rw_lock_x_unlock(&page_hash_latch);
505
515
        buf_pool_mutex_exit();
506
 
@@ -1102,6 +1504,30 @@
 
516
@@ -1102,6 +1514,34 @@
507
517
        buf_chunk_t*    chunk;
508
518
        buf_chunk_t*    chunks;
509
519
 
524
534
+               memcpy(&(shm_info->chunk_backup), chunk, sizeof(buf_chunk_t));
525
535
+
526
536
+               if (srv_fast_shutdown < 2) {
527
 
+                       shm_info->checksum = ut_fold_binary_32((byte*)chunk->mem + sizeof(buf_shm_info_t),
528
 
+                                                           chunk->mem_size - sizeof(buf_shm_info_t));
 
537
+                       if (srv_buffer_pool_shm_checksum) {
 
538
+                               shm_info->checksum = ut_fold_binary_32((byte*)chunk->mem + sizeof(buf_shm_info_t),
 
539
+                                                                      chunk->mem_size - sizeof(buf_shm_info_t));
 
540
+                       } else {
 
541
+                               shm_info->checksum = BUF_NO_CHECKSUM_MAGIC;
 
542
+                       }
529
543
+                       shm_info->clean = TRUE;
530
544
+               }
531
545
+
534
548
        chunks = buf_pool->chunks;
535
549
        chunk = chunks + buf_pool->n_chunks;
536
550
 
537
 
@@ -1110,10 +1536,13 @@
 
551
@@ -1110,10 +1550,13 @@
538
552
                would fail at shutdown. */
539
553
                os_mem_free_large(chunk->mem, chunk->mem_size);
540
554
        }
548
562
        mem_free(buf_pool);
549
563
        buf_pool = NULL;
550
564
 }
551
 
@@ -1308,6 +1737,11 @@
 
565
@@ -1308,6 +1751,11 @@
552
566
        //buf_pool_mutex_enter();
553
567
        mutex_enter(&LRU_list_mutex);
554
568
 
560
574
 shrink_again:
561
575
        if (buf_pool->n_chunks <= 1) {
562
576
 
563
 
@@ -1551,6 +1985,11 @@
 
577
@@ -1551,6 +1999,11 @@
564
578
 buf_pool_resize(void)
565
579
 /*=================*/
566
580
 {
649
663
diff -ruN a/storage/innodb_plugin/handler/ha_innodb.cc b/storage/innodb_plugin/handler/ha_innodb.cc
650
664
--- a/storage/innodb_plugin/handler/ha_innodb.cc        2010-07-14 16:34:18.597725479 +0900
651
665
+++ b/storage/innodb_plugin/handler/ha_innodb.cc        2010-07-14 16:40:16.159323612 +0900
652
 
@@ -11340,6 +11340,11 @@
 
666
@@ -197,6 +197,7 @@
 
667
 static my_bool innobase_create_status_file             = FALSE;
 
668
 static my_bool innobase_stats_on_metadata              = TRUE;
 
669
 static my_bool innobase_use_sys_stats_table            = FALSE;
 
670
+static my_bool innobase_buffer_pool_shm_checksum       = TRUE;
 
671
 
 
672
 static char*   internal_innobase_data_file_path        = NULL;
 
673
 
 
674
@@ -2417,6 +2418,7 @@
 
675
        srv_use_doublewrite_buf = (ibool) innobase_use_doublewrite;
 
676
        srv_use_checksums = (ibool) innobase_use_checksums;
 
677
        srv_fast_checksum = (ibool) innobase_fast_checksum;
 
678
+       srv_buffer_pool_shm_checksum = (ibool) innobase_buffer_pool_shm_checksum;
 
679
 
 
680
 #ifdef HAVE_LARGE_PAGES
 
681
         if ((os_use_large_pages = (ibool) my_use_large_pages))
 
682
@@ -11340,6 +11342,16 @@
653
683
   "The size of the memory buffer InnoDB uses to cache data and indexes of its tables.",
654
684
   NULL, NULL, 128*1024*1024L, 32*1024*1024L, LONGLONG_MAX, 1024*1024L);
655
685
 
658
688
+  "[experimental] The key value of shared memory segment for the buffer pool. 0 (default) disables the feature.",
659
689
+  NULL, NULL, 0, 0, INT_MAX32, 0);
660
690
+
 
691
+static MYSQL_SYSVAR_BOOL(buffer_pool_shm_checksum, innobase_buffer_pool_shm_checksum,
 
692
+  PLUGIN_VAR_NOCMDARG | PLUGIN_VAR_READONLY,
 
693
+  "Enable buffer_pool_shm checksum validation (enabled by default).",
 
694
+  NULL, NULL, TRUE);
 
695
+
661
696
 static MYSQL_SYSVAR_ULONG(commit_concurrency, innobase_commit_concurrency,
662
697
   PLUGIN_VAR_RQCMDARG,
663
698
   "Helps in performance tuning in heavily concurrent environments.",
664
 
@@ -11599,6 +11604,7 @@
 
699
@@ -11599,6 +11611,8 @@
665
700
   MYSQL_SYSVAR(additional_mem_pool_size),
666
701
   MYSQL_SYSVAR(autoextend_increment),
667
702
   MYSQL_SYSVAR(buffer_pool_size),
668
703
+  MYSQL_SYSVAR(buffer_pool_shm_key),
 
704
+  MYSQL_SYSVAR(buffer_pool_shm_checksum),
669
705
   MYSQL_SYSVAR(checksums),
670
706
   MYSQL_SYSVAR(fast_checksum),
671
707
   MYSQL_SYSVAR(commit_concurrency),
816
852
diff -ruN a/storage/innodb_plugin/include/srv0srv.h b/storage/innodb_plugin/include/srv0srv.h
817
853
--- a/storage/innodb_plugin/include/srv0srv.h   2010-07-14 16:32:49.695323045 +0900
818
854
+++ b/storage/innodb_plugin/include/srv0srv.h   2010-07-14 16:40:16.171325784 +0900
819
 
@@ -156,6 +156,8 @@
 
855
@@ -156,6 +156,9 @@
820
856
 extern ulint   srv_mem_pool_size;
821
857
 extern ulint   srv_lock_table_size;
822
858
 
823
859
+extern uint    srv_buffer_pool_shm_key;
 
860
+extern ibool   srv_buffer_pool_shm_checksum;
824
861
+
825
862
 extern ibool   srv_thread_concurrency_timer_based;
826
863
 
1057
1094
diff -ruN a/storage/innodb_plugin/srv/srv0srv.c b/storage/innodb_plugin/srv/srv0srv.c
1058
1095
--- a/storage/innodb_plugin/srv/srv0srv.c       2010-07-14 16:33:23.848391648 +0900
1059
1096
+++ b/storage/innodb_plugin/srv/srv0srv.c       2010-07-14 16:40:16.177323553 +0900
1060
 
@@ -211,6 +211,9 @@
 
1097
@@ -211,6 +211,10 @@
1061
1098
 UNIV_INTERN ulint      srv_mem_pool_size       = ULINT_MAX;
1062
1099
 UNIV_INTERN ulint      srv_lock_table_size     = ULINT_MAX;
1063
1100
 
1064
1101
+/* key value for shm */
1065
1102
+UNIV_INTERN uint       srv_buffer_pool_shm_key = 0;
 
1103
+UNIV_INTERN ibool      srv_buffer_pool_shm_checksum = TRUE;
1066
1104
+
1067
1105
 /* This parameter is deprecated. Use srv_n_io_[read|write]_threads
1068
1106
 instead. */