Debian Codegraph @

storage/innobase/fsp/fsp0sysspace.cc

raw
1 /*****************************************************************************
2
3 Copyright (c) 2013, 2026, Oracle and/or its affiliates.
4
5 This program is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License, version 2.0, as published by the
7 Free Software Foundation.
8
9 This program is designed to work with certain software (including
10 but not limited to OpenSSL) that is licensed under separate terms,
11 as designated in a particular file or component or in included license
12 documentation. The authors of MySQL hereby grant you an additional
13 permission to link the program and your derivative works with the
14 separately licensed software that they have either included with
15 the program or referenced in the documentation.
16
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
20 for more details.
21
22 You should have received a copy of the GNU General Public License along with
23 this program; if not, write to the Free Software Foundation, Inc.,
24 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
26 *****************************************************************************/
27
28 /** @file fsp/fsp0space.cc
29 Multi file, shared, system tablespace implementation.
30
31 Created 2012-11-16 by Sunny Bains as srv/srv0space.cc
32 Refactored 2013-7-26 by Kevin Lewis
33 *******************************************************/
34
35 #include <stdlib.h>
36 #include <sys/types.h>
37
38 #include "dict0load.h"
39 #include "fsp0sysspace.h"
40 #ifndef UNIV_HOTBACKUP
41 #include "ha_prototypes.h"
42 #include "mem0mem.h"
43
44 /** The server header file is included to access opt_initialize global variable.
45 If server passes the option for create/open DB to SE, we should remove such
46 direct reference to server header and global variable */
47 #include "mysqld.h"
48 #endif /* !UNIV_HOTBACKUP */
49 #include "os0file.h"
50 #ifndef UNIV_HOTBACKUP
51 #include "row0mysql.h"
52 #endif /* !UNIV_HOTBACKUP */
53 #include "srv0start.h"
54 #include "trx0sys.h"
55 #include "ut0new.h"
56
57 /** The control info of the system tablespace. */
58 SysTablespace srv_sys_space;
59
60 /** The control info of a temporary table shared tablespace. */
61 SysTablespace srv_tmp_space;
62
63 /** If the last data file is auto-extended, we add this many pages to it
64 at a time. We have to make this public because it is a config variable. */
65 ulong sys_tablespace_auto_extend_increment;
66
67 #ifdef UNIV_DEBUG
68 /** Control if extra debug checks need to be done for temporary tablespace.
69 Default = true that is disable such checks.
70 This variable is not exposed to end-user but still kept as variable for
71 developer to enable it during debug. */
72 bool srv_skip_temp_table_checks_debug = true;
73 #endif /* UNIV_DEBUG */
74
75 /** Put the pointer to the next byte after a valid file name. Note that we must
76 step over the ':' in a Windows filepath.
77 A Windows path normally looks like "C:\ibdata\ibdata1:1G", but a Windows raw
78 partition may have a specification like "\\.\C::1Gnewraw" or
79 "\\.\PHYSICALDRIVE2:1Gnewraw".
80 @param[in] ptr system tablespace file path spec
81 @return next character in string after the file name */
82 char *SysTablespace::parse_file_name(char *ptr) {
83 const char *start = ptr;
84
85 while ((*ptr != ':' && *ptr != '\0') ||
86 (ptr != start && *ptr == ':' &&
87 (*(ptr + 1) == '\\' || *(ptr + 1) == '/' || *(ptr + 1) == ':'))) {
88 ptr++;
89 }
90
91 return (ptr);
92 }
93
94 /** Convert a numeric string representing a number of bytes
95 optionally ending in upper or lower case G, M, or K,
96 to a number of megabytes, rounding down to the nearest megabyte.
97 Then return the number of pages in the file.
98 @param[in,out] ptr Pointer to a numeric string
99 @return the number of pages in the file. */
100 page_no_t SysTablespace::parse_units(char *&ptr) {
101 char *endp;
102 ulint num = strtoul(ptr, &endp, 10);
103 ulint megs;
104
105 ptr = endp;
106
107 switch (*ptr) {
108 case 'G':
109 case 'g':
110 megs = num * 1024;
111 ++ptr;
112 break;
113
114 case 'M':
115 case 'm':
116 megs = num;
117 ++ptr;
118 break;
119 case 'K':
120 case 'k':
121 megs = num / 1024;
122 ++ptr;
123 break;
124 default:
125 megs = num / (1024 * 1024);
126 break;
127 }
128
129 return (static_cast<page_no_t>(megs * (1024 * 1024 / UNIV_PAGE_SIZE)));
130 }
131
132 /** Parse the input params and populate member variables.
133 @param[in] filepath_spec path to data files
134 @param[in] supports_raw true if the tablespace supports raw devices
135 @return true on success parse */
136 bool SysTablespace::parse_params(const char *filepath_spec, bool supports_raw) {
137 char *filepath;
138 page_no_t size;
139 ulint n_files = 0;
140
141 ut_ad(m_last_file_size_max == 0);
142 ut_ad(!m_auto_extend_last_file);
143
144 char *input_str = mem_strdup(filepath_spec);
145 char *ptr = input_str;
146
147 /*---------------------- PASS 1 ---------------------------*/
148 /* First calculate the number of data files and check syntax. */
149 while (*ptr != '\0') {
150 filepath = ptr;
151
152 ptr = parse_file_name(ptr);
153
154 if (ptr == filepath) {
155 ib::error(ER_IB_MSG_431) << "File Path Specification '" << filepath_spec
156 << "' is missing a file name.";
157
158 ut::free(input_str);
159 return (false);
160 }
161
162 if (*ptr == '\0') {
163 ib::error(ER_IB_MSG_432) << "File Path Specification '" << filepath_spec
164 << "' is missing a file size.";
165
166 ut::free(input_str);
167 return (false);
168 }
169
170 ptr++;
171
172 size = parse_units(ptr);
173
174 if (size == 0) {
175 invalid_size:
176 ib::error(ER_IB_MSG_433)
177 << "Invalid File Path Specification: '" << filepath_spec
178 << "'. An invalid file size was specified.";
179
180 ut::free(input_str);
181 return (false);
182 }
183
184 if (0 == strncmp(ptr, ":autoextend", (sizeof ":autoextend") - 1)) {
185 ptr += (sizeof ":autoextend") - 1;
186
187 if (0 == strncmp(ptr, ":max:", (sizeof ":max:") - 1)) {
188 ptr += (sizeof ":max:") - 1;
189
190 page_no_t max = parse_units(ptr);
191
192 if (max < size) {
193 goto invalid_size;
194 }
195 }
196
197 if (*ptr == ';') {
198 ib::error(ER_IB_MSG_434)
199 << "Invalid File Path Specification: '" << filepath_spec
200 << "'. Only the last"
201 " file defined can be 'autoextend'.";
202
203 ut::free(input_str);
204 return (false);
205 }
206 }
207
208 if (0 == strncmp(ptr, "new", (sizeof "new") - 1)) {
209 ptr += (sizeof "new") - 1;
210 }
211
212 if (0 == strncmp(ptr, "raw", (sizeof "raw") - 1)) {
213 if (!supports_raw) {
214 ib::error(ER_IB_MSG_435)
215 << "Invalid File Path Specification: '" << filepath_spec
216 << "' Tablespace"
217 " doesn't support raw devices";
218
219 ut::free(input_str);
220 return (false);
221 }
222
223 ptr += (sizeof "raw") - 1;
224 }
225
226 ++n_files;
227
228 if (*ptr == ';') {
229 ptr++;
230 } else if (*ptr != '\0') {
231 ptr[0] = '\0';
232 ib::error(ER_IB_MSG_436)
233 << "File Path Specification: '" << filepath_spec
234 << "' has unrecognized characters after '" << input_str << "'";
235
236 ut::free(input_str);
237 return (false);
238 }
239 }
240
241 if (n_files == 0) {
242 ib::error(ER_IB_MSG_437) << "File Path Specification: '" << filepath_spec
243 << "' must contain"
244 " at least one data file definition";
245
246 ut::free(input_str);
247 return (false);
248 }
249
250 /*---------------------- PASS 2 ---------------------------*/
251 /* Then store the actual values to our arrays */
252 ptr = input_str;
253 ulint order = 0;
254
255 while (*ptr != '\0') {
256 filepath = ptr;
257
258 ptr = parse_file_name(ptr);
259
260 if (*ptr == ':') {
261 /* Make filepath a null-terminated string */
262 *ptr = '\0';
263 ptr++;
264 }
265
266 size = parse_units(ptr);
267 ut_ad(size > 0);
268
269 if (0 == strncmp(ptr, ":autoextend", (sizeof ":autoextend") - 1)) {
270 m_auto_extend_last_file = true;
271
272 ptr += (sizeof ":autoextend") - 1;
273
274 if (0 == strncmp(ptr, ":max:", (sizeof ":max:") - 1)) {
275 ptr += (sizeof ":max:") - 1;
276
277 m_last_file_size_max = parse_units(ptr);
278 }
279 }
280
281 m_files.push_back(Datafile(filepath, flags(), size, order));
282 Datafile *datafile = &m_files.back();
283 datafile->make_filepath(path(), filepath, NO_EXT);
284
285 if (0 == strncmp(ptr, "new", (sizeof "new") - 1)) {
286 ptr += (sizeof "new") - 1;
287 }
288
289 if (0 == strncmp(ptr, "raw", (sizeof "raw") - 1)) {
290 ut_a(supports_raw);
291
292 ptr += (sizeof "raw") - 1;
293
294 /* Initialize new raw device only during initialize */
295 m_files.back().m_type =
296 #ifndef UNIV_HOTBACKUP
297 opt_initialize ? SRV_NEW_RAW : SRV_OLD_RAW;
298 #else /* !UNIV_HOTBACKUP */
299 SRV_OLD_RAW;
300 #endif /* !UNIV_HOTBACKUP */
301 }
302
303 if (*ptr == ';') {
304 ++ptr;
305 }
306 order++;
307 }
308
309 ut_ad(n_files == ulint(m_files.size()));
310
311 ut::free(input_str);
312
313 return (true);
314 }
315
316 /** Frees the memory allocated by the parse method. */
317 void SysTablespace::shutdown() {
318 Tablespace::shutdown();
319
320 m_auto_extend_last_file = false;
321 m_last_file_size_max = 0;
322 m_created_new_raw = false;
323 m_is_tablespace_full = false;
324 m_sanity_checks_done = false;
325 }
326
327 /** Verify the size of the physical file.
328 @param[in] file data file object
329 @return DB_SUCCESS if OK else error code. */
330 dberr_t SysTablespace::check_size(Datafile &file) {
331 os_offset_t size = os_file_get_size(file.m_handle);
332 ut_a(size != (os_offset_t)-1);
333
334 /* Under some error conditions like disk full scenarios
335 or file size reaching filesystem limit the data file
336 could contain an incomplete extent at the end. When we
337 extend a data file and if some failure happens, then
338 also the data file could contain an incomplete extent.
339 So we need to round the size downward to a megabyte. */
340
341 page_no_t rounded_size_pages = get_pages_from_size(size);
342
343 /* If last file */
344 if (&file == &m_files.back() && m_auto_extend_last_file) {
345 if (file.m_size > rounded_size_pages ||
346 (m_last_file_size_max > 0 &&
347 m_last_file_size_max < rounded_size_pages)) {
348 ib::error(ER_IB_MSG_438)
349 << "The Auto-extending " << name() << " data file '"
350 << file.filepath()
351 << "' is"
352 " of a different size "
353 << rounded_size_pages
354 << " pages (rounded down to MB) than specified"
355 " in the .cnf file: initial "
356 << file.m_size << " pages, max " << m_last_file_size_max
357 << " (relevant if non-zero) pages!";
358 return (DB_ERROR);
359 }
360
361 file.m_size = rounded_size_pages;
362 }
363
364 if (rounded_size_pages != file.m_size) {
365 ib::error(ER_IB_MSG_439)
366 << "The " << name() << " data file '" << file.filepath()
367 << "' is of a different size " << rounded_size_pages
368 << " pages (rounded down to MB)"
369 " than the "
370 << file.m_size
371 << " pages specified in"
372 " the .cnf file!";
373 return (DB_ERROR);
374 }
375
376 return (DB_SUCCESS);
377 }
378
379 /** Set the size of the file.
380 @param[in,out] file data file object
381 @return DB_SUCCESS or error code */
382 dberr_t SysTablespace::set_size(Datafile &file) {
383 ut_a(!srv_read_only_mode || m_ignore_read_only);
384
385 /* We created the data file and now write it full of zeros */
386 ib::info(ER_IB_MSG_440)
387 << "Setting file '" << file.filepath() << "' size to "
388 << (file.m_size >> (20 - UNIV_PAGE_SIZE_SHIFT))
389 << " MB."
390 " Physically writing the file full; Please wait ...";
391
392 bool success = os_file_set_size(
393 file.m_filepath, file.m_handle, 0,
394 static_cast<os_offset_t>(file.m_size) << UNIV_PAGE_SIZE_SHIFT, true);
395
396 if (success) {
397 ib::info(ER_IB_MSG_441)
398 << "File '" << file.filepath() << "' size is now "
399 << (file.m_size >> (20 - UNIV_PAGE_SIZE_SHIFT)) << " MB.";
400 } else {
401 ib::error(ER_IB_MSG_442)
402 << "Could not set the file size of '" << file.filepath()
403 << "'. Probably out of disk space";
404
405 return (DB_ERROR);
406 }
407
408 return (DB_SUCCESS);
409 }
410
411 /** Create a data file.
412 @param[in,out] file data file object
413 @return DB_SUCCESS or error code */
414 dberr_t SysTablespace::create_file(Datafile &file) {
415 dberr_t err = DB_SUCCESS;
416
417 ut_a(!file.m_exists);
418 ut_a(!srv_read_only_mode || m_ignore_read_only);
419
420 switch (file.m_type) {
421 case SRV_NEW_RAW:
422
423 /* The partition is opened, not created; then it is
424 written over */
425 m_created_new_raw = true;
426
427 [[fallthrough]];
428
429 case SRV_OLD_RAW:
430
431 srv_start_raw_disk_in_use = true;
432
433 [[fallthrough]];
434
435 case SRV_NOT_RAW:
436 err =
437 file.open_or_create(m_ignore_read_only ? false : srv_read_only_mode);
438 break;
439 }
440
441 if (err == DB_SUCCESS && file.m_type != SRV_OLD_RAW) {
442 err = set_size(file);
443 }
444
445 return (err);
446 }
447
448 /** Open a data file.
449 @param[in,out] file data file object
450 @return DB_SUCCESS or error code */
451 dberr_t SysTablespace::open_file(Datafile &file) {
452 dberr_t err = DB_SUCCESS;
453
454 ut_a(file.m_exists);
455
456 switch (file.m_type) {
457 case SRV_NEW_RAW:
458 /* The partition is opened, not created; then it is
459 written over */
460 m_created_new_raw = true;
461
462 [[fallthrough]];
463
464 case SRV_OLD_RAW:
465 srv_start_raw_disk_in_use = true;
466
467 if (srv_read_only_mode && !m_ignore_read_only) {
468 ib::error(ER_IB_MSG_443)
469 << "Can't open a raw device '" << file.m_filepath
470 << "' when"
471 " --innodb-read-only is set";
472
473 return (DB_ERROR);
474 }
475
476 [[fallthrough]];
477
478 case SRV_NOT_RAW:
479 err =
480 file.open_or_create(m_ignore_read_only ? false : srv_read_only_mode);
481
482 if (err != DB_SUCCESS) {
483 return (err);
484 }
485 break;
486 }
487
488 switch (file.m_type) {
489 case SRV_NEW_RAW:
490 /* Set file size for new raw device. */
491 err = set_size(file);
492 break;
493
494 case SRV_NOT_RAW:
495 /* Check file size for existing file. */
496 err = check_size(file);
497 break;
498
499 case SRV_OLD_RAW:
500 err = DB_SUCCESS;
501 break;
502 }
503
504 if (err != DB_SUCCESS) {
505 file.close();
506 }
507
508 return (err);
509 }
510
511 #ifndef UNIV_HOTBACKUP
512
513 dberr_t SysTablespace::read_lsn_and_check_flags(lsn_t *flushed_lsn) {
514 /* Only relevant for the system tablespace. */
515 ut_ad(space_id() == TRX_SYS_SPACE);
516
517 files_t::iterator it = m_files.begin();
518
519 ut_a(it->m_exists);
520 ut_ad(it->is_open());
521 dberr_t err = it->read_first_page();
522
523 if (err != DB_SUCCESS) {
524 return (err);
525 }
526
527 ut_a(it->order() == 0);
528
529 err = recv_sys->dblwr->load();
530
531 if (err != DB_SUCCESS) {
532 return (err);
533 }
534
535 err = recv_sys->dblwr->reduced_load();
536
537 if (err != DB_SUCCESS) {
538 return (err);
539 }
540
541 /* Check the contents of the first page of the first datafile. */
542 err = it->validate_first_page(space_id(), flushed_lsn, false);
543 if (err != DB_SUCCESS) {
544 /* Perhaps the first page was torn? Recover it and validate again. */
545 if (it->open_or_create(srv_read_only_mode) != DB_SUCCESS ||
546 it->restore_from_doublewrite(0) != DB_SUCCESS) {
547 it->close();
548 return err;
549 }
550 err = it->validate_first_page(space_id(), flushed_lsn, false);
551 if (err != DB_SUCCESS) {
552 return err;
553 }
554 }
555 ut_ad(!it->is_open());
556
557 /* The flags of srv_sys_space do not have SDI Flag set.
558 Update the flags of system tablespace to indicate the presence
559 of SDI */
560 set_flags(it->flags());
561
562 return (DB_SUCCESS);
563 }
564
565 /** Check if a file can be opened in the correct mode.
566 @param[in,out] file data file object
567 @param[out] reason exact reason if file_status check failed.
568 @return DB_SUCCESS or error code. */
569 dberr_t SysTablespace::check_file_status(const Datafile &file,
570 file_status_t &reason) {
571 os_file_stat_t stat;
572
573 memset(&stat, 0x0, sizeof(stat));
574
575 dberr_t err =
576 os_file_get_status(file.m_filepath, &stat, true,
577 m_ignore_read_only ? false : srv_read_only_mode);
578
579 reason = FILE_STATUS_VOID;
580 /* File exists but we can't read the rw-permission settings. */
581 switch (err) {
582 case DB_FAIL:
583 ib::error(ER_IB_MSG_445)
584 << "os_file_get_status() failed on '" << file.filepath()
585 << "'. Can't determine file permissions";
586 err = DB_ERROR;
587 reason = FILE_STATUS_RW_PERMISSION_ERROR;
588 break;
589
590 case DB_SUCCESS:
591
592 /* Note: stat.rw_perm is only valid for "regular" files */
593
594 if (stat.type == OS_FILE_TYPE_FILE) {
595 if (!stat.rw_perm) {
596 const char *p = (!srv_read_only_mode || m_ignore_read_only)
597 ? "writable"
598 : "readable";
599
600 ib::error(ER_IB_MSG_446) << "The " << name() << " data file"
601 << " '" << file.name() << "' must be " << p;
602
603 err = DB_ERROR;
604 reason = FILE_STATUS_READ_WRITE_ERROR;
605 }
606
607 } else {
608 /* Not a regular file, bail out. */
609 ib::error(ER_IB_MSG_447)
610 << "The " << name() << " data file '" << file.name()
611 << "' is not a regular"
612 " InnoDB data file.";
613
614 err = DB_ERROR;
615 reason = FILE_STATUS_NOT_REGULAR_FILE_ERROR;
616 }
617 break;
618
619 case DB_NOT_FOUND:
620 break;
621
622 default:
623 ut_d(ut_error);
624 }
625
626 return (err);
627 }
628
629 /** Note that the data file was not found.
630 @param[in] file data file object
631 @param[in] create_new_db true if a new instance to be created
632 @return DB_SUCCESS or error code */
633 dberr_t SysTablespace::file_not_found(Datafile &file, bool create_new_db) {
634 file.m_exists = false;
635
636 if (srv_read_only_mode && !m_ignore_read_only) {
637 ib::error(ER_IB_MSG_448) << "Can't create file '" << file.filepath()
638 << "' when --innodb-read-only is set";
639
640 return (DB_ERROR);
641
642 } else if (&file == &m_files.front()) {
643 /* First data file. */
644
645 if (space_id() == TRX_SYS_SPACE && create_new_db) {
646 ib::info(ER_IB_MSG_449)
647 << "The first " << name() << " data file '" << file.name()
648 << "' did not exist."
649 " A new tablespace will be created!";
650 }
651
652 } else {
653 ib::info(ER_IB_MSG_450) << "Need to create a new " << name()
654 << " data file '" << file.name() << "'.";
655 }
656
657 /* We allow add new files at end even if dict_init_mode is
658 not creating files. */
659 if (!create_new_db && (&file == &m_files.front())) {
660 return (DB_SUCCESS);
661 }
662
663 /* Set the file create mode. */
664 switch (file.m_type) {
665 case SRV_NOT_RAW:
666 file.set_open_flags(OS_FILE_CREATE);
667 break;
668
669 case SRV_NEW_RAW:
670 case SRV_OLD_RAW:
671 file.set_open_flags(OS_FILE_OPEN_RAW);
672 break;
673 }
674
675 return (DB_SUCCESS);
676 }
677
678 /** Note that the data file was found.
679 @param[in,out] file data file object */
680 void SysTablespace::file_found(Datafile &file) {
681 /* Note that the file exists and can be opened
682 in the appropriate mode. */
683 file.m_exists = true;
684
685 /* Set the file open mode */
686 switch (file.m_type) {
687 case SRV_NOT_RAW:
688 file.set_open_flags(&file == &m_files.front() ? OS_FILE_OPEN_RETRY
689 : OS_FILE_OPEN);
690 break;
691
692 case SRV_NEW_RAW:
693 case SRV_OLD_RAW:
694 file.set_open_flags(OS_FILE_OPEN_RAW);
695 break;
696 }
697 }
698
699 /** Check the data file specification.
700 @param[in] create_new_db True if a new database is to be created
701 @param[in] min_expected_size Minimum expected tablespace size in bytes
702 @return DB_SUCCESS if all OK else error code */
703 dberr_t SysTablespace::check_file_spec(bool create_new_db,
704 ulint min_expected_size) {
705 if (m_files.size() >= 1000) {
706 ib::error(ER_IB_MSG_451) << "There must be < 1000 data files in " << name()
707 << " but " << m_files.size()
708 << " have been"
709 " defined.";
710
711 return (DB_ERROR);
712 }
713
714 if (get_sum_of_sizes() < min_expected_size / UNIV_PAGE_SIZE) {
715 ib::error(ER_IB_MSG_452) << "Tablespace size must be at least "
716 << min_expected_size / (1024 * 1024) << " MB";
717
718 return (DB_ERROR);
719 }
720
721 dberr_t err = DB_SUCCESS;
722
723 ut_a(!m_files.empty());
724
725 /* If there is more than one data file and the last data file
726 doesn't exist, that is OK. We allow adding of new data files. */
727
728 files_t::iterator begin = m_files.begin();
729 files_t::iterator end = m_files.end();
730
731 for (files_t::iterator it = begin; it != end; ++it) {
732 file_status_t reason_if_failed;
733 err = check_file_status(*it, reason_if_failed);
734
735 if (err == DB_NOT_FOUND) {
736 err = file_not_found(*it, create_new_db);
737
738 if (err != DB_SUCCESS) {
739 break;
740 }
741
742 } else if (err != DB_SUCCESS) {
743 if (reason_if_failed == FILE_STATUS_READ_WRITE_ERROR) {
744 const char *p = (!srv_read_only_mode || m_ignore_read_only)
745 ? "writable"
746 : "readable";
747 ib::error(ER_IB_MSG_453) << "The " << name() << " data file"
748 << " '" << it->name() << "' must be " << p;
749 }
750
751 ut_a(err != DB_FAIL);
752 break;
753
754 } else if (create_new_db && !(*it).is_raw_type()) {
755 ib::error(ER_IB_MSG_454)
756 << "The " << name() << " data file '" << begin->m_name
757 << "' was not found but"
758 " one of the other data files '"
759 << it->m_name << "' exists.";
760
761 err = DB_ERROR;
762 break;
763
764 } else {
765 ut_ad(err == DB_SUCCESS);
766 file_found(*it);
767 }
768 }
769
770 /* We assume doublewirte blocks in the first data file. */
771 if (err == DB_SUCCESS && begin->m_size < TRX_SYS_DOUBLEWRITE_BLOCK_SIZE * 3) {
772 ib::error(ER_IB_MSG_455)
773 << "The " << name() << " data file "
774 << "'" << begin->name() << "' must be at least "
775 << TRX_SYS_DOUBLEWRITE_BLOCK_SIZE * 3 * UNIV_PAGE_SIZE / (1024 * 1024)
776 << " MB";
777
778 err = DB_ERROR;
779 }
780
781 return (err);
782 }
783
784 dberr_t SysTablespace::open_or_create(bool is_temp, bool create_new_db,
785 page_no_t *sum_new_sizes,
786 lsn_t *flush_lsn) {
787 dberr_t err = DB_SUCCESS;
788 fil_space_t *space = nullptr;
789
790 ut_ad(!m_files.empty());
791
792 if (sum_new_sizes) {
793 *sum_new_sizes = 0;
794 }
795
796 files_t::iterator begin = m_files.begin();
797 files_t::iterator end = m_files.end();
798
799 ut_ad(begin->order() == 0);
800
801 for (files_t::iterator it = begin; it != end; ++it) {
802 if (it->m_exists) {
803 err = open_file(*it);
804
805 /* For new raw device increment new size. */
806 if (sum_new_sizes && it->m_type == SRV_NEW_RAW) {
807 *sum_new_sizes += it->m_size;
808 }
809
810 } else {
811 err = create_file(*it);
812
813 if (sum_new_sizes) {
814 *sum_new_sizes += it->m_size;
815 }
816
817 /* Set the correct open flags now that we have
818 successfully created the file. */
819 if (err == DB_SUCCESS) {
820 /* We ignore new_db OUT parameter here
821 as the information is known at this stage */
822 file_found(*it);
823 }
824 }
825
826 if (err != DB_SUCCESS) {
827 return (err);
828 }
829
830 #if !defined(NO_FALLOCATE) && defined(UNIV_LINUX)
831 /* Note: This should really be per node and not per
832 tablespace because a tablespace can contain multiple
833 files (nodes). The implication is that all files of
834 the tablespace should be on the same medium. */
835
836 if (fil_fusionio_enable_atomic_write(it->m_handle)) {
837 if (dblwr::is_enabled()) {
838 ib::info(ER_IB_MSG_456) << "FusionIO atomic IO enabled,"
839 " disabling the double write buffer";
840
841 dblwr::g_mode = dblwr::Mode::OFF;
842 }
843
844 it->m_atomic_write = true;
845 } else {
846 it->m_atomic_write = false;
847 }
848 #else
849 it->m_atomic_write = false;
850 #endif /* !NO_FALLOCATE && UNIV_LINUX*/
851 }
852
853 if (flush_lsn != nullptr) {
854 if (create_new_db) {
855 /* There are no data files, so we assign the initial value
856 to flush_lsn instead of reading it from disk. */
857 *flush_lsn = LOG_START_LSN + LOG_BLOCK_HDR_SIZE;
858 } else {
859 /* Validate the header page in the first datafile in the
860 system tablespace and read flush_lsn from the validated
861 header page. */
862 err = read_lsn_and_check_flags(flush_lsn);
863 if (err != DB_SUCCESS) {
864 return (err);
865 }
866 }
867 }
868
869 /* Close the current handles, add space and file info to the
870 fil_system cache and the Data Dictionary, and re-open them
871 in file_system cache so that they stay open until shutdown. */
872 ulint node_counter = 0;
873 for (files_t::iterator it = begin; it != end; ++it) {
874 it->close();
875 it->m_exists = true;
876
877 if (it == begin) {
878 /* First data file. */
879
880 /* Create the tablespace entry for the multi-file
881 tablespace in the tablespace manager. */
882 space =
883 fil_space_create(name(), space_id(), flags(),
884 is_temp ? FIL_TYPE_TEMPORARY : FIL_TYPE_TABLESPACE);
885 }
886
887 ut_ad(fil_validate());
888
889 page_no_t max_size =
890 (++node_counter == m_files.size()
891 ? (m_last_file_size_max == 0 ? PAGE_NO_MAX : m_last_file_size_max)
892 : it->m_size);
893
894 /* Add the datafile to the fil_system cache. */
895 if (!fil_node_create(it->m_filepath, it->m_size, space,
896 it->m_type != SRV_NOT_RAW, it->m_atomic_write,
897 max_size)) {
898 err = DB_ERROR;
899 break;
900 }
901 }
902
903 return (err);
904 }
905 #endif /* !UNIV_HOTBACKUP */
906
907 /**
908 @return next increment size */
909 page_no_t SysTablespace::get_increment() const {
910 page_no_t increment;
911
912 if (m_last_file_size_max == 0) {
913 increment = get_autoextend_increment();
914 } else {
915 increment = m_last_file_size_max - last_file_size();
916 }
917
918 if (increment > get_autoextend_increment()) {
919 increment = get_autoextend_increment();
920 }
921
922 return (increment);
923 }