~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/myisam/mf_keycache.c

  • Committer: Mark Atwood
  • Date: 2008-10-16 11:33:16 UTC
  • mto: (520.1.13 drizzle)
  • mto: This revision was merged to the branch mainline in revision 530.
  • Revision ID: mark@fallenpegasus.com-20081016113316-ff6jdt31ck90sjdh
an implemention of the errmsg plugin

Show diffs side-by-side

added added

removed removed

Lines of Context:
161
161
  struct st_block_link *block;       /* reference to the block for the page: */
162
162
  File file;                         /* from such a file                     */
163
163
  my_off_t diskpos;                  /* with such an offset                  */
164
 
  uint requests;                     /* number of requests for the page      */
 
164
  uint32_t requests;                     /* number of requests for the page      */
165
165
};
166
166
 
167
167
/* simple states of a block */
193
193
    *next_changed, **prev_changed; /* for lists of file dirty/clean blocks   */
194
194
  struct st_hash_link *hash_link; /* backward ptr to referring hash_link     */
195
195
  KEYCACHE_WQUEUE wqueue[2]; /* queues on waiting requests for new/old pages */
196
 
  uint requests;          /* number of requests for the block                */
197
 
  uchar *buffer;           /* buffer for the block page                       */
198
 
  uint offset;            /* beginning of modified data in the buffer        */
199
 
  uint length;            /* end of data in the buffer                       */
200
 
  uint status;            /* state of the block                              */
 
196
  uint32_t requests;          /* number of requests for the block                */
 
197
  unsigned char *buffer;           /* buffer for the block page                       */
 
198
  uint32_t offset;            /* beginning of modified data in the buffer        */
 
199
  uint32_t length;            /* end of data in the buffer                       */
 
200
  uint32_t status;            /* state of the block                              */
201
201
  enum BLOCK_TEMPERATURE temperature; /* block temperature: cold, warm, hot */
202
 
  uint hits_left;         /* number of hits left until promotion             */
 
202
  uint32_t hits_left;         /* number of hits left until promotion             */
203
203
  uint64_t last_hit_time; /* timestamp of the last hit                      */
204
204
  KEYCACHE_CONDVAR *condvar; /* condition variable for 'no readers' event    */
205
205
};
236
236
#define keycache_pthread_mutex_unlock pthread_mutex_unlock
237
237
#define keycache_pthread_cond_signal pthread_cond_signal
238
238
 
239
 
static inline uint next_power(uint value)
 
239
static inline uint32_t next_power(uint32_t value)
240
240
{
241
241
  return (uint) my_round_up_to_next_power((uint32_t) value) << 1;
242
242
}
267
267
 
268
268
*/
269
269
 
270
 
int init_key_cache(KEY_CACHE *keycache, uint key_cache_block_size,
271
 
                   size_t use_mem, uint division_limit,
272
 
                   uint age_threshold)
 
270
int init_key_cache(KEY_CACHE *keycache, uint32_t key_cache_block_size,
 
271
                   size_t use_mem, uint32_t division_limit,
 
272
                   uint32_t age_threshold)
273
273
{
274
274
  uint32_t blocks, hash_links;
275
275
  size_t length;
408
408
  }
409
409
  if (keycache->block_root)
410
410
  {
411
 
    my_free((uchar*) keycache->block_root, MYF(0));
 
411
    free((unsigned char*) keycache->block_root);
412
412
    keycache->block_root= NULL;
413
413
  }
414
414
  my_errno= error;
446
446
    (when cnt_for_resize=0).
447
447
*/
448
448
 
449
 
int resize_key_cache(KEY_CACHE *keycache, uint key_cache_block_size,
450
 
                     size_t use_mem, uint division_limit,
451
 
                     uint age_threshold)
 
449
int resize_key_cache(KEY_CACHE *keycache, uint32_t key_cache_block_size,
 
450
                     size_t use_mem, uint32_t division_limit,
 
451
                     uint32_t age_threshold)
452
452
{
453
453
  int blocks;
454
454
 
580
580
    age_threshold.
581
581
*/
582
582
 
583
 
void change_key_cache_param(KEY_CACHE *keycache, uint division_limit,
584
 
                            uint age_threshold)
 
583
void change_key_cache_param(KEY_CACHE *keycache, uint32_t division_limit,
 
584
                            uint32_t age_threshold)
585
585
{
586
586
  keycache_pthread_mutex_lock(&keycache->cache_lock);
587
587
  if (division_limit)
618
618
    {
619
619
      free(keycache->block_mem);
620
620
      keycache->block_mem= NULL;
621
 
      my_free((uchar*) keycache->block_root, MYF(0));
 
621
      free((unsigned char*) keycache->block_root);
622
622
      keycache->block_root= NULL;
623
623
    }
624
624
    keycache->disk_blocks= -1;
1779
1779
          block->buffer= ADD_TO_PTR(keycache->block_mem,
1780
1780
                                    ((uint32_t) keycache->blocks_used*
1781
1781
                                     keycache->key_cache_block_size),
1782
 
                                    uchar*);
 
1782
                                    unsigned char*);
1783
1783
          keycache->blocks_used++;
1784
1784
          assert(!block->next_used);
1785
1785
        }
