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:
@ -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);
|
||||
|
Reference in New Issue
Block a user