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
static const uint32_t HEADER_TRAILER_BYTES= sizeof(uint32_t) + /* 4-byte msg type header */
53
sizeof(uint32_t) + /* 4-byte length header */
54
sizeof(uint32_t); /* 4 byte checksum trailer */
56
typedef std::vector<TransactionLogEntry> Entries;
57
typedef std::vector<TransactionLogTransactionEntry> TransactionEntries;
59
* The state the log is in
64
OFFLINE, /* Default state, uninited. */
68
static const uint32_t SYNC_METHOD_OS= 0; ///< Rely on operating system to sync log file
69
static const uint32_t SYNC_METHOD_EVERY_WRITE= 1; //< Sync on every write to the log file
70
static const uint32_t SYNC_METHOD_EVERY_SECOND= 2; ///< Sync no more than once a second
72
TransactionLog(const std::string in_log_file_path,
73
uint32_t in_sync_method);
79
* Returns the current offset into the log
81
inline off_t getLogOffset()
87
* Returns the filename of the transaction log
89
const std::string &getLogFilename();
92
* Returns the filename of the transaction log
94
const std::string &getLogFilepath();
97
* Returns the state that the log is in
99
inline enum Status getState()
105
* Writes a chunk of data to the log file of a specified
106
* length and returns the offset at which the chunk of
109
* @param[in] Bytes to write
110
* @param[in[ Length of bytes to write
113
* Returns the write offset if the write succeeded, OFF_T_MAX otherwise.
115
off_t writeEntry(const uint8_t *data, size_t data_length);
118
* Truncates the existing log file
122
* This is only called currently during debugging and testing of the
123
* command log...when the global command_log_truncate variable is
124
* set to anything other than false, this is called.
129
* Takes a global transaction ID and a reference to a string to fill
130
* with the name of the log file which contains the command with the
131
* transaction ID. If the transaction ID is contained in a log file,
132
* the function returns true, false otherwise.
134
* @param[in] Global transaction ID to search on
135
* @param[inout] String to fill with name of logfile containing command with
136
* the needed transaction ID
143
bool findLogFilenameContainingTransactionId(const drizzled::ReplicationServices::GlobalTransactionId &to_find,
144
std::string &out_filename) const;
147
* Returns whether the log is currently in error.
149
bool hasError() const;
152
* Returns the log's current error message
154
const std::string &getErrorMessage() const;
156
/* Don't allows these */
158
TransactionLog(const TransactionLog &other);
159
TransactionLog &operator=(const TransactionLog &other);
161
* Clears the current error message
165
* Helper method which synchronizes/flushes the transaction log file
166
* according to the transaction_log_sync_method system variable
171
* >0 == Failure. Error code.
175
int log_file; ///< Handle for our log file
176
Status state; ///< The state the log is in
177
const std::string log_file_path; ///< Full path to the log file
178
std::string log_file_name; ///< Name of the log file
179
drizzled::atomic<off_t> log_offset; ///< Offset in log file where log will write next command
180
bool has_error; ///< Is the log in error?
181
std::string error_message; ///< Current error message
182
uint32_t sync_method; ///< Determines behaviour of syncing log file
183
time_t last_sync_time; ///< Last time the log file was synced (only set in SYNC_METHOD_EVERY_SECOND)
186
#endif /* PLUGIN_TRANSACTION_LOG_TRANSACTION_LOG_H */