~jlukas79/+junk/mysql-server

« back to all changes in this revision

Viewing changes to sql/backup/api_types.h

manual merge 6.0-main --> 6.0-bka-review

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
   Classes @c Db_ref and @c Table_ref are used to identify databases and tables
41
41
   inside mysql server instance.
42
42
 
43
 
   These classes abstract the way a table or database is identified inside mysqld,
44
 
   so that when this changes (introduction of global db/table ids, introduction
45
 
   of catalogues) it is easy to adapt backup code to the new identification schema.
 
43
   These classes abstract the way a table or database is identified inside 
 
44
   mysqld, so that when this changes (introduction of global db/table ids, 
 
45
   introduction of catalogues) it is easy to adapt backup code to the new 
 
46
   identification schema.
46
47
 
47
48
   Regardless of the internal representation, classes provide methods returning
48
 
   db/table name as a @c String object. Also, each table belongs to some database
49
 
   and a method returning @c Db_ref object identifying this database is present. 
50
 
   For @c Db_ref objects there is @c catalog() method returning name of the 
51
 
   catalogue, but currently it always returns null string.
 
49
   db/table name as a @c String object. Also, each table belongs to some 
 
50
   database and a method returning @c Db_ref object identifying this database is
 
51
   present. For @c Db_ref objects there is @c catalog() method returning name of
 
52
   the catalogue, but currently it always returns null string.
52
53
 
53
54
   Classes are implemented so that the memory for storing names can be allocated
54
55
   outside an instance. This allows for sharing space used e.g., to store 
68
69
 public:
69
70
 
70
71
  // Construct invalid reference
71
 
  Db_ref(): m_name(NULL)
 
72
  Db_ref() :m_name(NULL)
72
73
  {}
73
74
 
74
75
  const bool is_valid() const
81
82
  { return my_null_string; }
82
83
 
83
84
  bool operator==(const Db_ref &db) const
84
 
  { return stringcmp(m_name,&db.name())==0; }
 
85
  { return stringcmp(m_name, &db.name()) == 0; }
85
86
 
86
87
  bool operator!=(const Db_ref &db) const
87
 
  { return ! this->operator==(db); }
 
88
  { return ! this->operator == (db); }
88
89
 
89
90
 protected:
90
91
 
91
92
  // Constructors are made protected as clients of this class are
92
93
  // not supposed to create instances (see comment inside Table_ref)
93
94
 
94
 
  Db_ref(const String &name): m_name(&name)
 
95
  Db_ref(const String &name) :m_name(&name)
95
96
  {}
96
97
 
97
98
  friend class Table_ref;
106
107
 public:
107
108
 
108
109
  // Construct invalid reference
109
 
  Table_ref(): m_name(NULL)
 
110
  Table_ref() :m_name(NULL)
110
111
  {}
111
112
 
112
113
  const bool is_valid() const
121
122
  bool operator==(const Table_ref &t) const
122
123
  {
123
124
    return m_db == t.db() &&
124
 
           stringcmp(m_name,&t.name()) == 0;
 
125
           stringcmp(m_name, &t.name()) == 0;
125
126
  }
126
127
 
127
128
  bool operator!=(const Table_ref &db) const
128
129
  { return ! this->operator==(db); }
129
130
 
130
 
  typedef char describe_buf[512];
131
 
 
132
 
  /// Produce string identifying the table (e.g. for error reporting)
133
 
  const char* describe(char *buf, size_t len) const
134
 
  {
135
 
    my_snprintf(buf,len,"%s.%s",db().name().ptr(),name().ptr());
136
 
    return buf;
137
 
  }
138
 
 
139
 
  const char* describe(describe_buf &buf) const
140
 
  { return describe(buf,sizeof(buf)); }
 
131
  typedef char name_buf[FN_REFLEN];
 
132
 
 
133
  // Produce string identifying the table (e.g. for error reporting)
 
134
  const char* describe(char *buf, size_t len) const;
 
135
  const char* describe(name_buf &buf) const
 
136
  { return describe(buf, sizeof(buf)); }
 
137
 
 
138
  // Produce string identifying the table in internal format. 
 
139
  const char* internal_name(char *buf, size_t len) const;
 
140
  const char* internal_name(name_buf &buf) const
 
141
  { return internal_name(buf, sizeof(buf)); };
