~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/transaction_log/info_schema.cc

  • Committer: Monty Taylor
  • Date: 2009-12-25 08:50:15 UTC
  • mto: This revision was merged to the branch mainline in revision 1255.
  • Revision ID: mordred@inaugust.com-20091225085015-83sux5qsvy312gew
MEM_ROOT == memory::Root

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
 
3
 *
 
4
 *  Copyright (C) 2009 Sun Microsystems
 
5
 *
 
6
 *  Authors:
 
7
 *
 
8
 *  Jay Pipes <joinfu@sun.com>
 
9
 *
 
10
 *  This program is free software; you can redistribute it and/or modify
 
11
 *  it under the terms of the GNU General Public License as published by
 
12
 *  the Free Software Foundation; either version 2 of the License, or
 
13
 *  (at your option) any later version.
 
14
 *
 
15
 *  This program is distributed in the hope that it will be useful,
 
16
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
18
 *  GNU General Public License for more details.
 
19
 *
 
20
 *  You should have received a copy of the GNU General Public License
 
21
 *  along with this program; if not, write to the Free Software
 
22
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
23
 */
 
24
 
 
25
/**
 
26
 * @file
 
27
 *
 
28
 * Implements the INFORMATION_SCHEMA views which allows querying the
 
29
 * state of the transaction log and its entries.
 
30
 *
 
31
 * There are three views defined for the transaction log:
 
32
 *
 
33
 * CREATE TABLE INFORMATION_SCHEMA.TRANSACTION_LOG (
 
34
 *   FILE_NAME VARCHAR NOT NULL
 
35
 * , FILE_LENGTH BIGINT NOT NULL
 
36
 * , NUM_LOG_ENTRIES BIGINT NOT NULL
 
37
 * , NUM_TRANSACTIONS BIGINT NOT NULL
 
38
 * , MIN_TRANSACTION_ID BIGINT NOT NULL
 
39
 * , MAX_TRANSACTION_ID BIGINT NOT NULL
 
40
 * , MIN_END_TIMESTAMP BIGINT NOT NULL
 
41
 * , MAX_END_TIMESTAMP BIGINT NOT NULL
 
42
 * );
 
43
 * 
 
44
 * CREATE TABLE INFORMATION_SCHEMA.TRANSACTION_LOG_ENTRIES (
 
45
 *   ENTRY_OFFSET BIGINT NOT NULL
 
46
 * , ENTRY_TYPE VARCHAR NOT NULL
 
47
 * , ENTRY_LENGTH BIGINT NOT NULL
 
48
 * );
 
49
 * 
 
50
 * CREATE TABLE INFORMATION_SCHEMA.TRANSACTION_LOG_TRANSACTIONS (
 
51
 *   ENTRY_OFFSET BIGINT NOT NULL
 
52
 * , TRANSACTION_ID BIGINT NOT NULL
 
53
 * , SERVER_ID INT NOT NULL
 
54
 * , START_TIMESTAMP BIGINT NOT NULL
 
55
 * , END_TIMESTAMP BIGINT NOT NULL
 
56
 * , NUM_STATEMENTS INT NOT NULL
 
57
 * , CHECKSUM BIGINT NOT NULL // had to be BIGINT b/c we have no unsigned int.
 
58
 * );
 
59
 */
 
60
 
 
61
#include "config.h"
 
62
#include <drizzled/session.h>
 
63
#include <drizzled/show.h>
 
64
 
 
65
#include "transaction_log.h"
 
66
#include "transaction_log_entry.h"
 
67
#include "transaction_log_index.h"
 
68
#include "info_schema.h"
 
69
 
 
70
#include <fcntl.h>
 
71
#include <sys/stat.h>
 
72
 
 
73
#include <string>
 
74
#include <vector>
 
75
#include <functional>
 
76
 
 
77
using namespace std;
 
78
using namespace drizzled;
 
79
 
 
80
extern TransactionLog *transaction_log; /* the singleton transaction log */
 
81
extern TransactionLogIndex *transaction_log_index; /* the singleton transaction log index */
 
