1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2009 Sun Microsystems
8
* Jay Pipes <joinfu@sun.com>
9
* Joseph Daly <skinny.moey@gmail.com>
11
* This program is free software; you can redistribute it and/or modify
12
* it under the terms of the GNU General Public License as published by
13
* the Free Software Foundation; either version 2 of the License, or
14
* (at your option) any later version.
16
* This program is distributed in the hope that it will be useful,
17
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
* GNU General Public License for more details.
21
* You should have received a copy of the GNU General Public License
22
* along with this program; if not, write to the Free Software
23
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29
* Implements the DATA_DICTIONARY views which allows querying the
30
* state of the transaction log and its entries.
32
* There are three views defined for the transaction log:
34
* CREATE TABLE DATA_DICTIONARY.TRANSACTION_LOG (
35
* FILE_NAME VARCHAR NOT NULL
36
* , FILE_LENGTH BIGINT NOT NULL
37
* , NUM_LOG_ENTRIES BIGINT NOT NULL
38
* , NUM_TRANSACTIONS BIGINT NOT NULL
39
* , MIN_TRANSACTION_ID BIGINT NOT NULL
40
* , MAX_TRANSACTION_ID BIGINT NOT NULL
41
* , MIN_END_TIMESTAMP BIGINT NOT NULL
42
* , MAX_END_TIMESTAMP BIGINT NOT NULL
45
* CREATE TABLE DATA_DICTIONARY.TRANSACTION_LOG_ENTRIES (
46
* ENTRY_OFFSET BIGINT NOT NULL
47
* , ENTRY_TYPE VARCHAR NOT NULL
48
* , ENTRY_LENGTH BIGINT NOT NULL
51
* CREATE TABLE DATA_DICTIONARY.TRANSACTION_LOG_TRANSACTIONS (
52
* ENTRY_OFFSET BIGINT NOT NULL
53
* , TRANSACTION_ID BIGINT NOT NULL
54
* , SERVER_ID BIGINT NOT NULL
55
* , START_TIMESTAMP BIGINT NOT NULL
56
* , END_TIMESTAMP BIGINT NOT NULL
57
* , NUM_STATEMENTS BIGINT NOT NULL
58
* , CHECKSUM BIGINT NOT NULL
63
#include "data_dictionary_schema.h"
64
#include "transaction_log_index.h"
70
using namespace drizzled;
72
extern TransactionLog *transaction_log; /* the singleton transaction log */
73
extern TransactionLogIndex *transaction_log_index; /* the singleton transaction log index */
77
* TRANSACTION_LOG_INFO
81
TransactionLogTool::TransactionLogTool() :
82
plugin::TableFunction("DATA_DICTIONARY", "TRANSACTION_LOG")
84
add_field("FILE_NAME");
85
add_field("FILE_LENGTH", plugin::TableFunction::NUMBER);
86
add_field("NUM_LOG_ENTRIES", plugin::TableFunction::NUMBER);
87
add_field("NUM_TRANSACTIONS", plugin::TableFunction::NUMBER);
88
add_field("MIN_TRANSACTION_ID", plugin::TableFunction::NUMBER);
89
add_field("MAX_TRANSACTION_ID", plugin::TableFunction::NUMBER);
90
add_field("MIN_END_TIMESTAMP", plugin::TableFunction::NUMBER);
91
add_field("MAX_END_TIMESTAMP", plugin::TableFunction::NUMBER);
94
TransactionLogTool::Generator::Generator(Field **arg) :
95
plugin::TableFunction::Generator(arg)
100
bool TransactionLogTool::Generator::populate()
107
const string &filename= transaction_log->getLogFilename();
108
push(filename.c_str());
110
/* Grab the file size of the log */
111
struct stat file_stat;
112
(void) stat(filename.c_str(), &file_stat);
113
push(file_stat.st_size);
115
push(transaction_log_index->getNumLogEntries());
116
push(transaction_log_index->getNumTransactionEntries());
117
push(transaction_log_index->getMinTransactionId());
118
push(transaction_log_index->getMaxTransactionId());
119
push(transaction_log_index->getMinEndTimestamp());
120
push(transaction_log_index->getMaxEndTimestamp());
128
* TRANSACTION_LOG_ENTRIES view
132
TransactionLogEntriesTool::TransactionLogEntriesTool() :
133
plugin::TableFunction("DATA_DICTIONARY", "TRANSACTION_LOG_ENTRIES")
135
add_field("ENTRY_OFFSET", plugin::TableFunction::NUMBER);
136
add_field("ENTRY_TYPE");
137
add_field("ENTRY_LENGTH", plugin::TableFunction::NUMBER);
140
TransactionLogEntriesTool::Generator::Generator(Field **arg) :
141
plugin::TableFunction::Generator(arg)
143
it= transaction_log_index->getEntries().begin();
144
end= transaction_log_index->getEntries().end();
147
bool TransactionLogEntriesTool::Generator::populate()
154
TransactionLogEntry &entry= *it;
156
push(entry.getOffset());
157
push(entry.getTypeAsString());
158
push(entry.getLengthInBytes());
167
* TRANSACTION_LOG_TRANSACTIONS view
171
TransactionLogTransactionsTool::TransactionLogTransactionsTool() :
172
plugin::TableFunction("DATA_DICTIONARY", "TRANSACTION_LOG_TRANSACTIONS")
174
add_field("ENTRY_OFFSET", plugin::TableFunction::NUMBER);
175
add_field("TRANSACTION_ID", plugin::TableFunction::NUMBER);
176
add_field("SERVER_ID", plugin::TableFunction::NUMBER);
177
add_field("START_TIMESTAMP", plugin::TableFunction::NUMBER);
178
add_field("END_TIMESTAMP", plugin::TableFunction::NUMBER);
179
add_field("NUM_STATEMENTS", plugin::TableFunction::NUMBER);
180
add_field("CHECKSUM", plugin::TableFunction::NUMBER);
183
TransactionLogTransactionsTool::Generator::Generator(Field **arg) :
184
plugin::TableFunction::Generator(arg)
186
it= transaction_log_index->getTransactionEntries().begin();
187
end= transaction_log_index->getTransactionEntries().end();
190
bool TransactionLogTransactionsTool::Generator::populate()
197
TransactionLogTransactionEntry &entry= *it;
199
push(entry.getOffset());
200
push(entry.getTransactionId());
201
push(entry.getServerId());
202
push(entry.getStartTimestamp());
203
push(entry.getEndTimestamp());
204
push(entry.getNumStatements());
205
push(entry.getChecksum());