29
* Defines the API of the transaction log file descriptor.
24
* Defines the API of the default command log.
26
* @see drizzled/plugin/replicator.h
27
* @see drizzled/plugin/applier.h
33
* Basically, the TransactionLog is a descriptor for a log
34
* file containing transaction messages that is written by
35
* the TransactionLogApplier plugin(s).
31
* The CommandLog applies events it receives from the ReplicationServices
32
* server component to a simple log file on disk.
34
* Commands are received in no guaranteed order and the command log
35
* is in charge of writing these events to the log as they are received.
38
#ifndef PLUGIN_TRANSACTION_LOG_TRANSACTION_LOG_H
39
#define PLUGIN_TRANSACTION_LOG_TRANSACTION_LOG_H
38
#ifndef PLUGIN_COMMAND_LOG_COMMAND_LOG_H
39
#define PLUGIN_COMMAND_LOG_COMMAND_LOG_H
41
41
#include <drizzled/atomics.h>
42
42
#include <drizzled/replication_services.h>
44
#include "transaction_log_entry.h"
43
#include <drizzled/plugin/command_replicator.h>
44
#include <drizzled/plugin/command_applier.h>
49
class CommandLog: public drizzled::plugin::CommandApplier
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
55
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
60
int log_file; /**< Handle for our log file */
61
enum status state; /**< The state the log is in */
62
drizzled::atomic<bool> do_checksum; ///< Do a CRC32 checksum when writing Command message to log?
63
const char *log_file_path; /**< Full path to the log file */
64
drizzled::atomic<off_t> log_offset; /**< Offset in log file where log will write next command */
72
TransactionLog(const std::string in_log_file_path,
73
uint32_t in_sync_method);
66
CommandLog(std::string name_arg,
67
const char *in_log_file_path, bool in_do_checksum);
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();
73
* Applies a Command to the serial log
77
* It is important to note that memory allocation for the
78
* supplied pointer is not guaranteed after the completion
79
* of this function -- meaning the caller can dispose of the
80
* supplied message. Therefore, appliers which are
81
* implementing an asynchronous replication system must copy
82
* the supplied message to their own controlled memory storage
85
* @param Command message to be replicated
87
void apply(const drizzled::message::Command &to_apply);
97
90
* Returns the state that the log is in
99
inline enum Status getState()
92
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
98
* Truncates the existing log file
143
123
bool findLogFilenameContainingTransactionId(const drizzled::ReplicationServices::GlobalTransactionId &to_find,
144
124
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 */
127
#endif /* PLUGIN_COMMAND_LOG_COMMAND_LOG_H */