Skip to content

Commit 24821e9

Browse files
committed
Copied recent improvements for MyISAM to Aria
- data files will be opened in readonly mode for repair if --quick is used. - Added information about check progress if --verbose is used. - Added new option --keys-active= as a simpler version of keys-used. Internal changes: - Store open file mode in share->index_mode and share->data_mode instead of in share->mode. - Removed not needed 'mode' argument from maria_clone_internal()
1 parent 6a4fe99 commit 24821e9

File tree

6 files changed

+101
-28
lines changed

6 files changed

+101
-28
lines changed

storage/maria/aria_chk.c

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ enum options_mc {
248248
OPT_MAX_RECORD_LENGTH, OPT_AUTO_CLOSE, OPT_STATS_METHOD, OPT_TRANSACTION_LOG,
249249
OPT_ZEROFILL_KEEP_LSN,
250250
OPT_REQUIRE_CONTROL_FILE, OPT_IGNORE_CONTROL_FILE,
251-
OPT_LOG_DIR, OPT_WARNING_FOR_WRONG_TRANSID
251+
OPT_LOG_DIR, OPT_WARNING_FOR_WRONG_TRANSID,OPT_ACTIVE_KEYS
252252
};
253253

254254
static struct my_option my_long_options[] =
@@ -319,10 +319,16 @@ static struct my_option my_long_options[] =
319319
(uchar**)&opt_ignore_control_file, 0, 0, GET_BOOL, NO_ARG,
320320
0, 0, 0, 0, 0, 0},
321321
{"keys-used", 'k',
322-
"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.",
322+
"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",
323323
&check_param.keys_in_use,
324324
&check_param.keys_in_use,
325325
0, GET_ULL, REQUIRED_ARG, -1, 0, 0, 0, 0, 0},
326+
{"keys-active", OPT_ACTIVE_KEYS,
327+
"Threat all not listed keys as disabled. If used with repair, the keys "
328+
"will be disabled permanently. The argument is a list of key numbers, "
329+
"starting from 1, separated by ','. "
330+
"keys-active and keys-used are two ways to do the same thing",
331+
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
326332
{"datadir", 'h',
327333
"Path for control file (and logs if --logdir not used).",
328334
(char**) &maria_data_root, 0, 0, GET_STR, REQUIRED_ARG,
@@ -455,7 +461,7 @@ static struct my_option my_long_options[] =
455461
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
456462
{ "stats_method", OPT_STATS_METHOD,
457463
"Specifies how index statistics collection code should treat NULLs. "
458-
"Possible values of name are \"nulls_unequal\" (default behavior for 4.1/5.0), "
464+
"Possible values of name are \"nulls_unequal\" (default behavior for MySQL 4.1/5.0), "
459465
"\"nulls_equal\" (emulate 4.0 behavior), and \"nulls_ignored\".",
460466
(char**) &maria_stats_method_str, (char**) &maria_stats_method_str, 0,
461467
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
@@ -472,7 +478,7 @@ static struct my_option my_long_options[] =
472478

473479
static void print_version(void)
474480
{
475-
printf("%s Ver 1.3 for %s on %s\n", my_progname, SYSTEM_TYPE,
481+
printf("%s Ver 1.4 for %s on %s\n", my_progname, SYSTEM_TYPE,
476482
MACHINE_TYPE);
477483
}
478484

@@ -566,6 +572,11 @@ Recover (repair)/ options (When using '--recover' or '--safe-recover'):\n\
566572
-k, --keys-used=# Tell Aria to update only some specific keys. # is a\n\
567573
bit mask of which keys to use. This can be used to\n\
568574
get faster inserts.\n\
575+
--keys-active\n\
576+
Treat all not listed keys as disabled. If used with repair, the keys\n\
577+
will be disabled permanently. The argument is a list of key numbers,\n\
578+
starting from 1, separated by ','\n\
579+
keys-active and keys-used are two ways to do the same thing\n\
569580
--max-record-length=#\n\
570581
Skip rows bigger than this if aria_chk can't allocate\n\
571582
memory to hold it.\n\
@@ -750,6 +761,32 @@ get_one_option(const struct my_option *opt,
750761
case 'k':
751762
check_param.keys_in_use= (ulonglong) strtoll(argument, NULL, 10);
752763
break;
764+
case OPT_ACTIVE_KEYS:
765+
if (argument == disabled_my_option)
766+
check_param.keys_in_use= ~0LL;
767+
else
768+
{
769+
const char *start;
770+
char *end, *str_end= strend(argument);
771+
check_param.keys_in_use= 0;
772+
for (start= argument; *start ; start= end)
773+
{
774+
int error;
775+
longlong key;
776+
end= str_end;
777+
key= my_strtoll10(start, &end, &error);
778+
if (error || key > 64 || (*end && *end != ','))
779+
{
780+
fprintf(stderr, "Wrong argument to active-keys. Expected a list of "
781+
"numbers like 1,2,3,4\n");
782+
exit(1); /* Change to my_exit after merge */
783+
}
784+
check_param.keys_in_use|= 1LL << (key-1);
785+
if (*end == ',')
786+
end++;
787+
}
788+
}
789+
break;
753790
case 'm':
754791
if (argument == disabled_my_option)
755792
check_param.testflag&= ~T_MEDIUM;
@@ -1032,7 +1069,9 @@ static int maria_chk(HA_CHECK *param, char *filename)
10321069
if (!(info=maria_open(filename,
10331070
(param->testflag & (T_DESCRIPT | T_READONLY)) ?
10341071
O_RDONLY : O_RDWR,
1035-
HA_OPEN_FOR_REPAIR |
1072+
HA_OPEN_FOR_REPAIR | HA_OPEN_FORCE_MODE |
1073+
((param->testflag & T_QUICK) ?
1074+
HA_OPEN_DATA_READONLY : 0) |
10361075
((param->testflag & T_WAIT_FOREVER) ?
10371076
HA_OPEN_WAIT_IF_LOCKED :
10381077
(param->testflag & T_DESCRIPT) ?
@@ -1160,6 +1199,13 @@ static int maria_chk(HA_CHECK *param, char *filename)
11601199
DBUG_RETURN(0);
11611200
}
11621201
}
1202+
1203+
/* Don't allow disable of active auto_increment keys for repair */
1204+
if (share->base.auto_key &&
1205+
(share->state.key_map & (1LL << share->base.auto_key)) &&
1206+
param->testflag & (T_REP_ANY | T_SORT_RECORDS | T_SORT_INDEX))
1207+
check_param.keys_in_use|= (1LL << share->base.auto_key);
1208+
11631209
if ((param->testflag & (T_REP_ANY | T_STATISTICS |
11641210
T_SORT_RECORDS | T_SORT_INDEX)) &&
11651211
(((param->testflag & T_UNPACK) &&

storage/maria/ma_check.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,11 @@ int maria_chk_key(HA_CHECK *param, register MARIA_HA *info)
594594
param->max_level=0;
595595
if (chk_index(param, info,keyinfo, &page, &keys, param->key_crc+key,1))
596596
DBUG_RETURN(-1);
597+
if ((param->testflag & T_WRITE_LOOP) && param->verbose)
598+
{
599+
puts(" \r");
600+
fflush(stdout);
601+
}
597602
if (!(keyinfo->flag & (HA_FULLTEXT | HA_SPATIAL | HA_RTREE_INDEX)))
598603
{
599604
if (keys != share->state.state.records)
@@ -695,7 +700,8 @@ int maria_chk_key(HA_CHECK *param, register MARIA_HA *info)
695700
puts("");
696701
}
697702
if (param->key_file_blocks != share->state.state.key_file_length &&
698-
share->state.key_map == ~(ulonglong) 0)
703+
maria_is_all_keys_active(share->state.key_map, share->base.keys) &&
704+
!full_text_keys)
699705
_ma_check_print_warning(param, "Some data are unreferenced in keyfile");
700706
if (found_keys != full_text_keys)
701707
param->record_checksum=old_record_checksum-init_checksum; /* Remove delete links */
@@ -1089,6 +1095,15 @@ static int chk_index(HA_CHECK *param, MARIA_HA *info, MARIA_KEYDEF *keyinfo,
10891095
goto err;
10901096
}
10911097
param->record_checksum+= (ha_checksum) record;
1098+
if ((param->testflag & T_WRITE_LOOP) && param->verbose &&
1099+
(*keys % WRITE_COUNT) == 0)
1100+
{
1101+
char llbuff[22];
1102+
ulonglong records= info->state->records;
1103+
printf("%15s (%3.4f%%)\r", llstr(*keys, llbuff),
1104+
((double) *keys / (records > *keys ? records : *keys)) *100);
1105+
fflush(stdout);
1106+
}
10921107
}
10931108
if (keypos != endpos)
10941109
{
@@ -5721,6 +5736,7 @@ static int sort_key_write(MARIA_SORT_PARAM *sort_param, const uchar *a)
57215736
{
57225737
_ma_check_print_error(param,
57235738
"Internal error: Keys are not in order from sort");
5739+
DBUG_ASSERT(0);
57245740
return(1);
57255741
}
57265742
#endif

storage/maria/ma_checkpoint.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ static int collect_tables(LEX_STRING *str, LSN checkpoint_start_log_horizon)
790790
MARIA_SHARE *share= info->s;
791791
/* the first three variables below can never change */
792792
if (share->base.born_transactional && !share->temporary &&
793-
share->mode != O_RDONLY &&
793+
(share->index_mode != O_RDONLY && share->data_mode != O_RDONLY) &&
794794
!(share->in_checkpoint & MARIA_CHECKPOINT_SEEN_IN_LOOP))
795795
{
796796
/*

storage/maria/ma_dynrec.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ my_bool _ma_dynmap_file(MARIA_HA *info, my_off_t size)
7070
*/
7171
info->s->file_map= (uchar*)
7272
my_mmap(0, (size_t)(size + MEMMAP_EXTRA_MARGIN),
73-
info->s->mode==O_RDONLY ? PROT_READ :
73+
info->s->index_mode==O_RDONLY ? PROT_READ :
7474
PROT_READ | PROT_WRITE,
7575
MAP_SHARED | MAP_NORESERVE,
7676
info->dfile.file, 0L);

storage/maria/ma_open.c

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ MARIA_HA *_ma_test_if_reopen(const char *filename)
7575
SYNOPSIS
7676
maria_clone_internal()
7777
share Share of already open table
78-
mode Mode of table (O_RDONLY | O_RDWR)
7978
data_file Filedescriptor of data file to use < 0 if one should open
8079
open it.
8180
internal_table <> 0 if this is an internal temporary table
@@ -86,7 +85,7 @@ MARIA_HA *_ma_test_if_reopen(const char *filename)
8685
*/
8786

8887
static MARIA_HA *maria_clone_internal(MARIA_SHARE *share,
89-
int mode, File data_file,
88+
File data_file,
9089
uint internal_table,
9190
struct ms3_st *s3)
9291
{
@@ -100,11 +99,6 @@ static MARIA_HA *maria_clone_internal(MARIA_SHARE *share,
10099
errpos= 0;
101100
bzero((uchar*) &info,sizeof(info));
102101

103-
if (mode == O_RDWR && share->mode == O_RDONLY)
104-
{
105-
my_errno=EACCES; /* Can't open in write mode */
106-
goto err;
107-
}
108102
if (data_file >= 0)
109103
info.dfile.file= data_file;
110104
else if (_ma_open_datafile(&info, share))
@@ -261,7 +255,8 @@ static MARIA_HA *maria_clone_internal(MARIA_SHARE *share,
261255
MARIA_HA *maria_open(const char *name, int mode, uint open_flags,
262256
S3_INFO *s3)
263257
{
264-
int open_mode= 0,save_errno;
258+
int save_errno;
259+
int open_mode, try_open_mode;
265260
uint i,j,len,errpos,head_length,base_pos,keys, realpath_err,
266261
key_parts,base_key_parts,unique_key_parts,fulltext_keys,uniques;
267262
uint internal_table= MY_TEST(open_flags & HA_OPEN_INTERNAL_TABLE);
@@ -345,14 +340,24 @@ MARIA_HA *maria_open(const char *name, int mode, uint open_flags,
345340
goto err;
346341
});
347342
DEBUG_SYNC_C("mi_open_kfile");
343+
344+
/*
345+
We first try to open the file on read-write mode to ensure
346+
that the table is usable for future read and write queries in
347+
MariaDB. Only if the read-write mode fails we try to readonly.
348+
*/
349+
try_open_mode= (open_flags & HA_OPEN_FORCE_MODE) ? mode : O_RDWR;
350+
348351
if ((kfile=mysql_file_open(key_file_kfile, name_buff,
349-
(open_mode=O_RDWR) | O_SHARE | O_NOFOLLOW | O_CLOEXEC,
352+
(open_mode=try_open_mode) | O_SHARE |
353+
O_NOFOLLOW | O_CLOEXEC,
350354
MYF(common_flag | MY_NOSYMLINKS))) < 0)
351355
{
352-
if ((errno != EROFS && errno != EACCES) ||
356+
if ((errno != EROFS && errno != EACCES) || open_mode == O_RDONLY ||
353357
mode != O_RDONLY ||
354358
(kfile=mysql_file_open(key_file_kfile, name_buff,
355-
(open_mode=O_RDONLY) | O_SHARE | O_NOFOLLOW | O_CLOEXEC,
359+
(open_mode=O_RDONLY) | O_SHARE |
360+
O_NOFOLLOW | O_CLOEXEC,
356361
MYF(common_flag | MY_NOSYMLINKS))) < 0)
357362
goto err;
358363
}
@@ -400,7 +405,9 @@ MARIA_HA *maria_open(const char *name, int mode, uint open_flags,
400405
}
401406
#endif /* WITH_S3_STORAGE_ENGINE */
402407

403-
share->mode=open_mode;
408+
share->index_mode= share->data_mode= open_mode;
409+
if (open_flags & HA_OPEN_DATA_READONLY)
410+
share->data_mode= O_RDONLY;
404411
if (memcmp(share->state.header.file_version, maria_file_magic, 4))
405412
{
406413
DBUG_PRINT("error",("Wrong header in %s",name_buff));
@@ -447,7 +454,9 @@ MARIA_HA *maria_open(const char *name, int mode, uint open_flags,
447454
my_errno= HA_WRONG_CREATE_OPTION;
448455
goto err;
449456
}
450-
share->mode|= O_NOFOLLOW; /* all symlinks are resolved by realpath() */
457+
/* all symlinks are resolved by realpath() */
458+
share->index_mode|= O_NOFOLLOW;
459+
share->data_mode|= O_NOFOLLOW;
451460
}
452461
}
453462
else
@@ -1171,7 +1180,7 @@ MARIA_HA *maria_open(const char *name, int mode, uint open_flags,
11711180
s3f.free(&index_header);
11721181
#endif /* WITH_S3_STORAGE_ENGINE */
11731182

1174-
if (!(m_info= maria_clone_internal(share, mode, data_file,
1183+
if (!(m_info= maria_clone_internal(share, data_file,
11751184
internal_table, s3_client)))
11761185
goto err;
11771186

@@ -2053,12 +2062,12 @@ void _ma_set_index_pagecache_callbacks(PAGECACHE_FILE *file,
20532062

20542063
int _ma_open_datafile(MARIA_HA *info, MARIA_SHARE *share)
20552064
{
2056-
myf flags= ((share->mode & O_NOFOLLOW) ? MY_NOSYMLINKS | MY_WME : MY_WME) |
2057-
share->malloc_flag;
2065+
myf flags= ((share->data_mode & O_NOFOLLOW) ?
2066+
MY_NOSYMLINKS | MY_WME : MY_WME) | share->malloc_flag;
20582067
DEBUG_SYNC_C("mi_open_datafile");
20592068
info->dfile.file= share->bitmap.file.file=
20602069
mysql_file_open(key_file_dfile, share->data_file_name.str,
2061-
share->mode | O_SHARE | O_CLOEXEC, flags);
2070+
share->data_mode | O_SHARE | O_CLOEXEC, flags);
20622071
return info->dfile.file >= 0 ? 0 : 1;
20632072
}
20642073

@@ -2072,8 +2081,9 @@ int _ma_open_keyfile(MARIA_SHARE *share)
20722081
mysql_mutex_lock(&share->intern_lock);
20732082
share->kfile.file= mysql_file_open(key_file_kfile,
20742083
share->unique_file_name.str,
2075-
share->mode | O_SHARE | O_NOFOLLOW | O_CLOEXEC,
2076-
MYF(MY_WME | MY_NOSYMLINKS));
2084+
share->index_mode | O_SHARE | O_NOFOLLOW |
2085+
O_CLOEXEC,
2086+
MYF(MY_WME | MY_NOSYMLINKS));
20772087
mysql_mutex_unlock(&share->intern_lock);
20782088
return (share->kfile.file < 0);
20792089
}

storage/maria/maria_def.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,8 @@ typedef struct st_maria_share
765765
PAGECACHE_FILE kfile; /* Shared keyfile */
766766
S3_INFO *s3_path; /* Connection and path in s3 */
767767
File data_file; /* Shared data file */
768-
int mode; /* mode of file on open */
768+
int index_mode; /* mode on index file on open */
769+
int data_mode; /* mode of data file on open */
769770
uint reopen; /* How many times opened */
770771
uint in_trans; /* Number of references by trn */
771772
uint w_locks, r_locks, tot_locks; /* Number of read/write locks */

0 commit comments

Comments
 (0)