20
20
#endif
21
21
22
22
#include "maria_def.h"
23
+ #include "trnman_public.h"
24
+ #include "trnman.h"
23
25
#include <queues.h>
24
26
#include <my_tree.h>
25
27
#include "mysys_err.h"
30
32
#define __GNU_LIBRARY__ /* Skip warnings in getopt.h */
31
33
#endif
32
34
#include <my_getopt.h>
33
- #include <assert .h>
35
+ #include <my_handler_errors .h>
34
36
35
37
#if SIZEOF_LONG_LONG > 4
36
38
#define BITS_SAVED 64
37
39
#else
38
40
#define BITS_SAVED 32
39
41
#endif
42
+ #ifndef MAX_INTERNAL_TRID
43
+ #define MAX_INTERNAL_TRID 0xffffffffffffLL
44
+ #endif
40
45
41
46
#define IS_OFFSET ((uint) 32768) /* Bit if offset or char in tree */
42
47
#define HEAD_LENGTH 32
@@ -178,18 +183,19 @@ static void fakebigcodes(HUFF_COUNTS *huff_counts, HUFF_COUNTS *end_count);
178
183
static int fakecmp (my_off_t * * count1 , my_off_t * * count2 );
179
184
#endif
180
185
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 ;
186
186
/*
187
187
tree_buff_length is somewhat arbitrary. The bigger it is the better
188
188
the chance to win in terms of compression factor. On the other hand,
189
189
this table becomes part of the compressed file header. And its length
190
190
is coded with 16 bits in the header. Hence the limit is 2**16 - 1.
191
191
*/
192
192
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 ;
193
199
static char tmp_dir [FN_REFLEN ]= {0 },* join_table ;
194
200
static my_off_t intervall_length ;
195
201
static ha_checksum glob_crc ;
@@ -199,19 +205,52 @@ static HUFF_COUNTS *global_count;
199
205
static char zero_string []= {0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 };
200
206
static const char * load_default_groups []= { "ariapack" ,0 };
201
207
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 */
203
223
204
224
int main (int argc , char * * argv )
205
225
{
206
226
int error ,ok ;
207
227
PACK_MRG_INFO merge ;
208
228
char * * default_argv ;
229
+ my_bool no_control_file = 0 ;
209
230
MY_INIT (argv [0 ]);
210
231
232
+ maria_data_root = (char * )"." ;
211
233
load_defaults_or_exit ("my" , load_default_groups , & argc , & argv );
212
234
default_argv = argv ;
213
235
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
+ }
214
248
maria_init ();
249
+ if (no_control_file || force_pack )
250
+ {
251
+ /* Assume that all rows exists */
252
+ trnman_init (MAX_INTERNAL_TRID - 16 );
253
+ }
215
254
216
255
error = ok = isamchk_neaded = 0 ;
217
256
if (join_table )
@@ -239,9 +278,13 @@ int main(int argc, char **argv)
239
278
}
240
279
if (ok && isamchk_neaded && !silent )
241
280
puts ("Remember to run aria_chk -rq on compressed tables" );
281
+
282
+ end :
242
283
fflush (stdout );
243
284
fflush (stderr );
244
285
free_defaults (default_argv );
286
+ my_error_unregister (HA_ERR_FIRST ,
287
+ HA_ERR_FIRST + array_elements (handler_error_messages )- 1 );
245
288
maria_end ();
246
289
my_end (verbose ? MY_CHECK_ERROR | MY_GIVE_INFO : MY_CHECK_ERROR );
247
290
exit (error ? 2 : 0 );
@@ -263,17 +306,29 @@ static struct my_option my_long_options[] =
263
306
{"character-sets-dir" , OPT_CHARSETS_DIR_MP ,
264
307
"Directory where character sets are." , (char * * ) & charsets_dir ,
265
308
(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 },
266
313
{"debug" , '#' , "Output debug log. Often this is 'd:t:o,filename'." ,
267
314
0 , 0 , 0 , GET_STR , OPT_ARG , 0 , 0 , 0 , 0 , 0 , 0 },
268
315
{"force" , 'f' ,
269
316
"Force packing of table even if it gets bigger or if tempfile exists." ,
270
317
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 },
271
322
{"join" , 'j' ,
272
323
"Join all given tables into 'new_table_name'. All tables MUST have identical layouts." ,
273
324
& join_table , & join_table , 0 , GET_STR , REQUIRED_ARG , 0 , 0 , 0 ,
274
325
0 , 0 , 0 },
275
326
{"help" , '?' , "Display this help and exit." ,
276
327
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 },
277
332
{"silent" , 's' , "Be more silent." ,
278
333
0 , 0 , 0 , GET_NO_ARG , NO_ARG , 0 , 0 , 0 , 0 , 0 , 0 },
279
334
{"tmpdir" , 'T' , "Use temporary directory to store temporary table." ,
@@ -396,17 +451,58 @@ static void get_options(int *argc,char ***argv)
396
451
}
397
452
398
453
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
+
399
495
static MARIA_HA * open_maria_file (char * name ,int mode )
400
496
{
401
497
MARIA_HA * isam_file ;
402
498
MARIA_SHARE * share ;
403
499
DBUG_ENTER ("open_maria_file" );
404
500
405
501
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 ))))
408
504
{
409
- fprintf ( stderr , "%s gave error %d on open\n" , name , my_errno );
505
+ print_error ( my_errno , name );
410
506
DBUG_RETURN (0 );
411
507
}
412
508
share = isam_file -> s ;
0 commit comments