82
 
 
83
class DeletePtr
 
84
{
 
85
public:
 
86
  template<typename T>
 
87
  inline void operator()(const T *ptr) const
 
88
  {
 
89
    delete ptr;
 
90
  }
 
91
};
 
92
 
 
93
/*
 
94
 * Vectors of columns for I_S tables.
 
95
 */
 
96
static vector<const plugin::ColumnInfo *> *transaction_log_view_columns= NULL;
 
97
static vector<const plugin::ColumnInfo *> *transaction_log_entries_view_columns= NULL;
 
98
static vector<const plugin::ColumnInfo *> *transaction_log_transactions_view_columns= NULL;
 
99
 
 
100
/*
 
101
 * Methods for I_S tables.
 
102
 */
 
103
static plugin::InfoSchemaMethods *transaction_log_view_methods= NULL;
 
104
static plugin::InfoSchemaMethods *transaction_log_entries_view_methods= NULL;
 
105
static plugin::InfoSchemaMethods *transaction_log_transactions_view_methods= NULL;
 
106
 
 
107
/*
 
108
 * I_S tables.
 
109
 */
 
110
plugin::InfoSchemaTable *transaction_log_view= NULL;
 
111
plugin::InfoSchemaTable *transaction_log_entries_view= NULL;
 
112
plugin::InfoSchemaTable *transaction_log_transactions_view= NULL;
 
113
 
 
114
static bool createTransactionLogViewColumns(vector<const drizzled::plugin::ColumnInfo *> &cols);
 
115
static bool createTransactionLogEntriesViewColumns(vector<const drizzled::plugin::ColumnInfo *> &cols);
 
116
static bool createTransactionLogTransactionsViewColumns(vector<const drizzled::plugin::ColumnInfo *> &cols);
 
117
 
 
118
int TransactionLogViewISMethods::fillTable(Session *,
 
119
                                           Table *table,
 
120
                                           plugin::InfoSchemaTable *schema_table)
 
121
{
 
122
  if (transaction_log != NULL)
 
123
  {
 
124
    table->restoreRecordAsDefault();
 
125
 
 
126
    table->setWriteSet(0);
 
127
    table->setWriteSet(1);
 
128
    table->setWriteSet(2);
 
129
    table->setWriteSet(3);
 
130
    table->setWriteSet(4);
 
131
    table->setWriteSet(5);
 
132
    table->setWriteSet(6);
 
133
    table->setWriteSet(7);
 
134
 
 
135
    const string &filename= transaction_log->getLogFilename();
 
136
    table->field[0]->store(filename.c_str(), filename.length(), system_charset_info);
 
137
 
 
138
    /* Grab the file size of the log */
 
139
    struct stat file_stat;
 
140
    (void) stat(filename.c_str(), &file_stat);
 
141
 
 
142
    table->field[1]->store(static_cast<int64_t>(file_stat.st_size));
 
143
 
 
144
    table->field[2]->store(static_cast<int64_t>(transaction_log_index->getNumLogEntries()));
 
145
    table->field[3]->store(static_cast<int64_t>(transaction_log_index->getNumTransactionEntries()));
 
146
    table->field[4]->store(static_cast<int64_t>(transaction_log_index->getMinTransactionId()));
 
147
    table->field[5]->store(static_cast<int64_t>(transaction_log_index->getMaxTransactionId()));
 
148
    table->field[6]->store(static_cast<int64_t>(transaction_log_index->getMinEndTimestamp()));
 
149
    table->field[7]->store(static_cast<int64_t>(transaction_log_index->getMaxEndTimestamp()));
 
150
 
 
151
    /* store the actual record now */
 
152
    schema_table->addRow(table->record[0], table->s->reclength);
 
153
  }
 
154
  return 0;
 
155
}
 
156
 
 
157
int TransactionLogEntriesViewISMethods::fillTable(Session *,
 
158
                                                  Table *table,
 
159
                                                  plugin::InfoSchemaTable *schema_table)
 
