Skip to content

Commit dbde95d

Browse files
committed
Updated aria_pack to support transactional tables
Added options: --datadir --ignore-control-file --require-control-file - Improved error messages if open fails - If control file can't be found/opened, assume that all rows in the tables are commited.
1 parent 517f659 commit dbde95d

File tree

1 file changed

+106
-10
lines changed

1 file changed

+106
-10
lines changed

storage/maria/maria_pack.c

Lines changed: 106 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#endif
2121

2222
#include "maria_def.h"
23+
#include "trnman_public.h"
24+
#include "trnman.h"
2325
#include <queues.h>
2426
#include <my_tree.h>
2527
#include "mysys_err.h"
@@ -30,13 +32,16 @@
3032
#define __GNU_LIBRARY__ /* Skip warnings in getopt.h */
3133
#endif
3234
#include <my_getopt.h>
33-
#include <assert.h>
35+
#include <my_handler_errors.h>
3436

3537
#if SIZEOF_LONG_LONG > 4
3638
#define BITS_SAVED 64
3739
#else
3840
#define BITS_SAVED 32
3941
#endif
42+
#ifndef MAX_INTERNAL_TRID
43+
#define MAX_INTERNAL_TRID 0xffffffffffffLL
44+
#endif
4045

4146
#define IS_OFFSET ((uint) 32768) /* Bit if offset or char in tree */
4247
#define HEAD_LENGTH 32
@@ -178,18 +183,19 @@ static void fakebigcodes(HUFF_COUNTS *huff_counts, HUFF_COUNTS *end_count);
178183
static int fakecmp(my_off_t **count1, my_off_t **count2);
179184
#endif
180185

