17 #include "my_global.h"
19 #ifdef HAVE_REPLICATION
21 #include "rpl_tblmap.h"
27 #define MAYBE_TABLE_NAME(T) ("")
29 #define MAYBE_TABLE_NAME(T) ((T) ? (T)->s->table_name.str : "<>")
31 #define TABLE_ID_HASH_SIZE 32
32 #define TABLE_ID_CHUNK 256
34 table_mapping::table_mapping()
44 (void) my_hash_init(&m_table_ids,&my_charset_bin,TABLE_ID_HASH_SIZE,
45 offsetof(
entry,table_id),
sizeof(ulonglong),
48 init_alloc_root(&m_mem_root, TABLE_ID_HASH_SIZE*
sizeof(
entry), 0);
51 table_mapping::~table_mapping()
56 my_hash_free(&m_table_ids);
57 free_root(&m_mem_root, MYF(0));
60 TABLE* table_mapping::get_table(ulonglong table_id)
62 DBUG_ENTER(
"table_mapping::get_table(ulonglong)");
63 DBUG_PRINT(
"enter", (
"table_id: %llu", table_id));
64 entry *e= find_entry(table_id);
67 DBUG_PRINT(
"info", (
"tid %llu -> table 0x%lx (%s)",
68 table_id, (
long) e->table,
69 MAYBE_TABLE_NAME(e->table)));
70 DBUG_RETURN(e->table);
73 DBUG_PRINT(
"info", (
"tid %llu is not mapped!", table_id));
82 int table_mapping::expand()
90 entry *tmp= (
entry *)alloc_root(&m_mem_root, TABLE_ID_CHUNK*
sizeof(
entry));
92 return ERR_MEMORY_ALLOCATION;
95 entry *e_end= tmp+TABLE_ID_CHUNK-1;
96 for (
entry *e= tmp; e < e_end; e++)
103 int table_mapping::set_table(ulonglong table_id,
TABLE*
table)
105 DBUG_ENTER(
"table_mapping::set_table(ulong,TABLE*)");
106 DBUG_PRINT(
"enter", (
"table_id: %llu table: 0x%lx (%s)",
108 (
long) table, MAYBE_TABLE_NAME(table)));
109 entry *e= find_entry(table_id);
112 if (m_free == 0 && expand())
113 DBUG_RETURN(ERR_MEMORY_ALLOCATION);
115 m_free= m_free->next;
120 free_table_map_log_event(e->table);
122 my_hash_delete(&m_table_ids,(uchar *)e);
124 e->table_id= table_id;
126 if (my_hash_insert(&m_table_ids,(uchar *)e))
131 DBUG_RETURN(ERR_MEMORY_ALLOCATION);
134 DBUG_PRINT(
"info", (
"tid %llu -> table 0x%lx (%s)",
135 table_id, (
long) e->table,
136 MAYBE_TABLE_NAME(e->table)));
140 int table_mapping::remove_table(ulonglong table_id)
142 entry *e= find_entry(table_id);
145 my_hash_delete(&m_table_ids,(uchar *)e);
158 void table_mapping::clear_tables()
160 DBUG_ENTER(
"table_mapping::clear_tables()");
161 for (uint
i= 0;
i < m_table_ids.records;
i++)
163 entry *e= (
entry *)my_hash_element(&m_table_ids,
i);
165 free_table_map_log_event(e->table);
170 my_hash_reset(&m_table_ids);