2098
2098
*/
2099
2099
 
2100
2100
static void read_block(KEY_CACHE *keycache,
2101
 
                       BLOCK_LINK *block, uint read_length,
2102
 
                       uint min_length, bool primary)
 
2101
                       BLOCK_LINK *block, uint32_t read_length,
 
2102
                       uint32_t min_length, bool primary)
2103
2103
{
2104
 
  uint got_length;
 
2104
  uint32_t got_length;
2105
2105
 
2106
2106
  /* On entry cache_lock is locked */
2107
2107
 
2197
2197
    have to be a multiple of key_cache_block_size;
2198
2198
*/
2199
2199
 
2200
 
uchar *key_cache_read(KEY_CACHE *keycache,
 
2200
unsigned char *key_cache_read(KEY_CACHE *keycache,
2201
2201
                      File file, my_off_t filepos, int level,
2202
 
                      uchar *buff, uint length,
2203
 
                      uint block_length __attribute__((unused)),
 
2202
                      unsigned char *buff, uint32_t length,
 
2203
                      uint32_t block_length __attribute__((unused)),
2204
2204
                      int return_buffer __attribute__((unused)))
2205
2205
{
2206
2206
  bool locked_and_incremented= false;
2207
2207
  int error=0;
2208
 
  uchar *start= buff;
 
2208
  unsigned char *start= buff;
2209
2209
 
2210
2210
  if (keycache->key_cache_inited)
2211
2211
  {
2212
2212
    /* Key cache is used */
2213
2213
    register BLOCK_LINK *block;
2214
 
    uint read_length;
2215
 
    uint offset;
2216
 
    uint status;
 
2214
    uint32_t read_length;
 
2215
    uint32_t offset;
 
2216
    uint32_t status;
2217
2217
    int page_st;
2218
2218
 
2219
2219
    /*
2270
2270
        */
2271
2271
        keycache->global_cache_read++;
2272
2272
        keycache_pthread_mutex_unlock(&keycache->cache_lock);
2273
 
        error= (pread(file, (uchar*) buff, read_length, filepos + offset) == 0);
 
2273
        error= (pread(file, (unsigned char*) buff, read_length, filepos + offset) == 0);
2274
2274
        keycache_pthread_mutex_lock(&keycache->cache_lock);
2275
2275
        goto next_block;
2276
2276
      }
2354
2354
 
2355
2355
  if (locked_and_incremented)
2356
2356
    keycache_pthread_mutex_unlock(&keycache->cache_lock);
2357
 
  if (pread(file, (uchar*) buff, length, filepos))
 
2357
  if (pread(file, (unsigned char*) buff, length, filepos))
2358
2358
    error= 1;
2359
2359
  if (locked_and_incremented)
2360
2360
    keycache_pthread_mutex_lock(&keycache->cache_lock);
2365
2365
    dec_counter_for_resize_op(keycache);
2366
2366
    keycache_pthread_mutex_unlock(&keycache->cache_lock);
2367
2367
  }
2368
 
  return(error ? (uchar*) 0 : start);
 
2368
  return(error ? (unsigned char*) 0 : start);
2369
2369
}
2370
2370
 
2371
2371
 
2391
2391
 
2392
2392
int key_cache_insert(KEY_CACHE *keycache,
2393
2393
                     File file, my_off_t filepos, int level,
2394
 
                     uchar *buff, uint length)
 
2394
                     unsigned char *buff, uint32_t length)