160
{
 
161
  if (transaction_log != NULL)
 
162
  {
 
163
    /** @todo trigger indexing update here. */
 
164
    for (TransactionLog::Entries::iterator entry_iter= transaction_log_index->getEntries().begin();
 
165
         entry_iter != transaction_log_index->getEntries().end();
 
166
         ++entry_iter)
 
167
    {
 
168
      TransactionLogEntry &entry= *entry_iter;
 
169
 
 
170
      table->restoreRecordAsDefault();
 
171
 
 
172
      table->setWriteSet(0);
 
173
      table->setWriteSet(1);
 
174
      table->setWriteSet(2);
 
175
 
 
176
      table->field[0]->store(static_cast<int64_t>(entry.getOffset()));
 
177
      const char *type_string= entry.getTypeAsString();
 
178
      table->field[1]->store(type_string, strlen(type_string), system_charset_info);
 
179
      table->field[2]->store(static_cast<int64_t>(entry.getLengthInBytes()));
 
180
 
 
181
      /* store the actual record now */
 
182
      schema_table->addRow(table->record[0], table->s->reclength);
 
183
    }
 
184
  }
 
185
  return 0;
 
186
}
 
187
 
 
188
int TransactionLogTransactionsViewISMethods::fillTable(Session *,
 
189
                                                       Table *table,
 
190
                                                       plugin::InfoSchemaTable *schema_table)
 
191
{
 
192
  if (transaction_log != NULL)
 
193
  {
 
194
    /** @todo trigger indexing update here. */
 
195
    for (TransactionLog::TransactionEntries::iterator entry_iter= transaction_log_index->getTransactionEntries().begin();
 
196
         entry_iter != transaction_log_index->getTransactionEntries().end();
 
197
         ++entry_iter)
 
198
    {
 
199
      TransactionLogTransactionEntry &entry= *entry_iter;
 
200
 
 
201
      table->restoreRecordAsDefault();
 
202
 
 
203
      table->setWriteSet(0);
 
204
      table->setWriteSet(1);
 
205
      table->setWriteSet(2);
 
206
      table->setWriteSet(3);
 
207
      table->setWriteSet(4);
 
208
      table->setWriteSet(5);
 
209
      table->setWriteSet(6);
 
210
 
 
211
      table->field[0]->store(static_cast<int64_t>(entry.getOffset()));
 
212
      table->field[1]->store(static_cast<int64_t>(entry.getTransactionId()));
 
213
      table->field[2]->store(static_cast<int64_t>(entry.getServerId()));
 
214
      table->field[3]->store(static_cast<int64_t>(entry.getStartTimestamp()));
 
215
      table->field[4]->store(static_cast<int64_t>(entry.getEndTimestamp()));
 
216
      table->field[5]->store(static_cast<int64_t>(entry.getNumStatements()));
 
217
      table->field[6]->store(static_cast<int64_t>(entry.getChecksum()));
 
218
 
 
219
      /* store the actual record now */
 
220
      schema_table->addRow(table->record[0], table->s->reclength);
 
221
    }
 
222
  }
 
223
  return 0;
 
224
}
 
225
 
 
226
static bool createTransactionLogViewColumns(vector<const plugin::ColumnInfo *> &cols)
 
