~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/myisam/mf_keycache.c

Round 1 - removal DBUG from keycache

Show diffs side-by-side

added added

removed removed

Lines of Context:
225
225
                          pthread_mutex_t *mutex);
226
226
static void release_whole_queue(KEYCACHE_WQUEUE *wqueue);
227
227
static void free_block(KEY_CACHE *keycache, BLOCK_LINK *block);
228
 
#if !defined(DBUG_OFF)
229
 
static void test_key_cache(KEY_CACHE *keycache,
230
 
                           const char *where, my_bool lock);
231
 
#endif
232
228
 
233
229
#define KEYCACHE_HASH(f, pos)                                                 \
234
230
(((ulong) ((pos) / keycache->key_cache_block_size) +                          \
363
359
  ulong blocks, hash_links;
364
360
  size_t length;
365
361
  int error;
366
 
  DBUG_ENTER("init_key_cache");
367
362
  DBUG_ASSERT(key_cache_block_size >= 512);
368
363
 
369
364
  KEYCACHE_DEBUG_OPEN;
370
365
  if (keycache->key_cache_inited && keycache->disk_blocks > 0)
371
366
  {
372
 
    DBUG_PRINT("warning",("key cache already in use"));
373
367
    DBUG_RETURN(0);
374
368
  }
375
369
 
394
388
 
395
389
  keycache->key_cache_mem_size= use_mem;
396
390
  keycache->key_cache_block_size= key_cache_block_size;
397
 
  DBUG_PRINT("info", ("key_cache_block_size: %u",
398
 
                      key_cache_block_size));
399
391
 
400
392
  blocks= (ulong) (use_mem / (sizeof(BLOCK_LINK) + 2 * sizeof(HASH_LINK) +
401
393
                              sizeof(HASH_LINK*) * 5/4 + key_cache_block_size));
477
469
 
478
470
    keycache->waiting_for_hash_link.last_thread= NULL;
479
471
    keycache->waiting_for_block.last_thread= NULL;
480
 
    DBUG_PRINT("exit",
481
 
               ("disk_blocks: %d  block_root: 0x%lx  hash_entries: %d\
482
 
 hash_root: 0x%lx  hash_links: %d  hash_link_root: 0x%lx",
483
 
                keycache->disk_blocks,  (long) keycache->block_root,
484
 
                keycache->hash_entries, (long) keycache->hash_root,
485
 
                keycache->hash_links,   (long) keycache->hash_link_root));
486
472
    bzero((uchar*) keycache->changed_blocks,
487
473
          sizeof(keycache->changed_blocks[0]) * CHANGED_BLOCKS_HASH);
488
474
    bzero((uchar*) keycache->file_blocks,
551
537
                     uint age_threshold)
552
538
{
553
539
  int blocks;
554
 
  DBUG_ENTER("resize_key_cache");
555
540
 
556
541
  if (!keycache->key_cache_inited)
557
542
    DBUG_RETURN(keycache->disk_blocks);
685
670
void change_key_cache_param(KEY_CACHE *keycache, uint division_limit,
686
671
                            uint age_threshold)
687
672
{
688
 
  DBUG_ENTER("change_key_cache_param");
689
 
 
690
673
  keycache_pthread_mutex_lock(&keycache->cache_lock);
691
674
  if (division_limit)
692
675
    keycache->min_warm_blocks= (keycache->disk_blocks *
713
696
 
714
697
void end_key_cache(KEY_CACHE *keycache, my_bool cleanup)
715
698
{
716
 
  DBUG_ENTER("end_key_cache");
717
 
  DBUG_PRINT("enter", ("key_cache: 0x%lx", (long) keycache));
718
 
 
719
699
  if (!keycache->key_cache_inited)
720
700
    DBUG_VOID_RETURN;
721
701
 
733
713
    keycache->blocks_changed= 0;
734
714
  }
735
715
 
736
 
  DBUG_PRINT("status", ("used: %lu  changed: %lu  w_requests: %lu  "
737
 
                        "writes: %lu  r_requests: %lu  reads: %lu",
738
 
                        keycache->blocks_used, keycache->global_blocks_changed,
739
 
                        (ulong) keycache->global_cache_w_requests,
740
 
                        (ulong) keycache->global_cache_write,
741
 
                        (ulong) keycache->global_cache_r_requests,
742
 
                        (ulong) keycache->global_cache_read));
743
 
 
744
716
  if (cleanup)
745
717
  {
746
718
    pthread_mutex_destroy(&keycache->cache_lock);
808
780
static void unlink_from_queue(KEYCACHE_WQUEUE *wqueue,
809
781
                                     struct st_my_thread_var *thread)
810
782
{
811
 
  KEYCACHE_DBUG_PRINT("unlink_from_queue", ("thread %ld", thread->id));
812
783
  DBUG_ASSERT(thread->next && thread->prev);
813
784
  if (thread->next == thread)
814
785
    /* The queue contains only one member */
879
850
  */
880
851
  do
881
852
  {
882
 
    KEYCACHE_DBUG_PRINT("wait", ("suspend thread %ld", thread->id));
883
853
    keycache_pthread_cond_wait(&thread->suspend, mutex);
884
854
  }
885
855
  while (thread->next);
916
886
  do
917
887
  {
918
888
    thread=next;
919
 
    KEYCACHE_DBUG_PRINT("release_whole_queue: signal",
920
 
                        ("thread %ld", thread->id));
921
889
    /* Signal the thread. */
922
890
    keycache_pthread_cond_signal(&thread->suspend);
923
891
    /* Take thread from queue. */
1120
1088
      */
1121
1089
      if ((HASH_LINK *) thread->opt_info == hash_link)
1122
1090
      {
1123
 
        KEYCACHE_DBUG_PRINT("link_block: signal", ("thread %ld", thread->id));
1124
1091
        keycache_pthread_cond_signal(&thread->suspend);
1125
1092
        unlink_from_queue(&keycache->waiting_for_block, thread);
1126
1093
        block->requests++;
1152
1119
    */
1153
1120
    block->status|= BLOCK_IN_EVICTION;
1154
1121
    KEYCACHE_THREAD_TRACE("link_block: after signaling");
1155
 
#if defined(KEYCACHE_DEBUG)
1156
 
    KEYCACHE_DBUG_PRINT("link_block",
1157
 
        ("linked,unlinked block %u  status=%x  #requests=%u  #available=%u",
1158
 
         BLOCK_NUMBER(block), block->status,
1159
 
         block->requests, keycache->blocks_available));
1160
 
#endif
1161
1122
    return;
1162
1123
  }
1163
1124
  pins= hot ? &keycache->used_ins : &keycache->used_last;
1180
1141
  KEYCACHE_THREAD_TRACE("link_block");
1181
1142
#if defined(KEYCACHE_DEBUG)
1182
1143
  keycache->blocks_available++;
1183
 
  KEYCACHE_DBUG_PRINT("link_block",
1184
 
      ("linked block %u:%1u  status=%x  #requests=%u  #available=%u",
1185
 
       BLOCK_NUMBER(block), at_end, block->status,
1186
 
       block->requests, keycache->blocks_available));
1187
1144
  KEYCACHE_DBUG_ASSERT((ulong) keycache->blocks_available <=
1188
1145
                       keycache->blocks_used);
1189
1146
#endif
1239
1196
#if defined(KEYCACHE_DEBUG)
1240
1197
  KEYCACHE_DBUG_ASSERT(keycache->blocks_available != 0);
1241
1198
  keycache->blocks_available--;
1242
 
  KEYCACHE_DBUG_PRINT("unlink_block",
1243
 
    ("unlinked block %u  status=%x   #requests=%u  #available=%u",
1244
 
     BLOCK_NUMBER(block), block->status,
1245
 
     block->requests, keycache->blocks_available));
1246
1199
#endif
1247
1200
}
1248
1201
 
1327
1280
      if (block->temperature == BLOCK_WARM)
1328
1281
        keycache->warm_blocks--;
1329
1282
      block->temperature= BLOCK_HOT;
1330
 
      KEYCACHE_DBUG_PRINT("unreg_request", ("#warm_blocks: %lu",
1331
 
                           keycache->warm_blocks));
1332
1283
    }
1333
1284
    link_block(keycache, block, hot, (my_bool)at_end);
1334
1285
    block->last_hit_time= keycache->keycache_time;
1359
1310
        keycache->warm_blocks++;
1360
1311
        block->temperature= BLOCK_WARM;
1361
1312
      }
1362
 
      KEYCACHE_DBUG_PRINT("unreg_request", ("#warm_blocks: %lu",
1363
 
                           keycache->warm_blocks));
1364
1313
    }
1365
1314
  }
1366
1315
}
1403
1352
  DBUG_ASSERT(!block->prev_used);
1404
1353
  while (block->hash_link->requests)
1405
1354
  {
1406
 
    KEYCACHE_DBUG_PRINT("wait_for_readers: wait",
1407
 
                        ("suspend thread %ld  block %u",
1408
 
                         thread->id, BLOCK_NUMBER(block)));
1409
1355
    /* There must be no other waiter. We have no queue here. */
1410
1356
    DBUG_ASSERT(!block->condvar);
1411
1357
    block->condvar= &thread->suspend;
1435
1381
 
1436
1382
static void unlink_hash(KEY_CACHE *keycache, HASH_LINK *hash_link)
1437
1383
{
1438
 
  KEYCACHE_DBUG_PRINT("unlink_hash", ("fd: %u  pos_ %lu  #requests=%u",
1439
 
      (uint) hash_link->file,(ulong) hash_link->diskpos, hash_link->requests));
1440
1384
  KEYCACHE_DBUG_ASSERT(hash_link->requests == 0);
1441
1385
  if ((*hash_link->prev= hash_link->next))
1442
1386
    hash_link->next->prev= hash_link->prev;
1465
1409
      */
1466
1410
      if (page->file == hash_link->file && page->filepos == hash_link->diskpos)
1467
1411
      {
1468
 
        KEYCACHE_DBUG_PRINT("unlink_hash: signal", ("thread %ld", thread->id));
1469
1412
        keycache_pthread_cond_signal(&thread->suspend);
1470
1413
        unlink_from_queue(&keycache->waiting_for_hash_link, thread);
1471
1414
      }
1493
1436
  int cnt;
1494
1437
#endif
1495
1438
 
1496
 
  KEYCACHE_DBUG_PRINT("get_hash_link", ("fd: %u  pos: %lu",
1497
 
                      (uint) file,(ulong) filepos));
1498
 
 
1499
1439
restart:
1500
1440
  /*
1501
1441
     Find the bucket in the hash table for the pair (file, filepos);
1517
1457
    {
1518
1458
      int i;
1519
1459
      for (i=0, hash_link= *start ;
1520
 
           i < cnt ; i++, hash_link= hash_link->next)
1521
 
      {
1522
 
        KEYCACHE_DBUG_PRINT("get_hash_link", ("fd: %u  pos: %lu",
1523
 
            (uint) hash_link->file,(ulong) hash_link->diskpos));
1524
 
      }
 
1460
           i < cnt ; i++, hash_link= hash_link->next) {/* Do Nothing */ }
1525
1461
    }
1526
1462
    KEYCACHE_DBUG_ASSERT(cnt <= keycache->hash_links_used);
1527
1463
#endif
1543
1479
      /* Wait for a free hash link */
1544
1480
      struct st_my_thread_var *thread= my_thread_var;
1545
1481
      KEYCACHE_PAGE page;
1546
 
      KEYCACHE_DBUG_PRINT("get_hash_link", ("waiting"));
1547
1482
      page.file= file;
1548
1483
      page.filepos= filepos;
1549
1484
      thread->opt_info= (void *) &page;
1550
1485
      link_into_queue(&keycache->waiting_for_hash_link, thread);
1551
 
      KEYCACHE_DBUG_PRINT("get_hash_link: wait",
1552
 
                        ("suspend thread %ld", thread->id));
1553
1486
      keycache_pthread_cond_wait(&thread->suspend,
1554
1487
                                 &keycache->cache_lock);
1555
1488
      thread->opt_info= NULL;
1612
1545
  int error= 0;
1613
1546
  int page_status;
1614
1547
 
1615
 
  DBUG_ENTER("find_key_block");
1616
 
  KEYCACHE_THREAD_TRACE("find_key_block:begin");
1617
 
  DBUG_PRINT("enter", ("fd: %d  pos: %lu  wrmode: %d",
1618
 
                       file, (ulong) filepos, wrmode));
1619
 
  KEYCACHE_DBUG_PRINT("find_key_block", ("fd: %d  pos: %lu  wrmode: %d",
1620
 
                                         file, (ulong) filepos,
1621
 
                                         wrmode));
1622
 
#if !defined(DBUG_OFF) && defined(EXTRA_DEBUG)
1623
 
  DBUG_EXECUTE("check_keycache2",
1624
 
               test_key_cache(keycache, "start of find_key_block", 0););
1625
 
#endif
1626
 
 
1627
1548
restart:
1628
1549
  /*
1629
1550
    If the flush phase of a resize operation fails, the cache is left
1714
1635
      link_into_queue(&keycache->waiting_for_block, thread);
1715
1636
      do
1716
1637
      {
1717
 
        KEYCACHE_DBUG_PRINT("find_key_block: wait",
1718
 
                            ("suspend thread %ld", thread->id));
1719
1638
        keycache_pthread_cond_wait(&thread->suspend,
1720
1639
                                   &keycache->cache_lock);
1721
1640
      } while (thread->next);
1926
1845
      (BLOCK_IN_SWITCH), readers of the block have not finished yet
1927
1846
      (BLOCK_REASSIGNED), or the evicting thread did not yet awake after
1928
1847
      the block has been selected for it (BLOCK_IN_EVICTION).
1929
 
    */
1930
1848
 
1931
 
    KEYCACHE_DBUG_PRINT("find_key_block",
1932
 
                        ("request for old page in block %u "
1933
 
                         "wrmode: %d  block->status: %d",
1934
 
                         BLOCK_NUMBER(block), wrmode, block->status));
1935
 
    /*
1936
1849
       Only reading requests can proceed until the old dirty page is flushed,
1937
1850
       all others are to be suspended, then resubmitted
1938
1851
    */
1962
1875
      */
1963
1876
      DBUG_ASSERT(hash_link->requests);
1964
1877
      hash_link->requests--;
1965
 
      KEYCACHE_DBUG_PRINT("find_key_block",
1966
 
                          ("request waiting for old page to be saved"));
1967
1878
      wait_on_queue(&block->wqueue[COND_FOR_SAVED], &keycache->cache_lock);
1968
 
      KEYCACHE_DBUG_PRINT("find_key_block",
1969
 
                          ("request for old page resubmitted"));
1970
1879
      /*
1971
1880
        The block is no longer assigned to this hash_link.
1972
1881
        Get another one.
2029
1938
        hash_link->block= block;
2030
1939
        link_to_file_list(keycache, block, file, 0);
2031
1940
        page_status= PAGE_TO_BE_READ;
2032
 
        KEYCACHE_DBUG_PRINT("find_key_block",
2033
 
                            ("got free or never used block %u",
2034
 
                             BLOCK_NUMBER(block)));
2035
1941
      }
2036
1942
      else
2037
1943
      {
2059
1965
          link_into_queue(&keycache->waiting_for_block, thread);
2060
1966
          do
2061
1967
          {
2062
 
            KEYCACHE_DBUG_PRINT("find_key_block: wait",
2063
 
                                ("suspend thread %ld", thread->id));
2064
1968
            keycache_pthread_cond_wait(&thread->suspend,
2065
1969
                                       &keycache->cache_lock);
2066
1970
          }
2113
2017
          /* this is a primary request for a new page */
2114
2018
          block->status|= BLOCK_IN_SWITCH;
2115
2019
 
2116
 
          KEYCACHE_DBUG_PRINT("find_key_block",
2117
 
                        ("got block %u for new page", BLOCK_NUMBER(block)));
2118
 
 
2119
2020
          if (block->status & BLOCK_CHANGED)
2120
2021
          {
2121
2022
            /* The block contains a dirty page - push it out of the cache */
2122
2023
 
2123
 
            KEYCACHE_DBUG_PRINT("find_key_block", ("block is dirty"));
2124
2024
            if (block->status & BLOCK_IN_FLUSH)
2125
2025
            {
2126
2026
              /*
2252
2152
            attached to the same hash_link and as such destined for the
2253
2153
            same file block.
2254
2154
          */
2255
 
          KEYCACHE_DBUG_PRINT("find_key_block",
2256
 
                              ("block->hash_link: %p  hash_link: %p  "
2257
 
                               "block->status: %u", block->hash_link,
2258
 
                               hash_link, block->status ));
2259
2155
          page_status= (((block->hash_link == hash_link) &&
2260
2156
                         (block->status & BLOCK_READ)) ?
2261
2157
                        PAGE_READ : PAGE_WAIT_TO_BE_READ);
2291
2187
                  ((block->status & BLOCK_READ) &&
2292
2188
                   !(block->status & (BLOCK_IN_EVICTION | BLOCK_IN_SWITCH))));
2293
2189
      reg_requests(keycache, block, 1);
2294
 
      KEYCACHE_DBUG_PRINT("find_key_block",
2295
 
                          ("block->hash_link: %p  hash_link: %p  "
2296
 
                           "block->status: %u", block->hash_link,
2297
 
                           hash_link, block->status ));
2298
2190
      page_status= (((block->hash_link == hash_link) &&
2299
2191
                     (block->status & BLOCK_READ)) ?
2300
2192
                    PAGE_READ : PAGE_WAIT_TO_BE_READ);
2313
2205
              ((block->hash_link->file == file) &&
2314
2206
               (block->hash_link->diskpos == filepos)));
2315
2207
  *page_st=page_status;
2316
 
  KEYCACHE_DBUG_PRINT("find_key_block",
2317
 
                      ("fd: %d  pos: %lu  block->status: %u  page_status: %d",
2318
 
                       file, (ulong) filepos, block->status,
2319
 
                       page_status));
2320
2208
 
2321
 
#if !defined(DBUG_OFF) && defined(EXTRA_DEBUG)
2322
 
  DBUG_EXECUTE("check_keycache2",
2323
 
               test_key_cache(keycache, "end of find_key_block",0););
2324
 
#endif
2325
2209
  KEYCACHE_THREAD_TRACE("find_key_block:end");
2326
2210
  DBUG_RETURN(block);
2327
2211
}
2375
2259
                fail_block(block));
