~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/archive/ha_archive.cc

  • Committer: brian
  • Date: 2008-07-03 12:39:14 UTC
  • Revision ID: brian@localhost.localdomain-20080703123914-lry82qf74f6cbyzs
Disabling myisam tools until incomming link patch from Monty

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
  along with this program; if not, write to the Free Software
14
14
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
 
16
#ifdef USE_PRAGMA_IMPLEMENTATION
 
17
#pragma implementation        // gcc: Class implementation
 
18
#endif
16
19
 
17
 
#include <drizzled/common_includes.h>
18
 
#include <storage/myisam/myisam.h>
 
20
#include "mysql_priv.h"
 
21
#include <myisam.h>
19
22
 
20
23
#include "ha_archive.h"
 
24
#include <my_dir.h>
 
25
 
 
26
#include <mysql/plugin.h>
21
27
 
22
28
/*
23
29
  First, if you want to understand storage engines you should look at 
98
104
#define ARM ".ARM"               // Meta file (deprecated)
99
105
 
100
106
/*
101
 
  unsigned char + unsigned char
 
107
  uchar + uchar
102
108
*/
103
109
#define DATA_BUFFER_SIZE 2       // Size of the data used in the data file
104
110
#define ARCHIVE_CHECK_HEADER 254 // The number we use to determine corruption
109
115
                                       MEM_ROOT *mem_root);
110
116
int archive_discover(handlerton *hton, THD* thd, const char *db, 
111
117
                     const char *name,
112
 
                     unsigned char **frmblob, 
 
118
                     uchar **frmblob, 
113
119
                     size_t *frmlen);
114
120
 
115
 
static bool archive_use_aio= false;
 
121
static my_bool archive_use_aio= FALSE;
116
122
 
117
123
/*
118
124
  Number of rows that will force a bulk insert.
134
140
/*
135
141
  Used for hash table that tracks open tables.
136
142
*/
137
 
static unsigned char* archive_get_key(ARCHIVE_SHARE *share, size_t *length,
138
 
                             bool not_used __attribute__((unused)))
 
143
static uchar* archive_get_key(ARCHIVE_SHARE *share, size_t *length,
 
144
                             my_bool not_used __attribute__((unused)))
139
145
{
140
146
  *length=share->table_name_length;
141
 
  return (unsigned char*) share->table_name;
 
147
  return (uchar*) share->table_name;
142
148
}
143
149
 
144
150
 
150
156
    void *
151
157
 
152
158
  RETURN
153
 
    false       OK
154
 
    true        Error
 
159
    FALSE       OK
 
160
    TRUE        Error
155
161
*/
156
162
 
157
163
int archive_db_init(void *p)
158
164
{
 
165
  DBUG_ENTER("archive_db_init");
159
166
  handlerton *archive_hton;
160
167
 
161
168
  archive_hton= (handlerton *)p;
162
169
  archive_hton->state= SHOW_OPTION_YES;
 
170
  archive_hton->db_type= DB_TYPE_ARCHIVE_DB;
163
171
  archive_hton->create= archive_create_handler;
164
172
  archive_hton->flags= HTON_NO_FLAGS;
165
173
  archive_hton->discover= archive_discover;
172
180
  if (hash_init(&archive_open_tables, system_charset_info, 32, 0, 0,
173
181
                (hash_get_key) archive_get_key, 0, 0))
174
182
  {
175
 
    pthread_mutex_destroy(&archive_mutex);
 
183
    VOID(pthread_mutex_destroy(&archive_mutex));
176
184
  }
177
185
  else
178
186
  {
179
 
    return(false);
 
187
    DBUG_RETURN(FALSE);
180
188
  }
181
189
error:
182
 
  return(true);
 
190
  DBUG_RETURN(TRUE);
183
191
}
184
192
 
185
193
/*
190
198
    void
191
199
 
192
200
  RETURN
193
 
    false       OK
 
201
    FALSE       OK
194
202
*/
195
203
 
196
 
int archive_db_done(void *p __attribute__((unused)))
 
204
int archive_db_done(void *p)
197
205
{
198
206
  hash_free(&archive_open_tables);
199
 
  pthread_mutex_destroy(&archive_mutex);
 
207
  VOID(pthread_mutex_destroy(&archive_mutex));
200
208
 
201
209
  return 0;
202
210
}
210
218
 
211
219
  /* The size of the offset value we will use for position() */
212
220
  ref_length= sizeof(my_off_t);
213
 
  archive_reader_open= false;
 
221
  archive_reader_open= FALSE;
214
222
}
215
223
 
216
 
