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 |
*
|
|
4 |
* Copyright (C) 2008-2009 Sun Microsystems
|
|
5 |
*
|
|
1143.2.10
by Jay Pipes
Phase 2 new replication work: |
6 |
* Authors:
|
7 |
*
|
|
8 |
* Jay Pipes <joinfu@sun.com>
|
|
9 |
*
|
|
1039.5.1
by Jay Pipes
* New serial event log plugin |
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 |
*
|
|
1143.2.10
by Jay Pipes
Phase 2 new replication work: |
28 |
* Defines the API of the default transaction log.
|
1039.5.1
by Jay Pipes
* New serial event log plugin |
29 |
*
|
30 |
* @see drizzled/plugin/replicator.h
|
|
31 |
* @see drizzled/plugin/applier.h
|
|
32 |
*
|
|
33 |
* @details
|
|
34 |
*
|
|
1143.2.10
by Jay Pipes
Phase 2 new replication work: |
35 |
* The TransactionLog applies events it receives from the ReplicationServices
|
1039.5.1
by Jay Pipes
* New serial event log plugin |
36 |
* server component to a simple log file on disk.
|
37 |
*
|
|
1143.2.10
by Jay Pipes
Phase 2 new replication work: |
38 |
* Transactions are received in no guaranteed order and the command log
|
1039.5.1
by Jay Pipes
* New serial event log plugin |
39 |
* is in charge of writing these events to the log as they are received.
|
40 |
*/
|
|
41 |
||
1143.2.24
by Jay Pipes
Fixes some stuff from make check (include guards). Also adds stuff for REPLACE logic that does not work. |
42 |
#ifndef PLUGIN_TRANSACTION_LOG_TRANSACTION_LOG_H
|
43 |
#define PLUGIN_TRANSACTION_LOG_TRANSACTION_LOG_H
|
|
1039.5.1
by Jay Pipes
* New serial event log plugin |
44 |
|
45 |
#include <drizzled/atomics.h> |
|
1039.5.41
by Jay Pipes
Adds a new plugin class interface for a reader of Command messages, |
46 |
#include <drizzled/replication_services.h> |
1143.2.10
by Jay Pipes
Phase 2 new replication work: |
47 |
#include <drizzled/plugin/transaction_replicator.h> |
48 |
#include <drizzled/plugin/transaction_applier.h> |
|
1039.5.1
by Jay Pipes
* New serial event log plugin |
49 |
|
1143.3.4
by Jay Pipes
Adds INFORMATION_SCHEMA views for the transaction log: |
50 |
#include "transaction_log_entry.h" |
51 |
||
1039.5.1
by Jay Pipes
* New serial event log plugin |
52 |
#include <vector> |
53 |
#include <string> |
|
54 |
||
1143.2.10
by Jay Pipes
Phase 2 new replication work: |
55 |
class TransactionLog: public drizzled::plugin::TransactionApplier |
1039.5.1
by Jay Pipes
* New serial event log plugin |
56 |
{
|
57 |
public: |
|
1143.2.15
by Jay Pipes
This patch does the following: |
58 |
static const uint32_t HEADER_TRAILER_BYTES= sizeof(uint32_t) + /* 4-byte msg type header */ |
59 |
sizeof(uint32_t) + /* 4-byte length header */ |
|
60 |
sizeof(uint32_t); /* 4 byte checksum trailer */ |
|
61 |
||
1143.3.4
by Jay Pipes
Adds INFORMATION_SCHEMA views for the transaction log: |
62 |
typedef std::vector<TransactionLogEntry> Entries; |
63 |
typedef std::vector<TransactionLogTransactionEntry> TransactionEntries; |
|
1143.2.15
by Jay Pipes
This patch does the following: |
64 |
/**
|
65 |
* The state the log is in
|
|
66 |
*/
|
|
67 |
enum Status |
|
1039.5.1
by Jay Pipes
* New serial event log plugin |
68 |
{
|
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. |
69 |
CRASHED= 0, |
70 |
OFFLINE, /* Default state, uninited. */ |
|
1039.5.1
by Jay Pipes
* New serial event log plugin |
71 |
ONLINE, |
72 |
WRITING
|
|
73 |
};
|
|
1143.4.13
by Jay Pipes
This patch adds support for a new transaction log configuration/CLI |
74 |
static const uint32_t SYNC_METHOD_OS= 0; ///< Rely on operating system to sync log file |
75 |
static const uint32_t SYNC_METHOD_EVERY_WRITE= 1; //< Sync on every write to the log file |
|
76 |
static const uint32_t SYNC_METHOD_EVERY_SECOND= 2; ///< Sync no more than once a second |
|
1039.5.1
by Jay Pipes
* New serial event log plugin |
77 |
public: |
1143.2.18
by Jay Pipes
Merge trunk and resolve conflicts. |
78 |
TransactionLog(std::string name_arg, |
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.. :) |
79 |
const std::string &in_log_file_path, |
1143.2.18
by Jay Pipes
Merge trunk and resolve conflicts. |
80 |
bool in_do_checksum); |
1039.5.1
by Jay Pipes
* New serial event log plugin |
81 |
|
82 |
/** Destructor */
|
|
1143.2.10
by Jay Pipes
Phase 2 new replication work: |
83 |
~TransactionLog(); |
1039.5.1
by Jay Pipes
* New serial event log plugin |
84 |
|
85 |
/**
|
|
1143.2.10
by Jay Pipes
Phase 2 new replication work: |
86 |
* Applies a Transaction to the serial log
|
1039.5.1
by Jay Pipes
* New serial event log plugin |
87 |
*
|
88 |
* @note
|
|
89 |
*
|
|
90 |
* It is important to note that memory allocation for the
|
|
91 |
* supplied pointer is not guaranteed after the completion
|
|
92 |
* of this function -- meaning the caller can dispose of the
|
|
93 |
* supplied message. Therefore, appliers which are
|
|
94 |
* implementing an asynchronous replication system must copy
|
|
95 |
* the supplied message to their own controlled memory storage
|
|
96 |
* area.
|
|
97 |
*
|
|
1143.2.10
by Jay Pipes
Phase 2 new replication work: |
98 |
* @param Transaction message to be replicated
|
1039.5.1
by Jay Pipes
* New serial event log plugin |
99 |
*/
|
1143.2.10
by Jay Pipes
Phase 2 new replication work: |
100 |
void apply(const drizzled::message::Transaction &to_apply); |
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.. :) |
101 |
|
102 |
/**
|
|
103 |
* Returns the current offset into the log
|
|
104 |
*/
|
|
105 |
inline off_t getLogOffset() |
|
106 |
{
|
|
107 |
return log_offset; |
|
108 |
}
|
|
109 |
||
110 |
/**
|
|
111 |
* Returns the filename of the transaction log
|
|
112 |
*/
|
|
113 |
const std::string &getLogFilename(); |
|
114 |
||
115 |
/**
|
|
116 |
* Returns the filename of the transaction log
|
|
117 |
*/
|
|
118 |
const std::string &getLogFilepath(); |
|
1039.5.1
by Jay Pipes
* New serial event log plugin |
119 |
|
1039.5.5
by Jay Pipes
This commit does two things: |
120 |
/**
|
1039.5.1
by Jay Pipes
* New serial event log plugin |
121 |
* Returns the state that the log is in
|
122 |
*/
|
|
1143.2.15
by Jay Pipes
This patch does the following: |
123 |
inline enum Status getState() |
1039.5.1
by Jay Pipes
* New serial event log plugin |
124 |
{
|
125 |
return state; |
|
126 |
}
|
|
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. |
127 |
|
128 |
/**
|
|
129 |
* Truncates the existing log file
|
|
130 |
*
|
|
131 |
* @note
|
|
132 |
*
|
|
133 |
* This is only called currently during debugging and testing of the
|
|
1039.5.28
by Jay Pipes
Renames serial event log to command log |
134 |
* 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. |
135 |
* set to anything other than false, this is called.
|
136 |
*/
|
|
137 |
void truncate(); |
|
1039.5.41
by Jay Pipes
Adds a new plugin class interface for a reader of Command messages, |
138 |
|
139 |
/**
|
|
140 |
* Takes a global transaction ID and a reference to a string to fill
|
|
141 |
* with the name of the log file which contains the command with the
|
|
142 |
* transaction ID. If the transaction ID is contained in a log file,
|
|
143 |
* the function returns true, false otherwise.
|
|
144 |
*
|
|
145 |
* @param[in] Global transaction ID to search on
|
|
146 |
* @param[inout] String to fill with name of logfile containing command with
|
|
147 |
* the needed transaction ID
|
|
148 |
*
|
|
149 |
* @retval
|
|
150 |
* true if found
|
|
151 |
* @retval
|
|
152 |
* false otherwise
|
|
153 |
*/
|
|
154 |
bool findLogFilenameContainingTransactionId(const drizzled::ReplicationServices::GlobalTransactionId &to_find, |
|
155 |
std::string &out_filename) const; |
|
1143.3.4
by Jay Pipes
Adds INFORMATION_SCHEMA views for the transaction log: |
156 |
|
157 |
/**
|
|
158 |
* Returns whether the log is currently in error.
|
|
159 |
*/
|
|
160 |
bool hasError() const; |
|
161 |
||
162 |
/**
|
|
163 |
* Returns the log's current error message
|
|
164 |
*/
|
|
165 |
const std::string &getErrorMessage() const; |
|
166 |
private: |
|
167 |
/* Don't allows these */
|
|
168 |
TransactionLog(); |
|
169 |
TransactionLog(const TransactionLog &other); |
|
170 |
TransactionLog &operator=(const TransactionLog &other); |
|
171 |
/**
|
|
172 |
* Clears the current error message
|
|
173 |
*/
|
|
174 |
void clearError(); |
|
1143.4.13
by Jay Pipes
This patch adds support for a new transaction log configuration/CLI |
175 |
/**
|
176 |
* Helper method which synchronizes/flushes the transaction log file
|
|
177 |
* according to the transaction_log_sync_method system variable
|
|
178 |
*
|
|
179 |
* @retval
|
|
180 |
* 0 == Success
|
|
181 |
* @retval
|
|
182 |
* >0 == Failure. Error code.
|
|
183 |
*/
|
|
184 |
int syncLogFile(); |
|
1143.3.4
by Jay Pipes
Adds INFORMATION_SCHEMA views for the transaction log: |
185 |
|
186 |
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. |
187 |
Status state; ///< The state the log is in |
1143.3.4
by Jay Pipes
Adds INFORMATION_SCHEMA views for the transaction log: |
188 |
drizzled::atomic<bool> do_checksum; ///< Do a CRC32 checksum when writing Transaction message to log? |
189 |
const std::string log_file_path; ///< Full path to the log file |
|
190 |
std::string log_file_name; ///< Name of the log file |
|
191 |
drizzled::atomic<off_t> log_offset; ///< Offset in log file where log will write next command |
|
192 |
bool has_error; ///< Is the log in error? |
|
193 |
std::string error_message; ///< Current error message |
|
1143.4.13
by Jay Pipes
This patch adds support for a new transaction log configuration/CLI |
194 |
time_t last_sync_time; ///< Last time the log file was synced (only set in SYNC_METHOD_EVERY_SECOND) |
1039.5.1
by Jay Pipes
* New serial event log plugin |
195 |
};
|
196 |
||
1143.2.23
by Jay Pipes
Merge trunk and resolve all conflicts. |
197 |
#endif /* PLUGIN_TRANSACTION_LOG_TRANSACTION_LOG_H */ |