141
142
  
142
143
 protected:
143
144
 
148
149
    when creating backup/restore driver.
149
150
  */
150
151
 
151
 
  Table_ref(const String &db, const String &name):
152
 
    m_db(db), m_name(&name)
 
152
  Table_ref(const String &db, const String &name)
 
153
    :m_db(db), m_name(&name)
153
154
  {}
154
155
};
155
156
 
174
175
   adds this interface to a list of tables represented by a linked list of
175
176
   @c TABLE_LIST structures as used elsewhere in the code. On the other hand, 
176
177
   much more space efficient implementations are possible, as for each table we 
177
 
   need to store only table's identity (db/table name). In any case, the interface
178
 
   to the list remains the same, as defined by this class.
179
 
 
180
 
   TODO: add iterators.
 
178
   need to store only table's identity (db/table name). In any case, the 
 
179
   interface to the list remains the same, as defined by this class.
181
180
 */
182
181
 
183
182
class Table_list
187
186
    virtual ~Table_list() {}
188
187
 
189
188
    /// Return reference to given list element. Elements are counted from 0.
190
 
    virtual Table_ref operator[](uint pos) const =0;
 
189
    virtual Table_ref operator[](ulong pos) const =0;
191
190
 
192
191
    /// Return number of elements in the list.
193
 
    virtual uint  count() const =0;
 
192
    virtual ulong count() const =0;
194
193
};
195
194
 
196
195
 
200
199
  @brief Used for data transfers between backup kernel and backup/restore
201
200
  drivers.
202
201
 
203
 
  Apart from allocated memory a @c Buffer structure contains fields informing about
204
 
  its size and holding other information about contained data. Buffers are
 
202
  Apart from allocated memory a @c Buffer structure contains fields informing 
 
203
  about its size and holding other information about contained data. Buffers are
205
204
  created and memory is allocated by backup kernel. It is also kernel's
206
205
  responsibility to write contents of buffers to a backup stream.
207
206
 
208
207
  Data created by a backup driver is opaque to the kernel. However, to support
209
208
  selective restores, each block of data can be assigned to one of the tables
210
 
  being backed-up. This is done by setting @c table_no member of the
 
209
  being backed-up. This is done by setting @c table_num member of the
211
210
  buffer structure to the number of the table to which this data belongs. Tables
212
211
  are numbered from 1 according to their position in the list passed when driver
213
212
  is created (@c m_tables member of @c Driver class). If
214
213
  some of the data doesn't correspond to any particular table, then
215
 
  @c table_no should be set to 0.
 
214
  @c table_num should be set to 0.
216
215
 
217
216
  This way, driver can create several "streams" of data blocks. For each table
218
217
  there is a stream corresponding to that table and there is one "shared stream"
219
 
  consisting of blocks with @c table_no set to 0. Upon restore, kernel
 
218
  consisting of blocks with @c table_num set to 0. Upon restore, kernel
220
219
  sends to a restore driver only blocks corresponding to the tables being
221
220
  restored plus all the blocks from the shared stream.
222
221
 
256
255
struct Buffer
257
256
{
258
257
  size_t  size;       ///< size of the buffer (of memory block pointed by data).
259
 
  uint    table_no;   ///< Number of the table to which data in the buffer belongs.
 
258
  uint    table_num;  ///< Number of the table to which data in the buffer belongs.
260
259
  bool    last;       ///< TRUE if this is last block of data in the stream.
261
260
  byte    *data;      ///< Pointer to data area.
262
261
 
263
 
  Buffer(): size(0),table_no(0),last(FALSE), data(NULL)
 
262
  Buffer() :size(0), table_num(0), last(FALSE), data(NULL)
264
263
  {}
265
264
 
266
265
  void reset(size_t len)
267
266
  {
268
267
    size= len;
269
 
    table_no= 0;
 
268
    table_num= 0;
270
269
    last= FALSE;
271
270
  }
272
271
};
280
279
 
281
280
typedef backup::result_t Backup_result_t;
282
281
typedef backup::Engine   Backup_engine;
283
 
typedef Backup_result_t backup_factory(::handlerton *,Backup_engine*&);
 
282
typedef Backup_result_t backup_factory(::handlerton *, Backup_engine*&);
284
283
 
285
284
#endif
286
285