~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/myisam/mf_keycache.cc

  • Committer: Padraig O'Sullivan
  • Date: 2009-09-13 01:03:01 UTC
  • mto: (1126.9.2 captain-20090915-01)
  • mto: This revision was merged to the branch mainline in revision 1133.
  • Revision ID: osullivan.padraig@gmail.com-20090913010301-tcvvezipx1124acy
Added calls to the dtrace delete begin/end probes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
101
101
  I/O finished.
102
102
*/
103
103
 
104
 
#include "config.h"
105
 
#include "drizzled/error.h"
106
 
#include "drizzled/internal/my_sys.h"
 
104
#include <drizzled/global.h>
 
105
#include <mysys/mysys_err.h>
 
106
#include <mysys/my_sys.h>
107
107
#include "keycache.h"
108
 
#include "drizzled/internal/m_string.h"
109
 
#include "drizzled/internal/my_bit.h"
 
108
#include <mystrings/m_string.h>
 
109
#include <mysys/my_bit.h>
110
110
#include <errno.h>
111
111
#include <stdarg.h>
112
112
 
113
 
using namespace drizzled;
114
 
 
115
 
static void change_key_cache_param(KEY_CACHE *keycache, uint32_t division_limit,
116
 
                            uint32_t age_threshold);
117
 
 
118
113
/*
119
114
  Some compilation flags have been added specifically for this module
120
115
  to control the following:
155
150
struct st_keycache_page
156
151
{
157
152
  int file;               /* file to which the page belongs to  */
158
 
  internal::my_off_t filepos;       /* position of the page in the file   */
 
153
  my_off_t filepos;       /* position of the page in the file   */
159
154
};
160
155
 
161
156
/* element in the chain of a hash table bucket */
163
158
{
164
159
  struct st_hash_link *next, **prev; /* to connect links in the same bucket  */
165
160
  struct st_block_link *block;       /* reference to the block for the page: */
166
 
  int file;                         /* from such a file                     */
167
 
  internal::my_off_t diskpos;                  /* with such an offset                  */
 
161
  File file;                         /* from such a file                     */
 
162
  my_off_t diskpos;                  /* with such an offset                  */
168
163
  uint32_t requests;                     /* number of requests for the page      */
169
164
};
170
165
 
238
233
 
239
234
static inline uint32_t next_power(uint32_t value)
240
235
{
241
 
  return my_round_up_to_next_power(value) << 1;
 
236
  return (uint) my_round_up_to_next_power((uint32_t) value) << 1;
242
237
}
243
238
 
244
239
 
338
333
      }
339
334
      if (blocks < 8)
340
335
      {
341
 
        errno= ENOMEM;
 
336
        my_errno= ENOMEM;
342
337
        my_error(EE_OUTOFMEMORY, MYF(0), blocks * keycache->key_cache_block_size);
343
338
        goto err;
344
339
      }
389
384
  }
390
385
  else
391
386
  {
392
 
    /* myisam_key_buffer_size is specified too small. Disable the cache. */
 
387
    /* key_buffer_size is specified too small. Disable the cache. */
393
388
    keycache->can_be_used= 0;
394
389
  }
395
390
 
397
392
  return((int) keycache->disk_blocks);
398
393
 
399
394
err:
400
 
  error= errno;
 
395
  error= my_errno;
401
396
  keycache->disk_blocks= 0;
402
397
  keycache->blocks=  0;
403
398
  if (keycache->block_mem)
410
405
    free((unsigned char*) keycache->block_root);
411
406
    keycache->block_root= NULL;
412
407
  }
413
 
  errno= error;
 
408
  my_errno= error;
414
409
  keycache->can_be_used= 0;
415
410
  return(0);
416
411
}
471
466
  */
472
467
  while (keycache->in_resize)
473
468
  {
 
469
    /* purecov: begin inspected */
474
470
    wait_on_queue(&keycache->resize_queue, &keycache->cache_lock);
 
471
    /* purecov: end */
475
472
  }
476
473
 
