summaryrefslogtreecommitdiffstats
path: root/xlators/features/changelog/src
diff options
context:
space:
mode:
authorShwetha K Acharya <sacharya@redhat.com>2019-11-14 12:37:24 +0530
committerAmar Tumballi <amarts@gmail.com>2020-01-01 07:11:23 +0000
commitec3df84dcfd7ccda0a18fa75e3b425c090209adf (patch)
tree90301b3304d589c101f3831352e219f9564f1819 /xlators/features/changelog/src
parentca3e5905ac02fb9c373ac3de10b44f061d04cd6f (diff)
features/changelog: Optimization in changelog
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>
Diffstat (limited to 'xlators/features/changelog/src')
-rw-r--r--xlators/features/changelog/src/changelog-helpers.c31
-rw-r--r--xlators/features/changelog/src/changelog-messages.h3
2 files changed, 31 insertions, 3 deletions
diff --git a/xlators/features/changelog/src/changelog-helpers.c b/xlators/features/changelog/src/changelog-helpers.c
index 021a75c6bbc..5463c9e0972 100644
--- a/xlators/features/changelog/src/changelog-helpers.c
+++ b/xlators/features/changelog/src/changelog-helpers.c
@@ -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)
@@ -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,
};
@@ -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);
@@ -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;
diff --git a/xlators/features/changelog/src/changelog-messages.h b/xlators/features/changelog/src/changelog-messages.h
index 134628596ae..a2eed0568fa 100644
--- a/xlators/features/changelog/src/changelog-messages.h
+++ b/xlators/features/changelog/src/changelog-messages.h
@@ -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"
@@ -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"