int archive_discover(handlerton *hton __attribute__((unused)),
217
 
                     THD* thd __attribute__((unused)),
218
 
                     const char *db,
 
224
int archive_discover(handlerton *hton, THD* thd, const char *db, 
219
225
                     const char *name,
220
 
                     unsigned char **frmblob,
 
226
                     uchar **frmblob, 
221
227
                     size_t *frmlen)
222
228
{
 
229
  DBUG_ENTER("archive_discover");
 
230
  DBUG_PRINT("archive_discover", ("db: %s, name: %s", db, name)); 
223
231
  azio_stream frm_stream;
224
232
  char az_file[FN_REFLEN];
225
233
  char *frm_ptr;
230
238
  if (stat(az_file, &file_stat))
231
239
    goto err;
232
240
 
233
 
  if (!(azopen(&frm_stream, az_file, O_RDONLY, AZ_METHOD_BLOCK)))
 
241
  if (!(azopen(&frm_stream, az_file, O_RDONLY|O_BINARY, AZ_METHOD_BLOCK)))
234
242
  {
235
243
    if (errno == EROFS || errno == EACCES)
236
 
      return(my_errno= errno);
237
 
    return(HA_ERR_CRASHED_ON_USAGE);
 
244
      DBUG_RETURN(my_errno= errno);
 
245
    DBUG_RETURN(HA_ERR_CRASHED_ON_USAGE);
238
246
  }
239
247
 
240
248
  if (frm_stream.frm_length == 0)
245
253
  azclose(&frm_stream);
246
254
 
247
255
  *frmlen= frm_stream.frm_length;
248
 
  *frmblob= (unsigned char*) frm_ptr;
 
256
  *frmblob= (uchar*) frm_ptr;
249
257
 
250
 
  return(0);
 
258
  DBUG_RETURN(0);
251
259
err:
252
260
  my_errno= 0;
253
 
  return(1);
 
261
  DBUG_RETURN(1);
254
262
}
255
263
 
256
264
/*
258
266
*/
259
267
int ha_archive::read_data_header(azio_stream *file_to_read)
260
268
{
 
269
  DBUG_ENTER("ha_archive::read_data_header");
 
270
 
261
271
  if (azread_init(file_to_read) == -1)
262
 
    return(HA_ERR_CRASHED_ON_USAGE);
 
272
    DBUG_RETURN(HA_ERR_CRASHED_ON_USAGE);
263
273
 
264
274
  if (file_to_read->version >= 3)
265
 
    return(0);
 
275
    DBUG_RETURN(0);
266
276
 
267
 
  return(1);
 
277
  DBUG_RETURN(1);
268
278
}
269
279
 
270
280
 
277
287
*/
278
288
ARCHIVE_SHARE *ha_archive::get_share(const char *table_name, int *rc)
279
289
{
280
 
  uint32_t length;
 
290
  uint length;
 
291
  DBUG_ENTER("ha_archive::get_share");
281
292
 
282
293
  pthread_mutex_lock(&archive_mutex);
283
294
  length=(uint) strlen(table_name);
284
295
 
285
296
  if (!(share=(ARCHIVE_SHARE*) hash_search(&archive_open_tables,
286
 
                                           (unsigned char*) table_name,
 
297
                                           (uchar*) table_name,
287
298
                                           length)))
288
299
  {
289
300
    char *tmp_name;
292
303
    if (!my_multi_malloc(MYF(MY_WME | MY_ZEROFILL),
293
304
                          &share, sizeof(*share),
294
305
                          &tmp_name, length+1,
295
 
                          NULL)) 
 
306
                          NullS)) 
296
307
    {
297
308
      pthread_mutex_unlock(&archive_mutex);
298
309
      *rc= HA_ERR_OUT_OF_MEM;
299
 
      return(NULL);
 
310
      DBUG_RETURN(NULL);
300
311
    }
301
312
 
302
313
    share->use_count= 0;
303
314
    share->table_name_length= length;
304
315
    share->table_name= tmp_name;
305
 
    share->crashed= false;
306
 
    share->archive_write_open= false;
 
316
    share->crashed= FALSE;
 
317
    share->archive_write_open= FALSE;
307
318
    fn_format(share->data_file_name, table_name, "",
308
319
              ARZ, MY_REPLACE_EXT | MY_UNPACK_FILENAME);
309
 
    my_stpcpy(share->table_name, table_name);
 
320
    strmov(share->table_name, table_name);
 
321
    DBUG_PRINT("ha_archive", ("Data File %s", 
 
322
                        share->data_file_name));
310
323
    /*
311
324
      We will use this lock for rows.
312
325
    */
313
 
    pthread_mutex_init(&share->mutex,MY_MUTEX_INIT_FAST);
 
326
    VOID(pthread_mutex_init(&share->mutex,MY_MUTEX_INIT_FAST));
314
327
    
315
328
    /*
316
329
      We read the meta file, but do not mark it dirty. Since we are not
318
331
      anything but reading... open it for write and we will generate null
319
332
      compression writes).
320
333
    */
321
 
    if (!(azopen(&archive_tmp, share->data_file_name, O_RDONLY,
 
334
    if (!(azopen(&archive_tmp, share->data_file_name, O_RDONLY|O_BINARY,
322
335
                 AZ_METHOD_BLOCK)))
323
336
    {
324
 
      pthread_mutex_destroy(&share->mutex);
 
337
      VOID(pthread_mutex_destroy(&share->mutex));
325
338
      free(share);
326
339
      pthread_mutex_unlock(&archive_mutex);
327
340
      *rc= HA_ERR_CRASHED_ON_REPAIR;
328
 
      return(NULL);
 
341
      DBUG_RETURN(NULL);
329
342
    }
330
343
    stats.auto_increment_value= archive_tmp.auto_increment + 1;
331
344
    share->rows_recorded= (ha_rows)archive_tmp.rows;
337
350
    }
338
351
    azclose(&archive_tmp);
339
352
 
340
 
    my_hash_insert(&archive_open_tables, (unsigned char*) share);
 
353
    VOID(my_hash_insert(&archive_open_tables, (uchar*) share));
341
354
    thr_lock_init(&share->lock);
342
355
  }
343
356
  share->use_count++;
 
357
  DBUG_PRINT("ha_archive", ("archive table %.*s has %d open handles now", 
 
358
                      share->table_name_length, share->table_name,
 
359
                      share->use_count));
344
360
  if (share->crashed)
345
361
    *rc= HA_ERR_CRASHED_ON_USAGE;
346
362
  pthread_mutex_unlock(&archive_mutex);
347
363
 
348
 
  return(share);
 
364
  DBUG_RETURN(share);
349
365
}
350
366
 
351
367
 
356
372
int ha_archive::free_share()
357
373
{
358
374
  int rc= 0;
 
375
  DBUG_ENTER("ha_archive::free_share");
 
376
  DBUG_PRINT("ha_archive",
 
377
             ("archive table %.*s has %d open handles on entrance", 
 
378
              share->table_name_length, share->table_name,
 
379
              share->use_count));
359
380
 
360
381
  pthread_mutex_lock(&archive_mutex);
361
382
  if (!--share->use_count)
362
383
  {
363
 
    hash_delete(&archive_open_tables, (unsigned char*) share);
 
384
    hash_delete(&archive_open_tables, (uchar*) share);
364
385
    thr_lock_delete(&share->lock);
365
 
    pthread_mutex_destroy(&share->mutex);
 
386
    VOID(pthread_mutex_destroy(&share->mutex));
366
387
    /* 
367
388
      We need to make sure we don't reset the crashed state.
368
389
      If we open a crashed file, wee need to close it as crashed unless
370
391
      Since we will close the data down after this, we go on and count
371
392
      the flush on close;
372
393
    */
373
 
    if (share->archive_write_open == true)
 
394
    if (share->archive_write_open == TRUE)
374
395
    {
375
396
      if (azclose(&(share->archive_write)))
376
397
        rc= 1;
377
398
    }
378
 
    free((unsigned char*) share);
 
399
    my_free((uchar*) share, MYF(0));
379
400
  }
380
401
  pthread_mutex_unlock(&archive_mutex);
381
402
 
382
 
  return(rc);
 
403
  DBUG_RETURN(rc);
383
404
}
384
405
 
385
406
int ha_archive::init_archive_writer()
386
407
{
 
408
  DBUG_ENTER("ha_archive::init_archive_writer");
387
409
  /* 
388
410
    It is expensive to open and close the data files and since you can't have
389
411
    a gzip file that can be both read and written we keep a writer open
390
412
    that is shared amoung all open tables.
391
413
  */
392
414
  if (!(azopen(&(share->archive_write), share->data_file_name, 
393
 
               O_RDWR, AZ_METHOD_BLOCK)))
 
415
               O_RDWR|O_BINARY, AZ_METHOD_BLOCK)))
394
416
  {
395
 
    share->crashed= true;
396
 
    return(1);
 
417
    DBUG_PRINT("ha_archive", ("Could not open archive write file"));
 
418
    share->crashed= TRUE;
 
419
    DBUG_RETURN(1);
397
420
  }
398
 
  share->archive_write_open= true;
 
421
  share->archive_write_open= TRUE;
399
422
 
400
 
  return(0);
 
423
  DBUG_RETURN(0);
401
424
}
402
425
 
403
426
 