227
{
 
228
  /*
 
229
   * Create each column for the INFORMATION_SCHEMA.TRANSACTION_LOG view
 
230
   */
 
231
  const plugin::ColumnInfo *file_name_col= 
 
232
    new (nothrow) plugin::ColumnInfo("FILE_NAME",
 
233
                                      255,
 
234
                                      DRIZZLE_TYPE_VARCHAR,
 
235
                                      0,
 
236
                                      0, 
 
237
                                      "Filename of the transaction log");
 
238
  if (file_name_col == NULL)
 
239
  {
 
240
    errmsg_printf(ERRMSG_LVL_ERROR, _("Failed to allocate ColumnInfo %s.  Got error: %s\n"), 
 
241
                  "FILE_NAME", 
 
242
                  strerror(errno));
 
243
    return true;
 
244
  }
 
245
 
 
246
  const plugin::ColumnInfo *file_length_col= 
 
247
    new (nothrow) plugin::ColumnInfo("FILE_LENGTH",
 
248
                                      8,
 
249
                                      DRIZZLE_TYPE_LONGLONG,
 
250
                                      0,
 
251
                                      0, 
 
252
                                      "Length in bytes of the transaction log");
 
253
  if (file_length_col == NULL)
 
254
  {
 
255
    errmsg_printf(ERRMSG_LVL_ERROR, _("Failed to allocate ColumnInfo %s.  Got error: %s\n"), 
 
256
                  "FILE_LENGTH", 
 
257
                  strerror(errno));
 
258
    return true;
 
259
  }
 
260
 
 
261
  const plugin::ColumnInfo *num_log_entries_col= 
 
262
    new (nothrow) plugin::ColumnInfo("NUM_LOG_ENTRIES",
 
263
                                      8,
 
264
                                      DRIZZLE_TYPE_LONGLONG,
 
265
                                      0,
 
266
                                      0, 
 
267
                                      "Total number of entries in the transaction log");
 
268
  if (num_log_entries_col == NULL)
 
269
  {
 
270
    errmsg_printf(ERRMSG_LVL_ERROR, _("Failed to allocate ColumnInfo %s.  Got error: %s\n"), 
 
271
                  "NUM_LOG_ENTRIES", 
 
272
                  strerror(errno));
 
273
    return true;
 
274
  }
 
275
 
 
276
  const plugin::ColumnInfo *num_transactions_col= 
 
277
    new (nothrow) plugin::ColumnInfo("NUM_TRANSACTIONS",
 
278
                                      8,
 
279
                                      DRIZZLE_TYPE_LONGLONG,
 
280
                                      0,
 
281
                                      0, 
 
282
                                      "Total number of transaction message entries in the transaction log");
 
283
  if (num_transactions_col == NULL)
 
284
  {
 
285
    errmsg_printf(ERRMSG_LVL_ERROR, _("Failed to allocate ColumnInfo %s.  Got error: %s\n"), 
 
286
                  "NUM_TRANSACTIONS", 
 
287
                  strerror(errno));
 
288
    return true;
 
289
  }
 
290
 
 
291
  const plugin::ColumnInfo *min_transaction_id_col= 
 
292
    new (nothrow) plugin::ColumnInfo("MIN_TRANSACTION_ID",
 
293
                                      8,
 
294
                                      DRIZZLE_TYPE_LONGLONG,
 
295
                                      0,
 
296
                                      0, 
 
297
                                      "Minimum transaction ID in the transaction log");
 
298
  if (min_transaction_id_col == NULL)
 
299
  {
 
300
    errmsg_printf(ERRMSG_LVL_ERROR, _("Failed to allocate ColumnInfo %s.  Got error: %s\n"), 
 
301
                  "MIN_TRANSACTION_ID", 
 
302
                  strerror(errno));
 
303
    return true;
 
304
  }
 
305
 
 
306
  const plugin::ColumnInfo *max_transaction_id_col= 
 
307
    new (nothrow) plugin::ColumnInfo("MAX_TRANSACTION_ID",
 
308
                                      8,
 
309
                                      DRIZZLE_TYPE_LONGLONG,
 
310
                                      0,
 
311
                                      0, 
 
312
                                      "Maximum transaction ID in the transaction log");
 
313
  if (max_transaction_id_col == NULL)
 
314
  {
 
315
    errmsg_printf(ERRMSG_LVL_ERROR, _("Failed to allocate ColumnInfo %s.  Got error: %s\n"), 
 
316
                  "MAX_TRANSACTION_ID", 
 
317
                  strerror(errno));
 
318
    return true;
 
319
  }
 
320
 
 
321
  const plugin::ColumnInfo *min_timestamp_col= 
 
322
    new (nothrow) plugin::ColumnInfo("MIN_END_TIMESTAMP",
 
323
                                      8,
 
324
                                      DRIZZLE_TYPE_LONGLONG,
 
325
                                      0,
 
326
                                      0, 
 
327
                                      "Minimum end timestamp for a transaction in the transaction log");
 
328
  if (min_timestamp_col == NULL)
 
329
  {
 
330
    errmsg_printf(ERRMSG_LVL_ERROR, _("Failed to allocate ColumnInfo %s.  Got error: %s\n"), 
 
331
                  "MIN_END_TIMESTAMP", 
 
332
                  strerror(errno));
 
333
    return true;
 
334
  }
 
335
 
 
336
  const plugin::ColumnInfo *max_timestamp_col= 
 
337
    new (nothrow) plugin::ColumnInfo("MAX_END_TIMESTAMP",
 
338
                                      8,
 
339
                                      DRIZZLE_TYPE_LONGLONG,
 
340
                                      0,
 
341
                                      0, 
 
342
                                      "Maximum end timestamp for a transaction in the transaction log");
 
343
  if (max_timestamp_col == NULL)
 
344
  {
 
345
    errmsg_printf(ERRMSG_LVL_ERROR, _("Failed to allocate ColumnInfo %s.  Got error: %s\n"), 
 
346
                  "MAX_END_TIMESTAMP", 
 
347
                  strerror(errno));
 
348
    return true;
 
349
  }
 
350
 
 
351
  cols.push_back(file_name_col);
 
352
  cols.push_back(file_length_col);
 
353
  cols.push_back(num_log_entries_col);
 
354
  cols.push_back(num_transactions_col);
 
355
  cols.push_back(min_transaction_id_col);
 
356
  cols.push_back(max_transaction_id_col);
 
357
  cols.push_back(min_timestamp_col);
 
358
  cols.push_back(max_timestamp_col);
 
359
 
 
360
  return false;
 
361
}
 
