43
43
server_version.extra.end= server_version.extra.begin +
44
44
strlen((const char*)server_version.extra.begin);
46
flags= 0; // TODO: set BSTREAM_FLAG_BIG_ENDIAN flag accordingly
49
bzero(&start_time,sizeof(start_time));
50
bzero(&end_time,sizeof(end_time));
51
bzero(&vp_time,sizeof(vp_time));
52
bzero(&binlog_pos,sizeof(binlog_pos));
53
bzero(&binlog_group,sizeof(binlog_group));
48
#ifdef WORDS_BIGENDIAN
49
flags|= BSTREAM_FLAG_BIG_ENDIAN;
54
52
bzero(m_snap, sizeof(m_snap));
57
55
Image_info::~Image_info()
59
// Delete snapshot objects
61
for (uint no=0; no<256; ++no)
63
Snapshot_info *snap= m_snap[no];
68
for (uint i=0; i < snap->table_count(); ++i)
70
Table_item *t= snap->get_table(i);
82
// delete server object instances as we own them.
84
for (uint i=0; i < db_count(); ++i)
92
for (uint i=0; i < m_items.size(); ++i)
94
PerDb_item *it= m_items[i];
102
void Image_info::save_time(const time_t t, bstream_time_t &buf)
106
buf.year= time.tm_year;
107
buf.mon= time.tm_mon;
108
buf.mday= time.tm_mday;
109
buf.hour= time.tm_hour;
110
buf.min= time.tm_min;
111
buf.sec= time.tm_sec;
114
result_t Image_info::Item::get_serialization(THD *thd, ::String &buf)
116
obs::Obj *obj= obj_ptr();
123
return obj->serialize(thd, &buf) ? ERROR : OK;
126
/// Add table to database's table list.
127
result_t Image_info::Db_item::add_table(Table_item &t)
134
m_tables= m_last_table= &t;
138
m_last_table->next_table= &t;
148
Locate in the catalogue an object described by the @c st_bstream_item_info
151
@todo Handle unknown item types.
154
Image_info::locate_item(const st_bstream_item_info *item) const
156
switch (item->type) {
58
We need to explicitly call destructors for all objects in the catalogue
59
since they are allocated using mem_root and thus destructors will not be
60
invoked when the mem_root is freed.
65
Ts_iterator tsit(*this);
68
while ((ts= static_cast<Ts*>(tsit++)))
71
Db_iterator dbit(*this);
74
// then databases and all objects inside each database
76
while ((db= static_cast<Db*>(dbit++)))
78
// iterate over objects in the database
80
Dbobj_iterator it(*this,*db);
89
free_root(&mem_root, MYF(0));
93
Add database to the catalogue.
95
@param[in] db_name name of the database
96
@param[in] pos position at which this database should be stored
98
@returns Pointer to @c Image_info::Db instance storing information
99
about the database or NULL in case of error.
104
Image_info::add_db(const String &db_name, uint pos)
106
Db *db= new (&mem_root) Db(db_name);
111
// call destructor if position is occupied
115
if (m_dbs.insert(pos, db))
124
Add tablespace to the catalogue.
126
@param[in] ts_name name of the tablespace
127
@param[in] pos position at which this database should be stored
129
@returns Pointer to @c Image_info::Ts instance storing information
130
about the tablespace or NULL in case of error.
135
Image_info::add_ts(const String &ts_name, uint pos)
137
Ts *ts= new (&mem_root) Ts(ts_name);
142
// call destructor if position is occupied
144
m_ts_map[pos]->~Ts();
146
if (m_ts_map.insert(pos, ts))
155
Add snapshot to the catalogue.
157
The snapshot should be non-empty, that is contain data of at least one table.
158
Snapshot is added to the list of snapshots used in the image and a number is
159
assigned to it. This number is stored in @c snap.m_num. If snapshot's number
160
is @c n then pointer to a corresponding @c Snapshot_info object is stored in
163
The @c Snapshot_info object is not owned by @c Image_info instance - it must
164
be deleted externally.
166
@returns Snapshot's number or -1 in case of error.
168
int Image_info::add_snapshot(Snapshot_info &snap)
170
uint num= st_bstream_image_header::snap_count++;
172
// The limit of 256 snapshots is imposed by backup stream format.
180
Store information about snapshot in the snapshot[] table for the
181
backup stream library
184
st_bstream_snapshot_info &info= snapshot[num];
186
bzero(&info, sizeof(st_bstream_snapshot_info));
187
info.type= enum_bstream_snapshot_type(snap.type());
188
info.version= snap.version();
189
info.table_count= snap.table_count();
191
if (snap.type() == Snapshot_info::NATIVE_SNAPSHOT)
193
Native_snapshot &ns= static_cast<Native_snapshot&>(snap);
194
uint se_ver= ns.se_ver();
195
const char *se_name= ns.se_name();
197
info.engine.major= se_ver >> 8;
198
info.engine.minor= se_ver & 0xFF;
199
info.engine.name.begin= (byte*)se_name;
200
info.engine.name.end= info.engine.name.begin + strlen(se_name);
207
Check if catalogue contains given database.
209
bool Image_info::has_db(const String &db_name)
211
for (uint n=0; n < m_dbs.count() ; ++n)
212
if (m_dbs[n] && m_dbs[n]->name() == db_name)
219
Add per database object to the catalogue.
221
@param[in] db database to which this object belongs - this database must
222
already be in the catalogue
223
@param[in] type type of the object
224
@param[in] name name of the object
225
@param[in] pos position where the object will be stored inside database's
228
@returns Pointer to @c Image_info::Dbobj instance storing information
229
about the object or NULL in case of error.
231
@note There is a specialized method @c add_table() for adding tables.
233
@see @c get_db_object().
235
Image_info::Dbobj* Image_info::add_db_object(Db &db,
236
const enum_bstream_item_type type,
237
const ::String &name, ulong pos)
239
Dbobj *o= new (&mem_root) Dbobj(db, type, name);
244
if (db.add_obj(*o, pos))
253
Return per database object stored in catalogue.
255
This method is used only for non-table objects.
257
@param[in] db_num position of object's database in the catalogue
258
@param[in] pos position of the object inside the database
260
@returns Pointer to @c Image_info::Dbobj instance storing information
261
about the object or NULL if there is no object with given coordinates.
263
Image_info::Dbobj* Image_info::get_db_object(uint db_num, ulong pos) const
265
Db *db= get_db(db_num);
270
return db->get_obj(pos);
274
Add table to the catalogue.
276
@param[in] db table's database - this database must already be in
278
@param[in] name name of the table
279
@param[in] snap snapshot containing table's data
280
@param[in] pos table's position within the snapshot
282
@returns Pointer to @c Image_info::Table instance storing information
283
about the table or NULL in case of error.
285
@note The snapshot is added to the catalogue if it was not there already.
290
Image_info::add_table(Db &db, const ::String &table_name,
291
Snapshot_info &snap, ulong pos)
293
Table *t= new (&mem_root) Table(db, table_name);
298
if (snap.add_table(*t, pos))
301
if (db.add_table(*t))
305
snap.m_num= add_snapshot(snap);
310
t->snap_num= snap.m_num - 1;
311
t->base.base.pos= pos;
319
Return table stored in the catalogue.
321
@param[in] snap_num position of table's snapshot within the catalogue
322
@param[in] pos position of the table within the snapshot
324
@returns Pointer to @c Image_info::Table instance storing information
325
about the table or NULL if there is no table with given coordinates.
328
Image_info::get_table(ushort snap_num, ulong pos) const
330
if (snap_num > snap_count() || m_snap[snap_num] == NULL)
333
Table *t= m_snap[snap_num]->get_table(pos);
342
Find object in the catalogue.
344
The object is identified by its coordinates stored in a
345
@c st_bstream_item_info structure. Normally these coordinates are
346
filled by backup stream library when reading backup image.
348
@returns Pointer to the corresponding @c Obj instance or NULL if object
351
Image_info::Obj *find_obj(const Image_info &info,
352
const st_bstream_item_info &item)
356
case BSTREAM_IT_TABLESPACE:
357
return info.get_ts(item.pos);
158
359
case BSTREAM_IT_DB:
159
return get_db(item->pos);
360
return info.get_db(item.pos);
161
362
case BSTREAM_IT_TABLE:
163
const st_bstream_table_info *ti= reinterpret_cast<const st_bstream_table_info*>(item);
164
return get_table(ti->snap_no,item->pos);
364
const st_bstream_table_info &ti=
365
reinterpret_cast<const st_bstream_table_info&>(item);
367
return info.get_table(ti.snap_num, item.pos);
167
370
case BSTREAM_IT_VIEW:
169
372
case BSTREAM_IT_SFUNC:
170
373
case BSTREAM_IT_EVENT:
171
374
case BSTREAM_IT_TRIGGER:
172
return get_db_object(item->pos);
376
const st_bstream_dbitem_info &it=
377
reinterpret_cast<const st_bstream_dbitem_info&>(item);
379
return info.get_db_object(it.db->base.pos, item.pos);
175
// TODO: warn or report error
181
Store in Backup_image all objects enumerated by the iterator.
183
int Image_info::add_objects(Db_item &dbi,
184
const enum_bstream_item_type type,
185
obs::ObjIterator &it)
191
while ((obj= it.next()))
192
if (!add_db_object(dbi, type, *obj))
201
Image_info::PerDb_item* Image_info::add_db_object(Db_item &dbi,
202
const enum_bstream_item_type type,
205
ulong pos= m_items.size();
207
PerDb_item *it= m_items.get_entry(pos);
220
Image_info::PerDb_item* Image_info::add_db_object(Db_item &dbi,
221
const enum_bstream_item_type type,
222
const ::String &name)
224
ulong pos= m_items.size();
226
PerDb_item *it= m_items.get_entry(pos);
235
it->m_db_name= dbi.name();
240
obs::Obj* Image_info::PerDb_item::obj_ptr(uint ver, ::String &sdata)
247
case BSTREAM_IT_VIEW:
248
m_obj= materialize_view(&m_db_name, &m_name, ver, &sdata); break;
249
case BSTREAM_IT_SPROC:
250
m_obj= materialize_stored_procedure(&m_db_name, &m_name, ver, &sdata); break;
251
case BSTREAM_IT_SFUNC:
252
m_obj= materialize_stored_function(&m_db_name, &m_name, ver, &sdata); break;
253
case BSTREAM_IT_EVENT:
254
m_obj= materialize_event(&m_db_name, &m_name, ver, &sdata); break;
255
case BSTREAM_IT_TRIGGER:
256
m_obj= materialize_trigger(&m_db_name, &m_name, ver, &sdata); break;
257
default: m_obj= NULL;
263
bool Image_info::Ditem_iterator::next()
266
ptr= ptr->next_table;
273
// advance to next element in other list if we are inside it
275
more= PerDb_iterator::next();
277
other_list= TRUE; // mark that we are now inside the other list
279
// return if there are no more elements in the other list
283
// find an element belonging to our database
286
PerDb_item *it= (PerDb_item*)PerDb_iterator::get_ptr();
291
if (it->m_db_name == db_name)
294
while (PerDb_iterator::next());
296
// we haven't found any object belonging to our database
300
387
} // backup namespace
303
/* catalogue services for backup stream library */
309
static uint cset_iter; ///< Used to implement trivial charset iterator.
310
static uint null_iter; ///< Used to implement trivial empty iterator.
312
void* bcat_iterator_get(st_bstream_image_header *catalogue, unsigned int type)
316
case BSTREAM_IT_PERDB:
318
new backup::Image_info::PerDb_iterator(*static_cast<backup::Image_info*>(catalogue));
320
case BSTREAM_IT_PERTABLE:
323
case BSTREAM_IT_CHARSET:
327
case BSTREAM_IT_USER:
330
case BSTREAM_IT_GLOBAL:
331
// only global items (for which meta-data is stored) are databases
334
new backup::Image_info::Db_iterator(*static_cast<backup::Image_info*>(catalogue));
335
// TODO: report error if iterator could not be created
343
struct st_bstream_item_info*
344
bcat_iterator_next(st_bstream_image_header *catalogue, void *iter)
346
/* If this is the null iterator, return NULL immediately */
347
if (iter == &null_iter)
350
static bstream_blob name= {NULL, NULL};
353
If it is cset iterator then cset_iter variable contains iterator position.
354
We return only 2 charsets: the utf8 charset used to encode all strings and
355
the default server charset.
357
if (iter == &cset_iter)
360
case 0: name.begin= (byte*)::my_charset_utf8_bin.csname; break;
361
case 1: name.begin= (byte*)::system_charset_info->csname; break;
362
default: name.begin= NULL; break;
365
name.end= name.begin ? name.begin + strlen((char*)name.begin) : NULL;
368
return name.begin ? (st_bstream_item_info*)&name : NULL;
372
In all other cases assume that iter points at instance of
373
@c Image_info::Iterator and use this instance to get next item.
375
const backup::Image_info::Item *ptr= (*(backup::Image_info::Iterator*)iter)++;
377
return ptr ? (st_bstream_item_info*)(ptr->info()) : NULL;
380
void bcat_iterator_free(st_bstream_image_header *catalogue, void *iter)
383
Do nothing for the null and cset iterators, but delete the
384
@c Image_info::Iterator object otherwise.
386
if (iter == &null_iter)
389
if (iter == &cset_iter)
392
delete (backup::Image_info::Iterator*)iter;
395
/* db-items iterator */
397
void* bcat_db_iterator_get(st_bstream_image_header *catalogue, struct st_bstream_db_info *db)
399
using namespace backup;
401
Image_info::Db_item *dbi = static_cast<Image_info::Db_item*>(db);
404
new Image_info::Ditem_iterator(*static_cast<backup::Image_info*>(catalogue),
408
struct st_bstream_dbitem_info*
409
bcat_db_iterator_next(st_bstream_image_header *catalogue,
410
struct st_bstream_db_info *db,
413
const backup::Image_info::Item *ptr= (*(backup::Image_info::Iterator*)iter)++;
415
return ptr ? (st_bstream_dbitem_info*)ptr->info() : NULL;
418
void bcat_db_iterator_free(st_bstream_image_header *catalogue,
419
struct st_bstream_db_info *db,
422
delete (backup::Image_info::Iterator*)iter;
389
template class Map<uint, backup::Image_info::Db>;