1039.5.1
by Jay Pipes
* New serial event log plugin |
1 |
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
|
2 |
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
|
|
3 |
*
|
|
1999.6.1
by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file |
4 |
* Copyright (C) 2008-2009 Sun Microsystems, Inc.
|
5 |
* Copyright (C) 2010 Jay Pipes <jaypipes@gmail.com>
|
|
1039.5.1
by Jay Pipes
* New serial event log plugin |
6 |
*
|
1143.2.10
by Jay Pipes
Phase 2 new replication work: |
7 |
* Authors:
|
8 |
*
|
|
1273.22.1
by Jay Pipes
Completes the blueprint for refactoring applier out of log descriptor. |
9 |
* Jay Pipes <jaypipes@gmail.com.com>
|
1143.2.10
by Jay Pipes
Phase 2 new replication work: |
10 |
*
|
1039.5.1
by Jay Pipes
* New serial event log plugin |
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 |
*
|
|
1273.22.1
by Jay Pipes
Completes the blueprint for refactoring applier out of log descriptor. |
29 |
* Defines the API of the transaction log file descriptor.
|
1039.5.1
by Jay Pipes
* New serial event log plugin |
30 |
*
|
31 |
* @details
|
|
32 |
*
|
|
1273.22.1
by Jay Pipes
Completes the blueprint for refactoring applier out of log descriptor. |
33 |
* Basically, the TransactionLog is a descriptor for a log
|
34 |
* file containing transaction messages that is written by
|
|
35 |
* the TransactionLogApplier plugin(s).
|
|
1039.5.1
by Jay Pipes
* New serial event log plugin |
36 |
*/
|
37 |
||
2234
by Brian Aker
Mass removal of ifdef/endif in favor of pragma once. |
38 |
#pragma once
|
1039.5.1
by Jay Pipes
* New serial event log plugin |
39 |
|
40 |
#include <drizzled/atomics.h> |
|
1039.5.41
by Jay Pipes
Adds a new plugin class interface for a reader of Command messages, |
41 |
#include <drizzled/replication_services.h> |
1039.5.1
by Jay Pipes
* New serial event log plugin |
42 |
|
1143.3.4
by Jay Pipes
Adds INFORMATION_SCHEMA views for the transaction log: |
43 |
#include "transaction_log_entry.h" |
44 |
||
1039.5.1
by Jay Pipes
* New serial event log plugin |
45 |
#include <vector> |
46 |
#include <string> |
|
47 |
||
2385.3.17
by Olaf van der Spek
Remove unnecessary constructors and destructors |
48 |
class TransactionLog : boost::noncopyable |
1039.5.1
by Jay Pipes
* New serial event log plugin |
49 |
{
|
50 |
public: |
|
1143.3.4
by Jay Pipes
Adds INFORMATION_SCHEMA views for the transaction log: |
51 |
typedef std::vector<TransactionLogEntry> Entries; |
52 |
typedef std::vector<TransactionLogTransactionEntry> TransactionEntries; |
|
1143.2.15
by Jay Pipes
This patch does the following: |
53 |
/**
|
54 |
* The state the log is in
|
|
55 |
*/
|
|
56 |
enum Status |
|
1039.5.1
by Jay Pipes
* New serial event log plugin |
57 |
{
|
1039.5.6
by Jay Pipes
Changes the way the log_offset is atomically incremented and its value retrieved. Hopefully, this removes any race condition for the variable's contents, but there is a note in the code describing my concern about a possible race condition. |
58 |
CRASHED= 0, |
59 |
OFFLINE, /* Default state, uninited. */ |
|
1039.5.1
by Jay Pipes
* New serial event log plugin |
60 |
ONLINE, |
61 |
WRITING
|
|
62 |
};
|
|
1726.2.1
by Vijay Samuel
Merge changes to transaction_log. Changed --transaction-log.sync-method to --transaction-log.flush-frequency |
63 |
static const uint32_t FLUSH_FREQUENCY_OS= 0; ///< Rely on operating system to sync log file |
64 |
static const uint32_t FLUSH_FREQUENCY_EVERY_WRITE= 1; //< Sync on every write to the log file |
|
65 |
static const uint32_t FLUSH_FREQUENCY_EVERY_SECOND= 2; ///< Sync no more than once a second |
|
1039.5.1
by Jay Pipes
* New serial event log plugin |
66 |
public: |
2353.2.3
by Stewart Smith
transaction_log: Function parameter 'in_log_file_path' is passed by value. It could be passed by reference instead. |
67 |
TransactionLog(const std::string &in_log_file_path, |
1726.2.1
by Vijay Samuel
Merge changes to transaction_log. Changed --transaction-log.sync-method to --transaction-log.flush-frequency |
68 |
uint32_t in_flush_frequency, |
1405.4.1
by Jay Pipes
Adds a vector of write buffers to the transaction log applier |
69 |
bool in_do_checksum); |
1039.5.1
by Jay Pipes
* New serial event log plugin |
70 |
|
71 |
/** Destructor */
|
|
1143.2.10
by Jay Pipes
Phase 2 new replication work: |
72 |
~TransactionLog(); |
1039.5.1
by Jay Pipes
* New serial event log plugin |
73 |
|
74 |
/**
|
|
1143.3.2
by Jay Pipes
Adds INFORMATION_SCHEMA views for the transaction log - Phase 1. Does not currently output correctly. Pushing for some help.. :) |
75 |
* Returns the current offset into the log
|
76 |
*/
|
|
77 |
inline off_t getLogOffset() |
|
78 |
{
|
|
79 |
return log_offset; |
|
80 |
}
|
|
81 |
||
82 |
/**
|
|
83 |
* Returns the filename of the transaction log
|
|
84 |
*/
|
|
85 |
const std::string &getLogFilename(); |
|
86 |
||
87 |
/**
|
|
88 |
* Returns the filename of the transaction log
|
|
89 |
*/
|
|
90 |
const std::string &getLogFilepath(); |
|
1039.5.1
by Jay Pipes
* New serial event log plugin |
91 |
|
1039.5.5
by Jay Pipes
This commit does two things: |
92 |
/**
|
1039.5.1
by Jay Pipes
* New serial event log plugin |
93 |
* Returns the state that the log is in
|
94 |
*/
|
|
1143.2.15
by Jay Pipes
This patch does the following: |
95 |
inline enum Status getState() |
1039.5.1
by Jay Pipes
* New serial event log plugin |
96 |
{
|
97 |
return state; |
|
98 |
}
|
|
1039.5.17
by Jay Pipes
Adds log truncation debugging functionality to the serial event log plugin. Cleans up the serial event log test suite to properly include and output result files. |
99 |
|
100 |
/**
|
|
1405.4.1
by Jay Pipes
Adds a vector of write buffers to the transaction log applier |
101 |
* Static helper method which returns the transaction
|
102 |
* log entry size in bytes of a given transaction
|
|
103 |
* message.
|
|
104 |
*
|
|
105 |
* @param[in] Transaction message
|
|
106 |
*/
|
|
107 |
static size_t getLogEntrySize(const drizzled::message::Transaction &trx); |
|
108 |
||
109 |
/**
|
|
110 |
* Method which packs into a raw byte buffer
|
|
111 |
* a transaction log entry. Supplied buffer should
|
|
112 |
* be of adequate size.
|
|
113 |
*
|
|
114 |
* Returns a pointer to the start of the original
|
|
115 |
* buffer.
|
|
116 |
*
|
|
117 |
* @param[in] Transaction message to pack
|
|
118 |
* @param[in] Raw byte buffer
|
|
119 |
* @param[out] Pointer to storage for checksum of message
|
|
120 |
*/
|
|
121 |
uint8_t *packTransactionIntoLogEntry(const drizzled::message::Transaction &trx, |
|
122 |
uint8_t *buffer, |
|
123 |
uint32_t *checksum_out); |
|
124 |
||
125 |
/**
|
|
1273.22.1
by Jay Pipes
Completes the blueprint for refactoring applier out of log descriptor. |
126 |
* Writes a chunk of data to the log file of a specified
|
127 |
* length and returns the offset at which the chunk of
|
|
128 |
* data was written.
|
|
129 |
*
|
|
130 |
* @param[in] Bytes to write
|
|
131 |
* @param[in[ Length of bytes to write
|
|
132 |
*
|
|
133 |
* @retval
|
|
134 |
* Returns the write offset if the write succeeded, OFF_T_MAX otherwise.
|
|
135 |
*/
|
|
136 |
off_t writeEntry(const uint8_t *data, size_t data_length); |
|
137 |
||
138 |
/**
|
|
1039.5.17
by Jay Pipes
Adds log truncation debugging functionality to the serial event log plugin. Cleans up the serial event log test suite to properly include and output result files. |
139 |
* Truncates the existing log file
|
140 |
*
|
|
141 |
* @note
|
|
142 |
*
|
|
143 |
* This is only called currently during debugging and testing of the
|
|
1039.5.28
by Jay Pipes
Renames serial event log to command log |
144 |
* command log...when the global command_log_truncate variable is
|
1039.5.17
by Jay Pipes
Adds log truncation debugging functionality to the serial event log plugin. Cleans up the serial event log test suite to properly include and output result files. |
145 |
* set to anything other than false, this is called.
|
146 |
*/
|
|
147 |
void truncate(); |
|
1039.5.41
by Jay Pipes
Adds a new plugin class interface for a reader of Command messages, |
148 |
|
149 |
/**
|
|
150 |
* Takes a global transaction ID and a reference to a string to fill
|
|
151 |
* with the name of the log file which contains the command with the
|
|
152 |
* transaction ID. If the transaction ID is contained in a log file,
|
|
153 |
* the function returns true, false otherwise.
|
|
154 |
*
|
|
155 |
* @param[in] Global transaction ID to search on
|
|
156 |
* @param[inout] String to fill with name of logfile containing command with
|
|
157 |
* the needed transaction ID
|
|
158 |
*
|
|
159 |
* @retval
|
|
160 |
* true if found
|
|
161 |
* @retval
|
|
162 |
* false otherwise
|
|
163 |
*/
|
|
164 |
bool findLogFilenameContainingTransactionId(const drizzled::ReplicationServices::GlobalTransactionId &to_find, |
|
165 |
std::string &out_filename) const; |
|
1143.3.4
by Jay Pipes
Adds INFORMATION_SCHEMA views for the transaction log: |
166 |
|
167 |
/**
|
|
168 |
* Returns whether the log is currently in error.
|
|
169 |
*/
|
|
170 |
bool hasError() const; |
|
171 |
||
172 |
/**
|
|
173 |
* Returns the log's current error message
|
|
174 |
*/
|
|
175 |
const std::string &getErrorMessage() const; |
|
176 |
private: |
|
1405.4.1
by Jay Pipes
Adds a vector of write buffers to the transaction log applier |
177 |
static const uint32_t HEADER_TRAILER_BYTES= sizeof(uint32_t) + /* 4-byte msg type header */ |
178 |
sizeof(uint32_t) + /* 4-byte length header */ |
|
179 |
sizeof(uint32_t); /* 4 byte checksum trailer */ |
|
180 |
||
1143.3.4
by Jay Pipes
Adds INFORMATION_SCHEMA views for the transaction log: |
181 |
/**
|
182 |
* Clears the current error message
|
|
183 |
*/
|
|
184 |
void clearError(); |
|
1143.4.13
by Jay Pipes
This patch adds support for a new transaction log configuration/CLI |
185 |
/**
|
186 |
* Helper method which synchronizes/flushes the transaction log file
|
|
1726.2.1
by Vijay Samuel
Merge changes to transaction_log. Changed --transaction-log.sync-method to --transaction-log.flush-frequency |
187 |
* according to the transaction_log_flush_frequency system variable
|
1143.4.13
by Jay Pipes
This patch adds support for a new transaction log configuration/CLI |
188 |
*
|
189 |
* @retval
|
|
190 |
* 0 == Success
|
|
191 |
* @retval
|
|
192 |
* >0 == Failure. Error code.
|
|
193 |
*/
|
|
194 |
int syncLogFile(); |
|
1143.3.4
by Jay Pipes
Adds INFORMATION_SCHEMA views for the transaction log: |
195 |
|
196 |
int log_file; ///< Handle for our log file |
|
1143.3.9
by Jay Pipes
Fixes information schema tests, adds a hexdump UDF for the transaction message. |
197 |
Status state; ///< The state the log is in |
1143.3.4
by Jay Pipes
Adds INFORMATION_SCHEMA views for the transaction log: |
198 |
const std::string log_file_path; ///< Full path to the log file |
199 |
std::string log_file_name; ///< Name of the log file |
|
200 |
drizzled::atomic<off_t> log_offset; ///< Offset in log file where log will write next command |
|
201 |
bool has_error; ///< Is the log in error? |
|
202 |
std::string error_message; ///< Current error message |
|
1726.2.1
by Vijay Samuel
Merge changes to transaction_log. Changed --transaction-log.sync-method to --transaction-log.flush-frequency |
203 |
uint32_t flush_frequency; ///< Determines behaviour of syncing log file |
204 |
time_t last_sync_time; ///< Last time the log file was synced (only set in FLUSH_FREQUENCY_EVERY_SECOND) |
|
1405.4.1
by Jay Pipes
Adds a vector of write buffers to the transaction log applier |
205 |
bool do_checksum; ///< Do a CRC32 checksum when writing Transaction message to log? |
1039.5.1
by Jay Pipes
* New serial event log plugin |
206 |
};
|
207 |