~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/archive/ha_archive.cc

  • Committer: Brian Aker
  • Date: 2008-07-13 21:20:24 UTC
  • Revision ID: brian@tangent.org-20080713212024-o6263c1vha7yxdeu
More bool removal. More cow bell!

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