270
267
typedef struct st_dynamic_array
272
unsigned char *buffer;
273
uint32_t elements,max_element;
274
uint32_t alloc_increment;
275
uint32_t size_of_element;
270
uint elements,max_element;
271
uint alloc_increment;
272
uint size_of_element;
278
275
typedef struct st_my_tmpdir
280
277
DYNAMIC_ARRAY full_list;
283
280
pthread_mutex_t mutex;
283
typedef struct st_dynamic_string
286
size_t length,max_length,alloc_increment;
290
typedef int (*IO_CACHE_CALLBACK)(struct st_io_cache*);
292
typedef struct st_io_cache_share
294
pthread_mutex_t mutex; /* To sync on reads into buffer. */
295
pthread_cond_t cond; /* To wait for signals. */
296
pthread_cond_t cond_writer; /* For a synchronized writer. */
297
/* Offset in file corresponding to the first byte of buffer. */
298
my_off_t pos_in_file;
299
/* If a synchronized write cache is the source of the data. */
300
struct st_io_cache *source_cache;
301
uchar *buffer; /* The read buffer. */
302
uchar *read_end; /* Behind last valid byte of buffer. */
303
int running_threads; /* threads not in lock. */
304
int total_threads; /* threads sharing the cache. */
305
int error; /* Last error. */
306
#ifdef NOT_YET_IMPLEMENTED
307
/* whether the structure should be free'd */
312
typedef struct st_io_cache /* Used when cacheing files */
314
/* Offset in file corresponding to the first byte of uchar* buffer. */
315
my_off_t pos_in_file;
317
The offset of end of file for READ_CACHE and WRITE_CACHE.
318
For SEQ_READ_APPEND it the maximum of the actual end of file and
319
the position represented by read_end.
321
my_off_t end_of_file;
322
/* Points to current read position in the buffer */
324
/* the non-inclusive boundary in the buffer for the currently valid read */
326
uchar *buffer; /* The read buffer */
327
/* Used in ASYNC_IO */
330
/* Only used in WRITE caches and in SEQ_READ_APPEND to buffer writes */
333
Only used in SEQ_READ_APPEND, and points to the current read position
334
in the write buffer. Note that reads in SEQ_READ_APPEND caches can
335
happen from both read buffer (uchar* buffer) and write buffer
336
(uchar* write_buffer).
338
uchar *append_read_pos;
339
/* Points to current write position in the write buffer */
341
/* The non-inclusive boundary of the valid write area */
345
Current_pos and current_end are convenience variables used by
346
my_b_tell() and other routines that need to know the current offset
347
current_pos points to &write_pos, and current_end to &write_end in a
348
WRITE_CACHE, and &read_pos and &read_end respectively otherwise
350
uchar **current_pos, **current_end;
352
The lock is for append buffer used in SEQ_READ_APPEND cache
353
need mutex copying from append buffer to read buffer.
355
pthread_mutex_t append_buffer_lock;
357
The following is used when several threads are reading the
358
same file in parallel. They are synchronized on disk
359
accesses reading the cached part of the file asynchronously.
360
It should be set to NULL to disable the feature. Only
361
READ_CACHE mode is supported.
363
IO_CACHE_SHARE *share;
365
A caller will use my_b_read() macro to read from the cache
366
if the data is already in cache, it will be simply copied with
367
memcpy() and internal variables will be accordinging updated with
368
no functions invoked. However, if the data is not fully in the cache,
369
my_b_read() will call read_function to fetch the data. read_function
370
must never be invoked directly.
372
int (*read_function)(struct st_io_cache *,uchar *,size_t);
374
Same idea as in the case of read_function, except my_b_write() needs to
375
be replaced with my_b_append() for a SEQ_READ_APPEND cache
377
int (*write_function)(struct st_io_cache *,const uchar *,size_t);
379
Specifies the type of the cache. Depending on the type of the cache
380
certain operations might not be available and yield unpredicatable
381
results. Details to be documented later
383
enum cache_type type;
385
Callbacks when the actual read I/O happens. These were added and
386
are currently used for binary logging of LOAD DATA INFILE - when a
387
block is read from the file, we create a block create/append event, and
388
when IO_CACHE is closed, we create an end event. These functions could,
389
of course be used for other things
391
IO_CACHE_CALLBACK pre_read;
392
IO_CACHE_CALLBACK post_read;
393
IO_CACHE_CALLBACK pre_close;
395
Counts the number of times, when we were forced to use disk. We use it to
396
increase the binlog_cache_disk_use status variable.
398
uint32_t disk_writes;
399
void* arg; /* for use by pre/post_read */
400
char *file_name; /* if used with 'open_cached_file' */
402
File file; /* file descriptor */
404
seek_not_done is set by my_b_seek() to inform the upcoming read/write
405
operation that a seek needs to be preformed prior to the actual I/O
406
error is 0 if the cache operation was successful, -1 if there was a
407
"hard" error, and the actual number of I/O-ed bytes if the read/write was
410
int seek_not_done,error;
411
/* buffer_length is memory size allocated for buffer or write_buffer */
412
size_t buffer_length;
413
/* read_length is the same as buffer_length except when we use async io */
415
myf myflags; /* Flags used to my_read/my_write */
417
alloced_buffer is 1 if the buffer was allocated by init_io_cache() and
418
0 if it was supplied by the user.
419
Currently READ_NET is the only one that will use a buffer allocated
425
As inidicated by ifdef, this is for async I/O, which is not currently
426
used (because it's not reliable on all systems)
429
my_off_t aio_read_pos;
430
my_aio_result aio_result;
287
434
typedef int (*qsort2_cmp)(const void *, const void *, const void *);
367
518
extern int my_delete_with_symlink(const char *name, myf MyFlags);
368
519
extern int my_rename_with_symlink(const char *from,const char *to,myf MyFlags);
369
520
extern int my_symlink(const char *content, const char *linkname, myf MyFlags);
370
extern size_t my_read(File Filedes,unsigned char *Buffer,size_t Count,myf MyFlags);
521
extern size_t my_read(File Filedes,uchar *Buffer,size_t Count,myf MyFlags);
371
522
extern int my_rename(const char *from,const char *to,myf MyFlags);
372
523
extern my_off_t my_seek(File fd,my_off_t pos,int whence,myf MyFlags);
373
524
extern my_off_t my_tell(File fd,myf MyFlags);
374
extern size_t my_write(File Filedes,const unsigned char *Buffer,size_t Count,
525
extern size_t my_write(File Filedes,const uchar *Buffer,size_t Count,
376
extern size_t my_fwrite(FILE *stream,const unsigned char *Buffer,size_t Count,
527
extern size_t my_fwrite(FILE *stream,const uchar *Buffer,size_t Count,
378
529
extern my_off_t my_fseek(FILE *stream,my_off_t pos,int whence,myf MyFlags);
379
530
extern void *_mymalloc(size_t uSize,const char *sFile,
380
uint32_t uLine, myf MyFlag);
531
uint uLine, myf MyFlag);
381
532
extern void *_myrealloc(void *pPtr,size_t uSize,const char *sFile,
382
uint32_t uLine, myf MyFlag);
383
extern void * my_multi_malloc (myf MyFlags, ...);
384
extern void _myfree(void *pPtr, const char *sFile, uint32_t uLine, myf MyFlag);
385
extern int _sanity(const char *sFile, uint32_t uLine);
533
uint uLine, myf MyFlag);
534
extern void * my_multi_malloc _VARARGS((myf MyFlags, ...));
535
extern void _myfree(void *pPtr,const char *sFile,uint uLine, myf MyFlag);
536
extern int _sanity(const char *sFile, uint uLine);
386
537
extern void *_my_memdup(const void *from, size_t length,
387
const char *sFile, uint32_t uLine,myf MyFlag);
388
extern char * _my_strdup(const char *from, const char *sFile, uint32_t uLine,
538
const char *sFile, uint uLine,myf MyFlag);
539
extern char * _my_strdup(const char *from, const char *sFile, uint uLine,
390
541
extern char *_my_strndup(const char *from, size_t length,
391
const char *sFile, uint32_t uLine,
542
const char *sFile, uint uLine,
394
545
#define my_access access
468
619
extern int init_record_cache(RECORD_CACHE *info,size_t cachesize,File file,
469
620
size_t reclength,enum cache_type type,
470
621
bool use_async_io);
471
extern int read_cache_record(RECORD_CACHE *info,unsigned char *to);
622
extern int read_cache_record(RECORD_CACHE *info,uchar *to);
472
623
extern int end_record_cache(RECORD_CACHE *info);
473
624
extern int write_cache_record(RECORD_CACHE *info,my_off_t filepos,
474
const unsigned char *record,size_t length);
625
const uchar *record,size_t length);
475
626
extern int flush_write_cache(RECORD_CACHE *info);
476
extern RETSIGTYPE sigtstp_handler(int signal_number);
627
extern sig_handler sigtstp_handler(int signal_number);
477
628
extern void handle_recived_signals(void);
479
extern RETSIGTYPE my_set_alarm_variable(int signo);
480
extern void my_string_ptr_sort(unsigned char *base,uint32_t items,size_t size);
481
extern void radixsort_for_str_ptr(unsigned char* base[], uint32_t number_of_elements,
482
size_t size_of_element,unsigned char *buffer[]);
483
extern RETQSORTTYPE my_qsort(void *base_ptr, size_t total_elems, size_t size,
485
extern RETQSORTTYPE my_qsort2(void *base_ptr, size_t total_elems, size_t size,
486
qsort2_cmp cmp, void *cmp_argument);
630
extern sig_handler my_set_alarm_variable(int signo);
631
extern void my_string_ptr_sort(uchar *base,uint items,size_t size);
632
extern void radixsort_for_str_ptr(uchar* base[], uint number_of_elements,
633
size_t size_of_element,uchar *buffer[]);
634
extern qsort_t my_qsort(void *base_ptr, size_t total_elems, size_t size,
636
extern qsort_t my_qsort2(void *base_ptr, size_t total_elems, size_t size,
637
qsort2_cmp cmp, void *cmp_argument);
487
638
extern qsort2_cmp get_ptr_compare(size_t);
488
void my_store_ptr(unsigned char *buff, size_t pack_length, my_off_t pos);
489
my_off_t my_get_ptr(unsigned char *ptr, size_t pack_length);
639
void my_store_ptr(uchar *buff, size_t pack_length, my_off_t pos);
640
my_off_t my_get_ptr(uchar *ptr, size_t pack_length);
641
extern int init_io_cache(IO_CACHE *info,File file,size_t cachesize,
642
enum cache_type type,my_off_t seek_offset,
643
bool use_async_io, myf cache_myflags);
644
extern bool reinit_io_cache(IO_CACHE *info,enum cache_type type,
645
my_off_t seek_offset,bool use_async_io,
647
extern void setup_io_cache(IO_CACHE* info);
648
extern int _my_b_read(IO_CACHE *info,uchar *Buffer,size_t Count);
649
extern int _my_b_read_r(IO_CACHE *info,uchar *Buffer,size_t Count);
650
extern void init_io_cache_share(IO_CACHE *read_cache, IO_CACHE_SHARE *cshare,
651
IO_CACHE *write_cache, uint num_threads);
652
extern void remove_io_thread(IO_CACHE *info);
653
extern int _my_b_seq_read(IO_CACHE *info,uchar *Buffer,size_t Count);
654
extern int _my_b_net_read(IO_CACHE *info,uchar *Buffer,size_t Count);
655
extern int _my_b_get(IO_CACHE *info);
656
extern int _my_b_async_read(IO_CACHE *info,uchar *Buffer,size_t Count);
657
extern int _my_b_write(IO_CACHE *info,const uchar *Buffer,size_t Count);
658
extern int my_b_append(IO_CACHE *info,const uchar *Buffer,size_t Count);
659
extern int my_b_safe_write(IO_CACHE *info,const uchar *Buffer,size_t Count);
661
extern int my_block_write(IO_CACHE *info, const uchar *Buffer,
662
size_t Count, my_off_t pos);
663
extern int my_b_flush_io_cache(IO_CACHE *info, int need_append_buffer_lock);
665
#define flush_io_cache(info) my_b_flush_io_cache((info),1)
667
extern int end_io_cache(IO_CACHE *info);
668
extern size_t my_b_fill(IO_CACHE *info);
669
extern void my_b_seek(IO_CACHE *info,my_off_t pos);
670
extern size_t my_b_gets(IO_CACHE *info, char *to, size_t max_length);
671
extern my_off_t my_b_filelength(IO_CACHE *info);
672
extern size_t my_b_printf(IO_CACHE *info, const char* fmt, ...);
673
extern size_t my_b_vprintf(IO_CACHE *info, const char* fmt, va_list ap);
674
extern bool open_cached_file(IO_CACHE *cache,const char *dir,
675
const char *prefix, size_t cache_size,
677
extern bool real_open_cached_file(IO_CACHE *cache);
678
extern void close_cached_file(IO_CACHE *cache);
490
679
File create_temp_file(char *to, const char *dir, const char *pfx,
491
680
int mode, myf MyFlags);
492
681
#define my_init_dynamic_array(A,B,C,D) init_dynamic_array2(A,B,NULL,C,D CALLER_INFO)
493
682
#define my_init_dynamic_array_ci(A,B,C,D) init_dynamic_array2(A,B,NULL,C,D ORIG_CALLER_INFO)
494
683
#define my_init_dynamic_array2(A,B,C,D,E) init_dynamic_array2(A,B,C,D,E CALLER_INFO)
495
684
#define my_init_dynamic_array2_ci(A,B,C,D,E) init_dynamic_array2(A,B,C,D,E ORIG_CALLER_INFO)
496
extern bool init_dynamic_array2(DYNAMIC_ARRAY *array,uint32_t element_size,
497
void *init_buffer, uint32_t init_alloc,
498
uint32_t alloc_increment
685
extern bool init_dynamic_array2(DYNAMIC_ARRAY *array,uint element_size,
686
void *init_buffer, uint init_alloc,
499
688
CALLER_INFO_PROTO);
500
689
/* init_dynamic_array() function is deprecated */
501
extern bool init_dynamic_array(DYNAMIC_ARRAY *array,uint32_t element_size,
502
uint32_t init_alloc,uint32_t alloc_increment
690
extern bool init_dynamic_array(DYNAMIC_ARRAY *array,uint element_size,
691
uint init_alloc,uint alloc_increment
503
692
CALLER_INFO_PROTO);
504
extern bool insert_dynamic(DYNAMIC_ARRAY *array,unsigned char * element);
505
extern unsigned char *alloc_dynamic(DYNAMIC_ARRAY *array);
506
extern unsigned char *pop_dynamic(DYNAMIC_ARRAY*);
507
extern bool set_dynamic(DYNAMIC_ARRAY *array,unsigned char * element,uint32_t array_index);
508
extern bool allocate_dynamic(DYNAMIC_ARRAY *array, uint32_t max_elements);
509
extern void get_dynamic(DYNAMIC_ARRAY *array,unsigned char * element,uint32_t array_index);
693
extern bool insert_dynamic(DYNAMIC_ARRAY *array,uchar * element);
694
extern uchar *alloc_dynamic(DYNAMIC_ARRAY *array);
695
extern uchar *pop_dynamic(DYNAMIC_ARRAY*);
696
extern bool set_dynamic(DYNAMIC_ARRAY *array,uchar * element,uint array_index);
697
extern bool allocate_dynamic(DYNAMIC_ARRAY *array, uint max_elements);
698
extern void get_dynamic(DYNAMIC_ARRAY *array,uchar * element,uint array_index);
510
699
extern void delete_dynamic(DYNAMIC_ARRAY *array);
511
extern void delete_dynamic_element(DYNAMIC_ARRAY *array, uint32_t array_index);
700
extern void delete_dynamic_element(DYNAMIC_ARRAY *array, uint array_index);
512
701
extern void freeze_size(DYNAMIC_ARRAY *array);
513
extern int get_index_dynamic(DYNAMIC_ARRAY *array, unsigned char * element);
702
extern int get_index_dynamic(DYNAMIC_ARRAY *array, uchar * element);
514
703
#define dynamic_array_ptr(array,array_index) ((array)->buffer+(array_index)*(array)->size_of_element)
515
704
#define dynamic_element(array,array_index,type) ((type)((array)->buffer) +(array_index))
516
705
#define push_dynamic(A,B) insert_dynamic((A),(B))
517
706
#define reset_dynamic(array) ((array)->elements= 0)
518
707
#define sort_dynamic(A,cmp) my_qsort((A)->buffer, (A)->elements, (A)->size_of_element, (cmp))
709
extern bool init_dynamic_string(DYNAMIC_STRING *str, const char *init_str,
710
size_t init_alloc,size_t alloc_increment);
711
extern bool dynstr_append(DYNAMIC_STRING *str, const char *append);
712
bool dynstr_append_mem(DYNAMIC_STRING *str, const char *append,
714
extern bool dynstr_append_os_quoted(DYNAMIC_STRING *str, const char *append,
716
extern bool dynstr_set(DYNAMIC_STRING *str, const char *init_str);
717
extern bool dynstr_realloc(DYNAMIC_STRING *str, size_t additional_size);
718
extern bool dynstr_trunc(DYNAMIC_STRING *str, size_t n);
719
extern void dynstr_free(DYNAMIC_STRING *str);
520
720
#define my_malloc_lock(A,B) my_malloc((A),(B))
721
#define my_free_lock(A,B) my_free((A),(B))
521
722
#define alloc_root_inited(A) ((A)->min_malloc != 0)
522
723
#define ALLOC_ROOT_MIN_BLOCK_SIZE (MALLOC_OVERHEAD + sizeof(USED_MEM) + 8)
523
724
#define clear_alloc_root(A) do { (A)->free= (A)->used= (A)->pre_alloc= 0; (A)->min_malloc=0;} while(0)
725
extern void init_alloc_root(MEM_ROOT *mem_root, size_t block_size,
726
size_t pre_alloc_size);
727
extern void *alloc_root(MEM_ROOT *mem_root, size_t Size);
728
extern void *multi_alloc_root(MEM_ROOT *mem_root, ...);
729
extern void free_root(MEM_ROOT *root, myf MyFLAGS);
730
extern void set_prealloc_root(MEM_ROOT *root, char *ptr);
731
extern void reset_root_defaults(MEM_ROOT *mem_root, size_t block_size,
732
size_t prealloc_size);
733
extern char *strdup_root(MEM_ROOT *root,const char *str);
734
extern char *strmake_root(MEM_ROOT *root,const char *str,size_t len);
735
extern void *memdup_root(MEM_ROOT *root,const void *str, size_t len);
524
736
extern int get_defaults_options(int argc, char **argv,
525
737
char **defaults, char **extra_defaults,
526
738
char **group_suffix);