📄 srv0start.c
字号:
for (; *str; str++) { if (*str == '/') { *str = '\\'; } }#endif} /*************************************************************************Adds a slash or a backslash to the end of a string if it is missingand the string is not empty. */char*srv_add_path_separator_if_needed(/*=============================*/ /* out: string which has the separator if the string is not empty */ char* str) /* in: null-terminated character string */{ char* out_str; ulint len = ut_strlen(str); if (len == 0 || str[len - 1] == SRV_PATH_SEPARATOR) { return(str); } out_str = ut_malloc(len + 2); memcpy(out_str, str, len); out_str[len] = SRV_PATH_SEPARATOR; out_str[len + 1] = 0; return(out_str);}/*************************************************************************Calculates the low 32 bits when a file size which is given as a numberdatabase pages is converted to the number of bytes. */staticulintsrv_calc_low32(/*===========*/ /* out: low 32 bytes of file size when expressed in bytes */ ulint file_size) /* in: file size in database pages */{ return(0xFFFFFFFFUL & (file_size << UNIV_PAGE_SIZE_SHIFT));}/*************************************************************************Calculates the high 32 bits when a file size which is given as a numberdatabase pages is converted to the number of bytes. */staticulintsrv_calc_high32(/*============*/ /* out: high 32 bytes of file size when expressed in bytes */ ulint file_size) /* in: file size in database pages */{ return(file_size >> (32 - UNIV_PAGE_SIZE_SHIFT));}#ifndef UNIV_HOTBACKUP/*************************************************************************Creates or opens the log files and closes them. */staticulintopen_or_create_log_file(/*====================*/ /* out: DB_SUCCESS or error code */ ibool create_new_db, /* in: TRUE if we should create a new database */ ibool* log_file_created, /* out: TRUE if new log file created */ ibool log_file_has_been_opened,/* in: TRUE if a log file has been opened before: then it is an error to try to create another log file */ ulint k, /* in: log group number */ ulint i) /* in: log file number in group */{ ibool ret; ulint size; ulint size_high; char name[10000]; UT_NOT_USED(create_new_db); *log_file_created = FALSE; srv_normalize_path_for_win(srv_log_group_home_dirs[k]); srv_log_group_home_dirs[k] = srv_add_path_separator_if_needed( srv_log_group_home_dirs[k]); ut_a(strlen(srv_log_group_home_dirs[k]) < (sizeof name) - 10 - sizeof "ib_logfile"); sprintf(name, "%s%s%lu", srv_log_group_home_dirs[k], "ib_logfile", (ulong) i); files[i] = os_file_create(name, OS_FILE_CREATE, OS_FILE_NORMAL, OS_LOG_FILE, &ret); if (ret == FALSE) { if (os_file_get_last_error(FALSE) != OS_FILE_ALREADY_EXISTS#ifdef UNIV_AIX /* AIX 5.1 after security patch ML7 may have errno set to 0 here, which causes our function to return 100; work around that AIX problem */ && os_file_get_last_error(FALSE) != 100#endif ) { fprintf(stderr, "InnoDB: Error in creating or opening %s\n", name); return(DB_ERROR); } files[i] = os_file_create(name, OS_FILE_OPEN, OS_FILE_AIO, OS_LOG_FILE, &ret); if (!ret) { fprintf(stderr, "InnoDB: Error in opening %s\n", name); return(DB_ERROR); } ret = os_file_get_size(files[i], &size, &size_high); ut_a(ret); if (size != srv_calc_low32(srv_log_file_size) || size_high != srv_calc_high32(srv_log_file_size)) { fprintf(stderr,"InnoDB: Error: log file %s is of different size %lu %lu bytes\n""InnoDB: than specified in the .cnf file %lu %lu bytes!\n", name, (ulong) size_high, (ulong) size, (ulong) srv_calc_high32(srv_log_file_size), (ulong) srv_calc_low32(srv_log_file_size)); return(DB_ERROR); } } else { *log_file_created = TRUE; ut_print_timestamp(stderr); fprintf(stderr, " InnoDB: Log file %s did not exist: new to be created\n", name); if (log_file_has_been_opened) { return(DB_ERROR); } fprintf(stderr, "InnoDB: Setting log file %s size to %lu MB\n", name, (ulong) srv_log_file_size >> (20 - UNIV_PAGE_SIZE_SHIFT)); fprintf(stderr, "InnoDB: Database physically writes the file full: wait...\n"); ret = os_file_set_size(name, files[i], srv_calc_low32(srv_log_file_size), srv_calc_high32(srv_log_file_size)); if (!ret) { fprintf(stderr, "InnoDB: Error in creating %s: probably out of disk space\n", name); return(DB_ERROR); } } ret = os_file_close(files[i]); ut_a(ret); if (i == 0) { /* Create in memory the file space object which is for this log group */ fil_space_create(name, 2 * k + SRV_LOG_SPACE_FIRST_ID, FIL_LOG); } ut_a(fil_validate()); fil_node_create(name, srv_log_file_size, 2 * k + SRV_LOG_SPACE_FIRST_ID, FALSE);#ifdef UNIV_LOG_ARCHIVE /* If this is the first log group, create the file space object for archived logs. Under MySQL, no archiving ever done. */ if (k == 0 && i == 0) { arch_space_id = 2 * k + 1 + SRV_LOG_SPACE_FIRST_ID; fil_space_create("arch_log_space", arch_space_id, FIL_LOG); } else { arch_space_id = ULINT_UNDEFINED; }#endif /* UNIV_LOG_ARCHIVE */ if (i == 0) { log_group_init(k, srv_n_log_files, srv_log_file_size * UNIV_PAGE_SIZE, 2 * k + SRV_LOG_SPACE_FIRST_ID, SRV_LOG_SPACE_FIRST_ID + 1); /* dummy arch space id */ } return(DB_SUCCESS);}/*************************************************************************Creates or opens database data files and closes them. */staticulintopen_or_create_data_files(/*======================*/ /* out: DB_SUCCESS or error code */ ibool* create_new_db, /* out: TRUE if new database should be created */#ifdef UNIV_LOG_ARCHIVE ulint* min_arch_log_no,/* out: min of archived log numbers in data files */ ulint* max_arch_log_no,/* out: */#endif /* UNIV_LOG_ARCHIVE */ dulint* min_flushed_lsn,/* out: min of flushed lsn values in data files */ dulint* max_flushed_lsn,/* out: */ ulint* sum_of_new_sizes)/* out: sum of sizes of the new files added */{ ibool ret; ulint i; ibool one_opened = FALSE; ibool one_created = FALSE; ulint size; ulint size_high; ulint rounded_size_pages; char name[10000]; if (srv_n_data_files >= 1000) { fprintf(stderr, "InnoDB: can only have < 1000 data files\n" "InnoDB: you have defined %lu\n", (ulong) srv_n_data_files); return(DB_ERROR); } *sum_of_new_sizes = 0; *create_new_db = FALSE; srv_normalize_path_for_win(srv_data_home); srv_data_home = srv_add_path_separator_if_needed(srv_data_home); for (i = 0; i < srv_n_data_files; i++) { srv_normalize_path_for_win(srv_data_file_names[i]); ut_a(strlen(srv_data_home) + strlen(srv_data_file_names[i]) < (sizeof name) - 1); sprintf(name, "%s%s", srv_data_home, srv_data_file_names[i]); if (srv_data_file_is_raw_partition[i] == 0) { /* First we try to create the file: if it already exists, ret will get value FALSE */ files[i] = os_file_create(name, OS_FILE_CREATE, OS_FILE_NORMAL, OS_DATA_FILE, &ret); if (ret == FALSE && os_file_get_last_error(FALSE) != OS_FILE_ALREADY_EXISTS#ifdef UNIV_AIX /* AIX 5.1 after security patch ML7 may have errno set to 0 here, which causes our function to return 100; work around that AIX problem */ && os_file_get_last_error(FALSE) != 100#endif ) { fprintf(stderr, "InnoDB: Error in creating or opening %s\n", name); return(DB_ERROR); } } else if (srv_data_file_is_raw_partition[i] == SRV_NEW_RAW) { /* The partition is opened, not created; then it is written over */ srv_start_raw_disk_in_use = TRUE; srv_created_new_raw = TRUE; files[i] = os_file_create( name, OS_FILE_OPEN_RAW, OS_FILE_NORMAL, OS_DATA_FILE, &ret); if (!ret) { fprintf(stderr, "InnoDB: Error in opening %s\n", name); return(DB_ERROR); } } else if (srv_data_file_is_raw_partition[i] == SRV_OLD_RAW) { srv_start_raw_disk_in_use = TRUE; ret = FALSE; } else { ut_a(0); } if (ret == FALSE) { /* We open the data file */ if (one_created) { fprintf(stderr, "InnoDB: Error: data files can only be added at the end\n"); fprintf(stderr, "InnoDB: of a tablespace, but data file %s existed beforehand.\n", name); return(DB_ERROR); } if (srv_data_file_is_raw_partition[i] == SRV_OLD_RAW) { files[i] = os_file_create( name, OS_FILE_OPEN_RAW, OS_FILE_NORMAL, OS_DATA_FILE, &ret); } else if (i == 0) { files[i] = os_file_create( name, OS_FILE_OPEN_RETRY, OS_FILE_NORMAL, OS_DATA_FILE, &ret); } else { files[i] = os_file_create( name, OS_FILE_OPEN, OS_FILE_NORMAL, OS_DATA_FILE, &ret); } if (!ret) { fprintf(stderr, "InnoDB: Error in opening %s\n", name); os_file_get_last_error(TRUE); return(DB_ERROR); } if (srv_data_file_is_raw_partition[i] == SRV_OLD_RAW) { goto skip_size_check; } ret = os_file_get_size(files[i], &size, &size_high); ut_a(ret); /* Round size downward to megabytes */ rounded_size_pages = (size / (1024 * 1024) + 4096 * size_high) << (20 - UNIV_PAGE_SIZE_SHIFT); if (i == srv_n_data_files - 1 && srv_auto_extend_last_data_file) { if (srv_data_file_sizes[i] > rounded_size_pages || (srv_last_file_size_max > 0 && srv_last_file_size_max < rounded_size_pages)) { fprintf(stderr,"InnoDB: Error: auto-extending data file %s is of a different size\n""InnoDB: %lu pages (rounded down to MB) than specified in the .cnf file:\n""InnoDB: initial %lu pages, max %lu (relevant if non-zero) pages!\n", name, (ulong) rounded_size_pages, (ulong) srv_data_file_sizes[i], (ulong) srv_last_file_size_max); return(DB_ERROR); } srv_data_file_sizes[i] = rounded_size_pages; } if (rounded_size_pages != srv_data_file_sizes[i]) { fprintf(stderr,"InnoDB: Error: data file %s is of a different size\n""InnoDB: %lu pages (rounded down to MB)\n""InnoDB: than specified in the .cnf file %lu pages!\n", name, (ulong) rounded_size_pages, (ulong) srv_data_file_sizes[i]); return(DB_ERROR); }skip_size_check: fil_read_flushed_lsn_and_arch_log_no(files[i], one_opened,#ifdef UNIV_LOG_ARCHIVE min_arch_log_no, max_arch_log_no,#endif /* UNIV_LOG_ARCHIVE */ min_flushed_lsn, max_flushed_lsn); one_opened = TRUE; } else { /* We created the data file and now write it full of zeros */ one_created = TRUE; if (i > 0) { ut_print_timestamp(stderr); fprintf(stderr, " InnoDB: Data file %s did not exist: new to be created\n", name); } else { fprintf(stderr, "InnoDB: The first specified data file %s did not exist:\n" "InnoDB: a new database to be created!\n", name); *create_new_db = TRUE; } ut_print_timestamp(stderr); fprintf(stderr, " InnoDB: Setting file %s size to %lu MB\n", name, (ulong) (srv_data_file_sizes[i] >> (20 - UNIV_PAGE_SIZE_SHIFT))); fprintf(stderr, "InnoDB: Database physically writes the file full: wait...\n"); ret = os_file_set_size(name, files[i], srv_calc_low32(srv_data_file_sizes[i]), srv_calc_high32(srv_data_file_sizes[i])); if (!ret) { fprintf(stderr, "InnoDB: Error in creating %s: probably out of disk space\n", name); return(DB_ERROR); } *sum_of_new_sizes = *sum_of_new_sizes + srv_data_file_sizes[i]; } ret = os_file_close(files[i]); ut_a(ret); if (i == 0) { fil_space_create(name, 0, FIL_TABLESPACE); } ut_a(fil_validate()); if (srv_data_file_is_raw_partition[i]) { fil_node_create(name, srv_data_file_sizes[i], 0, TRUE); } else { fil_node_create(name, srv_data_file_sizes[i], 0, FALSE); } } ios = 0; mutex_create(&ios_mutex); mutex_set_level(&ios_mutex, SYNC_NO_ORDER_CHECK); return(DB_SUCCESS);}/********************************************************************Starts InnoDB and creates a new database if database filesare not found and the user wants. Server parameters areread from a file of name "srv_init" in the ib_home directory. */intinnobase_start_or_create_for_mysql(void)/*====================================*/ /* out: DB_SUCCESS or error code */{ buf_pool_t* ret; ibool create_new_db; ibool log_file_created; ibool log_created = FALSE; ibool log_opened = FALSE; dulint min_flushed_lsn; dulint max_flushed_lsn;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -