~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/myisam/mi_keycache.cc

  • Committer: Brian Aker
  • Date: 2009-08-03 15:50:04 UTC
  • mfrom: (1106.3.2 heap)
  • Revision ID: brian@gaz-20090803155004-tq6ec51i68ay1aye
Merge of Brian

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
    #  Error code
46
46
*/
47
47
 
48
 
int mi_assign_to_key_cache(MI_INFO *info, KEY_CACHE *key_cache) 
 
48
int mi_assign_to_key_cache(MI_INFO *, KEY_CACHE *) 
49
49
{
50
 
  int error= 0;
51
 
  MYISAM_SHARE* share= info->s;
52
 
 
53
 
  /*
54
 
    Skip operation if we didn't change key cache. This can happen if we
55
 
    call this for all open instances of the same table
56
 
  */
57
 
  if (share->key_cache == key_cache)
58
 
    return(0);
59
 
 
60
 
  /*
61
 
    First flush all blocks for the table in the old key cache.
62
 
    This is to ensure that the disk is consistent with the data pages
63
 
    in memory (which may not be the case if the table uses delayed_key_write)
64
 
 
65
 
    Note that some other read thread may still fill in the key cache with
66
 
    new blocks during this call and after, but this doesn't matter as
67
 
    all threads will start using the new key cache for their next call to
68
 
    myisam library and we know that there will not be any changed blocks
69
 
    in the old key cache.
70
 
  */
71
 
 
72
 
  if (flush_key_blocks(share->key_cache, share->kfile, FLUSH_RELEASE))
73
 
  {
74
 
    error= my_errno;
75
 
    mi_print_error(info->s, HA_ERR_CRASHED);
76
 
    mi_mark_crashed(info);              /* Mark that table must be checked */
77
 
  }
78
 
 
79
 
  /*
80
 
    Flush the new key cache for this file.  This is needed to ensure
81
 
    that there is no old blocks (with outdated data) left in the new key
82
 
    cache from an earlier assign_to_keycache operation
83
 
 
84
 
    (This can never fail as there is never any not written data in the
85
 
    new key cache)
86
 
  */
87
 
  (void) flush_key_blocks(key_cache, share->kfile, FLUSH_RELEASE);
88
 
 
89
 
  /*
90
 
    ensure that setting the key cache and changing the multi_key_cache
91
 
    is done atomicly
92
 
  */
93
 
  pthread_mutex_lock(&share->intern_lock);
94
 
  /*
95
 
    Tell all threads to use the new key cache
96
 
    This should be seen at the lastes for the next call to an myisam function.
97
 
  */
98
 
  share->key_cache= key_cache;
99
 
 
100
 
  /* store the key cache in the global hash structure for future opens */
101
 
  if (multi_key_cache_set((unsigned char*) share->unique_file_name,
102
 
                          share->unique_name_length,
103
 
                          share->key_cache))
104
 
    error= my_errno;
105
 
  pthread_mutex_unlock(&share->intern_lock);
106
 
  return(error);
 
50
  return 0;
107
51
}
108
52
 
109
53
 
128
72
*/
129
73
 
130
74
 
131
 
void mi_change_key_cache(KEY_CACHE *old_key_cache,
132
 
                         KEY_CACHE *new_key_cache)
 
75
void mi_change_key_cache(KEY_CACHE *, KEY_CACHE *)
133
76
{
134
 
  /*
135
 
    Lock list to ensure that no one can close the table while we manipulate it
136
 
  */
137
 
  pthread_mutex_lock(&THR_LOCK_myisam);
138
 
  list<MI_INFO *>::iterator it= myisam_open_list.begin();
139
 
  while (it != myisam_open_list.end())
140
 
  {
141
 
    MI_INFO *info= *it;
142
 
    MYISAM_SHARE *share= info->s;
143
 
    if (share->key_cache == old_key_cache)
144
 
      mi_assign_to_key_cache(info, new_key_cache);
145
 
    ++it;
146
 
  }
147
 
 
148
 
  /*
149
 
    We have to do the following call while we have the lock on the
150
 
    MyISAM list structure to ensure that another thread is not trying to
151
 
    open a new table that will be associted with the old key cache
152
 
  */
153
 
  multi_key_cache_change(old_key_cache, new_key_cache);
154
 
  pthread_mutex_unlock(&THR_LOCK_myisam);
155
 
  return;
156
77
}