~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/myisam/mf_keycache.c

  • Committer: Brian Aker
  • Date: 2008-10-06 06:47:29 UTC
  • Revision ID: brian@tangent.org-20081006064729-2i9mhjkzyvow9xsm
RemoveĀ uint.

Show diffs side-by-side

added added

removed removed

Lines of Context:
104
104
#include <drizzled/global.h>
105
105
#include <mysys/mysys_err.h>
106
106
#include <mysys/my_sys.h>
107
 
#include "keycache.h"
 
107
#include <keycache.h>
108
108
#include <mystrings/m_string.h>
109
109
#include <mysys/my_bit.h>
110
110
#include <errno.h>
143
143
/* types of condition variables */
144
144
#define  COND_FOR_REQUESTED 0
145
145
#define  COND_FOR_SAVED     1
 
146
#define  COND_FOR_READERS   2
146
147
 
147
148
typedef pthread_cond_t KEYCACHE_CONDVAR;
148
149
 
219
220
                                     (uint32_t) (f)) & (keycache->hash_entries-1))
220
221
#define FILE_HASH(f)                 ((uint) (f) & (CHANGED_BLOCKS_HASH-1))
221
222
 
 
223
#define BLOCK_NUMBER(b)                                                       \
 
224
  ((uint) (((char*)(b)-(char *) keycache->block_root)/sizeof(BLOCK_LINK)))
 
225
#define HASH_LINK_NUMBER(h)                                                   \
 
226
  ((uint) (((char*)(h)-(char *) keycache->hash_link_root)/sizeof(HASH_LINK)))
222
227
 
223
228
#ifdef KEYCACHE_TIMEOUT
224
229
static int keycache_pthread_cond_wait(pthread_cond_t *cond,
326
331
          Allocate memory for blocks, hash_links and hash entries;
327
332
          For each block 2 hash links are allocated
328
333
        */
329
 
        if ((keycache->block_root= (BLOCK_LINK*) malloc(length)))
 
334
        if ((keycache->block_root= (BLOCK_LINK*) my_malloc(length,
 
335
                                                           MYF(0))))
330
336
          break;
331
337
        free(keycache->block_mem);
332
338
        keycache->block_mem= 0;
2194
2200
unsigned char *key_cache_read(KEY_CACHE *keycache,
2195
2201
                      File file, my_off_t filepos, int level,
2196
2202
                      unsigned char *buff, uint32_t length,
2197
 
                      uint32_t block_length,
2198
 
                      int return_buffer)
 
2203
                      uint32_t block_length __attribute__((unused)),
 
2204
                      int return_buffer __attribute__((unused)))
