~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/myisam/mf_keycache.cc

  • Committer: Monty Taylor
  • Date: 2010-02-05 08:11:15 UTC
  • mfrom: (1283 build)
  • mto: (1273.13.43 fix_is)
  • mto: This revision was merged to the branch mainline in revision 1300.
  • Revision ID: mordred@inaugust.com-20100205081115-dr82nvrwv4lvw7sd
Merged trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
110
110
#include <errno.h>
111
111
#include <stdarg.h>
112
112
 
 
113
using namespace drizzled;
 
114
 
113
115
static void change_key_cache_param(KEY_CACHE *keycache, uint32_t division_limit,
114
116
                            uint32_t age_threshold);
115
117
 
153
155
struct st_keycache_page
154
156
{
155
157
  int file;               /* file to which the page belongs to  */
156
 
  my_off_t filepos;       /* position of the page in the file   */
 
158
  internal::my_off_t filepos;       /* position of the page in the file   */
157
159
};
158
160
 
159
161
/* element in the chain of a hash table bucket */
162
164
  struct st_hash_link *next, **prev; /* to connect links in the same bucket  */
163
165
  struct st_block_link *block;       /* reference to the block for the page: */
164
166
  int file;                         /* from such a file                     */
165
 
  my_off_t diskpos;                  /* with such an offset                  */
 
167
  internal::my_off_t diskpos;                  /* with such an offset                  */
166
168
  uint32_t requests;                     /* number of requests for the page      */
167
169
};
168
170
 
236
238
 
237
239
static inline uint32_t next_power(uint32_t value)
238
240
{
239
 
  return (uint) my_round_up_to_next_power((uint32_t) value) << 1;
 
241
  return my_round_up_to_next_power(value) << 1;
240
242
}
241
243
 
242
244
 
266
268
*/
267
269
 
268
270
int init_key_cache(KEY_CACHE *keycache, uint32_t key_cache_block_size,
269
 
                   uint32_t use_mem, uint32_t division_limit,
 
271
                   size_t use_mem, uint32_t division_limit,
270
272
                   uint32_t age_threshold)
