1273.15.1
by Joe Daly
port transaction_log to use data_dictionary |
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 |
* Joseph Daly <skinny.moey@gmail.com>
|
|
10 |
*
|
|
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.
|
|
15 |
*
|
|
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.
|
|
20 |
*
|
|
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
|
|
24 |
*/
|
|
25 |
||
26 |
/**
|
|
27 |
* @file
|
|
28 |
*
|
|
29 |
* Implements the DATA_DICTIONARY views which allows querying the
|
|
30 |
* state of the transaction log and its entries.
|
|
31 |
*
|
|
32 |
* There are three views defined for the transaction log:
|
|
33 |
*
|
|
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
|
|
1273.1.33
by Jay Pipes
Adds concurrency tests for transaction log and its data dictionary table. Adds ability to see size of the in-memory index of the transaction log in bytes to the transaction_log data dictionary table. |
43 |
* , INDEX_SIZE_IN_BYTES BIGINT NOT NULL
|
1273.15.1
by Joe Daly
port transaction_log to use data_dictionary |
44 |
* );
|
45 |
*
|
|
46 |
* CREATE TABLE DATA_DICTIONARY.TRANSACTION_LOG_ENTRIES (
|
|
47 |
* ENTRY_OFFSET BIGINT NOT NULL
|
|
48 |
* , ENTRY_TYPE VARCHAR NOT NULL
|
|
49 |
* , ENTRY_LENGTH BIGINT NOT NULL
|
|
50 |
* );
|
|
51 |
*
|
|
52 |
* CREATE TABLE DATA_DICTIONARY.TRANSACTION_LOG_TRANSACTIONS (
|
|
53 |
* ENTRY_OFFSET BIGINT NOT NULL
|
|
54 |
* , TRANSACTION_ID BIGINT NOT NULL
|
|
55 |
* , SERVER_ID BIGINT NOT NULL
|
|
56 |
* , START_TIMESTAMP BIGINT NOT NULL
|
|
57 |
* , END_TIMESTAMP BIGINT NOT NULL
|
|
58 |
* , NUM_STATEMENTS BIGINT NOT NULL
|
|
59 |
* , CHECKSUM BIGINT NOT NULL
|
|
60 |
* );
|
|
61 |
*/
|
|
62 |
||
1273.13.65
by Brian Aker
Lint fixes. |
63 |
#include "config.h" |
1273.15.1
by Joe Daly
port transaction_log to use data_dictionary |
64 |
|
65 |
#include "data_dictionary_schema.h" |
|
66 |
#include "transaction_log_index.h" |
|
67 |
||
68 |
#include <fcntl.h> |
|
69 |
#include <sys/stat.h> |
|
70 |
||
71 |
using namespace std; |
|
72 |
using namespace drizzled; |
|
73 |
||
74 |
extern TransactionLog *transaction_log; /* the singleton transaction log */ |
|
75 |
extern TransactionLogIndex *transaction_log_index; /* the singleton transaction log index */ |
|
76 |
||
77 |
/*
|
|
78 |
*
|
|
79 |
* TRANSACTION_LOG_INFO
|
|
80 |
*
|
|
81 |
*/
|
|
82 |
||
83 |
TransactionLogTool::TransactionLogTool() : |
|
84 |
plugin::TableFunction("DATA_DICTIONARY", "TRANSACTION_LOG") |
|
85 |
{
|
|
86 |
add_field("FILE_NAME"); |
|
87 |
add_field("FILE_LENGTH", plugin::TableFunction::NUMBER); |
|
88 |
add_field("NUM_LOG_ENTRIES", plugin::TableFunction::NUMBER); |
|
89 |
add_field("NUM_TRANSACTIONS", plugin::TableFunction::NUMBER); |
|
90 |
add_field("MIN_TRANSACTION_ID", plugin::TableFunction::NUMBER); |
|
91 |
add_field("MAX_TRANSACTION_ID", plugin::TableFunction::NUMBER); |
|
92 |
add_field("MIN_END_TIMESTAMP", plugin::TableFunction::NUMBER); |
|
93 |
add_field("MAX_END_TIMESTAMP", plugin::TableFunction::NUMBER); |
|
1273.1.33
by Jay Pipes
Adds concurrency tests for transaction log and its data dictionary table. Adds ability to see size of the in-memory index of the transaction log in bytes to the transaction_log data dictionary table. |
94 |
add_field("INDEX_SIZE_IN_BYTES", plugin::TableFunction::NUMBER); |
1273.15.1
by Joe Daly
port transaction_log to use data_dictionary |
95 |
}
|
96 |
||
97 |
TransactionLogTool::Generator::Generator(Field **arg) : |
|
98 |
plugin::TableFunction::Generator(arg) |
|
99 |
{
|
|
100 |
is_done= false; |
|
101 |
}
|
|
102 |
||
103 |
bool TransactionLogTool::Generator::populate() |
|
104 |
{
|
|
105 |
if (is_done) |
|
106 |
{
|
|
107 |
return false; |
|
108 |
}
|
|
109 |
||
110 |
const string &filename= transaction_log->getLogFilename(); |
|
111 |
push(filename.c_str()); |
|
112 |
||
113 |
/* Grab the file size of the log */
|
|
114 |
struct stat file_stat; |
|
115 |
(void) stat(filename.c_str(), &file_stat); |
|
116 |
push(file_stat.st_size); |
|
117 |
||
118 |
push(transaction_log_index->getNumLogEntries()); |
|
119 |
push(transaction_log_index->getNumTransactionEntries()); |
|
120 |
push(transaction_log_index->getMinTransactionId()); |
|
121 |
push(transaction_log_index->getMaxTransactionId()); |
|
122 |
push(transaction_log_index->getMinEndTimestamp()); |
|
123 |
push(transaction_log_index->getMaxEndTimestamp()); |
|
1273.22.3
by Jay Pipes
Make OSX/FreeBSD happy about size_t != uint64_t != int64_t... |
124 |
push(static_cast<uint64_t>(transaction_log_index->getSizeInBytes())); |
1273.15.1
by Joe Daly
port transaction_log to use data_dictionary |
125 |
|
126 |
is_done= true; |
|
127 |
return true; |
|
128 |
}
|
|
129 |
||
130 |
/*
|
|
131 |
*
|
|
132 |
* TRANSACTION_LOG_ENTRIES view
|
|
133 |
*
|
|
134 |
*/
|
|
135 |
||
136 |
TransactionLogEntriesTool::TransactionLogEntriesTool() : |
|
137 |
plugin::TableFunction("DATA_DICTIONARY", "TRANSACTION_LOG_ENTRIES") |
|
138 |
{
|
|
139 |
add_field("ENTRY_OFFSET", plugin::TableFunction::NUMBER); |
|
140 |
add_field("ENTRY_TYPE"); |
|
141 |
add_field("ENTRY_LENGTH", plugin::TableFunction::NUMBER); |
|
142 |
}
|
|
143 |
||
144 |
TransactionLogEntriesTool::Generator::Generator(Field **arg) : |
|
145 |
plugin::TableFunction::Generator(arg) |
|
146 |
{
|
|
147 |
it= transaction_log_index->getEntries().begin(); |
|
148 |
end= transaction_log_index->getEntries().end(); |
|
149 |
}
|
|
150 |
||
151 |
bool TransactionLogEntriesTool::Generator::populate() |
|
152 |
{
|
|
153 |
if (it == end) |
|
154 |
{
|
|
155 |
return false; |
|
156 |
}
|
|
157 |
||
158 |
TransactionLogEntry &entry= *it; |
|
159 |
||
160 |
push(entry.getOffset()); |
|
161 |
push(entry.getTypeAsString()); |
|
1273.13.83
by Brian Aker
Mutual OSX/Fedora fix (finally). |
162 |
push(static_cast<uint64_t>(entry.getLengthInBytes())); |
1273.15.1
by Joe Daly
port transaction_log to use data_dictionary |
163 |
|
164 |
it++; |
|
165 |
||
166 |
return true; |
|
167 |
}
|
|
168 |
||
169 |
/*
|
|
170 |
*
|
|
171 |
* TRANSACTION_LOG_TRANSACTIONS view
|
|
172 |
*
|
|
173 |
*/
|
|
174 |
||
175 |
TransactionLogTransactionsTool::TransactionLogTransactionsTool() : |
|
176 |
plugin::TableFunction("DATA_DICTIONARY", "TRANSACTION_LOG_TRANSACTIONS") |
|
177 |
{
|
|
178 |
add_field("ENTRY_OFFSET", plugin::TableFunction::NUMBER); |
|
179 |
add_field("TRANSACTION_ID", plugin::TableFunction::NUMBER); |
|
180 |
add_field("SERVER_ID", plugin::TableFunction::NUMBER); |
|
181 |
add_field("START_TIMESTAMP", plugin::TableFunction::NUMBER); |
|
182 |
add_field("END_TIMESTAMP", plugin::TableFunction::NUMBER); |
|
183 |
add_field("NUM_STATEMENTS", plugin::TableFunction::NUMBER); |
|
184 |
add_field("CHECKSUM", plugin::TableFunction::NUMBER); |
|
185 |
}
|
|
186 |
||
187 |
TransactionLogTransactionsTool::Generator::Generator(Field **arg) : |
|
188 |
plugin::TableFunction::Generator(arg) |
|
189 |
{
|
|
190 |
it= transaction_log_index->getTransactionEntries().begin(); |
|
191 |
end= transaction_log_index->getTransactionEntries().end(); |
|
192 |
}
|
|
193 |
||
194 |
bool TransactionLogTransactionsTool::Generator::populate() |
|
195 |
{
|
|
196 |
if (it == end) |
|
197 |
{
|
|
198 |
return false; |
|
199 |
}
|
|
200 |
||
201 |
TransactionLogTransactionEntry &entry= *it; |
|
202 |
||
203 |
push(entry.getOffset()); |
|
204 |
push(entry.getTransactionId()); |
|
1273.13.82
by Brian Aker
Revert OSX fix, requiring more cast. |
205 |
push(static_cast<uint64_t>(entry.getServerId())); |
1273.15.1
by Joe Daly
port transaction_log to use data_dictionary |
206 |
push(entry.getStartTimestamp()); |
207 |
push(entry.getEndTimestamp()); |
|
1273.13.82
by Brian Aker
Revert OSX fix, requiring more cast. |
208 |
push(static_cast<uint64_t>(entry.getNumStatements())); |
209 |
push(static_cast<uint64_t>(entry.getChecksum())); |
|
1273.15.1
by Joe Daly
port transaction_log to use data_dictionary |
210 |
|
211 |
it++; |
|
212 |
||
213 |
return true; |
|
214 |
}
|