~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/table_share.h

  • Committer: Brian Aker
  • Date: 2009-05-13 07:40:06 UTC
  • Revision ID: brian@gaz-20090513074006-0fjfuq6gpqydslqy
Fix for processlist (Eric found).

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
  This class is shared between different table objects. There is one
23
23
  instance of table share per one table in the database.
24
24
*/
25
 
class TABLE_SHARE
 
25
class TableShare
26
26
{
27
27
public:
28
 
  TABLE_SHARE() {}                    /* Remove gcc warning */
 
28
  TableShare() 
 
29
  {
 
30
    init();
 
31
  }                    /* Remove gcc warning */
29
32
 
30
33
  /** Category of this table. */
31
34
  enum_table_category table_category;
38
41
  TYPELIB *intervals;                   /* pointer to interval info */
39
42
  pthread_mutex_t mutex;                /* For locking the share  */
40
43
  pthread_cond_t cond;                  /* To signal that share is ready */
41
 
  TABLE_SHARE *next,            /* Link to unused shares */
 
44
  TableShare *next,             /* Link to unused shares */
42
45
    **prev;
43
46
 
44
47
  /* The following is copied to each Table on OPEN */
88
91
  StorageEngine *storage_engine;                        /* storage engine plugin */
89
92
  inline StorageEngine *db_type() const /* table_type for handler */
90
93
  {
91
 
    // assert(storage_engine);
92
94
    return storage_engine;
93
95
  }
94
96
  enum row_type row_type;               /* How rows are stored */
102
104
  uint32_t null_bytes;
103
105
  uint32_t last_null_bit_pos;
104
106
  uint32_t fields;                              /* Number of fields */
105
 
  uint32_t stored_fields;                   /* Number of stored fields
106
 
                                           (i.e. without generated-only ones) */
107
107
  uint32_t rec_buff_length;                 /* Size of table->record[] buffer */
108
108
  uint32_t keys, key_parts;
109
109
  uint32_t max_key_length, max_unique_length, total_key_length;
124
124
  uint32_t error, open_errno, errarg;       /* error from open_table_def() */
125
125
  uint32_t column_bitmap_size;
126
126
 
127
 
  uint32_t vfields;                         /* Number of virtual fields */
128
127
  bool db_low_byte_first;               /* Portable row format */
129
128
  bool crashed;
130
129
  bool name_lock, replace_with_name_lock;
131
130
  bool waiting_on_cond;                 /* Protection against free */
132
 
  uint32_t table_map_id;                   /* for row-based replication */
133
 
  uint64_t table_map_version;
134
 
 
135
 
  /*
136
 
    Cache for row-based replication table share checks that does not
137
 
    need to be repeated. Possible values are: -1 when cache value is
138
 
    not calculated yet, 0 when table *shall not* be replicated, 1 when
139
 
    table *may* be replicated.
140
 
  */
141
 
  int cached_row_logging_check;
142
131
 
143
132
  /*
144
133
    Set share's table cache key and update its db and table name appropriately.
152
141
    NOTES
153
142
      Since 'key_buff' buffer will be referenced from share it should has same
154
143
      life-time as share itself.
155
 
      This method automatically ensures that TABLE_SHARE::table_name/db have
 
144
      This method automatically ensures that TableShare::table_name/db have
156
145
      appropriate values by using table cache key as their source.
157
146
  */
158
147
 
197
186
    return (table_category == TABLE_CATEGORY_USER);
198
187
  }
199
188
 
200
 
  inline uint32_t get_table_def_version()
201
 
  {
202
 
    return table_map_id;
203
 
  }
 
189
 
 
190
  /*
 
191
    Initialize share for temporary tables
 
192
 
 
193
    SYNOPSIS
 
194
    init()
 
195
    share       Share to fill
 
196
    key         Table_cache_key, as generated from create_table_def_key.
 
197
    must start with db name.
 
198
    key_length  Length of key
 
199
    table_name  Table name
 
200
    path        Path to file (possible in lower case) without .frm
 
201
 
 
202
    NOTES
 
203
    This is different from alloc_table_share() because temporary tables
 
204
    don't have to be shared between threads or put into the table def
 
205
    cache, so we can do some things notable simpler and faster
 
206
 
 
207
    If table is not put in session->temporary_tables (happens only when
 
208
    one uses OPEN TEMPORARY) then one can specify 'db' as key and
 
209
    use key_length= 0 as neither table_cache_key or key_length will be used).
 
210
  */
 
211
 
 
212
  void init()
 
213
  {
 
214
    init("", 0, "", "");
 
215
  }
 
216
 
 
217
  void init(const char *new_table_name,
 
218
            const char *new_path)
 
219
  {
 
220
    init("", 0, new_table_name, new_path);
 
221
  }
 
222
 
 
223
  void init(const char *key,
 
224
            uint32_t key_length, const char *new_table_name,
 
225
            const char *new_path)
 
226
  {
 
227
    memset(this, 0, sizeof(TableShare));
 
228
    init_sql_alloc(&mem_root, TABLE_ALLOC_BLOCK_SIZE, 0);
 
229
    table_category=         TABLE_CATEGORY_TEMPORARY;
 
230
    tmp_table=              INTERNAL_TMP_TABLE;
 
231
    db.str=                 (char*) key;
 
232
    db.length=           strlen(key);
 
233
    table_cache_key.str=    (char*) key;
 
234
    table_cache_key.length= key_length;
 
235
    table_name.str=         (char*) new_table_name;
 
236
    table_name.length=      strlen(new_table_name);
 
237
    path.str=               (char*) new_path;
 
238
    normalized_path.str=    (char*) new_path;
 
239
    path.length= normalized_path.length= strlen(new_path);
 
240
 
 
241
    return;
 
242
  }
 
243
 
 
244
  /*
 
245
    Free table share and memory used by it
 
246
 
 
247
    SYNOPSIS
 
248
    free_table_share()
 
249
    share               Table share
 
250
 
 
251
    NOTES
 
252
    share->mutex must be locked when we come here if it's not a temp table
 
253
  */
 
254
 
 
255
  void free_table_share()
 
256
  {
 
257
    MEM_ROOT new_mem_root;
 
258
    assert(ref_count == 0);
 
259
 
 
260
    /*
 
261
      If someone is waiting for this to be deleted, inform it about this.
 
262
      Don't do a delete until we know that no one is refering to this anymore.
 
263
    */
 
264
    if (tmp_table == NO_TMP_TABLE)
 
265
    {
 
266
      /* share->mutex is locked in release_table_share() */
 
267
      while (waiting_on_cond)
 
268
      {
 
269
        pthread_cond_broadcast(&cond);
 
270
        pthread_cond_wait(&cond, &mutex);
 
271
      }
 
272
      /* No thread refers to this anymore */
 
273
      pthread_mutex_unlock(&mutex);
 
274
      pthread_mutex_destroy(&mutex);
 
275
      pthread_cond_destroy(&cond);
 
276
    }
 
277
    hash_free(&name_hash);
 
278
 
 
279
    storage_engine= NULL;
 
280
 
 
281
    /* We must copy mem_root from share because share is allocated through it */
 
282
    memcpy(&new_mem_root, &mem_root, sizeof(new_mem_root));
 
283
    free_root(&new_mem_root, MYF(0));                 // Free's share
 
284
    return;
 
285
  }
 
286
 
204
287
 
205
288
};