406
429
*/
407
430
int ha_archive::init_archive_reader()
408
431
{
 
432
  DBUG_ENTER("ha_archive::init_archive_reader");
409
433
  /* 
410
434
    It is expensive to open and close the data files and since you can't have
411
435
    a gzip file that can be both read and written we keep a writer open
412
436
    that is shared amoung all open tables.
413
437
  */
414
 
  if (archive_reader_open == false)
 
438
  if (archive_reader_open == FALSE)
415
439
  {
416
440
    az_method method;
417
441
 
418
442
    switch (archive_use_aio)
419
443
    {
420
 
    case false:
 
444
    case FALSE:
421
445
      method= AZ_METHOD_BLOCK;
422
446
      break;
423
 
    case true:
 
447
    case TRUE:
424
448
      method= AZ_METHOD_AIO;
425
449
      break;
426
450
    default:
427
451
      method= AZ_METHOD_BLOCK;
428
452
    }
429
 
    if (!(azopen(&archive, share->data_file_name, O_RDONLY, 
 
453
    if (!(azopen(&archive, share->data_file_name, O_RDONLY|O_BINARY, 
430
454
                 method)))
431
455
    {
432
 
      share->crashed= true;
433
 
      return(1);
 
456
      DBUG_PRINT("ha_archive", ("Could not open archive read file"));
 
457
      share->crashed= TRUE;
 
458
      DBUG_RETURN(1);
434
459
    }
435
 
    archive_reader_open= true;
 
460
    archive_reader_open= TRUE;
436
461
  }
437
462
 
438
 
  return(0);
 
463
  DBUG_RETURN(0);
439
464
}
440
465
 
441
466
 
444
469
*/
445
470
static const char *ha_archive_exts[] = {
446
471
  ARZ,
447
 
  NULL
 
472
  NullS
448
473
};
449
474
 
450
475
const char **ha_archive::bas_ext() const
459
484
  Init out lock.
460
485
  We open the file we will read from.
461
486
*/
462
 
int ha_archive::open(const char *name,
463
 
                     int mode __attribute__((unused)),
464
 
                     uint32_t open_options)
 
487
int ha_archive::open(const char *name, int mode, uint open_options)
465
488
{
466
489
  int rc= 0;
 
490
  DBUG_ENTER("ha_archive::open");
 
491
 
 
492
  DBUG_PRINT("ha_archive", ("archive table was opened for crash: %s", 
 
493
                      (open_options & HA_OPEN_FOR_REPAIR) ? "yes" : "no"));
467
494
  share= get_share(name, &rc);
468
495
 
469
496
  if (rc == HA_ERR_CRASHED_ON_USAGE && !(open_options & HA_OPEN_FOR_REPAIR))
470
497
  {
471
498
    /* purecov: begin inspected */
472
499
    free_share();
473
 
    return(rc);
 
500
    DBUG_RETURN(rc);
474
501
    /* purecov: end */    
475
502
  }
476
503
  else if (rc == HA_ERR_OUT_OF_MEM)
477
504
  {
478
 
    return(rc);
 
505
    DBUG_RETURN(rc);
479
506
  }
480
507
 
481
 
  assert(share);
 
508
  DBUG_ASSERT(share);
482
509
 
483
510
  record_buffer= create_record_buffer(table->s->reclength + 
484
511
                                      ARCHIVE_ROW_HEADER_SIZE);
486
513
  if (!record_buffer)
487
514
  {
488
515
    free_share();
489
 
    return(HA_ERR_OUT_OF_MEM);
 
516
    DBUG_RETURN(HA_ERR_OUT_OF_MEM);
490
517
  }
491
518
 
492
519
  thr_lock_data_init(&share->lock, &lock, NULL);
493
520
 
 
521
  DBUG_PRINT("ha_archive", ("archive table was crashed %s", 
 
522
                      rc == HA_ERR_CRASHED_ON_USAGE ? "yes" : "no"));
494
523
  if (rc == HA_ERR_CRASHED_ON_USAGE && open_options & HA_OPEN_FOR_REPAIR)
495
524
  {
496
 
    return(0);
 
525
    DBUG_RETURN(0);
497
526
  }
498
527
  else
499
 
    return(rc);
 
528
    DBUG_RETURN(rc);
500
529
}
501
530
 
502
531
 
520
549
int ha_archive::close(void)
521
550
{
522
551
  int rc= 0;
 
552
  DBUG_ENTER("ha_archive::close");
523
553
 
524
554
  destroy_record_buffer(record_buffer);
525
555
 
526
556
  /* First close stream */
527
 
  if (archive_reader_open == true)
 
557
  if (archive_reader_open == TRUE)
528
558
  {
529
559
    if (azclose(&archive))
530
560
      rc= 1;
532
562
  /* then also close share */
533
563
  rc|= free_share();
534
564
 
535
 
  return(rc);
 
565
  DBUG_RETURN(rc);
536
566
}
537
567
 
538
568
 
545
575
  of creation.
546
576
*/
547
577
 
548
 
int ha_archive::create(const char *name, Table *table_arg,
 
578
int ha_archive::create(const char *name, TABLE *table_arg,
549
579
                       HA_CREATE_INFO *create_info)
550
580
{
551
581
  char name_buff[FN_REFLEN];
554
584
  azio_stream create_stream;            /* Archive file we are working with */
555
585
  File frm_file;                   /* File handler for readers */
556
586
  struct stat file_stat;
557
 
  unsigned char *frm_ptr;
 
587
  uchar *frm_ptr;
 
588
 
 
589
  DBUG_ENTER("ha_archive::create");
558
590
 
559
591
  stats.auto_increment_value= create_info->auto_increment_value;
560
592
 
561
 
  for (uint32_t key= 0; key < table_arg->sizeKeys(); key++)
 
593
  for (uint key= 0; key < table_arg->s->keys; key++)
562
594
  {
563
595
    KEY *pos= table_arg->key_info+key;
564
596
    KEY_PART_INFO *key_part=     pos->key_part;
571
603
      if (!(field->flags & AUTO_INCREMENT_FLAG))
572
604
      {
573
605
        error= -1;
 
606
        DBUG_PRINT("ha_archive", ("Index error in creating archive table"));
574
607
        goto error;
575
608
      }
576
609
    }
581
614
  */
582
615
  if (create_info->data_file_name && create_info->data_file_name[0] != '#')
583
616
  {
 
617
    DBUG_PRINT("ha_archive", ("archive will create stream file %s", 
 
618
                        create_info->data_file_name));
 
619
                        
584
620
    fn_format(name_buff, create_info->data_file_name, "", ARZ,
585
621
              MY_REPLACE_EXT | MY_UNPACK_FILENAME);
586
622
    fn_format(linkname, name, "", ARZ,
600
636
  if (!stat(name_buff, &file_stat))
601
637
  {
602
638
    my_errno= 0;
603
 
    if (!(azopen(&create_stream, name_buff, O_CREAT|O_RDWR,
 
639
    if (!(azopen(&create_stream, name_buff, O_CREAT|O_RDWR|O_BINARY,
604
640
                 AZ_METHOD_BLOCK)))
605
641
    {
606
642
      error= errno;
619
655
    {
620
656
      if (fstat(frm_file, &file_stat))
621
657
      {
622
 
        frm_ptr= (unsigned char *)my_malloc(sizeof(unsigned char) * file_stat.st_size, MYF(0));
 
658
        frm_ptr= (uchar *)my_malloc(sizeof(uchar) * file_stat.st_size, MYF(0));
623
659
        if (frm_ptr)
624
660
        {
625
661
          my_read(frm_file, frm_ptr, file_stat.st_size, MYF(0));
626
662
          azwrite_frm(&create_stream, (char *)frm_ptr, file_stat.st_size);
627
 
          free((unsigned char*)frm_ptr);
 
663
          my_free((uchar*)frm_ptr, MYF(0));
628
664
        }
629
665
      }
630
666
      my_close(frm_file, MYF(0));
649
685
  else
650
686
    my_errno= 0;
651
687
 
652
 
  return(0);
 
688
  DBUG_PRINT("ha_archive", ("Creating File %s", name_buff));
 
689
  DBUG_PRINT("ha_archive", ("Creating Link %s", linkname));
 
690
 
 
691
 
 
692
  DBUG_RETURN(0);
653
693
 
654
694
error2:
655
695
  delete_table(name);
656
696
error:
657
697
  /* Return error number, if we got one */
658
 
  return(error ? error : -1);
 
698
  DBUG_RETURN(error ? error : -1);
659
699
}
660
700
 
661
701
/*
662
702
  This is where the actual row is written out.
663
703
*/
664
 
int ha_archive::real_write_row(unsigned char *buf, azio_stream *writer)
 
704
int ha_archive::real_write_row(uchar *buf, azio_stream *writer)
665
705
{
666
706
  my_off_t written;
667
707
  unsigned int r_pack_length;
 
708
  DBUG_ENTER("ha_archive::real_write_row");
668
709
 
669
710
  /* We pack the row for writing */
670
711
  r_pack_length= pack_row(buf);
672
713
  written= azwrite_row(writer, record_buffer->buffer, r_pack_length);
673
714
  if (written != r_pack_length)
674
715
  {
675
 
    return(-1);
 
716
    DBUG_PRINT("ha_archive", ("Wrote %d bytes expected %d", 
 
717
                                              (uint32) written, 
 
718
                                              (uint32)r_pack_length));
 
719
    DBUG_RETURN(-1);
676
720
  }
677
721
 
678
722
  if (!delayed_insert || !bulk_insert)
679
 
    share->dirty= true;
 
723
    share->dirty= TRUE;
680
724
 
681
 
  return(0);
 
725
  DBUG_RETURN(0);
682
726
}
683
727
 
684
728
 
687
731
  the bytes required for the length in the header.
688
732
*/
689
733
 
690
 
uint32_t ha_archive::max_row_length(const unsigned char *buf __attribute__((unused)))
 
734
uint32 ha_archive::max_row_length(const uchar *buf)
691
735
{
692
 
  uint32_t length= (uint32_t)(table->getRecordLength() + table->sizeFields()*2);
 
736
  uint32 length= (uint32)(table->s->reclength + table->s->fields*2);
693
737
  length+= ARCHIVE_ROW_HEADER_SIZE;
694
738
 
695
 
  uint32_t *ptr, *end;
696
 
  for (ptr= table->getBlobField(), end=ptr + table->sizeBlobFields();
 
739
  uint *ptr, *end;
 
740
  for (ptr= table->s->blob_field, end=ptr + table->s->blob_fields ;
697
741
       ptr != end ;
698
742
       ptr++)
699
743
  {
704
748
}
705
749
 
706
750
 
707
 
unsigned int ha_archive::pack_row(unsigned char *record)
 
751
unsigned int ha_archive::pack_row(uchar *record)
708
752
{
709
 
  unsigned char *ptr;
 
753
  uchar *ptr;
 
754
 
 
755
  DBUG_ENTER("ha_archive::pack_row");
 
756
 
710
757
 
711
758
  if (fix_rec_buff(max_row_length(record)))
712
 
    return(HA_ERR_OUT_OF_MEM); /* purecov: inspected */
 
759
    DBUG_RETURN(HA_ERR_OUT_OF_MEM); /* purecov: inspected */
713
760
 
714
761
  /* Copy null bits */
715
762
  memcpy(record_buffer->buffer, record, table->s->null_bytes);
721
768
      ptr= (*field)->pack(ptr, record + (*field)->offset(record));
722
769
  }
723
770
 
724
 
  return((unsigned int) (ptr - record_buffer->buffer));
 
771
  DBUG_PRINT("ha_archive",("Pack row length %u", (unsigned int)
 
772
                           (ptr - record_buffer->buffer - 
 
773
                             ARCHIVE_ROW_HEADER_SIZE)));
 
774
 
 
775
  DBUG_RETURN((unsigned int) (ptr - record_buffer->buffer));
725
776
}
726
777
 
727
778
 
734
785
  for implementing start_bulk_insert() is that we could skip 
735
786
  setting dirty to true each time.
736
787
*/
737
 
int ha_archive::write_row(unsigned char *buf)
 
788
int ha_archive::write_row(uchar *buf)
738
789
{
739
790
  int rc;
740
 
  unsigned char *read_buf= NULL;
 
791
  uchar *read_buf= NULL;
741
792
  uint64_t temp_auto;
742
 
  unsigned char *record=  table->record[0];
 
793
  uchar *record=  table->record[0];
 
794
  DBUG_ENTER("ha_archive::write_row");
743
795
 
744
796
  if (share->crashed)
745
 
    return(HA_ERR_CRASHED_ON_USAGE);
 
797
    DBUG_RETURN(HA_ERR_CRASHED_ON_USAGE);
746
798
 
747
799
  ha_statistic_increment(&SSV::ha_write_count);
748
800
  if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_INSERT)
749
801
    table->timestamp_field->set_time();
750
802
  pthread_mutex_lock(&share->mutex);
751
803
 
752
 
  if (share->archive_write_open == false)
 
804
  if (share->archive_write_open == FALSE)
753
805
    if (init_archive_writer())
754
 
      return(HA_ERR_CRASHED_ON_USAGE);
 
806
      DBUG_RETURN(HA_ERR_CRASHED_ON_USAGE);
755
807
 
756
808
 
757
809
  if (table->next_number_field && record == table->record[0])
782
834
        First we create a buffer that we can use for reading rows, and can pass
783
835
        to get_row().
784
836
      */
785
 
      if (!(read_buf= (unsigned char*) my_malloc(table->s->reclength, MYF(MY_WME))))
 
837
      if (!(read_buf= (uchar*) my_malloc(table->s->reclength, MYF(MY_WME))))
786
838
      {
787
839
        rc= HA_ERR_OUT_OF_MEM;
788
840
        goto error;
832
884
error:
833
885
  pthread_mutex_unlock(&share->mutex);
834
886
  if (read_buf)
835
 
    free((unsigned char*) read_buf);
 
887
    my_free((uchar*) read_buf, MYF(0));
836
888
 
837
 
  return(rc);
 
889
  DBUG_RETURN(rc);
838
890
}
839
891
 
840
892
 
841
 
void ha_archive::get_auto_increment(uint64_t offset __attribute__((unused)),
842
 
                                    uint64_t increment __attribute__((unused)),
843
 
                                    uint64_t nb_desired_values __attribute__((unused)),
844
 
                                    uint64_t *first_value __attribute__((unused)),
845
 
                                    uint64_t *nb_reserved_values __attribute__((unused)))
 
893
void ha_archive::get_auto_increment(uint64_t offset, uint64_t increment,
 
894
                                    uint64_t nb_desired_values,
 
895
                                    uint64_t *first_value,
 
896
                                    uint64_t *nb_reserved_values)
846
897
{
847
 
  *nb_reserved_values= UINT64_MAX;
 
898
  *nb_reserved_values= ULONGLONG_MAX;
848
899
  *first_value= share->archive_write.auto_increment + 1;
849
900
}
850
901
 
851
902
/* Initialized at each key walk (called multiple times unlike rnd_init()) */
852
 
int ha_archive::index_init(uint32_t keynr, bool sorted __attribute__((unused)))
 
903
int ha_archive::index_init(uint keynr, bool sorted)
853
904
{
 
905
  DBUG_ENTER("ha_archive::index_init");
854
906
  active_index= keynr;
855
 
  return(0);
 
907
  DBUG_RETURN(0);
856
908
}
857
909
 
858
910
 
860
912
  No indexes, so if we get a request for an index search since we tell
861
913
  the optimizer that we have unique indexes, we scan
862
914
*/
863
 
int ha_archive::index_read(unsigned char *buf, const unsigned char *key,
864
 
                             uint32_t key_len, enum ha_rkey_function find_flag)
 
915
int ha_archive::index_read(uchar *buf, const uchar *key,
 
916
                             uint key_len, enum ha_rkey_function find_flag)
865
917
{
866
918
  int rc;
 
919
  DBUG_ENTER("ha_archive::index_read");
867
920
  rc= index_read_idx(buf, active_index, key, key_len, find_flag);
868
 
  return(rc);
 
921
  DBUG_RETURN(rc);
869
922
}
870
923
 
871
924
 
872
 
int ha_archive::index_read_idx(unsigned char *buf, uint32_t index, const unsigned char *key,
873
 
                               uint32_t key_len,
874
 
                               enum ha_rkey_function find_flag __attribute__((unused)))
 
925
int ha_archive::index_read_idx(uchar *buf, uint index, const uchar *key,
 
926
                                 uint key_len, enum ha_rkey_function find_flag)
875
927
{
876
928
  int rc;
877
929
  bool found= 0;
880
932
  current_key= key;
881
933
  current_key_len= key_len;
882
934
 
883
 
  rc= rnd_init(true);
 
935
 
 
936
  DBUG_ENTER("ha_archive::index_read_idx");
 
937
 
 
938
  rc= rnd_init(TRUE);
884
939
 
885
940
  if (rc)
886
941
    goto error;
895
950
  }
896
951
 
897
952
  if (found)
898
 
    return(0);
 
953
    DBUG_RETURN(0);
899
954
 
900
955
error:
901
 
  return(rc ? rc : HA_ERR_END_OF_FILE);
 
956
  DBUG_RETURN(rc ? rc : HA_ERR_END_OF_FILE);
902
957
}
903
958
 
904
959
 
905
 
int ha_archive::index_next(unsigned char * buf) 
 
960
int ha_archive::index_next(uchar * buf) 
906
961
907
962
  bool found= 0;
908
963
 
 
964
  DBUG_ENTER("ha_archive::index_next");
 
965
 
909
966
  while (!(get_row(&archive, buf)))
910
967
  {
911
968
    if (!memcmp(current_key, buf+current_k_offset, current_key_len))
915
972
    }
916
973
  }
917
974
 
918
 
  return(found ? 0 : HA_ERR_END_OF_FILE); 
 
975
  DBUG_RETURN(found ? 0 : HA_ERR_END_OF_FILE); 
919
976
}
920
977
 
921
978
/*
926
983
 
927
984
int ha_archive::rnd_init(bool scan)
928
985
{
 
986
  DBUG_ENTER("ha_archive::rnd_init");
 
987
  
929
988
  if (share->crashed)
930
 
      return(HA_ERR_CRASHED_ON_USAGE);
 
989
      DBUG_RETURN(HA_ERR_CRASHED_ON_USAGE);
931
990
 
932
991
  init_archive_reader();
933
992
 
934
993
  /* We rewind the file so that we can read from the beginning if scan */
935
994
  if (scan)
936
995
  {
 
996
    DBUG_PRINT("info", ("archive will retrieve %llu rows", 
 
997
                        (unsigned long long) scan_rows));
 
998
 
937
999
    if (read_data_header(&archive))
938
 
      return(HA_ERR_CRASHED_ON_USAGE);
 
1000
      DBUG_RETURN(HA_ERR_CRASHED_ON_USAGE);
939
1001
  }
940
1002
 
941
 
  return(0);
 
1003
  DBUG_RETURN(0);
942
1004
}
943
1005
 
944
1006
 
946
1008
  This is the method that is used to read a row. It assumes that the row is 
947
1009
  positioned where you want it.
948
1010
*/
949
 
int ha_archive::get_row(azio_stream *file_to_read, unsigned char *buf)
 
1011
int ha_archive::get_row(azio_stream *file_to_read, uchar *buf)
950
1012
{
951
1013
  int rc;
952
 
 
 
1014
  DBUG_ENTER("ha_archive::get_row");
 
1015
  DBUG_PRINT("ha_archive", ("Picking version for get_row() %d -> %d", 
 
1016
                            (uchar)file_to_read->version, 
 
1017
                            ARCHIVE_VERSION));
953
1018
  if (file_to_read->version == ARCHIVE_VERSION)
954
1019
    rc= get_row_version3(file_to_read, buf);
955
1020
  else
956
1021
    rc= -1;
957
1022
 
958
 
  return(rc);
 
1023
  DBUG_PRINT("ha_archive", ("Return %d\n", rc));
 
1024
 
 
1025
  DBUG_RETURN(rc);
959
1026
}
960
1027
 
961
1028
/* Reallocate buffer if needed */
962
1029
bool ha_archive::fix_rec_buff(unsigned int length)
963
1030
{
964
 
  assert(record_buffer->buffer);
 
1031
  DBUG_ENTER("ha_archive::fix_rec_buff");
 
1032
  DBUG_PRINT("ha_archive", ("Fixing %u for %u", 
 
1033
                            length, record_buffer->length));
 
1034
  DBUG_ASSERT(record_buffer->buffer);
965
1035
 
966
1036
  if (length > record_buffer->length)
967
1037
  {
968
 
    unsigned char *newptr;
969
 
    if (!(newptr=(unsigned char*) my_realloc((unsigned char*) record_buffer->buffer, 
 
1038
    uchar *newptr;
 
1039
    if (!(newptr=(uchar*) my_realloc((uchar*) record_buffer->buffer, 
970
1040
                                    length,
971
1041
                                    MYF(MY_ALLOW_ZERO_PTR))))
972
 
      return(1);
 
1042
      DBUG_RETURN(1);
973
1043
    record_buffer->buffer= newptr;
974
1044
    record_buffer->length= length;
975
1045
  }
976
1046
 
977
 
  assert(length <= record_buffer->length);
 
1047
  DBUG_ASSERT(length <= record_buffer->length);
978
1048
 
979
 
  return(0);
 
1049
  DBUG_RETURN(0);
980
1050
}
981
1051
 
982
 
int ha_archive::unpack_row(azio_stream *file_to_read, unsigned char *record)
 
1052
int ha_archive::unpack_row(azio_stream *file_to_read, uchar *record)
983
1053
{
 
1054
  DBUG_ENTER("ha_archive::unpack_row");
 
1055
 
984
1056
  unsigned int read;
985
1057
  int error;
986
 
  const unsigned char *ptr;
 
1058
  const uchar *ptr;
987
1059
 
988
1060
  read= azread_row(file_to_read, &error);
989
 
  ptr= (const unsigned char *)file_to_read->row_ptr;
 
1061
  ptr= (const uchar *)file_to_read->row_ptr;
990
1062
 
991
1063
  if (error || read == 0)
992
1064
  {
993
 
    return(-1);
 
1065
    DBUG_RETURN(-1);
994
1066
  }
995
1067
 
996
1068
  /* Copy null bits */
997
 
  memcpy(record, ptr, table->getNullBytes());
998
 
  ptr+= table->getNullBytes();
 
1069
  memcpy(record, ptr, table->s->null_bytes);
 
1070
  ptr+= table->s->null_bytes;
999
1071
  for (Field **field=table->field ; *field ; field++)
1000
1072
  {
1001
1073
    if (!((*field)->is_null()))
1003
1075
      ptr= (*field)->unpack(record + (*field)->offset(table->record[0]), ptr);
1004
1076
    }
1005
1077
  }
1006
 
  return(0);
 
1078
  DBUG_RETURN(0);
1007
1079
}
1008
1080
 
1009
1081
 
1010
 
int ha_archive::get_row_version3(azio_stream *file_to_read, unsigned char *buf)
 
1082
int ha_archive::get_row_version3(azio_stream *file_to_read, uchar *buf)
1011
1083
{
 
1084
  DBUG_ENTER("ha_archive::get_row_version3");
 
1085
 
1012
1086
  int returnable= unpack_row(file_to_read, buf);
1013
1087
 
1014
 
  return(returnable);
 
1088
  DBUG_RETURN(returnable);
1015
1089
}
1016
1090
 
1017
1091
 
1020
1094
  or by having had ha_archive::rnd_pos() called before it is called.
1021
1095
*/
1022
1096
 
1023
 
int ha_archive::rnd_next(unsigned char *buf)
 
1097
int ha_archive::rnd_next(uchar *buf)
1024
1098
{
1025
1099
  int rc;
 
1100
  DBUG_ENTER("ha_archive::rnd_next");
1026
1101
 
1027
1102
  if (share->crashed)
1028
 
      return(HA_ERR_CRASHED_ON_USAGE);
 
1103
      DBUG_RETURN(HA_ERR_CRASHED_ON_USAGE);
1029
1104
 
1030
1105
  if (!scan_rows)
1031
 
    return(HA_ERR_END_OF_FILE);
 
1106
    DBUG_RETURN(HA_ERR_END_OF_FILE);
1032
1107
  scan_rows--;
1033
1108
 
1034
1109
  ha_statistic_increment(&SSV::ha_read_rnd_next_count);
1037
1112
 
1038
1113
  table->status=rc ? STATUS_NOT_FOUND: 0;
1039
1114
 
1040
 
  return(rc);
 
1115
  DBUG_RETURN(rc);
1041
1116
}
1042
1117
 
1043
1118
 
1047
1122
  needed.
1048
1123
*/
1049
1124
 
1050
 
void ha_archive::position(const unsigned char *record __attribute__((unused)))
 
1125
void ha_archive::position(const uchar *record)
1051
1126
{
 
1127
  DBUG_ENTER("ha_archive::position");
1052
1128
  my_store_ptr(ref, ref_length, current_position);
1053
 
  return;
 
1129
  DBUG_VOID_RETURN;
1054
1130
}
1055
1131
 
1056
1132
 
1061
1137
  correctly ordered row.
1062
1138
*/
1063
1139
 
1064
 
int ha_archive::rnd_pos(unsigned char * buf, unsigned char *pos)
 
1140
int ha_archive::rnd_pos(uchar * buf, uchar *pos)
1065
1141
{
 
1142
  DBUG_ENTER("ha_archive::rnd_pos");
1066
1143
  ha_statistic_increment(&SSV::ha_read_rnd_next_count);
1067
1144
  current_position= (my_off_t)my_get_ptr(pos, ref_length);
1068
1145
  if (azseek(&archive, (size_t)current_position, SEEK_SET) == (size_t)(-1L))
1069
 
    return(HA_ERR_CRASHED_ON_USAGE);
1070
 
  return(get_row(&archive, buf));
 
1146
    DBUG_RETURN(HA_ERR_CRASHED_ON_USAGE);
 
1147
  DBUG_RETURN(get_row(&archive, buf));
1071
1148
}
1072
1149
 
1073
1150
/*
1077
1154
*/
1078
1155
int ha_archive::repair(THD* thd, HA_CHECK_OPT* check_opt)
1079
1156
{
 
1157
  DBUG_ENTER("ha_archive::repair");
1080
1158
  check_opt->flags= T_EXTEND;
1081
1159
  int rc= optimize(thd, check_opt);
1082
1160
 
1083
1161
  if (rc)
1084
 
    return(HA_ERR_CRASHED_ON_REPAIR);
 
1162
    DBUG_RETURN(HA_ERR_CRASHED_ON_REPAIR);
1085
1163
 
1086
 
  share->crashed= false;
1087
 
  return(0);
 
1164
  share->crashed= FALSE;
 
1165
  DBUG_RETURN(0);
1088
1166
}
1089
1167
 
1090
1168
/*
1091
1169
  The table can become fragmented if data was inserted, read, and then
1092
1170
  inserted again. What we do is open up the file and recompress it completely. 
1093
1171
*/
1094
 
int ha_archive::optimize(THD* thd __attribute__((unused)),
1095
 
                         HA_CHECK_OPT* check_opt __attribute__((unused)))
 
1172
int ha_archive::optimize(THD* thd, HA_CHECK_OPT* check_opt)
1096
1173
{
 
1174
  DBUG_ENTER("ha_archive::optimize");
1097
1175
  int rc= 0;
1098
1176
  azio_stream writer;
1099
1177
  char writer_filename[FN_REFLEN];
1104
1182
  if (share->archive_write_open)
1105
1183
  {
1106
1184
    azclose(&(share->archive_write));
1107
 
    share->archive_write_open= false;
 
1185
    share->archive_write_open= FALSE;
1108
1186
  }
1109
1187
 
1110
1188
  /* Lets create a file to contain the new data */
1111
1189
  fn_format(writer_filename, share->table_name, "", ARN, 
1112
1190
            MY_REPLACE_EXT | MY_UNPACK_FILENAME);
1113
1191
 
1114
 
  if (!(azopen(&writer, writer_filename, O_CREAT|O_RDWR, AZ_METHOD_BLOCK)))
1115
 
    return(HA_ERR_CRASHED_ON_USAGE); 
 
1192
  if (!(azopen(&writer, writer_filename, O_CREAT|O_RDWR|O_BINARY, AZ_METHOD_BLOCK)))
 
1193
    DBUG_RETURN(HA_ERR_CRASHED_ON_USAGE); 
1116
1194
 
1117
1195
  /* 
1118
1196
    An extended rebuild is a lot more effort. We open up each row and re-record it. 
1123
1201
  */
1124
1202
  if (1)
1125
1203
  {
 
1204
    DBUG_PRINT("ha_archive", ("archive extended rebuild"));
 
1205
 
1126
1206
    /*
1127
1207
      Now we will rewind the archive file so that we are positioned at the 
1128
1208
      start of the file.
1136
1216
    */
1137
1217
    if (!rc)
1138
1218
    {
1139
 
      uint64_t x;
1140
 
      uint64_t rows_restored;
 
1219
      unsigned long long x;
 
1220
      unsigned long long rows_restored;
1141
1221
      share->rows_recorded= 0;
1142
1222
      stats.auto_increment_value= 1;
1143
1223
      share->archive_write.auto_increment= 0;
 
1224
      my_bitmap_map *org_bitmap= dbug_tmp_use_all_columns(table, table->read_set);
1144
1225
 
1145
1226
      rows_restored= archive.rows;
1146
1227
 
1167
1248
              (share->archive_write.auto_increment= auto_value) + 1;
1168
1249
        }
1169
1250
      }
 
1251
      dbug_tmp_restore_column_map(table->read_set, org_bitmap);
1170
1252
      share->rows_recorded= (ha_rows)writer.rows;
1171
1253
    }
1172
1254
 
 
1255
    DBUG_PRINT("info", ("recovered %llu archive rows", 
 
1256
                        (unsigned long long)share->rows_recorded));
 
1257
 
 
1258
    DBUG_PRINT("ha_archive", ("recovered %llu archive rows", 
 
1259
                        (unsigned long long)share->rows_recorded));
 
1260
 
1173
1261
    if (rc && rc != HA_ERR_END_OF_FILE)
1174
1262
    {
1175
1263
      goto error;
1177
1265
  } 
1178
1266
 
1179
1267
  azclose(&writer);
1180
 
  share->dirty= false;
 
1268
  share->dirty= FALSE;
1181
1269
  
1182
1270
  azclose(&archive);
1183
1271
 
1185
1273
  rc = my_rename(writer_filename,share->data_file_name,MYF(0));
1186
1274
 
1187
1275
 
1188
 
  return(rc);
 
1276
  DBUG_RETURN(rc);
1189
1277
error:
 
1278
  DBUG_PRINT("ha_archive", ("Failed to recover, error was %d", rc));
1190
1279
  azclose(&writer);
1191
1280
 
1192
 
  return(rc); 
 
1281
  DBUG_RETURN(rc); 
1193
1282
}
1194
1283
 
1195
1284
/* 
1200
1289
                                       enum thr_lock_type lock_type)
1201
1290
{
1202
1291
  if (lock_type == TL_WRITE_DELAYED)
1203
 
    delayed_insert= true;
 
1292
    delayed_insert= TRUE;
1204
1293
  else
1205
 
    delayed_insert= false;
 
1294
    delayed_insert= FALSE;
1206
1295
 
1207
1296
  if (lock_type != TL_IGNORE && lock.type == TL_UNLOCK) 
1208
1297
  {
1209
1298
    /* 
1210
1299
      Here is where we get into the guts of a row level lock.
1211
1300
      If TL_UNLOCK is set 
1212
 
      If we are not doing a LOCK Table or DISCARD/IMPORT
 
1301
      If we are not doing a LOCK TABLE or DISCARD/IMPORT
1213
1302
      TABLESPACE, then allow multiple writers 
1214
1303
    */
1215
1304
 
1239
1328
 
1240
1329
void ha_archive::update_create_info(HA_CREATE_INFO *create_info)
1241
1330
{
 
1331
  DBUG_ENTER("ha_archive::update_create_info");
 
1332
 
1242
1333
  ha_archive::info(HA_STATUS_AUTO);
1243
1334
  if (!(create_info->used_fields & HA_CREATE_USED_AUTO))
1244
1335
  {
1248
1339
  if (!(my_readlink(share->real_path, share->data_file_name, MYF(0))))
1249
1340
    create_info->data_file_name= share->real_path;
1250
1341
 
1251
 
  return;
 
1342
  DBUG_VOID_RETURN;
1252
1343
}
1253
1344
 
1254
1345
 
1255
1346
/*
1256
1347
  Hints for optimizer, see ha_tina for more information
1257
1348
*/
1258
 
int ha_archive::info(uint32_t flag)
 
1349
int ha_archive::info(uint flag)
1259
1350
{
 
1351
  DBUG_ENTER("ha_archive::info");
 
1352
 
1260
1353
  /* 
1261
1354
    If dirty, we lock, and then reset/flush the data.
1262
1355
    I found that just calling azflush() doesn't always work.
1263
1356
  */
1264
1357
  pthread_mutex_lock(&share->mutex);
1265
 
  if (share->dirty == true)
 
1358
  if (share->dirty == TRUE)
1266
1359
  {
 
1360
    DBUG_PRINT("ha_archive", ("archive flushing out rows for scan"));
1267
1361
    azflush(&(share->archive_write), Z_SYNC_FLUSH);
1268
1362
    share->rows_recorded= share->archive_write.rows;
1269
 
    share->dirty= false;
 
1363
    share->dirty= FALSE;
1270
1364
    if (share->version < global_version)
1271
1365
    {
1272
1366
      share->version_rows= share->rows_recorded;
1285
1379
  scan_rows= stats.records;
1286
1380
  stats.deleted= 0;
1287
1381
 
 
1382
  DBUG_PRINT("ha_archive", ("Stats rows is %d\n", (int)stats.records));
1288
1383
  /* Costs quite a bit more to get all information */
1289
1384
  if (flag & HA_STATUS_TIME)
1290
1385
  {
1291
1386
    struct stat file_stat;  // Stat information for the data file
1292
1387
 
1293
 
    stat(share->data_file_name, &file_stat);
 
1388
    VOID(stat(share->data_file_name, &file_stat));
1294
1389
 
1295
 
    stats.mean_rec_length= table->getRecordLength()+ buffer.alloced_length();
 
1390
    stats.mean_rec_length= table->s->reclength + buffer.alloced_length();
1296
1391
    stats.data_file_length= file_stat.st_size;
1297
1392
    stats.create_time= file_stat.st_ctime;
1298
1393
    stats.update_time= file_stat.st_mtime;
1310
1405
    stats.auto_increment_value= archive.auto_increment + 1;
1311
1406
  }
1312
1407
 
1313
 
  return(0);
 
1408
  DBUG_RETURN(0);
1314
1409
}
1315
1410
 
1316
1411
 
1322
1417
*/
1323
1418
void ha_archive::start_bulk_insert(ha_rows rows)
1324
1419
{
 
1420
  DBUG_ENTER("ha_archive::start_bulk_insert");
1325
1421
  if (!rows || rows >= ARCHIVE_MIN_ROWS_TO_USE_BULK_INSERT)
1326
 
    bulk_insert= true;
1327
 
  return;
 
1422
    bulk_insert= TRUE;
 
1423
  DBUG_VOID_RETURN;
1328
1424
}
1329
1425
 
1330
1426
 
1334
1430
*/
1335
1431
int ha_archive::end_bulk_insert()
1336
1432
{
1337
 
  bulk_insert= false;
1338
 
  share->dirty= true;
1339
 
  return(0);
 
1433
  DBUG_ENTER("ha_archive::end_bulk_insert");
 
1434
  bulk_insert= FALSE;
 
1435
  share->dirty= TRUE;
 
1436
  DBUG_RETURN(0);
1340
1437
}
1341
1438
 
1342
1439
/*
1346
1443
*/
1347
1444
int ha_archive::delete_all_rows()
1348
1445
{
1349
 
  return(HA_ERR_WRONG_COMMAND);
 
1446
  DBUG_ENTER("ha_archive::delete_all_rows");
 
1447
  DBUG_RETURN(HA_ERR_WRONG_COMMAND);
1350
1448
}
1351
1449
 
1352
1450
/*
1354
1452
*/
1355
1453
bool ha_archive::is_crashed() const 
1356
1454
{
1357
 
  return(share->crashed); 
 
1455
  DBUG_ENTER("ha_archive::is_crashed");
 
1456
  DBUG_RETURN(share->crashed); 
1358
1457
}
1359
1458
 
1360
1459
/*
1361
1460
  Simple scan of the tables to make sure everything is ok.
1362
1461
*/
1363
1462
 
1364
 
int ha_archive::check(THD* thd,
1365
 
                      HA_CHECK_OPT* check_opt __attribute__((unused)))
 
1463
int ha_archive::check(THD* thd, HA_CHECK_OPT* check_opt)
1366
1464
{
1367
1465
  int rc= 0;
1368
1466
  const char *old_proc_info;
1369
 
  uint64_t x;
 
1467
  unsigned long long x;
 
1468
  DBUG_ENTER("ha_archive::check");
1370
1469
 
1371
 
  old_proc_info= get_thd_proc_info(thd);
1372
 
  set_thd_proc_info(thd, "Checking table");
 
1470
  old_proc_info= thd_proc_info(thd, "Checking table");
1373
1471
  /* Flush any waiting data */
1374
1472
  pthread_mutex_lock(&share->mutex);
1375
1473
  azflush(&(share->archive_write), Z_SYNC_FLUSH);
1390
1488
      break;
1391
1489
  }
1392
1490
 
1393
 
  set_thd_proc_info(thd, old_proc_info);
 
1491
  thd_proc_info(thd, old_proc_info);
1394
1492
 
1395
1493
  if ((rc && rc != HA_ERR_END_OF_FILE))  
1396
1494
  {
1397
 
    share->crashed= false;
1398
 
    return(HA_ADMIN_CORRUPT);
 
1495
    share->crashed= FALSE;
 
1496
    DBUG_RETURN(HA_ADMIN_CORRUPT);
1399
1497
  }
1400
1498
  else
1401
1499
  {
1402
 
    return(HA_ADMIN_OK);
 
1500
    DBUG_RETURN(HA_ADMIN_OK);
1403
1501
  }
1404
1502
}
1405
1503
 
1409
1507
bool ha_archive::check_and_repair(THD *thd) 
1410
1508
{
1411
1509
  HA_CHECK_OPT check_opt;
 
1510
  DBUG_ENTER("ha_archive::check_and_repair");
1412
1511
 
1413
1512
  check_opt.init();
1414
1513
 
1415
 
  return(repair(thd, &check_opt));
 
1514
  DBUG_RETURN(repair(thd, &check_opt));
1416
1515
}
1417
1516
 
1418
1517
archive_record_buffer *ha_archive::create_record_buffer(unsigned int length) 
1419
1518
{
 
1519
  DBUG_ENTER("ha_archive::create_record_buffer");
1420
1520
  archive_record_buffer *r;
1421
1521
  if (!(r= 
1422
1522
        (archive_record_buffer*) my_malloc(sizeof(archive_record_buffer),
1423
1523
                                           MYF(MY_WME))))
1424
1524
  {
1425
 
    return(NULL); /* purecov: inspected */
 
1525
    DBUG_RETURN(NULL); /* purecov: inspected */
1426
1526
  }
1427
1527
  r->length= (int)length;
1428
1528
 
1429
 
  if (!(r->buffer= (unsigned char*) my_malloc(r->length,
 
1529
  if (!(r->buffer= (uchar*) my_malloc(r->length,
1430
1530
                                    MYF(MY_WME))))
1431
1531
  {
1432
 
    free((char*) r);
1433
 
    return(NULL); /* purecov: inspected */
 
1532
    my_free((char*) r, MYF(MY_ALLOW_ZERO_PTR));
 
1533
    DBUG_RETURN(NULL); /* purecov: inspected */
1434
1534
  }
1435
1535
 
1436
 
  return(r);
 
1536
  DBUG_RETURN(r);
1437
1537
}
1438
1538
 
1439
1539
void ha_archive::destroy_record_buffer(archive_record_buffer *r) 
1440
1540
{
1441
 
  free((char*) r->buffer);
1442
 
  free((char*) r);
1443
 
  return;
 
1541
  DBUG_ENTER("ha_archive::destroy_record_buffer");
 
1542
  my_free((char*) r->buffer, MYF(MY_ALLOW_ZERO_PTR));
 
1543
  my_free((char*) r, MYF(MY_ALLOW_ZERO_PTR));
 
1544
  DBUG_VOID_RETURN;
1444
1545
}
1445
1546
 
1446
 
static DRIZZLE_SYSVAR_BOOL(aio, archive_use_aio,
 
1547
static MYSQL_SYSVAR_BOOL(aio, archive_use_aio,
1447
1548
  PLUGIN_VAR_NOCMDOPT,
1448
1549
  "Whether or not to use asynchronous IO.",
1449
 
  NULL, NULL, true);
 
1550
  NULL, NULL, TRUE);
1450
1551
 
1451
1552
static struct st_mysql_sys_var* archive_system_variables[]= {
1452
 
  DRIZZLE_SYSVAR(aio),
 
1553
  MYSQL_SYSVAR(aio),
1453
1554
  NULL
1454
1555
};
1455
1556
 
 
1557
struct st_mysql_storage_engine archive_storage_engine=
 
1558
{ MYSQL_HANDLERTON_INTERFACE_VERSION };
 
1559
 
1456
1560
mysql_declare_plugin(archive)
1457
1561
{
1458
 
  DRIZZLE_STORAGE_ENGINE_PLUGIN,
 
1562
  MYSQL_STORAGE_ENGINE_PLUGIN,
 
1563
  &archive_storage_engine,
1459
1564
  "ARCHIVE",
1460
 
  "3.5",
1461
1565
  "Brian Aker, MySQL AB",
1462
1566
  "Archive storage engine",
1463
1567
  PLUGIN_LICENSE_GPL,
1464
1568
  archive_db_init, /* Plugin Init */
1465
1569
  archive_db_done, /* Plugin Deinit */
 
1570
  0x0350 /* 3.0 */,
1466
1571
  NULL,                       /* status variables                */
1467
1572
  archive_system_variables,   /* system variables                */
1468
1573
  NULL                        /* config options                  */