2199
2205
{
2200
 
  (void)block_length;
2201
 
  (void)return_buffer;
2202
2206
  bool locked_and_incremented= false;
2203
2207
  int error=0;
2204
2208
  unsigned char *start= buff;
2350
2354
 
2351
2355
  if (locked_and_incremented)
2352
2356
    keycache_pthread_mutex_unlock(&keycache->cache_lock);
2353
 
  if (!pread(file, (unsigned char*) buff, length, filepos))
 
2357
  if (pread(file, (unsigned char*) buff, length, filepos))
2354
2358
    error= 1;
2355
2359
  if (locked_and_incremented)
2356
2360
    keycache_pthread_mutex_lock(&keycache->cache_lock);
2622
2626
int key_cache_write(KEY_CACHE *keycache,
2623
2627
                    File file, my_off_t filepos, int level,
2624
2628
                    unsigned char *buff, uint32_t length,
2625
 
                    uint32_t block_length,
 
2629
                    uint32_t block_length  __attribute__((unused)),
2626
2630
                    int dont_write)
2627
2631
{
2628
 
  (void)block_length;
2629
2632
  bool locked_and_incremented= false;
2630
2633
  int error=0;
2631
2634
 
3186
3189
    BLOCK_LINK *first_in_switch= NULL;
3187
3190
    BLOCK_LINK *last_in_flush;
3188
3191
    BLOCK_LINK *last_for_update;
3189
 
    BLOCK_LINK *last_in_switch;
3190
3192
    BLOCK_LINK *block, *next;
3191
3193
 
3192
3194
    if (type != FLUSH_IGNORE_CHANGED)
3213
3215
        changed blocks appear while we need to wait for something.
3214
3216
      */
3215
3217
      if ((count > FLUSH_CACHE) &&
3216
 
          !(cache= (BLOCK_LINK**) malloc(sizeof(BLOCK_LINK*)*count)))
 
3218
          !(cache= (BLOCK_LINK**) my_malloc(sizeof(BLOCK_LINK*)*count,
 
3219
                                            MYF(0))))
3217
3220
        cache= cache_buff;
3218
3221
      /*
3219
3222
        After a restart there could be more changed blocks than now.
3428
3431
 
3429
3432
    if (! (type == FLUSH_KEEP || type == FLUSH_FORCE_WRITE))
3430
3433
    {
3431
 
      last_for_update= NULL;
3432
 
      last_in_switch= NULL;
 
3434
      BLOCK_LINK *last_for_update= NULL;
 
3435
      BLOCK_LINK *last_in_switch= NULL;
3433
3436
      uint32_t total_found= 0;
3434
3437
      uint32_t found;
3435
3438
 
3752
3755
    0 on success (always because it can't fail)
3753
3756
*/
3754
3757
 
3755
 
int reset_key_cache_counters(const char *name, KEY_CACHE *key_cache)
 
3758
int reset_key_cache_counters(const char *name __attribute__((unused)),
 
3759
                             KEY_CACHE *key_cache)
3756
3760
{
3757
 
  (void)name;
3758
3761
  if (!key_cache->key_cache_inited)
3759
3762
  {
3760
3763
    return(0);
3769
3772
 
3770
3773
#if defined(KEYCACHE_TIMEOUT)
3771
3774
 
3772
 
 
3773
 
static inline
3774
 
unsigned int hash_link_number(HASH_LINK *hash_link, KEY_CACHE *keycache)
3775
 
{
3776
 
  return ((unsigned int) (((char*)hash_link-(char *) keycache->hash_link_root)/
3777
 
                  sizeof(HASH_LINK)));
3778
 
}
3779
 
 
3780
 
static inline
3781
 
unsigned int block_number(BLOCK_LINK *block, KEY_CACHE *keycache)
3782
 
{
3783
 
  return ((unsigned int) (((char*)block-(char *)keycache->block_root)/
3784
 
                  sizeof(BLOCK_LINK)));
3785
 
}
3786
 
 
3787
 
 
3788
3775
#define KEYCACHE_DUMP_FILE  "keycache_dump.txt"
3789
3776
#define MAX_QUEUE_LEN  100
3790
3777
 
3826
3813
      thread=thread->next;
3827
3814
      hash_link= (HASH_LINK *) thread->opt_info;
3828
3815
      fprintf(keycache_dump_file,
3829
 
              "thread:%u hash_link:%u (file,filepos)=(%u,%u)\n",
3830
 
              thread->id, (uint) hash_link_number(hash_link, keycache),
3831
 
              (uint) hash_link->file,(uint32_t) hash_link->diskpos);
 
3816
        "thread:%u hash_link:%u (file,filepos)=(%u,%u)\n",
 
3817
        thread->id, (uint) HASH_LINK_NUMBER(hash_link),
 
3818
        (uint) hash_link->file,(uint32_t) hash_link->diskpos);
3832
3819
      if (++i == MAX_QUEUE_LEN)
3833
3820
        break;
3834
3821
    }
3840
3827
    block= &keycache->block_root[i];
3841
3828
    hash_link= block->hash_link;
3842
3829
    fprintf(keycache_dump_file,
3843
 
            "block:%u hash_link:%d status:%x #requests=%u "
3844
 
            "waiting_for_readers:%d\n",
3845
 
            i, (int) (hash_link ? hash_link_number(hash_link, keycache) : -1),
3846
 
            block->status, block->requests, block->condvar ? 1 : 0);
 
3830
            "block:%u hash_link:%d status:%x #requests=%u waiting_for_readers:%d\n",
 
3831
            i, (int) (hash_link ? HASH_LINK_NUMBER(hash_link) : -1),
 
3832
            block->status, block->requests, block->condvar ? 1 : 0);
3847
3833
    for (j=0 ; j < 2; j++)
3848
3834
    {
3849
3835
      KEYCACHE_WQUEUE *wqueue=&block->wqueue[j];
3871
3857
    {
3872
3858
      block= block->next_used;
3873
3859
      fprintf(keycache_dump_file,
3874
 
              "block:%u, ", block_number(block, keycache));
 
3860
              "block:%u, ", BLOCK_NUMBER(block));
3875
3861
    }
3876
3862
    while (block != keycache->used_last);
3877
3863
  }