~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/myisam/mf_keycache.c

  • Committer: Monty Taylor
  • Date: 2009-03-04 02:16:28 UTC
  • mto: (917.1.2 mordred)
  • mto: This revision was merged to the branch mainline in revision 912.
  • Revision ID: mordred@inaugust.com-20090304021628-rfq0b16uoi09g8tx
Fix to make VPATH builds work again.

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