362
 
 
363
static bool createTransactionLogEntriesViewColumns(vector<const plugin::ColumnInfo *> &cols)
 
364
{
 
365
  /*
 
366
   * Create each column for the INFORMATION_SCHEMA.TRANSACTION_LOG_ENTRIES view
 
367
   */
 
368
  const plugin::ColumnInfo *entry_offset_col= 
 
369
    new (nothrow) plugin::ColumnInfo("ENTRY_OFFSET",
 
370
                                      8,
 
371
                                      DRIZZLE_TYPE_LONGLONG,
 
372
                                      0,
 
373
                                      0, 
 
374
                                      "Offset of this entry into the transaction log");
 
375
  if (entry_offset_col == NULL)
 
376
  {
 
377
    errmsg_printf(ERRMSG_LVL_ERROR, _("Failed to allocate ColumnInfo %s.  Got error: %s\n"), 
 
378
                  "ENTRY_OFFSET", 
 
379
                  strerror(errno));
 
380
    return true;
 
381
  }
 
382
 
 
383
  const plugin::ColumnInfo *entry_type_col= 
 
384
    new (nothrow) plugin::ColumnInfo("ENTRY_TYPE",
 
385
                                      32,
 
386
                                      DRIZZLE_TYPE_VARCHAR,
 
387
                                      0,
 
388
                                      0, 
 
389
                                      "Type of this entry");
 
390
  if (entry_type_col == NULL)
 
391
  {
 
392
    errmsg_printf(ERRMSG_LVL_ERROR, _("Failed to allocate ColumnInfo %s.  Got error: %s\n"), 
 
393
                  "ENTRY_TYPE", 
 
394
                  strerror(errno));
 
395
    return true;
 
396
  }
 
397
 
 
398
  const plugin::ColumnInfo *entry_length_col= 
 
399
    new (nothrow) plugin::ColumnInfo("ENTRY_LENGTH",
 
400
                                      8,
 
401
                                      DRIZZLE_TYPE_LONGLONG,
 
402
                                      0,
 
403
                                      0, 
 
404
                                      "Length in bytes of this entry");
 
405
  if (entry_length_col == NULL)
 
406
  {
 
407
    errmsg_printf(ERRMSG_LVL_ERROR, _("Failed to allocate ColumnInfo %s.  Got error: %s\n"), 
 
408
                  "ENTRY_LENGTH", 
 
409
                  strerror(errno));
 
410
    return true;
 
411
  }
 
412
 
 
413
  cols.push_back(entry_offset_col);
 
414
  cols.push_back(entry_type_col);
 
415
  cols.push_back(entry_length_col);
 
416
 
 
417
  return false;
 
418
}
 
