YoushouldhavereceivedacopyoftheGNUGeneralPublicLicense alongwiththisprogram;ifnot,writetotheFreeSoftware
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */
/* Describe, check and repair of MARIA tables */
#define VER "1.3" #include"ma_fulltext.h" #include <myisamchk.h> #include <my_bit.h> #include <m_ctype.h> #include <my_getopt.h> #include <my_check_opt.h> #include <my_handler_errors.h> /* Remove next line if you want aria_chk to produce a stack trace */ #undef HAVE_BACKTRACE #include <my_stacktrace.h> #include <welcome_copyright_notice.h>
staticstruct my_option my_long_options[] =
{
{"analyze", 'a', "Analyze distribution of keys. Will make some joins in MySQL faster. You can check the calculated distribution.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, #ifdef __NETWARE__
{"autoclose", OPT_AUTO_CLOSE, "Auto close the screen on exit for Netware.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, #endif
{"block-search", 'b', "No help available.", 0, 0, 0, GET_ULONG, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"backup", 'B', "Make a backup of the .MAD file as 'filename-time.BAK'.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"character-sets-dir", OPT_CHARSETS_DIR, "Directory where character sets are.",
(char**) &charsets_dir, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"check", 'c', "Check table for errors.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"check-only-changed", 'C', "Check only tables that have changed since last check. It also applies to other requested actions (e.g. --analyze will be ignored if the table is already analyzed).", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"correct-checksum", OPT_CORRECT_CHECKSUM, "Correct checksum information for table.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"create-missing-keys", OPT_CREATE_MISSING_KEYS, "Create missing keys. This assumes that the data file is correct and that " "the the number of rows stored in the index file is correct. Enables " "--quick", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, #ifndef DBUG_OFF
{"debug", '#', "Output debug log. Often this is 'd:t:o,filename'.", 0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0}, #endif
{"description", 'd', "Prints some information about table.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"data-file-length", 'D', "Max length of data file (when recreating data-file when it's full).",
&check_param.max_data_file_length,
&check_param.max_data_file_length, 0, GET_LL, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"extend-check", 'e', "If used when checking a table, ensure that the table is 100 percent consistent, which will take a long time. If used when repairing a table, try to recover every possible row from the data file. Normally this will also find a lot of garbage rows; Don't use this option with repair if you are not totally desperate.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"fast", 'F', "Check only tables that haven't been closed properly. It also applies to other requested actions (e.g. --analyze will be ignored if the table is already analyzed).", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"force", 'f', "Restart with -r if there are any errors in the table. States will be updated as with --update-state.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"HELP", 'H', "Print all argument options sorted alphabetically and exit.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"help", '?', "Print all options by groups and exit. See also --HELP", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"information", 'i', "Print statistics information about table that is checked.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{ "ignore-control-file", OPT_IGNORE_CONTROL_FILE, "Ignore the control file",
(uchar**)&opt_ignore_control_file, 0, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"keys-used", 'k', "Tell Aria to update only some specific keys. # is a bit mask of which keys to use. This can be used to get faster inserts. See also keys-active",
&check_param.keys_in_use,
&check_param.keys_in_use, 0, GET_ULL, REQUIRED_ARG, -1, 0, 0, 0, 0, 0},
{"keys-active", OPT_ACTIVE_KEYS, "Threat all not listed keys as disabled. If used with repair, the keys " "will be disabled permanently. The argument is a list of key numbers, " "starting from 1, separated by ','. " "keys-active and keys-used are two ways to do the same thing", 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"datadir", 'h', "Path for control file (and logs if --logdir not used).",
(char**) &maria_data_root, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"logdir", OPT_LOG_DIR, "Path for log files.",
(char**) &opt_log_dir, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"max-record-length", OPT_MAX_RECORD_LENGTH, "Skip rows bigger than this if aria_chk can't allocate memory to hold it",
&check_param.max_record_length,
&check_param.max_record_length, 0, GET_ULL, REQUIRED_ARG, LONGLONG_MAX, 0, LONGLONG_MAX, 0, 0, 0},
{"medium-check", 'm', "Faster than extend-check, but only finds 99.99% of all errors. Should be good enough for most cases.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"quick", 'q', "Faster repair by not modifying the data file.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"read-only", 'T', "Don't mark table as checked.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"recover", 'r', "Can fix almost anything except unique keys that aren't unique.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"parallel-recover", 'p', "Same as '-r' but creates all the keys in parallel.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"safe-recover", 'o', "Uses old recovery method; Slower than '-r' but can handle a couple of cases where '-r' reports that it can't fix the data file.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"sort-recover", 'n', "Force recovering with sorting even if the temporary file was very big.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{ "require-control-file", OPT_REQUIRE_CONTROL_FILE, "Abort if cannot find control file",
(uchar**)&opt_require_control_file, 0, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, #ifdef DEBUG
{"start-check-pos", OPT_START_CHECK_POS, "No help available.", 0, 0, 0, GET_ULL, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, #endif
{"set-auto-increment", 'A', "Force auto_increment to start at this or higher value. If no value is given, then sets the next auto_increment value to the highest used value for the auto key + 1.",
&check_param.auto_increment_value,
&check_param.auto_increment_value, 0, GET_ULL, OPT_ARG, 0, 0, 0, 0, 0, 0},
{"set-collation", OPT_SET_COLLATION, "Change the collation used by the index",
(char**) &set_collation_name, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"silent", 's', "Only print errors. One can use two -s to make aria_chk very silent.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"sort-index", 'S', "Sort index blocks. This speeds up 'read-next' in applications.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"sort-records", 'R', "Sort records according to an index. This makes your data much more localized and may speed up things. (It may be VERY slow to do a sort the first time!)",
&check_param.opt_sort_key,
&check_param.opt_sort_key, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"tmpdir", 't', "Path for temporary files.", (char**) &opt_tmpdir, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"transaction-log", OPT_TRANSACTION_LOG, "Log repair command to transaction log",
&opt_transaction_logging, &opt_transaction_logging, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"update-state", 'U', "Mark tables as crashed if any errors were found and clean if check " "didn't find any errors but table was marked as 'not clean' before. This " "allows one to get rid of warnings like 'table not properly closed'. " "If table was updated, update also the timestamp for when check was made. " "This option is on by default!",
&opt_update_state, &opt_update_state, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
{"unpack", 'u', "Unpack file packed with aria_pack.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"verbose", 'v', "Print more information. This can be used with --description and --check. Use many -v for more verbosity!", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"version", 'V', "Print version and exit.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"wait", 'w', "Wait if table is locked.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"warning-for-wrong-transaction-id", OPT_WARNING_FOR_WRONG_TRANSID, "Give a warning if we find a transaction id in the table that is bigger" "than what exists in the control file. Use --skip-... to disable warning",
&opt_warning_for_wrong_transid, &opt_warning_for_wrong_transid, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
{ "page_buffer_size", OPT_PAGE_BUFFER_SIZE, "Size of page buffer. Used by --safe-repair",
&check_param.use_buffers, &check_param.use_buffers, 0,
GET_ULONG, REQUIRED_ARG, PAGE_BUFFER_INIT, 1024L*1024L,
SIZE_T_MAX, 0, (long) IO_SIZE, 0},
{ "read_buffer_size", OPT_READ_BUFFER_SIZE, "Read buffer size for sequential reads during scanning",
&check_param.read_buffer_length,
&check_param.read_buffer_length, 0, GET_ULONG, REQUIRED_ARG,
(long) READ_BUFFER_INIT, (long) MALLOC_OVERHEAD,
~0ULL, 0, (long) 1L, 0},
{ "write_buffer_size", OPT_WRITE_BUFFER_SIZE, "Write buffer size for sequential writes during repair of fixed size or dynamic size rows",
&check_param.write_buffer_length,
&check_param.write_buffer_length, 0, GET_ULONG, REQUIRED_ARG,
(long) READ_BUFFER_INIT, (long) MALLOC_OVERHEAD,
~0UL, 0, (long) 1L, 0},
{ "sort_buffer_size", OPT_SORT_BUFFER_SIZE, "Size of sort buffer. Used by --recover",
&check_param.orig_sort_buffer_length,
&check_param.orig_sort_buffer_length, 0, GET_ULL, REQUIRED_ARG,
SORT_BUFFER_INIT, MARIA_MIN_SORT_MEMORY, SIZE_T_MAX/10, 0, 1L, 0},
{ "sort_key_blocks", OPT_SORT_KEY_BLOCKS, "Internal buffer for sorting keys; Don't touch :)",
&check_param.sort_key_blocks,
&check_param.sort_key_blocks, 0, GET_ULONG, REQUIRED_ARG,
BUFFERS_WHEN_SORTING, 4L, 100L, 0L, 1L, 0},
{ "decode_bits", OPT_DECODE_BITS, "", &decode_bits,
&decode_bits, 0, GET_UINT, REQUIRED_ARG, 9L, 4L, 17L, 0L, 1L, 0},
{ "ft_min_word_len", OPT_FT_MIN_WORD_LEN, "", &ft_min_word_len,
&ft_min_word_len, 0, GET_ULONG, REQUIRED_ARG, 4, 1, HA_FT_MAXCHARLEN, 0, 1, 0},
{ "ft_max_word_len", OPT_FT_MAX_WORD_LEN, "", &ft_max_word_len,
&ft_max_word_len, 0, GET_ULONG, REQUIRED_ARG, HA_FT_MAXCHARLEN, 10,
HA_FT_MAXCHARLEN, 0, 1, 0},
{ "aria_ft_stopword_file", OPT_FT_STOPWORD_FILE, "Use stopwords from this file instead of built-in list.",
(char**) &ft_stopword_file, (char**) &ft_stopword_file, 0, GET_STR,
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{ "stats_method", OPT_STATS_METHOD, "Specifies how index statistics collection code should treat NULLs. " "Possible values of name are \"nulls_unequal\" (default behavior for MySQL 4.1/5.0), " "\"nulls_equal\" (emulate 4.0 behavior), and \"nulls_ignored\".",
(char**) &maria_stats_method_str, (char**) &maria_stats_method_str, 0,
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{ "zerofill", 'z', "Fill empty space in data and index files with zeroes. This makes the data file movable between different servers. It also fixes any wrong transaction or LSN numbers in the table after a crash or if someone removed the Aria log files.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{ "zerofill-keep-lsn", OPT_ZEROFILL_KEEP_LSN, "Like --zerofill but does not zero out LSN of data/index pages;" " used only for testing and debugging", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
};
staticvoid usage(void)
{
print_version();
puts("By Monty, for your professional use");
puts("This software comes with NO WARRANTY: see the PUBLIC for details.\n");
puts("Description, check and repair of Aria tables.");
puts("Used without options all tables on the command will be checked for errors");
printf("Usage: %s [OPTIONS] tables[.MAI]\n", my_progname_short);
printf("\nGlobal options:\n"); #ifndef DBUG_OFF
printf("\
-#, --debug=... Output debug log. Often this is 'd:t:o,filename'.\n"); #endif
printf("\
-H, --HELP Print all argument options sorted alphabetically.\n\
-?, --help Print all options by groups\n\
--datadir=path Path for control file (and logs if --logdir not used)\n\
--logdir=path Path for log files\n\
--ignore-control-file Don't open the control file. Only use this if you\n\
are sure the tables are not in use by another\n\
program!\n\
--require-control-file Abort if we can't find/read the aria_log_control\n\
file\n\
-s, --silent Only print errors. One can use two -s to make\n\
maria_chk very silent.\n\
-t, --tmpdir=path Path for temporary files. Multiple paths can be\n\
specified, separated by "); #ifdefined( _WIN32)
printf("semicolon (;)"); #else
printf("colon (:)"); #endif
printf(", they will be used\n\
in a round-robin fashion.\n\
-v, --verbose Print more information. This can be used with\n\
--description and --check. Use many -v for more verbosity.\n\
-V, --version Print version andexit.\n\
-w, --wait Wait if table is locked.\n\n"); #ifdef DEBUG
puts(" --start-check-pos=# Start reading file at given offset.\n"); #endif
puts("Check options (check is the default action for aria_chk):\n\
-c, --check Check table for errors.\n\
-e, --extend-check Check the table VERY thoroughly. Only use this in\n\
extreme cases as aria_chk should normally be able to\n\
find out if the table is ok even without thisswitch.\n\
-F, --fast Check only tables that haven't been closed properly.\n\
-C, --check-only-changed\n\
Check only tables that have changed since last check.\n\
-f, --force Restart with '-r'if there are any errors in the table.\n\
States will be updated as with '--update-state'.\n\
-i, --information Print statistics information about table that is checked.\n\
-m, --medium-check Faster than extend-check, but only finds 99.99% of\n\
all errors. Should be good enough for most cases.\n\
-T, --read-only Don't mark table as checked.\n\
-U, --update-state Mark tables as crashed if any errors were found and\n\
clean if check didn't find any errors but table was\n\
marked as 'not clean' before. This allows one to get\n\
rid of warnings like 'table not properly closed'. If\n\
table was updated, update also the timestamp for when\n\
the check was made. This option is on by default!\n\
Use --skip-update-state to disable.\n\
--warning-for-wrong-transaction-id\n\
Give a warning if we find a transaction id in the table that is bigger\n\
than what exists in the control file. Use --skip-... to disable warning\n\ ");
puts("\
Recover (repair)/ options (When using'--recover'or'--safe-recover'):\n\
-B, --backup Make a backup of the .MAD file as 'filename-time.BAK'.\n\
--correct-checksum Correct checksum information for table.\n\
-D, --data-file-length=# Max length of data file (when recreating data\n\
file when it's full).\n\
--create-missing-keys\n\
Create missing keys. This assumes that the data\n\
file is correct and that the number of rows stored\n\
in the index file is correct. Enables --quick.\n\
-e, --extend-check Try to recover every possible row from the data file\n\
Normally this will also find a lot of garbage rows;\n\
Don't use this option if you are not totally desperate.\n\
-f, --force Overwrite old temporary files. Add another --force to\n\
avoid 'sort_buffer_size is too small' errors.\n\
In thiscase we will attempt to do the repair with the\n\
given sort_buffer_size and dynamically allocate\n\
as many management buffers as needed.\n\
-k, --keys-used=# Tell Aria to update only some specific keys. # is a\n\
bit mask of which keys to use. This can be used to\n\
get faster inserts.\n\
--keys-active\n\
Treat all not listed keys as disabled. If used with repair, the keys\n\
will be disabled permanently. The argument is a list of key numbers,\n\
starting from 1, separated by ','\n\
keys-active and keys-used are two ways to do the same thing\n\
--max-record-length=#\n\
Skip rows bigger than thisif aria_chk can't allocate\n\
memory to hold it.\n\
-r, --recover Can fix almost anything except unique keys that aren't\n\
unique.\n\
-n, --sort-recover Forces recovering with sorting even if the temporary\n\
file would be very big.\n\
-p, --parallel-recover\n\
Uses the same technique as '-r'and'-n', but creates\n\
all the keys in parallel, in different threads.");
puts("\
-o, --safe-recover Uses old recovery method; Slower than '-r' but can\n \
handle a couple of cases where '-r' reports that it\n\
can't fix the data file.\n\
--transaction-log Log repair command to transaction log. This is needed\n\ if one wants to use the aria_read_log to repeat the \n\
repair\n\
--character-sets-dir=...\n\
Directory where character sets are.\n\
--set-collation=name\n\
Change the collation used by the index.\n\
-q, --quick Faster repair by not modifying the data file.\n\
One can give a second '-q' to force aria_chk to\n\
modify the original datafile in case of duplicate keys.\n\
NOTE: Tables where the data file is corrupted can't be\n\
fixed with this option.\n\
-u, --unpack Unpack file packed with ariapack.\n\ ");
puts("Other actions:\n\
-a, --analyze Analyze distribution of keys. Will make some joins in\n\
MariaDB faster. You can check the calculated distribution\n\
by using'--description --verbose table_name'.\n\
--stats_method=name Specifies how index statistics collection code should\n\
treat NULLs. Possible values of name are \"nulls_unequal\"\n\
(defaultfor4.1/5.0), \"nulls_equal\" (emulate 4.0), and \n\
\"nulls_ignored\".\n\
-d, --description Prints some information about table.\n\
-A, --set-auto-increment[=value]\n\
Force auto_increment to start at thisor higher value\n\ If no value is given, then sets the next auto_increment\n\
value to the highest used value for the auto key + 1.\n\
-S, --sort-index Sort index blocks. This speeds up 'read-next' in\n\
applications.\n\
-R, --sort-records=#\n\
Sort records according to an index. This makes your\n\
data much more localized and may speed up things\n\
(It may be VERY slow to do a sort the first time!).\n\
-b, --block-search=#\n\
Find a record, a block at given offset belongs to.\n\
-z, --zerofill Fill empty space in data and index files with zeroes.\n\ This makes the data file movable between different \n\
servers. It also fixes any wrong transaction or LSN\n\
numbers in the table after a crash orif someone\n\
removed the Aria log files.\n\
--zerofill-keep-lsn Like --zerofill but does not zero out LSN of\n\
data/index pages.");
puts("Variables:\n\
--page_buffer_size=# Size of page buffer. Used by --safe-repair\n\
--read_buffer_size=# Read buffer size for sequential reads during scanning\n\
--sort_buffer_size=# Size of sort buffer. Used by --recover\n\
--sort_key_blocks=# Internal buffer for sorting keys; Don't touch :)\n\
--write_buffer_size=# Write buffer size for sequential writes during repair");
if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option)))
my_exit(ho_error);
/* If using repair, then update checksum if one uses --update-state */ if ((check_param.testflag & T_UPDATE_STATE) &&
(check_param.testflag & T_REP_ANY))
check_param.testflag|= T_CALC_CHECKSUM;
if (*argc == 0)
{
usage();
my_exit(-1);
}
if ((check_param.testflag & T_UNPACK) &&
(check_param.testflag & (T_QUICK | T_SORT_RECORDS)))
{
fprintf(stderr, "%s: --unpack can't be used with --quick or --sort-records\n",
my_progname_short);
my_exit(1);
} if ((check_param.testflag & T_READONLY) &&
(check_param.testflag &
(T_REP_ANY | T_STATISTICS | T_AUTO_INC |
T_SORT_RECORDS | T_SORT_INDEX | T_FORCE_CREATE)))
{
fprintf(stderr, "%s: Can't use --readonly when repairing or sorting\n",
my_progname_short);
my_exit(1);
}
if (!opt_debug)
{
DEBUGGER_OFF; /* Speed up things a bit */
} if (init_tmpdir(&maria_chk_tmpdir, opt_tmpdir))
my_exit(1);
check_param.tmpdir=&maria_chk_tmpdir;
if (set_collation_name) if (!(set_collation= get_charset_by_name(set_collation_name,
MYF(MY_UTF8_IS_UTF8MB3 | MY_WME))))
my_exit(1);
if (maria_data_root != default_log_dir && opt_log_dir == default_log_dir)
{ /* --datadir was used and --log-dir was not. Set log-dir to datadir */
opt_log_dir= maria_data_root;
}
/* If we are using zerofill, then we don't need to read the control file */ if ((check_param.testflag & (T_ZEROFILL_KEEP_LSN | T_ZEROFILL)) &&
!(check_param.testflag & ~(T_REP_ANY | T_SORT_RECORDS | T_SORT_INDEX | T_STATISTICS | T_CHECK | T_FAST | T_CHECK_ONLY_CHANGED)))
opt_ignore_control_file= 1;
param->out_flag= error= param->error_printed= recreate= 0;
param->warning_printed= param->wrong_trd_printed= 0;
datafile=0;
param->isam_file_name=filename; /* For error messages */
warning_printed_by_chk_status= 0; if (!(info=maria_open(filename,
(param->testflag & (T_DESCRIPT | T_READONLY)) ?
O_RDONLY : O_RDWR,
HA_OPEN_FOR_REPAIR | HA_OPEN_FORCE_MODE |
((param->testflag & T_QUICK) ?
HA_OPEN_DATA_READONLY : 0) |
((param->testflag & T_WAIT_FOREVER) ?
HA_OPEN_WAIT_IF_LOCKED :
(param->testflag & T_DESCRIPT) ?
HA_OPEN_IGNORE_IF_LOCKED : HA_OPEN_ABORT_IF_LOCKED), 0)))
{ /* Avoid twice printing of isam file name */
param->error_printed++; switch (my_errno) { case HA_ERR_CRASHED:
_ma_check_print_error(param,"'%s' doesn't have a correct index definition. You need to recreate it before you can do a repair",filename); break; case HA_ERR_NOT_A_TABLE:
_ma_check_print_error(param,"'%s' is not a Aria table",filename); break; case HA_ERR_CRASHED_ON_USAGE:
_ma_check_print_error(param,"'%s' is marked as crashed",filename); break; case HA_ERR_CRASHED_ON_REPAIR:
_ma_check_print_error(param,"'%s' is marked as crashed after last repair",filename); break; case HA_ERR_OLD_FILE:
_ma_check_print_error(param,"'%s' is a old type of Aria table", filename); break; case HA_ERR_NEW_FILE:
_ma_check_print_error(param,"'%s' uses new features not supported by this version of the Aria library", filename); break; case HA_ERR_END_OF_FILE:
_ma_check_print_error(param,"Couldn't read complete header from '%s'", filename); break; case EAGAIN:
_ma_check_print_error(param,"'%s' is locked. Use -w to wait until unlocked",filename); break; case ENOENT:
_ma_check_print_error(param,"File '%s' doesn't exist",filename); break; case EACCES:
_ma_check_print_error(param,"You don't have permission to use '%s'",
filename); break; default:
_ma_check_print_error(param,"%d when opening Aria table '%s'",
my_errno,filename); break;
}
DBUG_RETURN(1);
}
share= info->s;
share->tot_locks-= share->r_locks;
share->r_locks=0;
maria_block_size= share->base.block_size;
if (share->data_file_type == BLOCK_RECORD ||
((param->testflag & T_UNPACK) &&
share->state.header.org_data_file_type == BLOCK_RECORD))
{ if (param->testflag & T_SORT_RECORDS)
{
_ma_check_print_error(param, "Record format used by '%s' is is not yet supported with sort-records",
filename);
param->error_printed= 0;
error= 1; goto end2;
} /* We can't do parallel repair with BLOCK_RECORD yet */ if (param->testflag & T_REP_PARALLEL)
{
param->testflag&= ~T_REP_PARALLEL;
param->testflag|= T_REP_BY_SORT;
}
} if ((share->base.extra_options & MA_EXTRA_OPTIONS_ENCRYPTED) &&
!(param->testflag & T_DESCRIPT))
{
_ma_check_print_warning(param, "Table %s is encrypted. Only --description (-d) " "option is supported", filename);
param->warning_printed= 0; goto end2;
}
if (param->testflag & T_REP_ANY)
{
ulonglong tmp=share->state.key_map;
maria_copy_keys_active(share->state.key_map, share->base.keys,
param->keys_in_use); if (tmp != share->state.key_map)
info->update|=HA_STATE_CHANGED;
if (rep_quick &&
maria_chk_del(param, info, param->testflag & ~T_VERBOSE))
{ if (param->testflag & T_FORCE_CREATE)
{
rep_quick=0;
_ma_check_print_info(param,"Creating new data file\n");
} else
{
error=1;
_ma_check_print_error(param, "Quick-recover aborted; Run recovery without switch 'q'");
}
}
} if (!error)
{ /* Unlessthiswasonly--zerofill-keep-lsn,oldREDOsarenot applicable,telltheserver'sRecoverytoignorethem;wedon't knowwhatthelog'sendLSNisnow,sowejustlettheserverknow thatitwillhavetofindandstoreit. Thisistheonlycasewherecreate_rename_lsncanbeahorizonandnot aLSN. Ifthiswasonly--zerofill-keep-lsn,thetablecanbeusedin Recoveryandespeciallyinthisscenario:doadirty-copy-basedbackup (snapshot-like),--zerofill-keep-lsnonthecopiestoachievebetter compression,compressthecopieswithanexternaltool,andaftera restore,Recoverystillworks(becausepagesandstatestillhave theircorrectLSNs).
*/ if (share->base.born_transactional &&
((param->testflag & (T_REP_ANY | T_SORT_RECORDS | T_SORT_INDEX |
T_ZEROFILL | T_ZEROFILL_KEEP_LSN)) !=
(T_ZEROFILL | T_ZEROFILL_KEEP_LSN)))
{
share->state.create_rename_lsn= share->state.is_of_horizon=
share->state.skip_redo_lsn= LSN_NEEDS_NEW_STATE_LSNS;
share->state.create_trid= 0;
}
} if (!error && (param->testflag & T_REP_ANY))
{ if ((param->testflag & (T_REP_BY_SORT | T_REP_PARALLEL)) &&
(maria_is_any_key_active(share->state.key_map) ||
(rep_quick && !param->keys_in_use && !recreate)) &&
maria_test_if_sort_rep(info, info->state->records,
info->s->state.key_map,
param->force_sort))
{ if (param->testflag & T_REP_BY_SORT)
error=maria_repair_by_sort(param,info,filename,rep_quick); else
error=maria_repair_parallel(param,info,filename,rep_quick);
state_updated=1;
} else
error=maria_repair(param, info,filename,rep_quick);
} if (!error && (param->testflag & T_SORT_RECORDS))
{ /* Thedatafileisnowadaysreopenedintherepaircodesoweshould soonremovethefollowingreopen-code
*/ #ifndef TO_BE_REMOVED if (param->out_flag & O_NEW_DATA)
{ /* Change temp file to org file */
mysql_file_close(info->dfile.file, MYF(MY_WME)); /* Close new file */
error|=maria_change_to_newfile(filename,MARIA_NAME_DEXT,DATA_TMP_EXT, 0, MYF(0)); if (_ma_open_datafile(info, info->s))
error=1;
param->out_flag&= ~O_NEW_DATA; /* We are using new datafile */
param->read_cache.file= info->dfile.file;
} #endif if (! error)
{
uint key; /* Wecan'tupdatetheindexinmaria_sort_recordsifwehavea prefixcompressedorfulltextindex
*/
my_bool update_index=1; for (key=0 ; key < share->base.keys; key++) if (share->keyinfo[key].flag & HA_BINARY_PACK_KEY ||
share->keyinfo[key].key_alg == HA_KEY_ALG_FULLTEXT)
update_index=0;
error=maria_sort_records(param,info,filename,param->opt_sort_key, /* what is the following parameter for ? */
(my_bool) !(param->testflag & T_REP),
update_index);
datafile= info->dfile.file; /* This is now locked */ if (!error && !update_index)
{ if (param->verbose)
puts("Table had a compressed index; We must now recreate the index");
error=maria_repair_by_sort(param,info,filename,1);
}
}
} if (!error && (param->testflag & T_SORT_INDEX))
error= maria_sort_index(param,info,filename); if (!error && (param->testflag & T_ZEROFILL))
error= maria_zerofill(param, info, filename); if (!error)
{
DBUG_PRINT("info", ("Resetting crashed state"));
share->state.changed&= ~(STATE_CHANGED | STATE_CRASHED_FLAGS |
STATE_IN_REPAIR);
share->crash_error= 0;
} else
maria_mark_crashed(info);
} elseif ((param->testflag & T_CHECK) || !(param->testflag & T_AUTO_INC))
{ if (!(param->testflag & T_VERY_SILENT) || param->testflag & T_INFO)
printf("Checking Aria file: %s\n",filename); if (!(param->testflag & T_SILENT))
printf("Data records: %7s Deleted blocks: %7s\n",
llstr(info->state->records,llbuff),
llstr(info->state->del,llbuff2));
maria_chk_init_for_check(param, info); if (opt_warning_for_wrong_transid == 0)
param->max_trid= ~ (ulonglong) 0;
error= maria_chk_status(param,info); /* Forget warning printed by maria_chk_status if no problems found */
warning_printed_by_chk_status= param->warning_printed;
param->warning_printed= 0;
if (param->not_visible_rows_found && (param->testflag & T_VERBOSE))
{ char buff[22];
printf("Max transaction id found: %s\n",
llstr(param->max_found_trid, buff));
}
fflush(stdout);
fflush(stderr);
if (param->error_printed)
{
error= 2; if (param->testflag & (T_REP_ANY | T_SORT_RECORDS | T_SORT_INDEX))
{
fprintf(stderr, "Aria table '%s' is not fixed because of errors\n",
filename); if (param->testflag & T_REP_ANY)
fprintf(stderr, "Try fixing it by using the --safe-recover (-o), " "the --force (-f) option or by not using the --quick (-q) " "flag\n");
} elseif (!(param->testflag & T_FORCE_CREATE))
fprintf(stderr, "Aria table '%s' is corrupted\nFix it using switch " "\"-r\" or \"-o\"\n", filename);
} elseif ((param->warning_printed || warning_printed_by_chk_status) &&
! (param->testflag & (T_REP_ANY | T_SORT_RECORDS | T_SORT_INDEX |
T_FORCE_CREATE)))
{ if (!error)
error= 1;
(void) fprintf(stderr, "Aria table '%s' is usable but should be fixed\n",
filename);
}
if (! maria_is_key_active(share->state.key_map, sort_key))
{
_ma_check_print_warning(param, "Can't sort table '%s' on key %d; No such key",
name,sort_key+1);
param->error_printed=0;
DBUG_RETURN(0); /* Nothing to do */
} if (keyinfo->key_alg == HA_KEY_ALG_FULLTEXT)
{
_ma_check_print_warning(param,"Can't sort table '%s' on FULLTEXT key %d",
name,sort_key+1);
param->error_printed=0;
DBUG_RETURN(0); /* Nothing to do */
} if (keyinfo->flag & HA_BINARY_PACK_KEY)
{
_ma_check_print_warning(param, "Can't sort table '%s' on a key with prefix " "packing %d",
name,sort_key+1);
param->error_printed=0;
DBUG_RETURN(0);
}
if (share->data_file_type == COMPRESSED_RECORD)
{
_ma_check_print_warning(param,"Can't sort read-only table '%s'", name);
param->error_printed=0;
DBUG_RETURN(0); /* Nothing to do */
} if (!(param->testflag & T_SILENT))
{
printf("- Sorting records for Aria table '%s'\n",name); if (write_info)
printf("Data records: %9s Deleted: %9s\n",
llstr(info->state->records,llbuff),
llstr(info->state->del,llbuff2));
} if (share->state.key_root[sort_key] == HA_OFFSET_ERROR)
DBUG_RETURN(0); /* Nothing to do */
if (init_io_cache(&info->rec_cache,-1,(uint) param->write_buffer_length,
WRITE_CACHE,share->pack.header_length,1,
MYF(MY_WME | MY_WAIT_IF_FULL))) goto err;
info->opt_flag|=WRITE_CACHE_USED;
if (!(temp_buff=(uchar*) my_alloca((uint) keyinfo->block_length)))
{
_ma_check_print_error(param,"Not enough memory for key block"); goto err;
}
if (!(sort_param.record= (uchar*) my_malloc(PSI_INSTRUMENT_ME,
(uint) share->base.default_rec_buff_size, MYF(0))))
{
_ma_check_print_error(param,"Not enough memory for record"); goto err;
}
fn_format(param->temp_filename,name,"", MARIA_NAME_DEXT,2+4+32);
new_file= mysql_file_create(key_file_tmp,
fn_format(param->temp_filename,
param->temp_filename, "",
DATA_TMP_EXT,
MY_REPLACE_EXT | MY_UNPACK_FILENAME), 0, param->tmpfile_createflag, MYF(0)); if (new_file < 0)
{
_ma_check_print_error(param,"Can't create new tempfile: '%s'",
param->temp_filename); goto err;
} if (share->pack.header_length) if (maria_filecopy(param, new_file, info->dfile.file, 0L,
share->pack.header_length, "datafile-header")) goto err;
info->rec_cache.file=new_file; /* Use this file for cacheing*/
if (info->state->records != old_record_count)
{
_ma_check_print_error(param,"found %s of %s records",
llstr(info->state->records,llbuff),
llstr(old_record_count,llbuff2)); goto err;
}
mysql_file_close(info->dfile.file, MYF(MY_WME));
param->out_flag|=O_NEW_DATA; /* Data in new file */
info->dfile.file= new_file; /* Use new datafile */
_ma_set_data_pagecache_callbacks(&info->dfile, info->s);
info->state->del=0;
info->state->empty=0;
share->state.dellink= HA_OFFSET_ERROR;
info->state->data_file_length=sort_param.filepos;
share->state.split=info->state->records; /* Only hole records */
share->state.version=(ulong) time((time_t*) 0);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.