Only write monitor journal when it changes
The state of the monitored servers is only persisted if the states of the servers have changed. This removes the unnecessary disk IO caused by the writing on the monitor journal.
This commit is contained in:
parent
db61ec0d7e
commit
703230a930
@ -19,6 +19,7 @@
|
||||
#include <maxscale/cdefs.h>
|
||||
|
||||
#include <mysql.h>
|
||||
#include <openssl/sha.h>
|
||||
|
||||
#include <maxscale/config.h>
|
||||
#include <maxscale/dcb.h>
|
||||
@ -206,6 +207,7 @@ struct mxs_monitor
|
||||
time_t journal_max_age; /**< Maximum age of journal file */
|
||||
uint32_t script_timeout; /**< Timeout in seconds for the monitor scripts */
|
||||
bool master_has_failed; /**< Set to true when the latest event is a master_down event */
|
||||
uint8_t journal_hash[SHA_DIGEST_LENGTH]; /**< SHA1 hash of the latest written journal */
|
||||
struct mxs_monitor *next; /**< Next monitor in the linked list */
|
||||
};
|
||||
|
||||
|
@ -137,6 +137,7 @@ MXS_MONITOR* monitor_alloc(const char *name, const char *module)
|
||||
mon->script_timeout = DEFAULT_SCRIPT_TIMEOUT;
|
||||
mon->parameters = NULL;
|
||||
mon->server_pending_changes = false;
|
||||
memset(mon->journal_hash, 0, sizeof(mon->journal_hash));
|
||||
spinlock_init(&mon->lock);
|
||||
spinlock_acquire(&monLock);
|
||||
mon->next = allMonitors;
|
||||
@ -2262,27 +2263,39 @@ void store_server_journal(MXS_MONITOR *monitor, MXS_MONITORED_SERVER *master)
|
||||
|
||||
if (data)
|
||||
{
|
||||
/** Store the data in memory first */
|
||||
/** Store the data in memory first and compare the current hash to
|
||||
* the hash of the last stored journal. This isn't a fool-proof
|
||||
* method of detecting changes but any failures are mainly of
|
||||
* theoretical nature. */
|
||||
store_data(monitor, master, data, size);
|
||||
uint8_t hash[SHA_DIGEST_LENGTH];
|
||||
SHA1(data, size, hash);
|
||||
|
||||
FILE *file = open_tmp_file(monitor, path);
|
||||
|
||||
if (file)
|
||||
if (memcmp(monitor->journal_hash, hash, sizeof(hash)) != 0)
|
||||
{
|
||||
/** Write the data to a temp file and rename it to the final name */
|
||||
if (fwrite(data, 1, buffer_size, file) == buffer_size && fflush(file) == 0)
|
||||
FILE *file = open_tmp_file(monitor, path);
|
||||
|
||||
if (file)
|
||||
{
|
||||
if (!rename_tmp_file(monitor, path))
|
||||
/** Write the data to a temp file and rename it to the final name */
|
||||
if (fwrite(data, 1, buffer_size, file) == buffer_size && fflush(file) == 0)
|
||||
{
|
||||
unlink(path);
|
||||
if (!rename_tmp_file(monitor, path))
|
||||
{
|
||||
unlink(path);
|
||||
}
|
||||
else
|
||||
{
|
||||
memcpy(monitor->journal_hash, hash, sizeof(hash));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
MXS_ERROR("Failed to write journal data to disk: %d, %s",
|
||||
errno, mxs_strerror(errno));
|
||||
}
|
||||
fclose(file);
|
||||
}
|
||||
else
|
||||
{
|
||||
MXS_ERROR("Failed to write journal data to disk: %d, %s",
|
||||
errno, mxs_strerror(errno));
|
||||
}
|
||||
fclose(file);
|
||||
}
|
||||
}
|
||||
MXS_FREE(data);
|
||||
|
Loading…
x
Reference in New Issue
Block a user