419
 
 
420
static bool createTransactionLogTransactionsViewColumns(vector<const plugin::ColumnInfo *> &cols)
 
421
{
 
422
  /*
 
423
   * Create each column for the INFORMATION_SCHEMA.TRANSACTION_LOG_TRANSACTIONS view
 
424
   */
 
425
  const plugin::ColumnInfo *entry_offset_col= 
 
426
    new (nothrow) plugin::ColumnInfo("ENTRY_OFFSET",
 
427
                                      8,
 
428
                                      DRIZZLE_TYPE_LONGLONG,
 
429
                                      0,
 
430
                                      0, 
 
431
                                      "Offset of this entry into the transaction log");
 
432
  if (entry_offset_col == NULL)
 
433
  {
 
434
    errmsg_printf(ERRMSG_LVL_ERROR, _("Failed to allocate ColumnInfo %s.  Got error: %s\n"), 
 
435
                  "ENTRY_OFFSET", 
 
436
                  strerror(errno));
 
437
    return true;
 
438
  }
 
439
 
 
440
  const plugin::ColumnInfo *transaction_id_col= 
 
441
    new (nothrow) plugin::ColumnInfo("TRANSACTION_ID",
 
442
                                      8,
 
443
                                      DRIZZLE_TYPE_LONGLONG,
 
444
                                      0,
 
445
                                      0, 
 
446
                                      "Transaction ID for this entry");
 
447
  if (transaction_id_col == NULL)
 
448
  {
 
449
    errmsg_printf(ERRMSG_LVL_ERROR, _("Failed to allocate ColumnInfo %s.  Got error: %s\n"), 
 
450
                  "TRANSACTION_ID", 
 
451
                  strerror(errno));
 
452
    return true;
 
453
  }
 
454
 
 
455
  const plugin::ColumnInfo *server_id_col= 
 
456
    new (nothrow) plugin::ColumnInfo("SERVER_ID",
 
457
                                      8,
 
458
                                      DRIZZLE_TYPE_LONGLONG,
 
459
                                      0,
 
460
                                      0, 
 
461
                                      "Server ID for this entry");
 
462
  if (server_id_col == NULL)
 
463
  {
 
464
    errmsg_printf(ERRMSG_LVL_ERROR, _("Failed to allocate ColumnInfo %s.  Got error: %s\n"), 
 
465
                  "SERVER_ID", 
 
466
                  strerror(errno));
 
467
    return true;
 
468
  }
 
469
 
 
470
  const plugin::ColumnInfo *start_timestamp_col= 
 
471
    new (nothrow) plugin::ColumnInfo("START_TIMESTAMP",
 
472
                                      8,
 
473
                                      DRIZZLE_TYPE_LONGLONG,
 
474
                                      0,
 
475
                                      0, 
 
476
                                      "Start timestamp for this transaction");
 
477
  if (start_timestamp_col == NULL)
 
478
  {
 
479
    errmsg_printf(ERRMSG_LVL_ERROR, _("Failed to allocate ColumnInfo %s.  Got error: %s\n"), 
 
480
                  "START_TIMESTAMP", 
 
481
                  strerror(errno));
 
482
    return true;
 
483
  }
 
484
 
 
485
  const plugin::ColumnInfo *end_timestamp_col= 
 
486
    new (nothrow) plugin::ColumnInfo("END_TIMESTAMP",
 
487
                                      8,
 
488
                                      DRIZZLE_TYPE_LONGLONG,
 
489
                                      0,
 
490
                                      0, 
 
491
                                      "End timestamp for this transaction");
 
492
  if (end_timestamp_col == NULL)
 
493
  {
 
494
    errmsg_printf(ERRMSG_LVL_ERROR, _("Failed to allocate ColumnInfo %s.  Got error: %s\n"), 
 
495
                  "END_TIMESTAMP", 
 
496
                  strerror(errno));
 
497
    return true;
 
498
  }
 
499
 
 
500
  const plugin::ColumnInfo *num_statements_col= 
 
501
    new (nothrow) plugin::ColumnInfo("NUM_STATEMENTS",
 
502
                                      8,
 
503
                                      DRIZZLE_TYPE_LONGLONG,
 
504
                                      0,
 
505
                                      0, 
 
506
                                      "Number of statements in this transaction");
 
507
  if (num_statements_col == NULL)
 
508
  {
 
509
    errmsg_printf(ERRMSG_LVL_ERROR, _("Failed to allocate ColumnInfo %s.  Got error: %s\n"), 
 
510
                  "NUM_STATEMENTS", 
 
511
                  strerror(errno));
 
512
    return true;
 
513
  }
 
514
 
 
515
  const plugin::ColumnInfo *checksum_col= 
 
516
    new (nothrow) plugin::ColumnInfo("CHECKSUM",
 
517
                                      8,
 
518
                                      DRIZZLE_TYPE_LONGLONG,
 
519
                                      0,
 
520
                                      0, 
 
521
                                      "Checksum of this transaction");
 
522
  if (checksum_col == NULL)
 
523
  {
 
524
    errmsg_printf(ERRMSG_LVL_ERROR, _("Failed to allocate ColumnInfo %s.  Got error: %s\n"), 
 
525
                  "CHECKSUM", 
 
526
                  strerror(errno));
 
527
    return true;
 
528
  }
 
529
 
 
530
  cols.push_back(entry_offset_col);
 
531
  cols.push_back(transaction_id_col);
 
532
  cols.push_back(server_id_col);
 
533
  cols.push_back(start_timestamp_col);
 
534
  cols.push_back(end_timestamp_col);
 
535
  cols.push_back(num_statements_col);
 
536
  cols.push_back(checksum_col);
 
537
 
 
538
  return false;
 
539
}
 