2376
2260
    DBUG_ASSERT((block->requests > 0) || fail_block(block));
2377
2261
 
2378
 
    KEYCACHE_DBUG_PRINT("read_block",
2379
 
                        ("page to be read by primary request"));
2380
 
 
2381
2262
    keycache->global_cache_read++;
2382
2263
    /* Page is not in buffer yet, is to be read from disk */
2383
2264
    keycache_pthread_mutex_unlock(&keycache->cache_lock);
2412
2293
        keycache->key_cache_block_size.
2413
2294
      */
2414
2295
    }
2415
 
    KEYCACHE_DBUG_PRINT("read_block",
2416
 
                        ("primary request: new page in cache"));
2417
2296
    /* Signal that all pending requests for this page now can be processed */
2418
2297
    release_whole_queue(&block->wqueue[COND_FOR_REQUESTED]);
2419
2298
  }
2428
2307
      for the requested file block nor the file and position. So we have
2429
2308
      to assert this in the caller.
2430
2309
    */
2431
 
    KEYCACHE_DBUG_PRINT("read_block",
2432
 
                      ("secondary request waiting for new page to be read"));
2433
2310
    wait_on_queue(&block->wqueue[COND_FOR_REQUESTED], &keycache->cache_lock);
2434
 
    KEYCACHE_DBUG_PRINT("read_block",
2435
 
                        ("secondary request: new page in cache"));