181-
182-
static int error_on_write=0,test_only=0,verbose=0,silent=0,
183-
write_loop=0,force_pack=0, isamchk_neaded=0;
184-
static int tmpfile_createflag=O_RDWR | O_TRUNC | O_EXCL;
185-
static my_bool backup, opt_wait;
186186
/*
187187
tree_buff_length is somewhat arbitrary. The bigger it is the better
188188
the chance to win in terms of compression factor. On the other hand,
189189
this table becomes part of the compressed file header. And its length
190190
is coded with 16 bits in the header. Hence the limit is 2**16 - 1.
191191
*/
192192
static uint tree_buff_length= 65536 - MALLOC_OVERHEAD;
193+
194+
static int error_on_write=0,test_only=0,verbose=0,silent=0,
195+
write_loop=0,force_pack=0, isamchk_neaded=0;
196+
static int tmpfile_createflag=O_RDWR | O_TRUNC | O_EXCL;
197+
static my_bool backup, opt_wait;
198+
static my_bool opt_ignore_control_file, opt_require_control_file;
193199
static char tmp_dir[FN_REFLEN]={0},*join_table;
194200
static my_off_t intervall_length;
195201
static ha_checksum glob_crc;
@@ -199,19 +205,52 @@ static HUFF_COUNTS *global_count;
199205
static char zero_string[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
200206
static const char *load_default_groups[]= { "ariapack",0 };
201207

202-
/* The main program */
208+
/*
209+
Register handler error messages for usage with my_error()
210+
211+
NOTES
212+
This is safe to call multiple times as my_error_register()
213+
will ignore calls to register already registered error numbers.
214+
*/
215+
216+
static const char **get_handler_error_messages(int e __attribute__((unused)))
217+
{
218+
return handler_error_messages;
219+
}
220+
221+
222+
/* The main program */
203223

204224
int main(int argc, char **argv)
205225
{
206226
int error,ok;
207227
PACK_MRG_INFO merge;
208228
char **default_argv;
229+
my_bool no_control_file= 0;
209230
MY_INIT(argv[0]);
210231

232+
maria_data_root= (char *)".";
211233
load_defaults_or_exit("my", load_default_groups, &argc, &argv);
212234
default_argv= argv;
213235
get_options(&argc,&argv);
236+
my_error_register(get_handler_error_messages, HA_ERR_FIRST,
237+
HA_ERR_FIRST+ array_elements(handler_error_messages)-1);
238+
239+
if (!opt_ignore_control_file &&
240+
(no_control_file= ma_control_file_open(FALSE,
241+
(opt_require_control_file ||
242+
!silent))) &&
243+
opt_require_control_file)
244+
{
245+
error= 1;
246+
goto end;
247+
}
214248
maria_init();
249+
if (no_control_file || force_pack)
250+
{
251+
/* Assume that all rows exists */
252+
trnman_init(MAX_INTERNAL_TRID-16);
253+
}
215254

216255
error=ok=isamchk_neaded=0;
217256
if (join_table)
@@ -239,9 +278,13 @@ int main(int argc, char **argv)
239278
}
240279
if (ok && isamchk_neaded && !silent)
241280
puts("Remember to run aria_chk -rq on compressed tables");
281+
282+
end:
242283
fflush(stdout);
243284
fflush(stderr);
244285
free_defaults(default_argv);
286+
my_error_unregister(HA_ERR_FIRST,
287+
HA_ERR_FIRST+ array_elements(handler_error_messages)-1);
245288
maria_end();
246289
my_end(verbose ? MY_CHECK_ERROR | MY_GIVE_INFO : MY_CHECK_ERROR);
247290
exit(error ? 2 : 0);
@@ -263,17 +306,29 @@ static struct my_option my_long_options[] =
263306
{"character-sets-dir", OPT_CHARSETS_DIR_MP,
264307
"Directory where character sets are.", (char**) &charsets_dir,
265308
(char**) &charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
309+
{"datadir", 'h',
310+
"Path for control file (and logs if --logdir not used).",
311+
&maria_data_root, 0, 0, GET_STR, REQUIRED_ARG,
312+
0, 0, 0, 0, 0, 0},
266313
{"debug", '#', "Output debug log. Often this is 'd:t:o,filename'.",
267314
0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
268315
{"force", 'f',
269316
"Force packing of table even if it gets bigger or if tempfile exists.",
270317
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
318+
{ "ignore-control-file", 0,
319+
"Ignore the control file",
320+
(uchar**)&opt_ignore_control_file, 0, 0, GET_BOOL, NO_ARG,
321+
0, 0, 0, 0, 0, 0},
271322
{"join", 'j',
272323
"Join all given tables into 'new_table_name'. All tables MUST have identical layouts.",
273324
&join_table, &join_table, 0, GET_STR, REQUIRED_ARG, 0, 0, 0,
274325
0, 0, 0},
275326
{"help", '?', "Display this help and exit.",
276327
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
328+
{ "require-control-file", 0,
329+
"Abort if cannot find control file",
330+
(uchar**)&opt_require_control_file, 0, 0, GET_BOOL, NO_ARG,
331+
0, 0, 0, 0, 0, 0},
277332
{"silent", 's', "Be more silent.",
278333
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
279334
{"tmpdir", 'T', "Use temporary directory to store temporary table.",
@@ -396,17 +451,58 @@ static void get_options(int *argc,char ***argv)
396451
}
397452

398453

454+
static void print_error(int error, const char *filename)
455+
{
456+
switch (error) {
457+
case HA_ERR_CRASHED:
458+
fprintf(stderr, "'%s' doesn't have a correct index definition. You need to recreate it before you can do a repair",filename);
459+
break;
460+
case HA_ERR_NOT_A_TABLE:
461+
fprintf(stderr, "'%s' is not a Aria table",filename);
462+
break;
463+
case HA_ERR_CRASHED_ON_USAGE:
464+
fprintf(stderr, "'%s' is marked as crashed",filename);
465+
break;
466+
case HA_ERR_CRASHED_ON_REPAIR:
467+
fprintf(stderr, "'%s' is marked as crashed after last repair",filename);
468+
break;
469+
case HA_ERR_OLD_FILE:
470+
fprintf(stderr, "'%s' has transactions newer than registered in control file. If this is ok, please re-run with --ignore-control-file", filename);
471+
break;
472+
case HA_ERR_NEW_FILE:
473+
fprintf(stderr, "'%s' uses new features not supported by this version of the Aria library", filename);
474+
break;
475+
case HA_ERR_END_OF_FILE:
476+
fprintf(stderr, "Couldn't read complete header from '%s'", filename);
477+
break;
478+
case EAGAIN:
479+
fprintf(stderr, "'%s' is locked. Use -w to wait until unlocked",filename);
480+
break;
481+
case ENOENT:
482+
fprintf(stderr, "File '%s' doesn't exist",filename);
483+
break;
484+
case EACCES:
485+
fprintf(stderr, "You don't have permission to use '%s'", filename);
486+
break;
487+
default:
488+
fprintf(stderr, "%d when opening Aria table '%s'", error, filename);
489+
break;
490+
}
491+
fputc('\n',stderr);
492+
}
493+
494+
399495
static MARIA_HA *open_maria_file(char *name,int mode)
400496
{
401497
MARIA_HA *isam_file;
402498
MARIA_SHARE *share;
403499
DBUG_ENTER("open_maria_file");
404500

405501
if (!(isam_file=maria_open(name, mode, HA_OPEN_IGNORE_MOVED_STATE |
406-
(opt_wait ? HA_OPEN_WAIT_IF_LOCKED :
407-
HA_OPEN_ABORT_IF_LOCKED))))
502+
(opt_wait ? HA_OPEN_WAIT_IF_LOCKED :
503+
HA_OPEN_ABORT_IF_LOCKED))))
408504
{
409-
fprintf(stderr, "%s gave error %d on open\n", name, my_errno);
505+
print_error(my_errno, name);
410506
DBUG_RETURN(0);
411507
}
412508
share=isam_file->s;

0 commit comments

Comments
 (0)