540
 
 
541
bool initViewColumns()
 
542
{
 
543
  transaction_log_view_columns= new (nothrow) vector<const plugin::ColumnInfo *>;
 
544
  if (transaction_log_view_columns == NULL)
 
545
  {
 
546
    return true;
 
547
  }
 
548
  transaction_log_entries_view_columns= new (nothrow) vector<const plugin::ColumnInfo *>;
 
549
  if (transaction_log_entries_view_columns == NULL)
 
550
  {
 
551
    return true;
 
552
  }
 
553
  transaction_log_transactions_view_columns= new (nothrow) vector<const plugin::ColumnInfo *>;
 
554
  if (transaction_log_transactions_view_columns == NULL)
 
555
  {
 
556
    return true;
 
557
  }
 
558
 
 
559
  if (createTransactionLogViewColumns(*transaction_log_view_columns))
 
560
  {
 
561
    return true;
 
562
  }
 
563
 
 
564
  if (createTransactionLogEntriesViewColumns(*transaction_log_entries_view_columns))
 
565
  {
 
566
    return true;
 
567
  }
 
568
 
 
569
  if (createTransactionLogTransactionsViewColumns(*transaction_log_transactions_view_columns))
 
570
  {
 
571
    return true;
 
572
  }
 
573
 
 
574
  return false;
 
575
}
 
576
 
 
577
static void clearViewColumns(vector<const plugin::ColumnInfo *> &cols)
 
578
{
 
579
  for_each(cols.begin(), cols.end(), DeletePtr());
 
580
  cols.clear();
 
581
}
 
582
 
 
583
void cleanupViewColumns()
 
584
{
 
585
  clearViewColumns(*transaction_log_view_columns);
 
586
  delete transaction_log_view_columns;
 
587
  clearViewColumns(*transaction_log_entries_view_columns);
 
588
  delete transaction_log_entries_view_columns;
 
589
  clearViewColumns(*transaction_log_transactions_view_columns);
 
590
  delete transaction_log_transactions_view_columns;
 
591
}
 
592
 
 
593
bool initViewMethods()
 