271
273
{
272
274
  uint32_t blocks, hash_links;
444
446
*/
445
447
 
446
448
int resize_key_cache(KEY_CACHE *keycache, uint32_t key_cache_block_size,
447
 
                     uint32_t use_mem, uint32_t division_limit,
 
449
                     size_t use_mem, uint32_t division_limit,
448
450
                     uint32_t age_threshold)
449
451
{
450
452
  int blocks;
648
650
*/
649
651
 
650
652
static void link_into_queue(KEYCACHE_WQUEUE *wqueue,
651
 
                                   struct st_my_thread_var *thread)
 
653
                            internal::st_my_thread_var *thread)
652
654
{
653
 
  struct st_my_thread_var *last;
 
655
  internal::st_my_thread_var *last;
654
656
 
655
657
  assert(!thread->next && !thread->prev);
656
658
  if (! (last= wqueue->last_thread))
685
687
*/
686
688
 
687
689
static void unlink_from_queue(KEYCACHE_WQUEUE *wqueue,
688
 
                                     struct st_my_thread_var *thread)
 
690
                                     internal::st_my_thread_var *thread)
689
691
{
690
692
  assert(thread->next && thread->prev);
691
693
  if (thread->next == thread)
696
698
    thread->next->prev= thread->prev;
697
699
    *thread->prev=thread->next;
698
700
    if (wqueue->last_thread == thread)
699
 
      wqueue->last_thread= STRUCT_PTR(struct st_my_thread_var, next,
 
701
      wqueue->last_thread= STRUCT_PTR(internal::st_my_thread_var, next,
700
702
                                      thread->prev);
701
703
  }
702
704
  thread->next= NULL;
730
732
static void wait_on_queue(KEYCACHE_WQUEUE *wqueue,
731
733
                          pthread_mutex_t *mutex)
732
734
{
733
 
  struct st_my_thread_var *last;
734
 
  struct st_my_thread_var *thread= my_thread_var;
 
735
  internal::st_my_thread_var *last;
 
736
  internal::st_my_thread_var *thread= my_thread_var;
735
737
 
736
738
  /* Add to queue. */
737
739
  assert(!thread->next);
775
777
 
776
778
static void release_whole_queue(KEYCACHE_WQUEUE *wqueue)
777
779
{
778
 
  struct st_my_thread_var *last;
779
 
  struct st_my_thread_var *next;
780
 
  struct st_my_thread_var *thread;
 
780
  internal::st_my_thread_var *last;
 
781
  internal::st_my_thread_var *next;
 
782
  internal::st_my_thread_var *thread;
781
783
 
782
784
  /* Queue may be empty. */
783
785
  if (!(last= wqueue->last_thread))
965
967
  if (!hot && keycache->waiting_for_block.last_thread)
966
968
  {
967
969
    /* Signal that in the LRU warm sub-chain an available block has appeared */
968
 
    struct st_my_thread_var *last_thread=
 
970
    internal::st_my_thread_var *last_thread=
969
971
                               keycache->waiting_for_block.last_thread;
970
 
    struct st_my_thread_var *first_thread= last_thread->next;
971
 
    struct st_my_thread_var *next_thread= first_thread;
 
972
    internal::st_my_thread_var *first_thread= last_thread->next;
 
973
    internal::st_my_thread_var *next_thread= first_thread;
972
974
    HASH_LINK *hash_link= (HASH_LINK *) first_thread->opt_info;
973
 
    struct st_my_thread_var *thread;
 
975
    internal::st_my_thread_var *thread;
974
976
    do
975
977
    {
976
978
      thread= next_thread;
1213
1215
static void wait_for_readers(KEY_CACHE *keycache,
1214
1216
                             BLOCK_LINK *block)
1215
1217
{
1216
 
  struct st_my_thread_var *thread= my_thread_var;
 
1218
  internal::st_my_thread_var *thread= my_thread_var;
1217
1219
  assert(block->status & (BLOCK_READ | BLOCK_IN_USE));
1218
1220
  assert(!(block->status & (BLOCK_ERROR | BLOCK_IN_FLUSH |
1219
1221
                                 BLOCK_CHANGED)));
1262
1264
  if (keycache->waiting_for_hash_link.last_thread)
1263
1265
  {
1264
1266
    /* Signal that a free hash link has appeared */
1265
 
    struct st_my_thread_var *last_thread=
 
1267
    internal::st_my_thread_var *last_thread=
1266
1268
                               keycache->waiting_for_hash_link.last_thread;
1267
 
    struct st_my_thread_var *first_thread= last_thread->next;
1268
 
    struct st_my_thread_var *next_thread= first_thread;
 
1269
    internal::st_my_thread_var *first_thread= last_thread->next;
 
1270
    internal::st_my_thread_var *next_thread= first_thread;
1269
1271
    KEYCACHE_PAGE *first_page= (KEYCACHE_PAGE *) (first_thread->opt_info);
1270
 
    struct st_my_thread_var *thread;
 
1272
    internal::st_my_thread_var *thread;
1271
1273
 
1272
1274
    hash_link->file= first_page->file;
1273
1275
    hash_link->diskpos= first_page->filepos;
1303
1305
*/
1304
1306
 
1305
1307
static HASH_LINK *get_hash_link(KEY_CACHE *keycache,
1306
 
                                int file, my_off_t filepos)
 
1308
                                int file, internal::my_off_t filepos)
1307
1309
{
1308
1310
  register HASH_LINK *hash_link, **start;
1309
1311
 
1335
1337
    else
1336
1338
    {
1337
1339
      /* Wait for a free hash link */
1338
 
      struct st_my_thread_var *thread= my_thread_var;
 
1340
      internal::st_my_thread_var *thread= my_thread_var;
1339
1341
      KEYCACHE_PAGE page;
1340
1342
      page.file= file;
1341
1343
      page.filepos= filepos;
1394
1396
*/
1395
1397
 
1396
1398
static BLOCK_LINK *find_key_block(KEY_CACHE *keycache,
1397
 
                                  int file, my_off_t filepos,
 
1399
                                  int file, internal::my_off_t filepos,
1398
1400
                                  int init_hits_left,
1399
1401
                                  int wrmode, int *page_st)
1400
1402
{
1457
1459
 
1458
1460
    if (!block)
1459
1461
    {
1460
 
      struct st_my_thread_var *thread;
 
1462
      internal::st_my_thread_var *thread;
1461
1463
 
1462
1464
      /*
1463
1465
        The file block is not in the cache. We don't need it in the
1818
1820
            it is marked BLOCK_IN_EVICTION.
1819
1821
          */
1820
1822
 
1821
 
          struct st_my_thread_var *thread= my_thread_var;
 
1823
          internal::st_my_thread_var *thread= my_thread_var;
1822
1824
          thread->opt_info= (void *) hash_link;
1823
1825
          link_into_queue(&keycache->waiting_for_block, thread);
1824
1826
          do
2193
2195
*/
2194
2196
 
2195
2197
unsigned char *key_cache_read(KEY_CACHE *keycache,
2196
 
                      int file, my_off_t filepos, int level,
 
2198
                      int file, internal::my_off_t filepos, int level,
2197
2199
                      unsigned char *buff, uint32_t length,
2198
2200
                      uint32_t block_length,
2199
2201
                      int return_buffer)
2387
2389
*/
2388
2390
 
2389
2391
int key_cache_insert(KEY_CACHE *keycache,
2390
 
                     int file, my_off_t filepos, int level,
 
2392
                     int file, internal::my_off_t filepos, int level,
2391
2393
                     unsigned char *buff, uint32_t length)
2392
2394
{
2393
2395
  int error= 0;
2621
2623
*/
2622
2624
 
2623
2625
int key_cache_write(KEY_CACHE *keycache,
2624
 
                    int file, my_off_t filepos, int level,
 
2626
                    int file, internal::my_off_t filepos, int level,
2625
2627
                    unsigned char *buff, uint32_t length,
2626
2628
                    uint32_t block_length,
2627
2629
                    int dont_write)
3056
3058
     As all blocks referred in 'cache' are marked by BLOCK_IN_FLUSH
3057
3059
     we are guarunteed no thread will change them
3058
3060
  */
3059
 
  my_qsort((unsigned char*) cache, count, sizeof(*cache), (qsort_cmp) cmp_sec_link);
 
3061
  internal::my_qsort((unsigned char*) cache, count, sizeof(*cache), (qsort_cmp) cmp_sec_link);
3060
3062
 
3061
3063
  keycache_pthread_mutex_lock(&keycache->cache_lock);
3062
3064
  /*
3176
3178
 
3177
3179
  cache= cache_buff;
3178
3180
  if (keycache->disk_blocks > 0 &&
3179
 
      (!my_disable_flush_key_blocks || type != FLUSH_KEEP))
 
3181
      (!internal::my_disable_flush_key_blocks || type != FLUSH_KEEP))
3180
3182
  {
3181
3183
    /* Key cache exists and flush is not disabled */
3182
3184
    int error= 0;
3466
3468
                                   BLOCK_REASSIGNED)))
3467
3469
            {
3468
3470
              struct st_hash_link *next_hash_link= NULL;
3469
 
              my_off_t            next_diskpos= 0;
 
3471
              internal::my_off_t            next_diskpos= 0;
3470
3472
              int                next_file= 0;
3471
3473
              uint32_t                next_status= 0;
3472
3474
              uint32_t                hash_requests= 0;
3782
3784
static void keycache_dump(KEY_CACHE *keycache)
3783
3785
{
3784
3786
  FILE *keycache_dump_file=fopen(KEYCACHE_DUMP_FILE, "w");
3785
 
  struct st_my_thread_var *last;
3786
 
  struct st_my_thread_var *thread;
 
3787
  internal::st_my_thread_var *last;
 
3788
  internal::st_my_thread_var *thread;
3787
3789
  BLOCK_LINK *block;
3788
3790
  HASH_LINK *hash_link;
3789
3791
  KEYCACHE_PAGE *page;