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 TransactionServices
32
* server component to a simple log file on disk.
34
* Events 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 DRIZZLE_PLUGIN_command_log_H
39
#define DRIZZLE_PLUGIN_command_log_H
41
#include <drizzled/server_includes.h>
41
42
#include <drizzled/atomics.h>
42
#include <drizzled/replication_services.h>
44
#include "transaction_log_entry.h"
43
#include <drizzled/plugin/replicator.h>
44
#include <drizzled/plugin/applier.h>
49
class CommandLog: public drizzled::plugin::Applier
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> is_enabled; /**< Internal toggle. Atomic to support online toggling of command log... */
63
drizzled::atomic<bool> is_active; /**< Internal toggle. If true, log was initialized properly... */
64
const char *log_file_path; /**< Full path to the log file */
65
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);
67
CommandLog(const char *in_log_file_path);
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(drizzled::message::Command *to_apply);
90
* Returns whether the command log is active.
95
* Disables the plugin.
96
* Disabled just means that the user has done an online set @command_log_enable= false
104
* Enables the plugin. Enabling is a bit different from isActive().
105
* Enabled just means that the user has done an online set global command_log_enable= true
106
* or has manually started up the server with --command-log-enable
97
114
* Returns the state that the log is in
99
inline enum Status getState()
116
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
122
* Truncates the existing log file
124
128
* 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 */
133
#endif /* DRIZZLE_PLUGIN_command_log_H */