1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008-2009 Sun Microsystems
5
* Copyright (c) 2010 Jay Pipes <jaypipes@gmail.com>
9
* Jay Pipes <jaypipes@gmail.com.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
* Defines the API of the transaction log file 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).
38
#ifndef PLUGIN_TRANSACTION_LOG_TRANSACTION_LOG_H
39
#define PLUGIN_TRANSACTION_LOG_TRANSACTION_LOG_H
41
#include <drizzled/atomics.h>
42
#include <drizzled/replication_services.h>
44
#include "transaction_log_entry.h"
52
typedef std::vector<TransactionLogEntry> Entries;
53
typedef std::vector<TransactionLogTransactionEntry> TransactionEntries;
55
* The state the log is in
60
OFFLINE, /* Default state, uninited. */
64
static const uint32_t FLUSH_FREQUENCY_OS= 0; ///< Rely on operating system to sync log file
65
static const uint32_t FLUSH_FREQUENCY_EVERY_WRITE= 1; //< Sync on every write to the log file
66
static const uint32_t FLUSH_FREQUENCY_EVERY_SECOND= 2; ///< Sync no more than once a second
68
TransactionLog(const std::string in_log_file_path,
69
uint32_t in_flush_frequency,
76
* Returns the current offset into the log
78
inline off_t getLogOffset()
84
* Returns the filename of the transaction log
86
const std::string &getLogFilename();
89
* Returns the filename of the transaction log
91
const std::string &getLogFilepath();
94
* Returns the state that the log is in
96
inline enum Status getState()
102
* Static helper method which returns the transaction
103
* log entry size in bytes of a given transaction
106
* @param[in] Transaction message
108
static size_t getLogEntrySize(const drizzled::message::Transaction &trx);
111
* Method which packs into a raw byte buffer
112
* a transaction log entry. Supplied buffer should
113
* be of adequate size.
115
* Returns a pointer to the start of the original
118
* @param[in] Transaction message to pack
119
* @param[in] Raw byte buffer
120
* @param[out] Pointer to storage for checksum of message
122
uint8_t *packTransactionIntoLogEntry(const drizzled::message::Transaction &trx,
124
uint32_t *checksum_out);
127
* Writes a chunk of data to the log file of a specified
128
* length and returns the offset at which the chunk of
131
* @param[in] Bytes to write
132
* @param[in[ Length of bytes to write
135
* Returns the write offset if the write succeeded, OFF_T_MAX otherwise.
137
off_t writeEntry(const uint8_t *data, size_t data_length);
140
* Truncates the existing log file
144
* This is only called currently during debugging and testing of the
145
* command log...when the global command_log_truncate variable is
146
* set to anything other than false, this is called.
151
* Takes a global transaction ID and a reference to a string to fill
152
* with the name of the log file which contains the command with the
153
* transaction ID. If the transaction ID is contained in a log file,
154
* the function returns true, false otherwise.
156
* @param[in] Global transaction ID to search on
157
* @param[inout] String to fill with name of logfile containing command with
158
* the needed transaction ID
165
bool findLogFilenameContainingTransactionId(const drizzled::ReplicationServices::GlobalTransactionId &to_find,
166
std::string &out_filename) const;
169
* Returns whether the log is currently in error.
171
bool hasError() const;
174
* Returns the log's current error message
176
const std::string &getErrorMessage() const;
178
static const uint32_t HEADER_TRAILER_BYTES= sizeof(uint32_t) + /* 4-byte msg type header */
179
sizeof(uint32_t) + /* 4-byte length header */
180
sizeof(uint32_t); /* 4 byte checksum trailer */
182
/* Don't allows these */
184
TransactionLog(const TransactionLog &other);
185
TransactionLog &operator=(const TransactionLog &other);
187
* Clears the current error message
191
* Helper method which synchronizes/flushes the transaction log file
192
* according to the transaction_log_flush_frequency system variable
197
* >0 == Failure. Error code.
201
int log_file; ///< Handle for our log file
202
Status state; ///< The state the log is in
203
const std::string log_file_path; ///< Full path to the log file
204
std::string log_file_name; ///< Name of the log file
205
drizzled::atomic<off_t> log_offset; ///< Offset in log file where log will write next command
206
bool has_error; ///< Is the log in error?
207
std::string error_message; ///< Current error message
208
uint32_t flush_frequency; ///< Determines behaviour of syncing log file
209
time_t last_sync_time; ///< Last time the log file was synced (only set in FLUSH_FREQUENCY_EVERY_SECOND)
210
bool do_checksum; ///< Do a CRC32 checksum when writing Transaction message to log?
213
#endif /* PLUGIN_TRANSACTION_LOG_TRANSACTION_LOG_H */