~jaypipes/drizzle/split-xa-resource-manager

« back to all changes in this revision

Viewing changes to plugin/transaction_log/data_dictionary_schema.cc

  • Committer: Jay Pipes
  • Date: 2010-02-14 20:26:43 UTC
  • mfrom: (1273.1.27 staging)
  • Revision ID: jpipes@serialcoder-20100214202643-ahuqvc8rhn8u7y33
Merge trunk and resolve conflicts

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
 *  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
 
43
 * );
 
44
 *
 
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
 
49
 * );
 
50
 *
 
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 
 
59
 * );
 
60
 */
 
61
 
 
62
 
 
63
#include "data_dictionary_schema.h"
 
64
#include "transaction_log_index.h"
 
65
 
 
66
#include <fcntl.h>
 
67
#include <sys/stat.h>
 
68
 
 
69
using namespace std;
 
70
using namespace drizzled;
 
71
 
 
72
extern TransactionLog *transaction_log; /* the singleton transaction log */
 
73
extern TransactionLogIndex *transaction_log_index; /* the singleton transaction log index */
 
74
 
 
75
/*
 
76
 *
 
77
 * TRANSACTION_LOG_INFO
 
78
 *
 
79
 */
 
80
 
 
81
TransactionLogTool::TransactionLogTool() :
 
82
  plugin::TableFunction("DATA_DICTIONARY", "TRANSACTION_LOG")
 
83
{
 
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);
 
92
}
 
93
 
 
94
TransactionLogTool::Generator::Generator(Field **arg) :
 
95
  plugin::TableFunction::Generator(arg)
 
96
{
 
97
  is_done= false;
 
98
}
 
99
 
 
100
bool TransactionLogTool::Generator::populate()
 
101
{
 
102
  if (is_done)
 
103
  {
 
104
    return false;
 
105
  }
 
106
 
 
107
  const string &filename= transaction_log->getLogFilename();
 
108
  push(filename.c_str());
 
109
  
 
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);
 
114
 
 
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()); 
 
121
 
 
122
  is_done= true;
 
123
  return true;
 
124
}
 
125
 
 
126
/*
 
127
 *
 
128
 * TRANSACTION_LOG_ENTRIES view
 
129
 *
 
130
 */
 
131
 
 
132
TransactionLogEntriesTool::TransactionLogEntriesTool() :
 
133
  plugin::TableFunction("DATA_DICTIONARY", "TRANSACTION_LOG_ENTRIES")
 
134
{
 
135
  add_field("ENTRY_OFFSET", plugin::TableFunction::NUMBER);
 
136
  add_field("ENTRY_TYPE");
 
137
  add_field("ENTRY_LENGTH", plugin::TableFunction::NUMBER);
 
138
}
 
139
 
 
140
TransactionLogEntriesTool::Generator::Generator(Field **arg) :
 
141
  plugin::TableFunction::Generator(arg)
 
142
{
 
143
  it= transaction_log_index->getEntries().begin();
 
144
  end= transaction_log_index->getEntries().end(); 
 
145
}
 
146
 
 
147
bool TransactionLogEntriesTool::Generator::populate()
 
148
{
 
149
  if (it == end)
 
150
  { 
 
151
    return false;
 
152
  } 
 
153
 
 
154
  TransactionLogEntry &entry= *it;
 
155
 
 
156
  push(entry.getOffset());
 
157
  push(entry.getTypeAsString());
 
158
  push(entry.getLengthInBytes());
 
159
 
 
160
  it++;
 
161
 
 
162
  return true;
 
163
}
 
164
 
 
165
/*
 
166
 *
 
167
 * TRANSACTION_LOG_TRANSACTIONS view
 
168
 *
 
169
 */
 
170
 
 
171
TransactionLogTransactionsTool::TransactionLogTransactionsTool() :
 
172
  plugin::TableFunction("DATA_DICTIONARY", "TRANSACTION_LOG_TRANSACTIONS")
 
173
{
 
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);
 
181
}
 
182
 
 
183
TransactionLogTransactionsTool::Generator::Generator(Field **arg) :
 
184
  plugin::TableFunction::Generator(arg)
 
185
{
 
186
  it= transaction_log_index->getTransactionEntries().begin();
 
187
  end= transaction_log_index->getTransactionEntries().end();
 
188
}
 
189
 
 
190
bool TransactionLogTransactionsTool::Generator::populate()
 
191
{
 
192
  if (it == end)
 
193
  {
 
194
    return false;
 
195
  }
 
196
 
 
197
  TransactionLogTransactionEntry &entry= *it;
 
198
 
 
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());
 
206
 
 
207
  it++;
 
208
 
 
209
  return true;
 
210
}