2436
2311
  }
2437
2312
}
2438
2313
 
2474
2349
  my_bool locked_and_incremented= FALSE;
2475
2350
  int error=0;
2476
2351
  uchar *start= buff;
2477
 
  DBUG_ENTER("key_cache_read");
2478
 
  DBUG_PRINT("enter", ("fd: %u  pos: %lu  length: %u",
2479
 
               (uint) file, (ulong) filepos, length));
2480
2352
 
2481
2353
  if (keycache->key_cache_inited)
2482
2354
  {
2668
2540
                     uchar *buff, uint length)
2669
2541
{
2670
2542
  int error= 0;
2671
 
  DBUG_ENTER("key_cache_insert");
2672
 
  DBUG_PRINT("enter", ("fd: %u  pos: %lu  length: %u",
2673
 
               (uint) file,(ulong) filepos, length));
2674
2543
 
2675
2544
  if (keycache->key_cache_inited)
2676
2545
  {
2816
2685
            only a writer may set block->offset down from
2817
2686
            keycache->key_cache_block_size.
2818
2687
          */
2819
 
          KEYCACHE_DBUG_PRINT("key_cache_insert",
2820
 
                              ("primary request: new page in cache"));
2821
2688
          /* Signal all pending requests. */
2822
2689
          release_whole_queue(&block->wqueue[COND_FOR_REQUESTED]);
2823
2690
        }
2913
2780
{
2914
2781
  my_bool locked_and_incremented= FALSE;
2915
2782
  int error=0;
2916
 
  DBUG_ENTER("key_cache_write");
2917
 
  DBUG_PRINT("enter",
2918
 
             ("fd: %u  pos: %lu  length: %u  block_length: %u"
2919
 
              "  key_block_length: %u",
2920
 
              (uint) file, (ulong) filepos, length, block_length,
2921
 
              keycache ? keycache->key_cache_block_size : 0));
2922
2783
 
2923
2784
  if (!dont_write)
2924
2785
  {
2932
2793
    /* purecov: end */
2933
2794
  }
2934
2795
 
2935
 
#if !defined(DBUG_OFF) && defined(EXTRA_DEBUG)
2936
 
  DBUG_EXECUTE("check_keycache",
2937
 
               test_key_cache(keycache, "start of key_cache_write", 1););
2938
 
#endif
2939
 
 
2940
2796
  if (keycache->key_cache_inited)
2941
2797
  {
2942
2798
    /* Key cache is used */
3181
3037
    dec_counter_for_resize_op(keycache);
3182
3038
    keycache_pthread_mutex_unlock(&keycache->cache_lock);
3183
3039
  }
3184
 
#if !defined(DBUG_OFF) && defined(EXTRA_DEBUG)
3185
 
  DBUG_EXECUTE("exec",
3186
 
               test_key_cache(keycache, "end of key_cache_write", 1););
3187
 
#endif
3188
3040
  DBUG_RETURN(error);
3189
3041
}
3190
3042
 
3218
3070
 
3219
3071
static void free_block(KEY_CACHE *keycache, BLOCK_LINK *block)
3220
3072
{
3221
 
  KEYCACHE_THREAD_TRACE("free block");
3222
 
  KEYCACHE_DBUG_PRINT("free_block",
3223
 
                      ("block %u to be freed, hash_link %p",
3224
 
                       BLOCK_NUMBER(block), block->hash_link));
3225
3073
  /*
3226
3074
    Assert that the block is not free already. And that it is in a clean
3227
3075
    state. Note that the block might just be assigned to a hash_link and
3321
3169
  block->status= 0;
3322
3170
  block->length= 0;
3323
3171
  block->offset= keycache->key_cache_block_size;
3324
 
  KEYCACHE_THREAD_TRACE("free block");
3325
 
  KEYCACHE_DBUG_PRINT("free_block", ("block is freed"));
3326
3172
 
3327
3173
  /* Enforced by unlink_changed(), but just to be sure. */
3328
3174
  DBUG_ASSERT(!block->next_changed && !block->prev_changed);
3377
3223
  for ( ; cache != end ; cache++)
3378
3224
  {
3379
3225
    BLOCK_LINK *block= *cache;
3380
 
 
3381
 
    KEYCACHE_DBUG_PRINT("flush_cached_blocks",
3382
 
                        ("block %u to be flushed", BLOCK_NUMBER(block)));
3383
3226
    /*
3384
3227
      If the block contents is going to be changed, we abandon the flush
3385
3228
      for this block. flush_key_blocks_int() will restart its search and
3486
3329
  BLOCK_LINK *cache_buff[FLUSH_CACHE],**cache;
3487
3330
  int last_errno= 0;
3488
3331
  int last_errcnt= 0;
3489
 
  DBUG_ENTER("flush_key_blocks_int");
3490
 
  DBUG_PRINT("enter",("file: %d  blocks_used: %lu  blocks_changed: %lu",
3491
 
              file, keycache->blocks_used, keycache->blocks_changed));
3492
 
 
3493
 
#if !defined(DBUG_OFF) && defined(EXTRA_DEBUG)
3494
 
    DBUG_EXECUTE("check_keycache",
3495
 
                 test_key_cache(keycache, "start of flush_key_blocks", 0););
3496
 
#endif
3497
3332
 
3498
3333
  cache= cache_buff;
3499
3334
  if (keycache->disk_blocks > 0 &&
3902
3737
 
3903
3738
  } /* if (keycache->disk_blocks > 0 */
3904
3739
 
3905
 
#ifndef DBUG_OFF
3906
 
  DBUG_EXECUTE("check_keycache",
3907
 
               test_key_cache(keycache, "end of flush_key_blocks", 0););
3908
 
#endif
3909
3740
err:
3910
3741
  if (cache != cache_buff)
3911
3742
    my_free((uchar*) cache, MYF(0));
3934
3765
                     File file, enum flush_type type)
3935
3766
{
3936
3767
  int res= 0;
3937
 
  DBUG_ENTER("flush_key_blocks");
3938
 
  DBUG_PRINT("enter", ("keycache: 0x%lx", (long) keycache));
3939
3768
 
3940
3769
  if (!keycache->key_cache_inited)
3941
3770
    DBUG_RETURN(0);
3991
3820
  uint          total_found;
3992
3821
  uint          found;
3993
3822
  uint          idx;
3994
 
  DBUG_ENTER("flush_all_key_blocks");
3995
3823
 
3996
3824
  do
3997
3825
  {
4106
3934
int reset_key_cache_counters(const char *name __attribute__((unused)),
4107
3935
                             KEY_CACHE *key_cache)
4108
3936
{
4109
 
  DBUG_ENTER("reset_key_cache_counters");
4110
3937
  if (!key_cache->key_cache_inited)
4111
3938
  {
4112
 
    DBUG_PRINT("info", ("Key cache %s not initialized.", name));
4113
3939
    DBUG_RETURN(0);
4114
3940
  }
4115
 
  DBUG_PRINT("info", ("Resetting counters for key cache %s.", name));
4116
 
 
4117
3941
  key_cache->global_blocks_changed= 0;   /* Key_blocks_not_flushed */
4118
3942
  key_cache->global_cache_r_requests= 0; /* Key_read_requests */
4119
3943
  key_cache->global_cache_read= 0;       /* Key_reads */
4122
3946
  DBUG_RETURN(0);
4123
3947
}
4124
3948
 
4125
 
 
4126
 
#ifndef DBUG_OFF
4127
 
/*
4128
 
  Test if disk-cache is ok
4129
 
*/
4130
 
static void test_key_cache(KEY_CACHE *keycache __attribute__((unused)),
4131
 
                           const char *where __attribute__((unused)),
4132
 
                           my_bool lock __attribute__((unused)))
4133
 
{
4134
 
  /* TODO */
4135
 
}
4136
 
#endif
4137
 
 
4138
3949
#if defined(KEYCACHE_TIMEOUT)
4139
3950
 
4140
3951
#define KEYCACHE_DUMP_FILE  "keycache_dump.txt"
4354
4165
#endif /* defined(KEYCACHE_DEBUG) */
4355
4166
 
4356
4167
#if !defined(DBUG_OFF)
4357
 
#define F_B_PRT(_f_, _v_) DBUG_PRINT("assert_fail", (_f_, _v_))
 
4168
#define F_B_PRT(_f_, _v_) 
4358
4169
 
4359
4170
static int fail_block(BLOCK_LINK *block)
4360
4171
{