2395
2395
{
2396
2396
  int error= 0;
2397
2397
 
2399
2399
  {
2400
2400
    /* Key cache is used */
2401
2401
    register BLOCK_LINK *block;
2402
 
    uint read_length;
2403
 
    uint offset;
 
2402
    uint32_t read_length;
 
2403
    uint32_t offset;
2404
2404
    int page_st;
2405
2405
    bool locked_and_incremented= false;
2406
2406
 
2625
2625
 
2626
2626
int key_cache_write(KEY_CACHE *keycache,
2627
2627
                    File file, my_off_t filepos, int level,
2628
 
                    uchar *buff, uint length,
2629
 
                    uint block_length  __attribute__((unused)),
 
2628
                    unsigned char *buff, uint32_t length,
 
2629
                    uint32_t block_length  __attribute__((unused)),
2630
2630
                    int dont_write)
2631
2631
{
2632
2632
  bool locked_and_incremented= false;
2648
2648
  {
2649
2649
    /* Key cache is used */
2650
2650
    register BLOCK_LINK *block;
2651
 
    uint read_length;
2652
 
    uint offset;
 
2651
    uint32_t read_length;
 
2652
    uint32_t offset;
2653
2653
    int page_st;
2654
2654
 
2655
2655
    /*
2709
2709
          /* Used in the server. */
2710
2710
          keycache->global_cache_write++;
2711
2711
          keycache_pthread_mutex_unlock(&keycache->cache_lock);
2712
 
          if (pwrite(file, (uchar*) buff, read_length, filepos + offset) == 0)
 
2712
          if (pwrite(file, (unsigned char*) buff, read_length, filepos + offset) == 0)
2713
2713
            error=1;
2714
2714
          keycache_pthread_mutex_lock(&keycache->cache_lock);
2715
2715
        }
2873
2873
    keycache->global_cache_write++;
2874
2874
    if (locked_and_incremented)
2875
2875
      keycache_pthread_mutex_unlock(&keycache->cache_lock);
2876
 
    if (pwrite(file, (uchar*) buff, length, filepos) == 0)
 
2876
    if (pwrite(file, (unsigned char*) buff, length, filepos) == 0)
2877
2877
      error=1;
2878
2878
    if (locked_and_incremented)
2879
2879
      keycache_pthread_mutex_lock(&keycache->cache_lock);
3052
3052
{
3053
3053
  int error;
3054
3054
  int last_errno= 0;
3055
 
  uint count= (uint) (end-cache);
 
3055
  uint32_t count= (uint) (end-cache);
3056
3056
 
3057
3057
  /* Don't lock the cache during the flush */
3058
3058
  keycache_pthread_mutex_unlock(&keycache->cache_lock);
3060
3060
     As all blocks referred in 'cache' are marked by BLOCK_IN_FLUSH
3061
3061
     we are guarunteed no thread will change them
3062
3062
  */
3063
 
  my_qsort((uchar*) cache, count, sizeof(*cache), (qsort_cmp) cmp_sec_link);
 
3063
  my_qsort((unsigned char*) cache, count, sizeof(*cache), (qsort_cmp) cmp_sec_link);
3064
3064
 
3065
3065
  keycache_pthread_mutex_lock(&keycache->cache_lock);
3066
3066
  /*
3184
3184
  {
3185
3185
    /* Key cache exists and flush is not disabled */
3186
3186
    int error= 0;
3187
 
    uint count= FLUSH_CACHE;
 
3187
    uint32_t count= FLUSH_CACHE;
3188
3188
    BLOCK_LINK **pos,**end;
3189
3189
    BLOCK_LINK *first_in_switch= NULL;
3190
3190
    BLOCK_LINK *last_in_flush;
3433
3433
    {
3434
3434
      BLOCK_LINK *last_for_update= NULL;
3435
3435
      BLOCK_LINK *last_in_switch= NULL;
3436
 
      uint total_found= 0;
3437
 
      uint found;
 
3436
      uint32_t total_found= 0;
 
3437
      uint32_t found;
3438
3438
 
3439
3439
      /*
3440
3440
        Finally free all clean blocks for this file.
3472
3472
              struct st_hash_link *next_hash_link= NULL;
3473
3473
              my_off_t            next_diskpos= 0;
3474
3474
              File                next_file= 0;
3475
 
              uint                next_status= 0;
3476
 
              uint                hash_requests= 0;
 
3475
              uint32_t                next_status= 0;
 
3476
              uint32_t                hash_requests= 0;
3477
3477
 
3478
3478
              total_found++;
3479
3479
              found++;
3573
3573
 
3574
3574
err:
3575
3575
  if (cache != cache_buff)
3576
 
    my_free((uchar*) cache, MYF(0));
 
3576
    free((unsigned char*) cache);
3577
3577
  if (last_errno)
3578
3578
    errno=last_errno;                /* Return first error */
3579
3579
  return(last_errno != 0);
3651
3651
static int flush_all_key_blocks(KEY_CACHE *keycache)
3652
3652
{
3653
3653
  BLOCK_LINK    *block;
3654
 
  uint          total_found;
3655
 
  uint          found;
3656
 
  uint          idx;
 
3654
  uint32_t          total_found;
 
3655
  uint32_t          found;
 
3656
  uint32_t          idx;
3657
3657
 
3658
3658
  do
3659
3659
  {
3784
3784
  BLOCK_LINK *block;
3785
3785
  HASH_LINK *hash_link;
3786
3786
  KEYCACHE_PAGE *page;
3787
 
  uint i;
 
3787
  uint32_t i;
3788
3788
 
3789
3789
  fprintf(keycache_dump_file, "thread:%u\n", thread->id);
3790
3790