~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to sql/rpl_tblmap.h

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2005 MySQL AB
 
2
 
 
3
   This program is free software; you can redistribute it and/or modify
 
4
   it under the terms of the GNU General Public License as published by
 
5
   the Free Software Foundation; version 2 of the License.
 
6
 
 
7
   This program is distributed in the hope that it will be useful,
 
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
   GNU General Public License for more details.
 
11
 
 
12
   You should have received a copy of the GNU General Public License
 
13
   along with this program; if not, write to the Free Software
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
15
 
 
16
#ifndef TABLE_MAPPING_H
 
17
#define TABLE_MAPPING_H
 
18
 
 
19
/* Forward declarations */
 
20
#ifndef MYSQL_CLIENT
 
21
struct st_table;
 
22
typedef st_table TABLE;
 
23
#else
 
24
class Table_map_log_event;
 
25
typedef Table_map_log_event TABLE;
 
26
void free_table_map_log_event(TABLE *table);
 
27
#endif
 
28
 
 
29
 
 
30
/*
 
31
  CLASS table_mapping
 
32
 
 
33
  RESPONSIBILITIES
 
34
    The table mapping is used to map table id's to table pointers
 
35
 
 
36
  COLLABORATION
 
37
    RELAY_LOG    For mapping table id:s to tables when receiving events.
 
38
 */
 
39
 
 
40
/*
 
41
  Guilhem to Mats:
 
42
  in the table_mapping class, the memory is allocated and never freed (until
 
43
  destruction). So this is a good candidate for allocating inside a MEM_ROOT:
 
44
  it gives the efficient allocation in chunks (like in expand()). So I have
 
45
  introduced a MEM_ROOT.
 
46
 
 
47
  Note that inheriting from Sql_alloc had no effect: it has effects only when
 
48
  "ptr= new table_mapping" is called, and this is never called. And it would
 
49
  then allocate from thd->mem_root which is a highly volatile object (reset
 
50
  from example after executing each query, see dispatch_command(), it has a
 
51
  free_root() at end); as the table_mapping object is supposed to live longer
 
52
  than a query, it was dangerous.
 
53
  A dedicated MEM_ROOT needs to be used, see below.
 
54
*/
 
55
 
 
56
class table_mapping {
 
57
 
 
58
private:
 
59
  MEM_ROOT m_mem_root;
 
60
 
 
61
public:
 
62
 
 
63
  enum enum_error {
 
64
      ERR_NO_ERROR = 0,
 
65
      ERR_LIMIT_EXCEEDED,
 
66
      ERR_MEMORY_ALLOCATION
 
67
  };
 
68
 
 
69
  table_mapping();
 
70
  ~table_mapping();
 
71
 
 
72
  TABLE* get_table(ulong table_id);
 
73
 
 
74
  int       set_table(ulong table_id, TABLE* table);
 
75
  int       remove_table(ulong table_id);
 
76
  void      clear_tables();
 
77
  ulong     count() const { return m_table_ids.records; }
 
78
 
 
79
private:
 
80
  /*
 
81
    This is a POD (Plain Old Data).  Keep it that way (we apply offsetof() to
 
82
    it, which only works for PODs)
 
83
  */
 
84
  struct entry { 
 
85
    ulong table_id;
 
86
    union {
 
87
      TABLE *table;
 
88
      entry *next;
 
89
    };
 
90
  };
 
91
 
 
92
  entry *find_entry(ulong table_id)
 
93
  {
 
94
    return (entry *)hash_search(&m_table_ids,
 
95
                                (uchar*)&table_id,
 
96
                                sizeof(table_id));
 
97
  }
 
98
  int expand();
 
99
 
 
100
  /*
 
101
    Head of the list of free entries; "free" in the sense that it's an
 
102
    allocated entry free for use, NOT in the sense that it's freed
 
103
    memory.
 
104
  */
 
105
  entry *m_free;
 
106
 
 
107
  /* Correspondance between an id (a number) and a TABLE object */
 
108
  HASH m_table_ids;
 
109
};
 
110
 
 
111
#endif