594
{
 
595
  transaction_log_view_methods= new (nothrow) TransactionLogViewISMethods();
 
596
  if (transaction_log_view_methods == NULL)
 
597
  {
 
598
    errmsg_printf(ERRMSG_LVL_ERROR, _("Failed to allocate TransactionLogViewISMethods.  Got error: %s\n"), 
 
599
                  strerror(errno));
 
600
    return true;
 
601
  }
 
602
 
 
603
  transaction_log_entries_view_methods= new (nothrow) TransactionLogEntriesViewISMethods();
 
604
  if (transaction_log_entries_view_methods == NULL)
 
605
  {
 
606
    errmsg_printf(ERRMSG_LVL_ERROR, _("Failed to allocate TransactionLogEntriesViewISMethods.  Got error: %s\n"), 
 
607
                  strerror(errno));
 
608
    return true;
 
609
  }
 
610
 
 
611
  transaction_log_transactions_view_methods= new (nothrow) TransactionLogTransactionsViewISMethods();
 
612
  if (transaction_log_transactions_view_methods == NULL)
 
613
  {
 
614
    errmsg_printf(ERRMSG_LVL_ERROR, _("Failed to allocate TransactionLogTransactionsViewISMethods.  Got error: %s\n"), 
 
615
                  strerror(errno));
 
616
    return true;
 
617
  }
 
618
 
 
619
  return false;
 
620
}
 
621
 
 
622
void cleanupViewMethods()
 
623
{
 
624
  delete transaction_log_view_methods;
 
625
  delete transaction_log_entries_view_methods;
 
626
  delete transaction_log_transactions_view_methods;
 
627
}
 
628
 
 
629
bool initViews()
 
630
{
 
631
  transaction_log_view= 
 
632
    new (nothrow) plugin::InfoSchemaTable("TRANSACTION_LOG",
 
633
                                          *transaction_log_view_columns,
 
634
                                          -1, -1, false, false, 0,
 
635
                                          transaction_log_view_methods);
 
636
  if (transaction_log_view == NULL)
 
637
  {
 
638
    errmsg_printf(ERRMSG_LVL_ERROR, _("Failed to allocate InfoSchemaTable for %s.  Got error: %s\n"), 
 
639
                  "TRANSACTION_LOG",
 
640
                  strerror(errno));
 
641
    return true;
 
642
  }
 
643
 
 
644
  transaction_log_entries_view= 
 
645
    new (nothrow) plugin::InfoSchemaTable("TRANSACTION_LOG_ENTRIES",
 
646
                                          *transaction_log_entries_view_columns,
 
647
                                          -1, -1, false, false, 0,
 
648
                                          transaction_log_entries_view_methods);
 
649
  if (transaction_log_entries_view == NULL)
 
650
  {
 
651
    errmsg_printf(ERRMSG_LVL_ERROR, _("Failed to allocate InfoSchemaTable for %s.  Got error: %s\n"), 
 
652
                  "TRANSACTION_LOG_ENTRIES",
 
653
                  strerror(errno));
 
654
    return true;
 
655
  }
 
656
 
 
657
  transaction_log_transactions_view= 
 
658
    new (nothrow) plugin::InfoSchemaTable("TRANSACTION_LOG_TRANSACTIONS",
 
659
                                          *transaction_log_transactions_view_columns,
 
660
                                          -1, -1, false, false, 0,
 
661
                                          transaction_log_transactions_view_methods);
 
662
  if (transaction_log_transactions_view == NULL)
 
663
  {
 
664
    errmsg_printf(ERRMSG_LVL_ERROR, _("Failed to allocate InfoSchemaTable for %s.  Got error: %s\n"), 
 
665
                  "TRANSACTION_LOG_TRANSACTIONS",
 
666
                  strerror(errno));
 
667
    return true;
 
668
  }
 
669
 
 
670
  return false;
 
671
}
 
672
 
 
673
void cleanupViews()
 
674
{
 
675
  delete transaction_log_view;
 
676
  delete transaction_log_entries_view;
 
677
  delete transaction_log_transactions_view;
 
678
}