477
474
  /*
577
574
    age_threshold.
578
575
*/
579
576
 
580
 
static void change_key_cache_param(KEY_CACHE *keycache, uint32_t division_limit,
 
577
void change_key_cache_param(KEY_CACHE *keycache, uint32_t division_limit,
581
578
                            uint32_t age_threshold)
582
579
{
583
580
  keycache_pthread_mutex_lock(&keycache->cache_lock);
650
647
*/
651
648
 
652
649
static void link_into_queue(KEYCACHE_WQUEUE *wqueue,
653
 
                            internal::st_my_thread_var *thread)
 
650
                                   struct st_my_thread_var *thread)
654
651
{
655
 
  internal::st_my_thread_var *last;
 
652
  struct st_my_thread_var *last;
656
653
 
657
654
  assert(!thread->next && !thread->prev);
658
655
  if (! (last= wqueue->last_thread))
687
684
*/
688
685
 
689
686
static void unlink_from_queue(KEYCACHE_WQUEUE *wqueue,
690
 
                                     internal::st_my_thread_var *thread)
 
687
                                     struct st_my_thread_var *thread)
691
688
{
692
689
  assert(thread->next && thread->prev);
693
690
  if (thread->next == thread)
698
695
    thread->next->prev= thread->prev;
699
696
    *thread->prev=thread->next;
700
697
    if (wqueue->last_thread == thread)
701
 
      wqueue->last_thread= STRUCT_PTR(internal::st_my_thread_var, next,
 
698
      wqueue->last_thread= STRUCT_PTR(struct st_my_thread_var, next,
702
699
                                      thread->prev);
703
700
  }
704
701
  thread->next= NULL;
732
729
static void wait_on_queue(KEYCACHE_WQUEUE *wqueue,
733
730
                          pthread_mutex_t *mutex)
734
731
{
735
 
  internal::st_my_thread_var *last;
736
 
  internal::st_my_thread_var *thread= my_thread_var;
 
732
  struct st_my_thread_var *last;
 
733
  struct st_my_thread_var *thread= my_thread_var;
737
734
 
738
735
  /* Add to queue. */
739
736
  assert(!thread->next);
777
774
 
778
775
static void release_whole_queue(KEYCACHE_WQUEUE *wqueue)
779
776
{
780
 
  internal::st_my_thread_var *last;
781
 
  internal::st_my_thread_var *next;
782
 
  internal::st_my_thread_var *thread;
 
777
  struct st_my_thread_var *last;
 
778
  struct st_my_thread_var *next;
 
779
  struct st_my_thread_var *thread;
783
780
 
784
781
  /* Queue may be empty. */
785
782
  if (!(last= wqueue->last_thread))
967
964
  if (!hot && keycache->waiting_for_block.last_thread)
968
965
  {
969
966
    /* Signal that in the LRU warm sub-chain an available block has appeared */
970
 
    internal::st_my_thread_var *last_thread=
 
967
    struct st_my_thread_var *last_thread=
971
968
                               keycache->waiting_for_block.last_thread;
972
 
    internal::st_my_thread_var *first_thread= last_thread->next;
973
 
    internal::st_my_thread_var *next_thread= first_thread;
 
969
    struct st_my_thread_var *first_thread= last_thread->next;
 
970
    struct st_my_thread_var *next_thread= first_thread;
974
971
    HASH_LINK *hash_link= (HASH_LINK *) first_thread->opt_info;
975
 
    internal::st_my_thread_var *thread;
 
972
    struct st_my_thread_var *thread;
976
973
    do
977
974
    {
978
975
      thread= next_thread;
1215
1212
static void wait_for_readers(KEY_CACHE *keycache,
1216
1213
                             BLOCK_LINK *block)
1217
1214
{
1218
 
  internal::st_my_thread_var *thread= my_thread_var;
 
1215
  struct st_my_thread_var *thread= my_thread_var;
1219
1216
  assert(block->status & (BLOCK_READ | BLOCK_IN_USE));
1220
1217
  assert(!(block->status & (BLOCK_ERROR | BLOCK_IN_FLUSH |
1221
1218
                                 BLOCK_CHANGED)));
1264
1261
  if (keycache->waiting_for_hash_link.last_thread)
1265
1262
  {
1266
1263
    /* Signal that a free hash link has appeared */
1267
 
    internal::st_my_thread_var *last_thread=
 
1264
    struct st_my_thread_var *last_thread=
1268
1265
                               keycache->waiting_for_hash_link.last_thread;
1269
 
    internal::st_my_thread_var *first_thread= last_thread->next;
1270
 
    internal::st_my_thread_var *next_thread= first_thread;
 
1266
    struct st_my_thread_var *first_thread= last_thread->next;
 
1267
    struct st_my_thread_var *next_thread= first_thread;
1271
1268
    KEYCACHE_PAGE *first_page= (KEYCACHE_PAGE *) (first_thread->opt_info);
1272
 
    internal::st_my_thread_var *thread;
 
1269
    struct st_my_thread_var *thread;
1273
1270
 
1274
1271
    hash_link->file= first_page->file;
1275
1272
    hash_link->diskpos= first_page->filepos;
1305
1302
*/
1306
1303
 
1307
1304
static HASH_LINK *get_hash_link(KEY_CACHE *keycache,
1308
 
                                int file, internal::my_off_t filepos)
 
1305
                                int file, my_off_t filepos)
1309
1306
{
1310
1307
  register HASH_LINK *hash_link, **start;
1311
1308
 
1337
1334
    else
1338
1335
    {
1339
1336
      /* Wait for a free hash link */
1340
 
      internal::st_my_thread_var *thread= my_thread_var;
 
1337
      struct st_my_thread_var *thread= my_thread_var;
1341
1338
      KEYCACHE_PAGE page;
1342
1339
      page.file= file;
1343
1340
      page.filepos= filepos;
1396
1393
*/
1397
1394
 
1398
1395
static BLOCK_LINK *find_key_block(KEY_CACHE *keycache,
1399
 
                                  int file, internal::my_off_t filepos,
 
1396
                                  File file, my_off_t filepos,
1400
1397
                                  int init_hits_left,
1401
1398
                                  int wrmode, int *page_st)
1402
1399
{
1459
1456
 
1460
1457
    if (!block)
1461
1458
    {
1462
 
      internal::st_my_thread_var *thread;
 
1459
      struct st_my_thread_var *thread;
1463
1460
 
1464
1461
      /*
1465
1462
        The file block is not in the cache. We don't need it in the
1820
1817
            it is marked BLOCK_IN_EVICTION.
1821
1818
          */
1822
1819
 
1823
 
          internal::st_my_thread_var *thread= my_thread_var;
 
1820
          struct st_my_thread_var *thread= my_thread_var;
1824
1821
          thread->opt_info= (void *) hash_link;
1825
1822
          link_into_queue(&keycache->waiting_for_block, thread);
1826
1823
          do
2195
2192
*/
2196
2193
 
2197
2194
unsigned char *key_cache_read(KEY_CACHE *keycache,
2198
 
                      int file, internal::my_off_t filepos, int level,
 
2195
                      File file, my_off_t filepos, int level,
2199
2196
                      unsigned char *buff, uint32_t length,
2200
2197
                      uint32_t block_length,
2201
2198
                      int return_buffer)
2298
2295
            this could only happen if we are using a file with
2299
2296
            small key blocks and are trying to read outside the file
2300
2297
          */
2301
 
          errno= -1;
 
2298
          my_errno= -1;
2302
2299
          block->status|= BLOCK_ERROR;
2303
2300
        }
2304
2301
      }
2389
2386
*/
2390
2387
 
2391
2388
int key_cache_insert(KEY_CACHE *keycache,
2392
 
                     int file, internal::my_off_t filepos, int level,
 
2389
                     File file, my_off_t filepos, int level,
2393
2390
                     unsigned char *buff, uint32_t length)
2394
2391
{
2395
2392
  int error= 0;
2623
2620
*/
2624
2621
 
2625
2622
int key_cache_write(KEY_CACHE *keycache,
2626
 
                    int file, internal::my_off_t filepos, int level,
 
2623
                    File file, my_off_t filepos, int level,
2627
2624
                    unsigned char *buff, uint32_t length,
2628
2625
                    uint32_t block_length,
2629
2626
                    int dont_write)
2634
2631
 
2635
2632
  if (!dont_write)
2636
2633
  {
 
2634
    /* purecov: begin inspected */
2637
2635
    /* Not used in the server. */
2638
2636
    /* Force writing from buff into disk. */
2639
2637
    keycache->global_cache_w_requests++;
2640
2638
    keycache->global_cache_write++;
2641
2639
    if (pwrite(file, buff, length, filepos) == 0)
2642
2640
      return(1);
 
2641
    /* purecov: end */
2643
2642
  }
2644
2643
 
2645
2644
  if (keycache->key_cache_inited)
3044
3043
*/
3045
3044
 
3046
3045
static int flush_cached_blocks(KEY_CACHE *keycache,
3047
 
                               int file, BLOCK_LINK **cache,
 
3046
                               File file, BLOCK_LINK **cache,
3048
3047
                               BLOCK_LINK **end,
3049
3048
                               enum flush_type type)
3050
3049
{
3058
3057
     As all blocks referred in 'cache' are marked by BLOCK_IN_FLUSH
3059
3058
     we are guarunteed no thread will change them
3060
3059
  */
3061
 
  internal::my_qsort((unsigned char*) cache, count, sizeof(*cache), (qsort_cmp) cmp_sec_link);
 
3060
  my_qsort((unsigned char*) cache, count, sizeof(*cache), (qsort_cmp) cmp_sec_link);
3062
3061
 
3063
3062
  keycache_pthread_mutex_lock(&keycache->cache_lock);
3064
3063
  /*
3170
3169
*/
3171
3170
 
3172
3171
static int flush_key_blocks_int(KEY_CACHE *keycache,
3173
 
                                int file, enum flush_type type)
 
3172
                                File file, enum flush_type type)
3174
3173
{
3175
3174
  BLOCK_LINK *cache_buff[FLUSH_CACHE],**cache;
3176
3175
  int last_errno= 0;
3178
3177
 
3179
3178
  cache= cache_buff;
3180
3179
  if (keycache->disk_blocks > 0 &&
3181
 
      (!internal::my_disable_flush_key_blocks || type != FLUSH_KEEP))
 
3180
      (!my_disable_flush_key_blocks || type != FLUSH_KEEP))
3182
3181
  {
3183
3182
    /* Key cache exists and flush is not disabled */
3184
3183
    int error= 0;
3468
3467
                                   BLOCK_REASSIGNED)))
3469
3468
            {
3470
3469
              struct st_hash_link *next_hash_link= NULL;
3471
 
              internal::my_off_t            next_diskpos= 0;
3472
 
              int                next_file= 0;
 
3470
              my_off_t            next_diskpos= 0;
 
3471
              File                next_file= 0;
3473
3472
              uint32_t                next_status= 0;
3474
3473
              uint32_t                hash_requests= 0;
3475
3474
 
3594
3593
*/
3595
3594
 
3596
3595
int flush_key_blocks(KEY_CACHE *keycache,
3597
 
                     int file, enum flush_type type)
 
3596
                     File file, enum flush_type type)
3598
3597
{
3599
3598
  int res= 0;
3600
3599
 
3784
3783
static void keycache_dump(KEY_CACHE *keycache)
3785
3784
{
3786
3785
  FILE *keycache_dump_file=fopen(KEYCACHE_DUMP_FILE, "w");
3787
 
  internal::st_my_thread_var *last;
3788
 
  internal::st_my_thread_var *thread;
 
3786
  struct st_my_thread_var *last;
 
3787
  struct st_my_thread_var *thread;
3789
3788
  BLOCK_LINK *block;
3790
3789
  HASH_LINK *hash_link;
3791
3790
  KEYCACHE_PAGE *page;