Skip to content

Commit

Permalink
features/changelog: Optimization in changelog
Browse files Browse the repository at this point in the history
Problem: Currently changelog is written in one directory, which over
time, results in very large changelog files.

Solution: Seperate directory under the changelogs directory
is created on daily basis following the format year/month/day.

Updates: #154
Change-Id: I1cdabe33728a0ba1f298c8908bd8c323b1871bda
Signed-off-by: Shwetha K Acharya <sacharya@redhat.com>
  • Loading branch information
Shwetha-Acharya authored and amarts committed Jan 1, 2020
1 parent ca3e590 commit ec3df84
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
31 changes: 29 additions & 2 deletions xlators/features/changelog/src/changelog-helpers.c
Expand Up @@ -22,6 +22,7 @@
#include "changelog-encoders.h"
#include "changelog-rpc-common.h"
#include <pthread.h>
#include <time.h>

static void
changelog_cleanup_free_mutex(void *arg_mutex)
Expand Down Expand Up @@ -388,12 +389,17 @@ changelog_rollover_changelog(xlator_t *this, changelog_priv_t *priv,
int ret = -1;
int notify = 0;
int cl_empty_flag = 0;
struct tm *gmt;
char yyyymmdd[40];
char ofile[PATH_MAX] = {
0,
};
char nfile[PATH_MAX] = {
0,
};
char nfile_dir[PATH_MAX] = {
0,
};
changelog_event_t ev = {
0,
};
Expand All @@ -417,10 +423,18 @@ changelog_rollover_changelog(xlator_t *this, changelog_priv_t *priv,
priv->changelog_fd = -1;
}

time_t time = (time_t)ts;

/* Get GMT time */
gmt = gmtime(&time);

strftime(yyyymmdd, sizeof(yyyymmdd), "%Y/%m/%d", gmt);

(void)snprintf(ofile, PATH_MAX, "%s/" CHANGELOG_FILE_NAME,
priv->changelog_dir);
(void)snprintf(nfile, PATH_MAX, "%s/" CHANGELOG_FILE_NAME ".%lu",
priv->changelog_dir, ts);
(void)snprintf(nfile, PATH_MAX, "%s/%s/" CHANGELOG_FILE_NAME ".%lu",
priv->changelog_dir, yyyymmdd, ts);
(void)snprintf(nfile_dir, PATH_MAX, "%s/%s", priv->changelog_dir, yyyymmdd);

if (cl_empty_flag == 1) {
ret = sys_unlink(ofile);
Expand All @@ -434,6 +448,19 @@ changelog_rollover_changelog(xlator_t *this, changelog_priv_t *priv,
} else {
ret = sys_rename(ofile, nfile);

/* Changelog file rename gets ENOENT when parent dir doesn't exist */
if (errno == ENOENT) {
ret = mkdir_p(nfile_dir, 0600, _gf_true);

if ((ret == -1) && (EEXIST != errno)) {
gf_smsg(this->name, GF_LOG_ERROR, errno,
CHANGELOG_MSG_MKDIR_ERROR, "%s", nfile_dir, NULL);
goto out;
}

ret = sys_rename(ofile, nfile);
}

if (ret && (errno == ENOENT)) {
ret = 0;
goto out;
Expand Down
3 changes: 2 additions & 1 deletion xlators/features/changelog/src/changelog-messages.h
Expand Up @@ -57,7 +57,7 @@ GLFS_MSGID(
CHANGELOG_MSG_NO_MEMORY, CHANGELOG_MSG_HTIME_STAT_ERROR,
CHANGELOG_MSG_HTIME_CURRENT_ERROR, CHANGELOG_MSG_BNOTIFY_COND_INFO,
CHANGELOG_MSG_NO_HTIME_CURRENT, CHANGELOG_MSG_HTIME_CURRENT,
CHANGELOG_MSG_NEW_HTIME_FILE);
CHANGELOG_MSG_NEW_HTIME_FILE, CHANGELOG_MSG_MKDIR_ERROR);

#define CHANGELOG_MSG_BARRIER_FOP_FAILED_STR \
"failed to barrier FOPs, disabling changelog barrier"
Expand All @@ -73,6 +73,7 @@ GLFS_MSGID(
#define CHANGELOG_MSG_HTIME_CURRENT_ERROR_STR "Error extracting HTIME_CURRENT."
#define CHANGELOG_MSG_UNLINK_OP_FAILED_STR "error unlinking empty changelog"
#define CHANGELOG_MSG_RENAME_ERROR_STR "error renaming"
#define CHANGELOG_MSG_MKDIR_ERROR_STR "unable to create directory"
#define CHANGELOG_MSG_BNOTIFY_INFO_STR \
"Explicit rollover changelog signaling bnotify"
#define CHANGELOG_MSG_BNOTIFY_COND_INFO_STR "Woke up: bnotify conditional wait"
Expand Down

0 comments on commit ec3df84

Please sign in to comment.